How are Regions Of Interest defined?


#1

Hi everybody,

I am new to Fiji and programming. So I got some trouble understanding the ImageJ documentation.
Nevertheless, I am trying to write a macro.
I used the RoiManager to calculate Rois for an image stack and used the getRoisAsArray command to get access to the different Rois. The problem is that I don’t understand how the RoiManager defines the different Rois. The are displayed as an array: [Traced, x=‘int’, y=‘int’, width=‘int’, 'height=‘int’]. If I am right this represents a Rectangle?
But the Rois I can see in the image look more like they consist of many Rectangles. If this assumption would be correct, wouldn’t there have to be an array defining one Roi consisting of many arrays, each displaying the rectangles, which are included in the specific Roi?
I would be very happy if someone could enlighten me.
Thanks in advance,

Ann


#2

Dear @Ann,

Welcome to the forum! :slight_smile:

Are you trying to write a macro in the ImageJ macro language or another language? The rest of your posts sounds more like you are implementing a Beanshell or Java script. If you are interested in writing a macro in the ImageJ macro language, you can forget about the rest of my post and might want to take a look at the Introduction into Macro Programming wiki page or the recording of @etarena’s scripting workshop.


RoiManager.getRoisAsArray() returns a Roi[]. You can take a look at the JavaDoc for Roi and all the known subclasses of it. In your case, you might be dealing with a FreehandRoi.

Best,
Stefan


#3

Hello @Ann!

ImageJ/Fiji has several different types of Rois: Rectangle, Oval, Polygon, Freehand, Traced, Straight Line, Polyline, Freeline, Angle, Composite, Point, Text, and Image. These types can refer to the shape of the Roi, or the method by which the Roi was created. Traced Rois, for example, are usually the result of using the Wand tool and they can be a variety of shapes.

The getRoisAsArray method returns a Roi[]. However, when you inspect this array or try to print its values it will call the toString method of Roi. In the case of Traced Rois, this will display the type of the Roi, the coordinates of the upper left hand corner of the bounding box, and the width and height of the bounding box.

So you are correct that what is being displayed when you print this element of the array ([Traced, x=‘int’, y=‘int’, width=‘int’, 'height=‘int’]) is defining a rectangle, but that rectangle is only the bounding box of the Traced Roi and the Traced Roi within this bounding box can take on a variety of shapes (such as many rectangles :slight_smile:). If you’d like the vertices of this Traced Roi you could call getXCoordinates and getYCoordinates on it.

Hopefully that helps, but if not please feel free to ask additional questions.

Cheers,

Alison