Posted by
Thomas Mandl-2 on
URL: http://imagej.273.s1.nabble.com/getPixel-for-loop-tp3702315p3702316.html
Hi,
To your questions (if I understand correctly):
(1) getPixel(0,0)
(2) simply declare it and update it (See below)
\begin{macrocode}
SOME_UPDATER=0;
mean=42; //need this so I can test
W = getWidth();
H = getHeight();
for (i=0; i<=H-1; i++) {
for (j=0; j<=W; j++) { //changed i to j
p = getPixel(j,i); //changed from p = getPixel(W,H);
b = (p-mean)^2;
//SOME UPDATER HERE TO A SUM OF b
SOME_UPDATER+=b;
}
}
print(SOME_UPDATER);
\end{macrocode}
Here's a different version/Approach. I use the calculator instead of a loop
(example image is called "R^2_pre1" without the quotes)
\begin{macrocode}
run("Subtract...", "stack value=42"); //subtract
run("Image Calculator...", "image1=R^2_pre1 operation=Multiply
image2=R^2_pre1 create 32-bit stack"); //square
run("Measure"); //get the mean (similar to the updater)
\end{macrocode}
Hope it helps!
TeM
-----Ursprüngliche Nachricht-----
Von: ImageJ Interest Group [mailto:
[hidden email]] Im Auftrag von Andy
Weller
Gesendet: Dienstag, 27. Juni 2006 15:48
An:
[hidden email]
Betreff: getPixel() for loop
Dear all,
I am trying to determine the normalised variance of an image. For this I
need to minus the grey-level mean from each pixel's grey-level and
square this value. I figure the best way to do this is to determine each
pixel value by using getPixel() in a for loop.
My first question: is the initial (origin) pixel getPixel(0,0) or
getPixel(1,1)?
My second question: if I need to sum these values, how can I keep an
'updater' variable in my for-loop?
So for example, I have:
W = getWidth();
H = getHeight();
for (i=0; i<=H-1; i++) { // Presuming that the origin is 0,0
// else I guess for (i=1; i<=H; i++)?
for (i=0; i<=W; i++) {
p = getPixel(W,H);
b = (p-mean)^2;
SOME UPDATER HERE TO A SUM OF b
}
}
Once out of the loop, I can do things to the total.
Cheers, Andy