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) 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 |
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 |
Thanks, but I don't want to create thousands of ROIs. I succeeded in moving
the ROI around using: rm.select(img,selectIndex); rm.translate(offsetX,offsetY); So the selected ROI has been moved to the place I wanted to move it to. The Image Plus object is associated with the ROI I'm moving around. Therefore, using: ImageStatistics stats = img.getStatistics(); Works well. But - I'd like to hide the image, and img is the Image Plus object. So I would have liked to work on the ImageProcessor object, like this: ImageProcessor ip = img.getProcessor(); ImageStatistics stats = ImageStatistics.getStatistics(ip, MEAN, cal); But this gives me strange values. Any idea how to link the Image Processor object with the currently selected ROI? The ImagePlus object is linked to the selected ROI. Thank you, Avital On Fri, Dec 5, 2014 at 11:33 PM, Rasband, Wayne (NIH/NIMH) [E] < [hidden email]> wrote: > 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 > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |