Re: Iterator over Roi points anywhere?
Posted by
Rasband, Wayne (NIH/NIMH) [E] on
Apr 11, 2016; 2:36am
URL: http://imagej.273.s1.nabble.com/Iterator-over-Roi-points-anywhere-tp5016087p5016091.html
> On Apr 10, 2016, at 11:08 AM, Burger Wilhelm <
[hidden email]> wrote:
>
> Hello all,
>
> does anyone know of a straight way to enumerate/iterate over all points contained in an (arbitrary) Roi? That is (in Java terms), something like this:
>
> ...
> Roi roi = im.getRoi();
> for (Point p : roi.getContainedPoints()) {
> ... // process p
> }
Get the ROI mask and use it to determine which pixels are contained in the ROI. The following JavaScript/BeanShell code calculates the mean value of the pixels contained in the current ROI or the mean of the entire image if there is no ROI.
-wayne
img = IJ.getImage();
ip = img.getProcessor();
bounds = ip.getRoi();
mask = img.getMask();
sum = 0;
count = 0;
for (y=0; y<bounds.height; y++) {
for (x=0; x<bounds.width; x++) {
if (mask==null||mask.getPixel(x,y)!=0) {
count++;
sum += ip.getf(x+bounds.x, y+bounds.y);
}
}
}
IJ.log("mean,count: "+IJ.d2s(sum/count,4)+" "+count);
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html