Posted by
Joachim Wesner on
Jul 03, 2006; 9:56pm
URL: http://imagej.273.s1.nabble.com/how-to-access-the-ROI-programmatically-tp3702303p3702305.html
Yes, there is contains(), and it´s in the docs
http://rsb.info.nih.gov/ij/developer/api/ij/gui/Roi.html (look for
contains)
but it´s very general yet a bit slow, in case you need to access it in a
tight loop you better create that mask Gabriel mentions once like
byte rMask[] = null;
Rectangle rRect = null;
if (roi != null) {
rRect = roi.getBounds();
ImageProcessor ipm = roi.getMask();
if (ipm != null) {
rMask = (byte[])ipm.getPixels();
}
}
and later use your own contains() function.
boolean contains(int ix, int iy, byte[] mask, Rectangle rect) {
if (rect == null)
return true;
if (!rect.contains(ix, iy))
return false;
if (mask == null)
return true;
return (mask[(iy-rect.y)*rect.width+(ix-rect.x)] != 0);
}
in a tight loop like
if (contains(ix, iy, rMask, rRect))
{
// do smothing if (ix,iy) is contained in the ROI
}
which is much faster!
JW
Gabriel Landini
<G.Landini@BHAM. An:
[hidden email]
AC.UK> Kopie:
Gesendet von: Thema: Re: how to access the ROI programmatically?
ImageJ Interest
Group
<
[hidden email]
.GOV>
03.07.2006 22:20
Bitte antworten
an ImageJ
Interest Group
> I need to do a check for whether or not a certain point/pixel coordinate
is
> contained in the ROI.
> My code is of the form
> for all pixels, if pixels is in ROI, do stuff
> The ROI is a path resulting from freehand selection.
>
> I was not able to find such a function in the API documentation. Is there
a
> function like the one I'm describing? Any suggestions on how to implement
it?
There is a method in Roi.java called "contains" which perhaps does what you
need (not entirely sure).
However if you have many pixels this may be slow.
Alternatively you could create a binary image that has just the filled ROI,
then use this image to direct the analysis (scan this image and all set
pixels give you the coordinates of the pixels in the original that need to
be
processed).
I hope it helps.
Gabriel
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit
http://www.messagelabs.com/email
______________________________________________________________________