Go to the documentation of this file.00001
00002 #ifndef brip_mutual_info_h_
00003 #define brip_mutual_info_h_
00004
00005
00006
00007
00008
00009
00010 #include <vil/vil_image_view.h>
00011 #include <vcl_vector.h>
00012 #include <vcl_cmath.h>
00013
00014 #define LN_2 0.69314718056
00015
00016
00017
00018 template<class T>
00019 double brip_mutual_info(const vil_image_view<T>& image1,
00020 const vil_image_view<T>& image2,
00021 double min, double max, unsigned n_bins);
00022
00023
00024
00025 inline
00026 double brip_hist_entropy(const vcl_vector<double>& histogram, double mag)
00027 {
00028 double entropy = 0.0;
00029 for ( vcl_vector<double>::const_iterator h_itr = histogram.begin();
00030 h_itr != histogram.end(); ++h_itr ){
00031 double prob = (*h_itr)/mag;
00032 entropy += -(prob?prob*vcl_log(prob):0);
00033 }
00034 return entropy/LN_2;
00035 }
00036
00037
00038
00039 inline
00040 double brip_hist_entropy(const vcl_vector<vcl_vector<double> >& histogram, double mag)
00041 {
00042 double entropy = 0.0;
00043 for ( vcl_vector<vcl_vector<double> >::const_iterator h_itr = histogram.begin();
00044 h_itr != histogram.end(); ++h_itr ){
00045 entropy += brip_hist_entropy(*h_itr,mag);
00046 }
00047 return entropy;
00048 }
00049
00050 #endif // brip_mutual_info_h_