Login  Register

Re: How to use setLocation and measure

Posted by Rasband, Wayne (NIH/NIMH) [E] on Dec 05, 2014; 9:33pm
URL: http://imagej.273.s1.nabble.com/How-to-use-setLocation-and-measure-tp5010795p5010802.html

On Dec 5, 2014, at 12:24 PM, Avital Steinberg <[hidden email]> wrote:
>
> Hi,
> I am trying to move an ROI around in a java plugin and measure the mean
> intensity. I am measuring the ImageStatistics on an ImageProcessor, since I
> don't want to display the image. The problem is that it is not actually
> moving the ROI around. Here is my code: (img is ImagePlus)

Create a new ROI for each location. The following example measures the mean of a circular ROI at 10 different locations.

-wayne

  img = IJ.createImage("Untitled", "16-bit ramp", 500, 500, 1);
  w = h = 50;
  for (i=0; i<10; i++) {
     roi = new OvalRoi(i*50, i*50, w, h);
     img.setRoi(roi);
     stats = img.getStatistics();
     IJ.log(i+" "+stats.mean);
  }


> I am giving a simple example with two different locations, but my purpose
> is to move the ROI to many different locations and measure the mean
> intensities.
>
>        ImageProcessor ip = img.getProcessor();
> Calibration cal = img.getCalibration();
>        img.setRoi(new OvalRoi(598, 380, 32, 59));
> Roi roi = img.getRoi();
>        ImageStatistics stats = ImageStatistics.getStatistics(ip, MEAN,
> cal);
> IJ.log("The mean intensity is: " + stats.mean);
> roi.setLocation(1056, 304);
> stats = ImageStatistics.getStatistics(ip, MEAN, cal);
> IJ.log("The mean intensity is now: " + stats.mean);
>
> How should I change my code so that it would really move the ROI to a new
> location and measure the mean intensity in this location?
>
> Thanks,
> Avital

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