Login  Register

Re: Iterator over Roi points anywhere?

Posted by Burger Wilhelm on Apr 12, 2016; 6:48am
URL: http://imagej.273.s1.nabble.com/Iterator-over-Roi-points-anywhere-tp5016087p5016105.html

Awesome, works great -- thanks much, Wayne!

--Wilhelm


-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Rasband, Wayne (NIH/NIMH) [E]
Sent: Dienstag, 12. April 2016 03:19
To: [hidden email]
Subject: Re: Iterator over Roi points anywhere?

> 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 }

The latest ImageJ daily build (1.51a5) adds an Roi.getContainedPoints() method which works with arbitrary ROIs, including point and line selections. Here is example Java code that calculates the mean pixel value of the current ROI:

 ImagePlus img = IJ.getImage();
 ImageProcessor ip = img.getProcessor();  Roi roi = img.getRoi();  double sum=0;  int count=0;  for (Point p : roi.getContainedPoints()) {
    count++;
    sum += ip.getf(p.x, p.y);
 }
 IJ.log("mean,count: "+IJ.d2s(sum/count,4)+" "+count);

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

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