//========================================================= // //This is a prog in the MutualInfo 0.9 package written by // Hanchuan Peng. // //Disclaimer: The author of program is Hanchuan Peng // at and . // //The CopyRight is reserved by the author. // //Last modification: Oct/23/2005: fix a programming bug which has not effect in mutualinfo.m (which does not really call that piece of code) // //======================================================== // //function to calculate the mutual information from joint and marginal probabilities //by Hanchuan Peng //April/2000 // calculate the mutual information based on thr probabilities // through a probability based method // MI = sum(p(a,b)log(p(a,b)/p(a)/p(b))) // // function mival = estmutualinfo(pab,pa,pb,displayflag) //input parameters: pab--the joint probility density of model and image intensity // pa--marign probility density of the model // pb--marign probility density of the model //output parameters: hab-- the mutual information #include "miinclude.h" void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if(nrhs != 3 && nrhs!=1) mexErrMsgTxt("Usage [mutual_info] = progname(jointprob_table, marginprob_1, marginprob2). The last two inputs are optional."); if(nlhs > 1) mexErrMsgTxt("Too many output argument ."); //check if parameters are correct long i,j; double *pab = mxGetPr(prhs[0]); long pabhei = mxGetM(prhs[0]); long pabwid = mxGetN(prhs[0]); double **pab2d = new double * [pabwid]; for(j=0;j