Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'mutual information of red andgreen channel of a...' topicStudent Support Forum > General > "mutual information of red andgreen channel of a..."

Next Comment >Help | Reply To Topic
Author Comment/Response
Matther Fergie
09/17/07 5:16pm

Hello

I am using the following code to calculate mutual information of red and green channel of an image.

I am calculating Ixy= Sum(i)Sum(j) P(REDi,GREENj) Log[P(REDi,GREENj)/P(REDi)/P(GREENj) ]

(that is this formula
http://upload.wikimedia.org/math/c/b/b/cbb518be041b820958181a932a5cd4ff.png )

I am getting an error of "Indeterminate expression 0(-∞) encountered. "

I believe I am getting this because I am taking Probability of Redi from a histogram that I have computed (value of REDi divided by total no of pixels ....as my probability of REDi. ame for GREENj
But that histogram has 0 at some places which is leading to divide by zero.

(i plotted that histogram to check that)

How should I calculated mutual information of red and green channel of an image.

( I use Mathematica 5.2 and dont have image processing package)
Thank You

Code is below:
-----------------------------------------------------------------------------------------------------------------
image=Import["c:/fish.ppm"];
(* Show[image]; *)



part=image[[1,1]];

red=part[[All,All,1]];

histRed=Table[0,{256}];

For[i=1,i<Dimensions[red][[1]],++i,
For[j=1,j<Dimensions[red][[2]],++j,
indxr=Floor[red[[i,j]]]+1;
histRed[[indxr]]=histRed[[indxr]]+1;
]
]
(* histR=ListPlot[histRed,PlotJoinedTrue]; *)

green=part[[All,All,2]];
histGreen=Table[0,{256}];

For[i=1,i<Dimensions[green][[1]],++i,
For[j=1,j<Dimensions[green][[2]],++j,
indxg=Floor[green[[i,j]]]+1;
histGreen[[indxg]]=histGreen[[indxg]]+1;
]
]
(* histG=ListPlot[histGreen,PlotJoinedTrue]; *)


(* Joint Prob. Matrix *)
joinRG=Table[0,{256},{256}];

For[i=1,i<Dimensions[red][[1]],++i,
   For[j=1,j<Dimensions[green][[2]], ++j,
      idx1=Floor[red[[i,j]]]+1;
      idx2=Floor[green[[i,j]]]+1;
      joinRG[[idx1,idx2]]=joinRG[[idx1,idx2]]+1;
   ]
]

(* Ixy= Sum(i)Sum(j) P(xi,yj) Log[P(xi,yj)/P(xi)/P(yj) *)

For[i=1,i<Dimensions[histRed][[1]],++i,
   For[j=1,j<Dimensions[histGreen][[1]],++j,
      Ixy = Ixy + joinRG[[i,j]] / 65536 * Log[2 , ,joinRG[[i,j]] / histRed[[i]] / histGreen[[j]] ]
   ]
]




Attachment: right.nb, URL: ,

Subject (listing for 'mutual information of red andgreen channel of a...')
Author Date Posted
mutual information of red andgreen channel of a... Matther Fergie 09/17/07 5:16pm
Re: mutual information of red andgreen channel ... yehuda ben-s... 09/18/07 2:08pm
Re: mutual information of red andgreen channel ... matt prior 09/21/07 10:09am
Next Comment >Help | Reply To Topic