Making new arbitrarily-shaped ROI's in plugin

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Making new arbitrarily-shaped ROI's in plugin

gibberfish
Hello,

I'm writing an ImageJ plugin where at a certain point I have to split a ROI into two separate ROI's. This should be done along a certain splitting path. The problem I'm having is that I can't find a way to re-define the results as two new ROI's. When looking at the Roi and RoiManager class it seems all the constructors offer is defining ROI's with very basic shapes (rectangles,...).

Is there any way to create a ROI from a Polygon/list of pixels in a plugin?
Reply | Threaded
Open this post in threaded view
|

Re: Making new arbitrarily-shaped ROI's in plugin

dscho
Hi,

On Thu, 5 May 2011, gibberfish wrote:

> I'm writing an ImageJ plugin where at a certain point I have to split a
> ROI into two separate ROI's. This should be done along a certain
> splitting path.

The easiest way is to work with ShapeROIs:
http://imagej.nih.gov/ij/developer/api/ij/gui/ShapeRoi.html

You basically can use the getShape() method to turn the ROI into an AWT
Shape and work with those. If you have a non-ShapeRoi, you can turn it
into a ShapeRoi with the ShapeRoi(Roi) constructor.

Ciao,
Johannes
Reply | Threaded
Open this post in threaded view
|

Re: Making new arbitrarily-shaped ROI's in plugin

gibberfish
This looks promising, thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Making new arbitrarily-shaped ROI's in plugin

Zian_Fanti
In reply to this post by gibberfish
Hello gibberfish, you can contruct a ShapeROI either with a list of pixels or wih Polygon. Try this:

// An array of Points previosly created
Point[] path;


GeneralPath gp = new GeneralPath();
gp.moveTo(path[0].x, path[0].y);
for (int i = 1; i < path.length; i++) {
      Point p = path[i];
      gp.lineTo(p.x, p.y);
}

Roi roi = new ShapeRoi(gp);
Overlay overlay = new Overlay();

// here you can add to the overlay all the rois you have
overlay.add(roi);

// set the overlay in an active ImagePlus for visualize the rois  
imp.setOverlay(overlay);