Re: getPixel() for loop

Posted by Gary Chinga on
URL: http://imagej.273.s1.nabble.com/getPixel-for-loop-tp3702315p3702319.html

You can get the standard deviation directly from the Analyze/Measure  
command in imageJ. The statistics you want can be defined in Analyze/
Set Measurements...

Try the following macro which measures several statistics for a  
series of images in a stack. The results are included in a result  
table which can be imported into e.g. excel.


run("Set Measurements...", "  mean standard modal min median skewness  
kurtosis slice redirect=None decimal=3");
run("Clear Results");
for (i=1; i<=nSlices;i++){
        setSlice(i);
        run("Measure");
}

Gary.



On Jun 27, 2006, at 3:47 PM, Andy Weller wrote:

> 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
>
>