Re: getPixel() for loop

Posted by Agnès Sauleda Brossa on
URL: http://imagej.273.s1.nabble.com/getPixel-for-loop-tp3702315p3702322.html

Hi,

First, yes, the origin is (0,0). And second, if you mean that you need to
have a sum of all b values for all the pixels you just have to add it to the
same variable as:

double b=0;
W = getWidth();
H = getHeight();
for (i=0; i<H; i++) {
        for (j=0; j<W; j++) {  //you need to define another variable here
                p = getPixel(i,j);    //you need a loop to all the pair of
coordinates i,j
                b += (p-mean)*(p-mean);   //adds the value to the variable
b. At the end of the loop you'll have
        }                                            // the sum of all
(p-mean)*(p-mean)
}

Anyway, I think that there is a way of asking for that value with some
method, but I'm sorry to say that I don't know how.

Hope it helps,

Agnès

On 27/06/06, Andy Weller <[hidden email]> 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
>