Posted by
Philippe GENDRE on
URL: http://imagej.273.s1.nabble.com/Specific-color-channel-to-retrieve-from-an-image-in-a-plugin-tp5004950p5005064.html
Dear List,
Recently, I posted a question to this list to retrieve a specific color
channel (the red one for example) from a RGB image. The answer
(ImageProcessor red = ((ColorProcessor)ip).getChannel(1, null);) is perfect
but I have realized that it is not what I need. In fact I need to retrieve
a specific color of pixel for example the blue ones and not the intensity
of the channel. According to that I wrote the following code:
ImageProcessor ipR=((ColorProcessor)ip).getChannel(1,null);
ImageProcessor ipG=((ColorProcessor)ip).getChannel(2,null);
ImageProcessor ipB=((ColorProcessor)ip).getChannel(3,null);
for (int x=0; x<frame_width; x++){
for (int y=0; y<frame_height; y++){
if
(ipB.getPixelValue(x,y)<ipR.getPixelValue(x,y)&&ipB.getPixelValue(x,y)<ipG.getPixelValue(x,y))
ipB.set(x,y,0);
}
}
That sounds good but slow. How to speed up this ?
Best regards,
Philippe
2013/9/26 Philippe GENDRE <
[hidden email]>
> ImageProcessor red = ((ColorProcessor)ip).getChannel(1, null) is exactly
> what I needed.
>
> This list is a marvel. Thanks a lot.
>
> Philippe
>
>
> 2013/9/26 Rasband, Wayne (NIH/NIMH) [E] <
[hidden email]>
>
> On Sep 26, 2013, at 1:02 PM, Philippe GENDRE wrote:
>>
>> > Dear List,
>> >
>> > I need to retrieve the red channel of an RGB image plus object as an
>> image
>> > processor in a plugin.
>> >
>> > What is the best solution ?
>>
>> Use the ImageProcessor.getChannel() method. Here is a JavaScript example:
>>
>> imp = IJ.openImage("
http://imagej.nih.gov/ij/images/clown.jpg");
>> ip = imp.getProcessor();
>> red = ip.getChannel(1, null);
>> new ImagePlus("Red Channel", red).show();
>>
>> In a plugin, it would look like this:
>>
>> ImagePlus imp = IJ.openImage("
>>
http://imagej.nih.gov/ij/images/clown.jpg");
>> ImageProcessor ip = imp.getProcessor();
>> ImageProcessor red = ((ColorProcessor)ip).getChannel(1, null);
>> new ImagePlus("Red Channel", red).show();
>>
>> -wayne
>>
>> --
>> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>>
>
>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html