Re: How to color differently each slice of a stack or each ImageProcessor

Posted by thehobbit on
URL: http://imagej.273.s1.nabble.com/How-to-color-differently-each-slice-of-a-stack-or-each-ImageProcessor-tp5000664p5000680.html

Hi, thanks for the replay.
Probably I did not explain the problem well, sorry, my english is not that good.
I have problems to draw on each single slice using JAVA.
When I draw some ROI on an image, all other images on the stack suffer the same modification, but I need only to draw on that specific slice.
I try to write here an example:


//This is a function I found on the internet and which I modified to my own needs
//the value of the variable imp is passed as IJ.getImage();

void labeltmp(ImagePlus imp, int x, int y) {
                Roi roi = imp.getRoi();
                if (roi != null) {
                        if (!(roi instanceof ShapeRoi))
                                roi = new ShapeRoi(roi);
                        ShapeRoi roiShape = (ShapeRoi) roi;
                        roiShape.or(getBrushRoi(x, y, brushWidth));
                } else
                        roi = getBrushRoi(x, y, brushWidth);
               
                roi.setFillColor(fillColor);
                imp.setRoi(roi);
                imp.updateAndDraw();
               
}

ShapeRoi getBrushRoi(int x, int y, int width) {
        return new ShapeRoi(new OvalRoi(x - width / 2, y - width / 2, width, width));
    }

This function works well, and draws a roi like a brush tool.
The problem, as explained before, is that this type of solution draws a Roi on all the images of the stack, even if I'm working on the 30th slice of 60.
I tried several functions like roi.setPosition(...) ecc.
I don't know if there is something wrong with using IJ.getImage(), or if there are some functions that get a single slice and automatically set the modifications on the ImageStack.

I hope the problem is clear now.
Thank you for your support.

Ferdinando