Posted by
Wayne Rasband on
Jan 22, 2008; 5:13pm
URL: http://imagej.273.s1.nabble.com/RGB-Split-setColor-Color-BLUE-tp3697482p3697488.html
Here is a faster version that uses a single for loop.
public class Split_Blue implements PlugIn {
public void run(String arg) {
ImagePlus imp = IJ.getImage();
if (imp.getBitDepth()!=24)
{IJ.error("RGB image required"); return;}
int[] pixels = (int[])imp.getProcessor().getPixels();
int w=imp.getWidth(), h=imp.getHeight();
int size = w*h;
ImageProcessor ip2 = new ByteProcessor(w, h);
byte[] bytes = (byte[])ip2.getPixels();
for (int i=0; i<size; i++)
bytes[i] = (byte)(pixels[i]&0xff);
new ImagePlus("Blue Channel", ip2).show();
}
}
-wayne
On Jan 22, 2008, at 11:31 AM, Marie-Laure Boizeau wrote:
> I had try to develop this double "for loop", but it's still slow.
> Is there anybody have an other way out ?
>
> Thank you for your help
>
> Marie
>
>
> -----Original Message-----
> From: Johannes Schindelin [mailto:
[hidden email]]
> Sent: Monday, January 21, 2008 1:05 PM
> To: Boizeau, Marie-Laure SMA/FR
> Cc:
[hidden email]
> Subject: Re: RGB Split setColor(Color.BLUE)
>
> Hi,
>
> On Mon, 21 Jan 2008, Marie-Laure Boizeau wrote:
>
>> I have develop a plugin with a step of splitting an RGB image and then
>
>> I have to threshold it.
>>
>> part of the plugin :
>>
>> ImagePlus imagetosave =win55.getImagePlus();
>> IJ.run("RGB Split");
>> IJ.setThreshold(128, 255);
>> IJ.run("Convert to Mask");
>> String pathsave =dir+"/imagesretraitees/"+listTIF[i];
>> IJ.saveAs("Tiff", pathsave);
>>
>> the IJ.run("RGB Split") take a lot of time.
>
> Why don't you do the split yourself?
>
> Something like
>
> int w = imagetosave.getWidth(), h = imagetosave.getHeight();
> byte[] pixels = new byte[w * h];
> for (int y = 0; y < h; y++)
> for (int x = 0; x < w; x++)
> byte[x + y * w] =
> (imagetosave.getPixel(x, y)[0] >= 128 ?
> 255 : 0);
> new ImagePlus("mask", new ByteProcessor(w, h, pixels, null));
>
> If that is still too slow, you will have to work on a lower level, such
> as getting the int[] array of the ColorProcessor directly, and get at
> the red value (or the blue value) with boolean operations.
>
> Hth,
> Dscho
>