Login  Register

Re: RGB Split setColor(Color.BLUE)

Posted by dscho on Jan 21, 2008; 12:05pm
URL: http://imagej.273.s1.nabble.com/RGB-Split-setColor-Color-BLUE-tp3697482p3697483.html

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