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 #include <vnl/vnl_math.h>
00014
00015
00016
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
00023
00024 inline
00025 double brip_hist_entropy(const vcl_vector<double>& histogram, double mag)
00026 {
00027 double entropy = 0.0;
00028 for ( vcl_vector<double>::const_iterator h_itr = histogram.begin();
00029 h_itr != histogram.end(); ++h_itr ){
00030 double prob = (*h_itr)/mag;
00031 entropy += -(prob?prob*vcl_log(prob):0);
00032 }
00033 return entropy/vnl_math::ln2;
00034 }
00035
00036
00037
00038 inline
00039 double brip_hist_entropy(const vcl_vector<vcl_vector<double> >& histogram, double mag)
00040 {
00041 double entropy = 0.0;
00042 for ( vcl_vector<vcl_vector<double> >::const_iterator h_itr = histogram.begin();
00043 h_itr != histogram.end(); ++h_itr ){
00044 entropy += brip_hist_entropy(*h_itr,mag);
00045 }
00046 return entropy;
00047 }
00048
00049 #endif // brip_mutual_info_h_