Login  Register

Re: Using API to create mask with multiple rectangles

Posted by Leonard Sitongia on Nov 19, 2007; 9:23pm
URL: http://imagej.273.s1.nabble.com/Using-API-to-create-mask-with-multiple-rectangles-tp3697968p3697973.html

Albert Cardona wrote:
> Use the ShapeRoi. You can add any other roi to it. For example:
>
> // make ShapeRoi from a rectangle roi:
> ShapeRoi sroi = new ShapeRoi(new Roi(0, 0, width1, height1));
>
> // add a second rectangle
> sroi.add(new ShapeRoi(new Roi(x,y,w,h));
I don't see an add method for the ShapeRoi.  I see that AWT Shape
subclasses like Rectangle have an add method, so one can add a Rectangle
to another Rectangle (but I don't understand what it means to have a
rectangle made up of two, possibly unrelated, rectangles).
>
> All the above can be done with the java.lang.geom.Area as well, with
> regular java.awt.Rectangle instances.
>
Yes, I see javax.awt.geom.Rectangle2D, which is a superclass of
Rectangle, can do this.

So, would I create one Rectangle and add others to it, giving me one ROI
made up of the union of all the Rectangles?  I should then be able to
set this on my ImageProcessor and have the operation apply to all pixels
within all Rectangles.  I tried this,

                Rectangle mask = new Rectangle();
                mask.add(new Rectangle(100,100,100,100));
                mask.add(new Rectangle(500,100,100,100));
                ip.setRoi(mask); // Set the Region Of Interest
                ip.multiply(1000.0); // Scale it up to make it visible

and the result is not as expected.  I don't get two separate rectangles
of 1000x value, but one rectangle of the dimensions of the largest of
the individual dimensions, that is one rectangle at (100,100) with a
size of 600x100.
>
> To get the sum of the pixel values within the ROI, get the mask first
> from the roi, and if the pixel in the mask in non-zero, add the
> corresponding pixel from the image.
I don't follow this.  I don't understand what the mask is in ImageJ.  I
see that irregular ROIs produce a mask, but I'm not sure what it is.  I
think it is what I want, the mask representing my multiple rectangles,
but I'm not sure.

Thank you!

--
==Leonard E. Sitongia
   High Altitude Observatory
   National Center for Atmospheric Research
   P.O. Box 3000 Boulder CO 80307  USA
   [hidden email]  voice: (303)497-2454  fax: (303)497-1589