Login  Register

Re: RGB Split setColor(Color.BLUE)

Posted by Boizeau marielaure on Jan 22, 2008; 4:31pm
URL: http://imagej.273.s1.nabble.com/RGB-Split-setColor-Color-BLUE-tp3697482p3697484.html

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