Thresholding from Java

Posted by Cspr on
URL: http://imagej.273.s1.nabble.com/Thresholding-from-Java-tp3688545.html

Hey everyone

I have an 8-bit image, and I'm trying to threshold using Fiji's Image -> Adjust -> Threshold. Let's say I do it manually using Fiji and it yeields "Result-image X".

Now I try to replicate that in Java. What I do it:

Get the image: implus imp = IJ.getImage();
I have checked that I get the right image.

Apply std. threshold: imp.getProcessor().setAutoThreshold("Default");

Apply threshold: imp.getProcessor().setThreshold(x,y,0);  
Where x, y are the lower and upper values from the threshold slider in the Threshold window from ImageJ. 0 is just the "Red" option.

And finally:
IJ.run(imp, "Convert to Mask", "");

To convert the image.

Unfortunately the result I get from the code vs. the result I see in "Result-image X" is not the same. From what I can see it seems that in ImageJ Fiji then lower and upper values from the sliders in the Threshold window somehow is... lost. Let's say that the lower and upper are 0 and 35.
When I run the code it seems that no matter what I do the lower and upper values are set to 0 and 0.

I have checked that the values I get in are the appropriate doubles and everything so I'm kinda stuck, and is hoping someone can provide an answer.

Thanks :)