Setting ROIs

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

Setting ROIs

Gabriel Landini
Hi,
Sorry for this clueless question.
In a plugin, I want to create a single circular ROI and move it around the
image to extract some local histograms.

If I put the ip.setROI ... (below) in a loop, do I need to discard any
previous ROI created? I do not know what happens to the ROI that was created
in the previous loop step and I would like to avoid creating lots of new ROIs
as I only need the current one.

ImageProcessor ip=imp.getProcessor();
int[] data;
ip.setRoi(new OvalRoi(x-radius, y- radius, radiusx2, radiusx2));
data = ip.getHistogram();


Many thanks for any clarification.
Cheers

Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Setting ROIs

Michael Schmid
Hi Gabriel,

you can use the roi's setLocation(x,y) method to displace it.
The main advantage of setLocation vs. creating a new Roi is that the mask
need not be calculated for each new roi (the mask is given only for the
points within the bounding rectangle).
Note, however, that setLocation works correctly only if you don't have
subpixel resolution, i.e., the x and y coordinates of the original roi and
the displaced one must be integer. Otherwise, you have to create a new
roi, because the old mask won't be valid any more.

In my experience, with today's computers, creating some 10^4 objects and
having the Garbage Collector automatically discard them when unused is not
an issue, it won't slow the program down significantly.  Time for Garbage
collection may become an issue for 10^5 or 10^6 objects or more, depending
on their size.

Michael
_______________________________________________________________________

On Sat, November 9, 2013 17:13, Gabriel Landini wrote:

> Hi,
> Sorry for this clueless question.
> In a plugin, I want to create a single circular ROI and move it around the
> image to extract some local histograms.
>
> If I put the ip.setROI ... (below) in a loop, do I need to discard any
> previous ROI created? I do not know what happens to the ROI that was
> created
> in the previous loop step and I would like to avoid creating lots of new
> ROIs
> as I only need the current one.
>
> ImageProcessor ip=imp.getProcessor();
> int[] data;
> ip.setRoi(new OvalRoi(x-radius, y- radius, radiusx2, radiusx2));
> data = ip.getHistogram();
>
>
> Many thanks for any clarification.
> Cheers
>
> Gabriel

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html