Posted by
Michael Schmid on
Mar 19, 2009; 4:50pm
URL: http://imagej.273.s1.nabble.com/Rectangle-roi-from-ImageStack-tp3693215p3693216.html
Hi Michael,
a few points about rois, maybe some of this helps you solve your
problem.
ImageProcessor.getRoi gives the roi bounds (rectangle), also for non-
rectangular rois. You can get the mask for non-rectangular rois.
Unless you are in the run(ip) method of a PlugInFilter, the rois of
an ImageProcessor do not necessarily reflect the roi of the ImagePlus
that the the ImageProcessor is part of. This is for avoiding
unnecessary calculations (calculating the mask takes some time).
See the PlugInFilterRunner in the ImageJ source code on how to
transfer the roi from an ImagePlus to the roi rectangle/mask of an
ImageProcessor.
Also note that the roi of an ImagePlus may be null. Then, in the run
(ip) method of a PlugInFilter you will get a roi rectangle enclosing
the whole image. This greatly facilitates programming plugin filters.
Hope this helps a bit.
Michael
________________________________________________________________
On 18 Mar 2009, at 14:09, Michael Doube wrote:
> Hi all
>
> I want to get the Rectangle ROI from an ImageStack that I have
> passed to a method, as in
>
> public void myMethod(ImageStack stack){
> Rectangle r = stack.getRoi();
> //do something with r
> return;
> }
>
> This is fine when there is a rectangle drawn, but if there is not
> an ROI drawn, I get a null pointer exception.
>
> Interestingly, if I set r to be a class variable
>
> Public Rectangle r;
>
> Then in the run() method set it with
>
> r = ip.getRoi();
>
> All the 'r's in my other methods behave sensibly and I don't get a
> null pointer exception when I haven't drawn an ROI on my stack.
>
> What is going on here?
>
> Mike