How to get area of Roi programatically; where is "Roi.getArea()"

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

How to get area of Roi programatically; where is "Roi.getArea()"

Jim Cant
I need to get the area of FreeRois programatically (not through the ImageJ GUI) and have spent a few hours on this without any luck.  I would expect that the Roi class would have a method like 'getArea()'... after all, it has getFeretsDiameter()  ;-)

I looked through the JavaDocs, the ImageJ forum, and googled around a bit with no luck.

I walked through the code starting with the 'Measure' button on the RoiManager and soon found myself in pluging country with somebody calling Executer.run( "Measure");

I feel there has to be simpler way that I am just missing.  Can anybody give me a hand here?

Thanks,

jim cant
Reply | Threaded
Open this post in threaded view
|

Re: How to get area of Roi programatically; where is "Roi.getArea()"

Wayne Rasband
> I need to get the area of FreeRois programatically (not through the
> ImageJ GUI) and have spent a few hours on this without any luck.
> I would expect that the Roi class would have a method like
> 'getArea()'...
> after all, it has getFeretsDiameter()  ;-)
>
> I looked through the JavaDocs, the ImageJ forum, and googled
> around a bit with no luck.
>
> I walked through the code starting with the 'Measure' button on the
> RoiManager and soon found myself in pluging country with somebody
> calling Executer.run( "Measure");
>
> I feel there has to be simpler way that I am just missing.  Can
> anybody give me a hand here?

Here a two ways to get the area of a selection in a plugin:

     ImagePlus img = IJ.getImage();
     double area1 = img.getStatistics().area;

     ImageProcessor ip = img.getProcessor();
     ip.setRoi(img.getRoi());
     ImageStatistics stats = ImageStatistics.getStatistics(ip,
Measurements.MEAN, img.getCalibration());
     double area2 = stats.area;

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: How to get area of Roi programatically; where is "Roi.getArea()"

Nathaniel Ryckman
Why does the returned value differ from the value returned by using Analyze->Measure?

Is the analyzer class or the statistics class more reliable?

Wayne Rasband wrote
> I need to get the area of FreeRois programatically (not through the
> ImageJ GUI) and have spent a few hours on this without any luck.
> I would expect that the Roi class would have a method like
> 'getArea()'...
> after all, it has getFeretsDiameter()  ;-)
>
> I looked through the JavaDocs, the ImageJ forum, and googled
> around a bit with no luck.
>
> I walked through the code starting with the 'Measure' button on the
> RoiManager and soon found myself in pluging country with somebody
> calling Executer.run( "Measure");
>
> I feel there has to be simpler way that I am just missing.  Can
> anybody give me a hand here?

Here a two ways to get the area of a selection in a plugin:

     ImagePlus img = IJ.getImage();
     double area1 = img.getStatistics().area;

     ImageProcessor ip = img.getProcessor();
     ip.setRoi(img.getRoi());
     ImageStatistics stats = ImageStatistics.getStatistics(ip,
Measurements.MEAN, img.getCalibration());
     double area2 = stats.area;

-wayne