How to work with color images?

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

How to work with color images?

Juanjo Vega
Hello everyone,

I need to work with colour images in a plugin I'm developing, and as it is my first time and I'm pretty confused.

I had a look into the "Color Threshold" plugin and found this:

int c, r, g, b;

...

c=ip.getPixel(x,y);

r = ((c&0xff0000)>>16);//R
g = ((c&0x00ff00)>>8);//G
b = ( c&0x0000ff); //B

So, do I have to convert every pixel like that before working with them? Is there no API for RGB images? Maybe a method to split the image in three different gray scale images and to merge them after being processed, would be helpful.

Any help will he welcome, plugins, API reference, etc. :)

Sincerely,

Juanjo.

------------------------------------------------------------
Juanjo Vega ([hidden email])

Unidad de Biocomputación. Laboratorio B-13.
Centro Nacional de Biotecnología. CNB-CSIC.
C\ Darwin, 3. Campus de Cantoblanco.
Universidad Autónoma de Madrid.
28049, Madrid, Spain.

http://www.cnb.csic.es
http://www.biocomp.cnb.csic.es

+34 91 585 4510

"Las mejores almas son capaces de los mayores vicios como de las mayores
virtudes, y aquellos que caminan despacio por el camino recto pueden
llegar más lejos que los que corren pero se apartan de él." - Discurso
del Método, René Descartes.
Reply | Threaded
Open this post in threaded view
|

Re: How to work with color images?

Gabriel Landini
On Wednesday 25 May 2011 11:09:41 you wrote:

> I need to work with colour images in a plugin I'm developing, and as it is
> my first time and I'm pretty confused.
>
> I had a look into the "Color Threshold" plugin and found this:
>
> int c, r, g, b;
> c=ip.getPixel(x,y);
> r = ((c&0xff0000)>>16);//R
> g = ((c&0x00ff00)>>8);//G
> b = ( c&0x0000ff); //B

Yes, the pixel has 3 values packed into an integer value, so you need to
unpack them.

You should read Werner Bailer's tutorial:
http://www.imagingbook.com/fileadmin/goodies/ijtutorial/tutorial171.pdf

Cheers
G.
Reply | Threaded
Open this post in threaded view
|

Re: How to work with color images?

ctrueden
In reply to this post by Juanjo Vega
Hi Juan,

So, do I have to convert every pixel like that before working with them? Is
> there no API for RGB images? Maybe a method to split the image in three
> different gray scale images and to merge them after being processed, would
> be helpful.
>

There are many different ways of dealing with it. To split into three
different grayscale images first, use a command such as:

  IJ.run(imp, "Split Channels", "");

(This is what the macro recorder produces when executing the command Image >
Color > Split Channels.)

But just using the bitmasking code you mentioned is fine too.

Regards,
Curtis

On Wed, May 25, 2011 at 5:09 AM, Juanjo Vega <[hidden email]> wrote:

> Hello everyone,
>
> I need to work with colour images in a plugin I'm developing, and as it is
> my first time and I'm pretty confused.
>
> I had a look into the "Color Threshold" plugin and found this:
>
> int c, r, g, b;
>
> ...
>
> c=ip.getPixel(x,y);
>
> r = ((c&0xff0000)>>16);//R
> g = ((c&0x00ff00)>>8);//G
> b = ( c&0x0000ff); //B
>
> So, do I have to convert every pixel like that before working with them? Is
> there no API for RGB images? Maybe a method to split the image in three
> different gray scale images and to merge them after being processed, would
> be helpful.
>
> Any help will he welcome, plugins, API reference, etc. :)
>
> Sincerely,
>
> Juanjo.
>
> ------------------------------------------------------------
> Juanjo Vega ([hidden email])
>
> Unidad de Biocomputación. Laboratorio B-13.
> Centro Nacional de Biotecnología. CNB-CSIC.
> C\ Darwin, 3. Campus de Cantoblanco.
> Universidad Autónoma de Madrid.
> 28049, Madrid, Spain.
>
> http://www.cnb.csic.es
> http://www.biocomp.cnb.csic.es
>
> +34 91 585 4510
>
> "Las mejores almas son capaces de los mayores vicios como de las mayores
> virtudes, y aquellos que caminan despacio por el camino recto pueden
> llegar más lejos que los que corren pero se apartan de él." - Discurso
> del Método, René Descartes.
>
Reply | Threaded
Open this post in threaded view
|

Re: How to work with color images?

Juanjo Vega
Thanks guys!

I just discovered:

ImagePlus.getPixel(i, j): int[]

It returns RGB values as an int array, so you don't need to mask the pixel value.

I'm not sure, but I think it may be a good apporach when you need to access pixels here and there, but for processing entire images, I think the bitmasking method would be faster.

The "split channels" is ok, but I want to do it in background, not showing the splitted channels. It has more to do with my other message about how o avoid showing results when running stuff programmatically.

Sincerely,

Juanjo.

On May 25, 2011, at 8:30 PM, Curtis Rueden wrote:

> Hi Juan,
>
> So, do I have to convert every pixel like that before working with them? Is
>> there no API for RGB images? Maybe a method to split the image in three
>> different gray scale images and to merge them after being processed, would
>> be helpful.
>>
>
> There are many different ways of dealing with it. To split into three
> different grayscale images first, use a command such as:
>
>  IJ.run(imp, "Split Channels", "");
>
> (This is what the macro recorder produces when executing the command Image >
> Color > Split Channels.)
>
> But just using the bitmasking code you mentioned is fine too.
>
> Regards,
> Curtis
>
> On Wed, May 25, 2011 at 5:09 AM, Juanjo Vega <[hidden email]> wrote:
>
>> Hello everyone,
>>
>> I need to work with colour images in a plugin I'm developing, and as it is
>> my first time and I'm pretty confused.
>>
>> I had a look into the "Color Threshold" plugin and found this:
>>
>> int c, r, g, b;
>>
>> ...
>>
>> c=ip.getPixel(x,y);
>>
>> r = ((c&0xff0000)>>16);//R
>> g = ((c&0x00ff00)>>8);//G
>> b = ( c&0x0000ff); //B
>>
>> So, do I have to convert every pixel like that before working with them? Is
>> there no API for RGB images? Maybe a method to split the image in three
>> different gray scale images and to merge them after being processed, would
>> be helpful.
>>
>> Any help will he welcome, plugins, API reference, etc. :)
>>
>> Sincerely,
>>
>> Juanjo.
>>
>> ------------------------------------------------------------
>> Juanjo Vega ([hidden email])
>>
>> Unidad de Biocomputación. Laboratorio B-13.
>> Centro Nacional de Biotecnología. CNB-CSIC.
>> C\ Darwin, 3. Campus de Cantoblanco.
>> Universidad Autónoma de Madrid.
>> 28049, Madrid, Spain.
>>
>> http://www.cnb.csic.es
>> http://www.biocomp.cnb.csic.es
>>
>> +34 91 585 4510
>>
>> "Las mejores almas son capaces de los mayores vicios como de las mayores
>> virtudes, y aquellos que caminan despacio por el camino recto pueden
>> llegar más lejos que los que corren pero se apartan de él." - Discurso
>> del Método, René Descartes.
>>

------------------------------------------------------------
Juanjo Vega ([hidden email])

Unidad de Biocomputación. Laboratorio B-13.
Centro Nacional de Biotecnología. CNB-CSIC.
C\ Darwin, 3. Campus de Cantoblanco.
Universidad Autónoma de Madrid.
28049, Madrid, Spain.

http://www.cnb.csic.es
http://www.biocomp.cnb.csic.es

+34 91 585 4510

"Las mejores almas son capaces de los mayores vicios como de las mayores
virtudes, y aquellos que caminan despacio por el camino recto pueden
llegar más lejos que los que corren pero se apartan de él." - Discurso
del Método, René Descartes.