Login  Register

Re: RoI mean values discrepant

Posted by Wayne Rasband-2 on Jan 22, 2021; 4:22pm
URL: http://imagej.273.s1.nabble.com/behavior-of-variable-when-function-is-called-tp5024336p5024406.html

> On Jan 21, 2021, at 1:09 PM, Herbie <[hidden email]> wrote:
>
> Dear experts and especially Wayne,
>
> please consider the following situation:

Hi Herbie,

You will get the expected results if your plugin assigns the ROI to the ImageProcessor. For example, when I run this macro

  newImage("TestNoise", "8-bit noise", 256, 256, 1);
  makeOval( 124, 124, 9, 9 );
  print("macro mean="+getValue("Mean"));

and then this script

 imp = IJ.getImage();
 ip = imp.getProcessor();
 ip.setRoi(new OvalRoi(124, 124, 9, 9));
 IJ.log("script mean="+ip.getStatistics().mean);

I get this output

macro mean=124.4493
script mean=124.44927536231884

Or better, in your plugin, use

 imp = IJ.getImage();
 imp.setRoi(new OvalRoi(124, 124, 9, 9));
 IJ.log("script mean="+imp.getStatistics().mean);

Note that your plugin would be simpler and easier to understand if it implanted the PlugIn interface.

-wayne

> A___________________________________________
> // create a test pattern
> newImage("TestNoise", "8-bit noise", 256, 256, 1);
>
> B___________________________________________
> // with image "TestNoise" run the macro:
> makeOval( 124, 124, 9, 9 );
> print( "macro mean: "+d2s(getValue("Mean"), 9)+";" );
> //
>
> C___________________________________________
> // with image "TestNoise" run the compiled plugin:
> import java.awt.*;
> import ij.*;
> import ij.gui.*;
> import ij.process.*;
> import ij.plugin.filter.PlugInFilter;
> public class My_PlugInFilter implements PlugInFilter {
> protected ImagePlus imp;
> public int setup( String arg, ImagePlus imp ) {
> if ( IJ.versionLessThan( "1.53g" ) )
> return DONE;
> if( imp != null ) {
> this.imp = imp;
> }
> return DOES_8G;
> }
> public void run( ImageProcessor ip ) {
> imp.setRoi( new OvalRoi( 124, 124, 9, 9 ) );
> IJ.log("plugin mean: "+imp.getProcessor().getStatistics().mean+";");
> }
> }
> //
>
> In general the resulting mean values are discrepant.
> Here are example values I got from the same image and RoI:
> macro mean 126.463768116;
> plugin mean 129.2962962962963;
>
>
> What am I doing wrong?
>
> Regards
>
> Herbie

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