Posted by
Michael Schmid on
Oct 07, 2014; 4:05pm
URL: http://imagej.273.s1.nabble.com/Thresholder-in-headless-macro-mode-results-in-NullPointerException-tp5009940p5009948.html
Hi Frank,
you can use getPixel and setPixel; but you have to get the color information from it by masking with bitwise 'and' (& operator) and shifting to the prper position of the hex number.
As an example, the following macro modifies the red and blue values for an image.
for (y=0; y<getHeight(); y++)
for (x=0; x<getWidth(); x++) {
c = getPixel(x,y); //get all colors
r = (c&0xff0000)>>16; //convert to separate colors r, g, b
g = (c&0xff00)>>8;
b = c&0xff;
//modify as you like, e.g.
r = round(0.9*r);
b = round(1.1*b);
// make sure values are not below 0 (can't happen in this example)
// and not above 255
if (r>255) r=255;
if (g>255) g=255;
if (b>255) b=255;
// put together into one number and write back
putPixel(x, y, (r<<16)+(g<<8)+b); //needs integer r, g, b
}
Michael
________________________________________________________________
Michael
________________________________________________________________
Michael Schmid email:
[hidden email]
Institut für Angewandte Physik, Technische Universität Wien
Wiedner Hauptstr. 8-10/E134, A 1040 Wien, Austria
Tel. +43 1 58801-13452 or -13453, Fax +43 1 58801 13499
________________________________________________________________
On Oct 7, 2014, at 17:57, Franklin Shaffer wrote:
> I want to change the rgb values of a single pixel.
>
> I believe changeValues(v1, v2, v3); changes the values of all pixels within a certain range.
>
> Thanks,
> Frank
>
>
>>>> Herbie <
[hidden email]> 10/7/2014 11:52 AM >>>
> Frank Shaffer,
>
> is this
>
> "changeValues(v1, v2, v3);
> Changes pixels in the image or selection that have a value in the range
> v1-v2 to v3. For example, changeValues(0,5,5) changes all pixels less
> than 5 to 5, and changeValues(0x0000ff,0x0000ff,0xff0000) changes all
> blue pixels in an RGB image to red."
>
> ImageJ-macro command, what you are looking for?
>
> For more macro commands have a look at:
>
> <
http://rsb.info.nih.gov/ij/developer/macro/functions.html>
>
> HTH
>
> Herbie
>
> :::::::::::::::::::::::::::::::::::::::::
> On 07.10.14 17:44, Franklin Shaffer wrote:
>> I'm reading values of color pixel from an image and converting the hex value to color values to r, g , b.
>>
>> I want to change the r,g,b values then write the new values to the pixel from a macro.
>>
>> I can make it work with the Fill tool, but it is extremely slow.
>>
>> Is there a better way to change the value of a color pixel from a macro?
>>
>> Thanks,
>> Frank Shaffer
>>
>>
>> Senior Research Engineer
>> USDOE National Energy Technology Laboratory
>> Office of Research & Development
>> Mail Stop 84-202
>> 626 Cochran's Mill Road
>> Pittsburgh, PA 15236
>>
>>
[hidden email]
>> Office: 412-386-5964
>> Cell: 724-970-7262
>>
>> --
>> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>>
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html