Go to the documentation of this file.00001
00002 #ifndef brip_blobwise_mutual_info_h_
00003 #define brip_blobwise_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 template<class T>
00017 void brip_blobwise_mutual_info ( const vil_image_view<T>& img1,
00018 const vil_image_view<T>& img2,
00019 const vil_image_view<T>& weights,
00020 const vil_image_view<bool>& mask,
00021 vil_image_view<T>& mi_img );
00022
00023
00024 template<class T>
00025 void brip_blobwise_kl_div( const vil_image_view<T>& img1,
00026 const vil_image_view<T>& img2,
00027 const vil_image_view<bool>& mask,
00028 vil_image_view<T>& mi_img );
00029
00030
00031 inline
00032 double brip_hist_kl_div(const vcl_vector<double>& P, double magP,
00033 const vcl_vector<double>& Q, double magQ)
00034 {
00035 double kl = 0.0;
00036 for (unsigned int i=0; i<P.size(); ++i) {
00037 double probP = P[i]/magP;
00038 double probQ = Q[i]/magQ;
00039 if (probP==0 || probQ==0) continue;
00040
00041 kl += probP * vcl_log( probP / probQ );
00042 }
00043 return kl/vnl_math::ln2;
00044 }
00045
00046 #endif // brip_blobwise_mutual_info_h_