Converting ROIs

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

Converting ROIs

Andy Weller
Dear all,

Is there a macro way to convert between different ROI types?

I am using the run("Create Selection") command that creates a composite
ROI but I need a "Polygonal or point selection" required. My previous
get-out clause was to do the following:

   run("Enlarge...", "enlarge=0");
   run("Fit Spline");

which seemed to work... Sometimes... I guess there's a 'clean' way to do
it as I've seen the various saving methods in class RoiWriter
(http://rsb.info.nih.gov/ij/developer/source/ij/plugin/filter/RoiWriter.java.html).

   case Roi.POLYGON: name="Polygon.roi"; break;
   case Roi.FREEROI: name="Freehand.roi"; break;
   case Roi.TRACED_ROI: name="TracedRoi.roi"; break;
   case Roi.OVAL: name="Oval.roi"; break;
   etc

Thanks, Andy
Reply | Threaded
Open this post in threaded view
|

Re: Converting ROIs

Andy Weller
One thought with this, is it possible to do something like:

   run("Create Selection");
   select = roi.getType();
   select = Roi.POLYLINE;

This is probably completely wrong and demonstrating my lack of
programming skills (!), but hopefully somebody should know what I am
after...?

Thanks, Andy

On Wed, 2 Aug 2006 14:16:33 +0200, Andy Weller <[hidden email]> wrote:

>Dear all,
>
>Is there a macro way to convert between different ROI types?
>
>I am using the run("Create Selection") command that creates a composite
>ROI but I need a "Polygonal or point selection" required. My previous
>get-out clause was to do the following:
>
>   run("Enlarge...", "enlarge=0");
>   run("Fit Spline");
>
>which seemed to work... Sometimes... I guess there's a 'clean' way to do
>it as I've seen the various saving methods in class RoiWriter
>(http://rsb.info.nih.gov/ij/developer/source/ij/plugin/filter/RoiWriter.java.html).
>
>   case Roi.POLYGON: name="Polygon.roi"; break;
>   case Roi.FREEROI: name="Freehand.roi"; break;
>   case Roi.TRACED_ROI: name="TracedRoi.roi"; break;
>   case Roi.OVAL: name="Oval.roi"; break;
>   etc
>
>Thanks, Andy
Reply | Threaded
Open this post in threaded view
|

Re: Converting ROIs

Andy Weller
Hi Gabriel,

I have played with this previously without much luck. It seems that
getSelectionCoordinates(xCoordinates, yCoordinates) just creates a box -
ie, 4 coordinates instead of all of them. This means I go from a
composite selection to a box which I don't want.

Why does getSelectionCoordinates() do this? Can I change it? It'd be
great if it read all the coordinates, making it more flexible.

Thanks, Andy

On Fri, 2006-08-04 at 10:45 +0100, Gabriel Landini wrote:

> On Friday 04 August 2006 10:20, Andy Weller wrote:
> > One thought with this, is it possible to do something like:
> >
> >    run("Create Selection");
> >    select = roi.getType();
> >    select = Roi.POLYLINE;
> > This is probably completely wrong and demonstrating my lack of
> > programming skills (!), but hopefully somebody should know what I am
> > after...?
>
> Have a look in the macro functions. This may help:
> --
> getSelectionCoordinates(xCoordinates, yCoordinates)
> Returns two arrays containing the X and Y coordinates of the points that
> define the current selection. See the SelectionCoordinates macro for an
> example. See also: selectionType, getSelectionBounds.
> --
>
> Then you could recreate a selection based on those coordinates with "type"
> as "polygon" with:
>
> --
> makeSelection(type, xcoord, ycoord)
> Creates a selection from a list of XY coordinates. The first argument should
> be "polygon", "freehand", "polyline", "freeline", "angle" or "point". In
> ImageJ 1.32g or later, it can also be the numeric value returned by
> selectionType. The xcoord and ycoord arguments are numeric arrays that
> contain the X and Y coordinates. See the MakeSelectionDemo macro for
> examples.
> --
>
> If this works, please let me know.
>
> Cheers,
>
> Gabriel
Reply | Threaded
Open this post in threaded view
|

Re: Converting ROIs

Gabriel Landini
On Friday 04 August 2006 11:33, Andy Weller wrote:
> I have played with this previously without much luck. It seems that
> getSelectionCoordinates(xCoordinates, yCoordinates) just creates a box -
> ie, 4 coordinates instead of all of them. This means I go from a
> composite selection to a box which I don't want.

Not sure what you did, but what I suggested works fine:

// provide a freehand ROI before running.

getSelectionCoordinates(x, y);

//show the ROI coordinates
for (i=0;i<x.length;i++){
 print (""+x[i]+"  "+y[i]);
}

run("Select None");
wait(500); // no ROI now

makeSelection("plygon", x, y);

Cheers,
G.
Reply | Threaded
Open this post in threaded view
|

Re: Converting ROIs

Andy Weller
Yep, this is strange - it must have something to do with run("Create
Selection") and the composite selection it produces.

Using your method does indeed store all coordinates, but I am still
getting just a box with run("Create Selection")?!

Thanks, Andy

On Fri, 2006-08-04 at 11:51 +0100, Gabriel Landini wrote:

> On Friday 04 August 2006 11:33, Andy Weller wrote:
> > I have played with this previously without much luck. It seems that
> > getSelectionCoordinates(xCoordinates, yCoordinates) just creates a box -
> > ie, 4 coordinates instead of all of them. This means I go from a
> > composite selection to a box which I don't want.
>
> Not sure what you did, but what I suggested works fine:
>
> // provide a freehand ROI before running.
>
> getSelectionCoordinates(x, y);
>
> //show the ROI coordinates
> for (i=0;i<x.length;i++){
>  print (""+x[i]+"  "+y[i]);
> }
>
> run("Select None");
> wait(500); // no ROI now
>
> makeSelection("plygon", x, y);
>
> Cheers,
> G.