Re: getPixel() for loop

Posted by Weller Andrew Francis on
URL: http://imagej.273.s1.nabble.com/getPixel-for-loop-tp3702315p3702317.html

Dear all,

If the 'origin' of getPixel is (0,0), then in the following for-loop,
what should the 'condition' be set to? My feeling is that as the
'initialization' is set to "0" that the 'condition' should be set to
"j<H-1" - is this correct? Or should it be "j<H", "j<=H", etc?

I've also tried in vain to replicate the result I get here with the
Analyze -> Measure command (as previously suggested for speed), but have
been unable to using various equations conatining the mean, standard
deviation, area, etc!? Perhaps I am missing something trivial...?

run("Set Measurements...", "  mean standard redirect=None decimal=5");
run("Measure");
mean = getResult("Mean");
stdev = getResult("StdDev");
W = getWidth();
H = getHeight();
b = 0;
for (j=0; j<H-1; j++) {
   for (i=0; i<W-1; i++) {
      p = getPixel(i,j);
      t = (p-mean)^2;
      b += t;
      }
   }
normVar = b/(H*W*mean);

Cheers, Andy