Login  Register

Re: Fill an ROI with transparent color (alpha value)

Posted by dscho on May 22, 2011; 10:39am
URL: http://imagej.273.s1.nabble.com/Fill-an-ROI-with-transparent-color-alpha-value-tp3684492p3684495.html

Hi Jan,

On Sun, 22 May 2011, Jan Eglinger wrote:

> thanks a lot for the helpful example!
>
> On 21.05.2011 7:17 PM, Rasband, Wayne (NIH/NIMH) [E] wrote:
> > You can do this by using the ImagePlus flatten() method. Here is an example:
> >
> >   imp = IJ.openImage("http://imagej.nih.gov/ij/images/FluorescentCells.zip");
> >   roi = new OvalRoi(130, 118, 254, 239);
> >   r=150; g=0; b=150; alpha=0.5;
> >   roi.setFillColor(new Color(r/255,g/255,b/255,alpha));
> >   imp.setOverlay(new Overlay(roi));
> >   imp = imp.flatten();
> >   imp.show();
>
> As far as I understand, this wouldn't work on a single slice of a stack,
> since imp.flatten() will flatten the whole stack, right?

The common workaround is to create a dummy ImagePlus with the single
slice:

        ImageProcessor ip = imp.getStack().getProcessor(15);
        ImagePlus dummy = new ImagePlus("dummy", ip);

        /* ... work on dummy, the pixel data are shared ... */

        // now the original image's current slice might be changed
        imp.updateAndDraw();

Ciao,
Dscho