change pixel values within a macro

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

change pixel values within a macro

Agustin Lobo
How can I change a given value for another within a macro?
For example, I want to replace all pixels with value 0 by values = 100.
I understand I have to first select and then use setPixel(), but cannot
find the way of selecting by value.

Thanks

Agus

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

Re: change pixel values within a macro

Kenton Arkill
Hi
A slow way is by getting each pixel and using and 'if' loop if it is 0.
eg:
for(x=0;x<xmax;x++){
for(y=0;y<ymax;y++){
test=getPixel(x,y);
if(test==0){setPixel(x,y,100);}
}}

Kenton




On 16 Apr 2013, at 11:02, Agustin Lobo wrote:

> How can I change a given value for another within a macro?
> For example, I want to replace all pixels with value 0 by values = 100.
> I understand I have to first select and then use setPixel(), but cannot
> find the way of selecting by value.
>
> Thanks
>
> Agus
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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

Re: change pixel values within a macro

Jean-Philippe Grossier
In reply to this post by Agustin Lobo
Hi,

the fastest for your specific case(if 0 is the minimum in your image):

run("Min...", "value=100");


otherwise for any val1 to replace by val2, instead of using setPixel (which
is slow):

val1=110;
val2=255;

setColor(val2,val2,val2);
setThreshold(val1,val1);
run("Create Selection");
fill();
run("Select None");


cheers,

jean-philippe Grosser

ps: sorry if double post


2013/4/16 Agustin Lobo <[hidden email]>

> How can I change a given value for another within a macro?
> For example, I want to replace all pixels with value 0 by values = 100.
> I understand I have to first select and then use setPixel(), but cannot
> find the way of selecting by value.
>
> Thanks
>
> Agus
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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

Re: change pixel values within a macro

Gabriel Landini
> How can I change a given value for another within a macro?
> For example, I want to replace all pixels with value 0 by values = 100.
> I understand I have to first select and then use setPixel(), but cannot
> find the way of selecting by value.

Have a look at the macro functions here:

http://imagej.nih.gov/ij/developer/macro/functions.html

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.

Cheers
Gabriel

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