Use of variables with hex value for 'changeValues' function?

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

Use of variables with hex value for 'changeValues' function?

HoweLab
Hi All.

I am trying to change all of the colors in an RGB image to specific grayscale values (there are 256 distinct RGB combinations in my image and I know how I want/need each of them to be 'assigned' to a grayscale intensity). I seem to be stuck, however, in that I cannot seem to get the 'changeValues' command to accept a variable with a hex value - i.e. if 'color' is a variable with a hex value, the command 'changeValues(0x0000ff, 0x0000ff, color) doesn't change anything. Here is a sample macro that demonstrates the problem:

newImage("blank", "RGB White", 200, 200, 1);
rvalue=10;
gvalue=255;
bvalue=10;
rhex=toHex(rvalue);
ghex=toHex(gvalue);
bhex= toHex(bvalue);
color = "0x" + rhex + ghex + bhex;
print(color);
selectImage("blank");
wait(500);
changeValues(0xffffff,0xffffff,0xff0000)
wait(500);
changeValues(0xff0000,0xff0000,color);

Even though the value of 'color' that is returned/printed looks correct, the box does not change to the correct color for that value. I found a macro - RGBtoHEX - that I thought might help; it utilized a syntax I'm not familiar with (~e.g. 'color = "0x" + pad(rhex) + "" + pad(ghex) + "" + pad(bhex)'; I've never seen the 'pad' command before in this context).

The reason I want to use a variable is because I simply didn't want to write 256 separate statements to get the job done and wanted to use a series of 'for' loops.

Any insights are greatly appreciated.

-Alan H.
Reply | Threaded
Open this post in threaded view
|

Re: Use of variables with hex value for 'changeValues' function?

Rasband, Wayne (NIH/NIMH) [E]
On Aug 30, 2013, at 5:30 PM, HoweLab wrote:

> Hi All.
>
> I am trying to change all of the colors in an RGB image to specific
> grayscale values (there are 256 distinct RGB combinations in my image and I
> know how I want/need each of them to be 'assigned' to a grayscale
> intensity). I seem to be stuck, however, in that I cannot seem to get the
> 'changeValues' command to accept a variable with a hex value - i.e. if
> 'color' is a variable with a hex value, the command 'changeValues(0x0000ff,
> 0x0000ff, color) doesn't change anything.

Use

   color = red<<16 + green<<8 + blue;

to merge red, green and blue values to create an RGB variable.

   newImage("blank", "RGB White", 200, 200, 1);
   rvalue=10;
   gvalue=255;
   bvalue=10;
   color = rvalue<<16 + gvalue<<8 + bvalue;
   wait(1000);
   changeValues(0xffffff,0xffffff,0xff0000)
   wait(1000);
   changeValues(0xff0000,0xff0000,color);

-wayne


> Here is a sample macro that
> demonstrates the problem:
>
> newImage("blank", "RGB White", 200, 200, 1);
> rvalue=10;
> gvalue=255;
> bvalue=10;
> rhex=toHex(rvalue);
> ghex=toHex(gvalue);
> bhex= toHex(bvalue);
> color = "0x" + rhex + ghex + bhex;
> print(color);
> selectImage("blank");
> wait(500);
> changeValues(0xffffff,0xffffff,0xff0000)
> wait(500);
> changeValues(0xff0000,0xff0000,color);
>
> Even though the value of 'color' that is returned/printed looks correct, the
> box does not change to the correct color for that value. I found a macro -
> RGBtoHEX - that I thought might help; it utilized a syntax I'm not familiar
> with (~e.g. 'color = "0x" + pad(rhex) + "" + pad(ghex) + "" + pad(bhex)';
> I've never seen the 'pad' command before in this context).
>
> The reason I want to use a variable is because I simply didn't want to write
> 256 separate statements to get the job done and wanted to use a series of
> 'for' loops.
>
> Any insights are greatly appreciated.
>
> -Alan H.
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Use-of-variables-with-hex-value-for-changeValues-function-tp5004617.html
> Sent from the ImageJ mailing list archive at Nabble.com.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Use of variables with hex value for 'changeValues' function?

HoweLab
Works perfectly. Thanks very much Wayne.

-Alan
--------
Alan K. Howe, Ph.D.
Vermont Cancer Center
Department of Pharmacology
University of Vermont