Login  Register

Strange results with latest API and line selections

Posted by Marcel on May 10, 2016; 10:32am
URL: http://imagej.273.s1.nabble.com/Strange-results-with-latest-API-and-line-selections-tp5016381.html

I'm using the latest ImageJ API to transfer and edit ROI selections. All other selections work fine so far.

However if I use the line selection I get different results when calculating the mean if I invoke the action "Measure" or when I use the new API to get the contained pixel values with: Roi.getContainedPoints().

Here an example:

imp = IJ.openImage("http://wsr.imagej.net/images/blobs.gif");
imp.show();
imp.setRoi(new Line(87,99,120,115));
IJ.run(imp, "Measure", "");

The mean in the measurements dialog is: 140.632

if I calculate now the mean from the pixel values in the ROI I get a different result:

count=0;
sum=0;
img = IJ.getImage();
ip=img.getProcessor();
  roi = img.getRoi();
  iter = roi.iterator();
  while (iter.hasNext()) {
     p = iter.next();
    sum+=ip.getPixelValue(p.x, p.y);
    count=count+1
  }
print(sum/count);

The mean is: 142.054

If I use an ImageJ macro instead oddly I get floating point results:

p=Roi.getContainedPoints(x,y);
 
for (i=0; i<x.length; i++){
   print(getPixel(x[i],y[i]));
}

Do I miss something or is this a bug for the line selection?

All other selections seems to give the correct (equal) results.