Login  Register

Re: Low level use of thresholder (Was: Headless ImageJ2-rc2 - Analyze Particles returns no result)

Posted by dscho on Jun 13, 2014; 5:55pm
URL: http://imagej.273.s1.nabble.com/Headless-ImageJ2-rc2-Analyze-Particles-returns-no-result-tp5008127p5008209.html

Hi Jan,

On Fri, 13 Jun 2014, Jan Eglinger wrote:

> I just noticed the comment in your example code:
>
> On 13.06.2014, 1:24 PM, Paul van Schayck wrote:
> > IJ.run(imp, "Convert to Mask", ""); // How to use ij.plugin.Thresholder?
>
>
> and wanted to share how I have done it [*1*]:
>
>     import ij.WindowManager;
>     import ij.plugin.Thresholder;
>
>     [...]
>
>     private Thresholder thr;
>
>     [...]
>
>     WindowManager.setTempCurrentImage(imp);
>     thr.run("mask");
>     WindowManager.setTempCurrentImage(null);
>
> If anyone has a more elegant solution, I would be happy to hear it.

You could also make use of the static methods in
fiji.threshold.Auto_Threshold (i.e. Gabriel Landini's Auto Threshold
plugin) with the histogram obtained via

        http://jenkins.imagej.net/job/ImageJ1-javadoc/javadoc/ij/process/ImageProcessor.html#getHistogram%28%29

then set the threshold via

        http://jenkins.imagej.net/job/ImageJ1-javadoc/javadoc/ij/process/ImageProcessor.html#setThreshold%28double,%20double,%20int%29

and if you need a mask, turn the threshold into a ROI via

        http://jenkins.imagej.net/job/ImageJ1-javadoc/javadoc/ij/plugin/filter/ThresholdToSelection.html#run%28ij.ImagePlus%29

and then make the mask by calling

        http://jenkins.imagej.net/job/ImageJ1-javadoc/javadoc/ij/process/ImageProcessor.html#setRoi%28ij.gui.Roi%29

and

        http://jenkins.imagej.net/job/ImageJ1-javadoc/javadoc/ij/process/ImageProcessor.html#getMask%28%29

I know, not very straight-forward... but thread-safe! Well, kinda...

Ciao,
Johannes

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