Getpixel() behaviour

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Getpixel() behaviour

Gilbert Bigras
Hi all,

A macro script I wrote was behaving strangely since ImageJ version 1.44. I found out that getpixel() built-in macro function is responsible of my problem.

For some reasons, I am using real numbers for x,y coordinates when investigating pixel value with getpixel(x,y) function. Prior version 1.44 the function probably rounded x,y to the closer integers values and returned the appropriate pixel value.... but no more. Is it a bug? I tested the following code under Linux and Windows with the same results.

I have simply fixed my issue by using round() macro like in getPixel(round(x),round(y)).

Regards,

=============================================================
macro "Test Bug"
{
requires("1.38m");

autoUpdate(true);
newImage("TestDebug","RGB",50,50,1);

red=125;
green=125;
blue=125;

//Create new image with grey value (125,125,125)
for (x=0;x<50;x++)
    for(y=0;y<50;y++)
        setPixel(x,y,256*256*red+256*green+blue);


//Set X,y coordinates with real numbers   
x=9.23;y=17.1;

// Set black color RGB
red = 0; green = 0; blue = 0;
setPixel(x,y,256*256*red+256*green+blue);

rgb = getPixel(x,y);
red = (rgb>>16)&0xff;  // extract red byte (bits 23-17)
green = (rgb>>8)&0xff; // extract green byte (bits 15-8)
blue = rgb&0xff;       // extract blue byte (bits 7-0)
print("With version 1.44 and above, The returned RGB value will not be 0,0,0" );
print("Using real coordinates "+"("+x+","+y+")"+" red="+red+" green="+green+" blue="+blue);

rgb = getPixel(round(x),round(y));
red = (rgb>>16)&0xff;  // extract red byte (bits 23-17)
green = (rgb>>8)&0xff; // extract green byte (bits 15-8)
blue = rgb&0xff;       // extract blue byte (bits 7-0)
print("Using Round() function, The returned RGB value will be 0,0,0" );
print("Using integer coordinates "+"("+round(x)+","+round(y)+")"+" red="+red+" green="+green+" blue="+blue);



=============================================================


Gilbert Bigras, M.D., Ph.D., FRCPC (Path)

Cross Cancer Institute
11560 University Avenue  Edmonton, Alberta  Canada T6G 1Z2   
Associate clinical Professor
  Department of Laboratory Medicine & Pathology
  University of Alberta, Canada
   
  Phone: 780-432-8445 (extension 8445)  Fax: 780-432-8455


 
____________________________________________________________________________________
Don't get soaked.  Take a quick peak at the forecast
with the Yahoo! Search weather shortcut.
http://tools.search.yahoo.com/shortcuts/#loc_weather
Reply | Threaded
Open this post in threaded view
|

Re: Getpixel() behaviour

Gabriel Landini
On Wednesday 09 Feb 2011 19:42:52 Gilbert Bigras wrote:

> A macro script I wrote was behaving strangely since ImageJ version 1.44. I
> found out that getpixel() built-in macro function is responsible of my
> problem.

Hi Gilbert,
Yes that was introduced in ij 1.44k:
"The getPixel(x,y) macro function now interpolates if x or y are non-integer."

I had completely forgotten about this.
By rounding the coordinates one avoid the interpolated value, so I think that
your solution is correct.
Cheers,

Gabriel