Login  Register

Re: find all locations of the same pixel value

Posted by Michael Doube-3 on Aug 14, 2012; 8:37am
URL: http://imagej.273.s1.nabble.com/calculating-DF-F-and-movement-correction-tp4999726p4999755.html

Dear Xin,

Maybe the compiler optimizers are better now, but in my experience it is
faster to declare the loop test value as a final value and not call a
function each time:

final int width = iproc.getWidth();
for (int x = 0; x < width; x++){

[and so on]

This is a small change that might make a big difference because your
loop iterates very many times.

Best regards,

Michael

On 14/08/12 08:09, 周鑫 wrote:

> Dear all,
>
> I want to find in one image all the locations which have the same pixel value.
>
> currently I wrote a function for that:
>
> =======================================
>
> ArrayList<int[]> locations = new ArrayList<int[]>();
>   for (int x=0; x<iproc.getWidth(); x++)
>   {
>    for(int y=0; y<iproc.getHeight(); y++)
>    {
>     if (iproc.getPixel(x, y) == pixelValue)
>     {
>      locations.add(new int[]{x,y});
>     }
>    }
>   }
>   return locations;
>
> =======================================
>
> but I wonder if there is something more smart, or build-in functions that can do the job quicker.
>
> This is for me a basic operation, which will be done again and again. There must be more intelligent ways.
>
> Many thanks, Xin
>
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html