contrib/brl/bseg/brip/brip_mutual_info.txx
Go to the documentation of this file.
00001 // This is brl/bseg/brip/brip_mutual_info.txx
00002 #ifndef brip_mutual_info_txx_
00003 #define brip_mutual_info_txx_
00004 //:
00005 // \file
00006 // \brief Calculate the mutual information between the images.
00007 // \author Matt Leotta
00008 
00009 #include "brip_mutual_info.h"
00010 
00011 #include "brip_histogram.h"
00012 #include <vcl_vector.h>
00013 #include <vcl_cassert.h>
00014 
00015 
00016 //: Calculate the Mutual Information between the images.
00017 template<class T>
00018 double brip_mutual_info(const vil_image_view<T>& image1,
00019                         const vil_image_view<T>& image2,
00020                         double min, double max, unsigned n_bins)
00021 {
00022   assert( (image1.ni() == image2.ni()) &&
00023           (image1.nj() == image2.nj()) &&
00024           (image1.nplanes() == image2.nplanes()) );
00025   vcl_vector<double> histogram1, histogram2;
00026   vcl_vector<vcl_vector<double> > joint_histogram;
00027 
00028   double mag1, mag2, mag3;
00029 
00030   mag1 = brip_histogram(image1, histogram1, min, max, n_bins);
00031   mag2 = brip_histogram(image2, histogram2, min, max, n_bins);
00032   mag3 = brip_joint_histogram(image1, image2, joint_histogram, min, max, n_bins);
00033 
00034   double H1, H2, H3;
00035   H1 = brip_hist_entropy(histogram1, mag1);
00036   H2 = brip_hist_entropy(histogram2, mag2);
00037   H3 = brip_hist_entropy(joint_histogram, mag3);
00038 
00039   return H1 + H2 - H3;
00040 }
00041 
00042 
00043 // Macro to perform manual instantiations
00044 #define BRIP_MUTUAL_INFO_INSTANTIATE(T) \
00045   template \
00046   double brip_mutual_info(const vil_image_view<T >& image1, \
00047                           const vil_image_view<T >& image2, \
00048                           double min, double max, unsigned n_bins)
00049 
00050 #endif // brip_mutual_info_txx_