Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: mutual information of red and green channel

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81327] Re: mutual information of red and green channel
  • From: dh <dh at metrohm.ch>
  • Date: Wed, 19 Sep 2007 05:32:24 -0400 (EDT)
  • References: <fcnljv$sc3$1@smc.vnet.net>


Hy,

to prevent zero divide errors, you can e.g. preload every bin with a 

small number.

hope this helps, Daniel



vickyisai at gmail.com wrote:

> 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(-=E2=88=9E) 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=EF=94=A2True]; *)

> 

> 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=EF=94=A2True]; *)

> 

> 

> (* 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]]   ]

> 	]

> ]

> 

> 




  • Prev by Date: Supercomputing Engine for Mathematica (SEM) now available
  • Next by Date: Re: SWF runs to fast
  • Previous by thread: mutual information of red and green channel
  • Next by thread: Re: mutual information of red and green channel