how to apply theshholds ot image

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

how to apply theshholds ot image

Aryeh Weiss
After I run:

ip.setThreshold(stats.mean-multiplier*stats.stdDev,    
2**imp.getBitDepth(), ImageProcessor.RED_LUT)

I have the thresholds associated with the image. I even see the correct
overlay.
However, I cannot figure how to apply these thresholds to the image in
order to create a binary image.

IJ.run(imp, "Convert to Mask", " background=Dark black")

applies one of the automatic threshholding methods, (even though I
removed that option from the argument list).

I tried also, ip.setBinaryThreshold(), but it does not appear to do what
I want (I am not quite sure what it does)

How are thresholds used to create a binary image?

Thanks again in advance
--aryeh

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how to apply theshholds ot image

Michael Schmid
Hi Aryeh,

if you have an 8-bit image you can apply the current threshold with
   imp = IJ.getImage();
   IJ.run(imp, "Convert to Mask", "");

(here it is written the Javascript or Python way)

You can find out with Plugins>Macros>Record; set the Recorder to
'JavaScript'.

Michael
________________________________________________________________

On 27/09/2017 20:20, Aryeh Weiss wrote:

> After I run:
>
> ip.setThreshold(stats.mean-multiplier*stats.stdDev,
> 2**imp.getBitDepth(), ImageProcessor.RED_LUT)
>
> I have the thresholds associated with the image. I even see the correct
> overlay.
> However, I cannot figure how to apply these thresholds to the image in
> order to create a binary image.
>
> IJ.run(imp, "Convert to Mask", " background=Dark black")
>
> applies one of the automatic threshholding methods, (even though I
> removed that option from the argument list).
>
> I tried also, ip.setBinaryThreshold(), but it does not appear to do what
> I want (I am not quite sure what it does)
>
> How are thresholds used to create a binary image?
>
> Thanks again in advance
> --aryeh
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how to apply theshholds to image

Aryeh Weiss
Hi Michael

Thanks again for your quick reply.


On 27/09/2017 23:24, Michael Schmid wrote:
> Hi Aryeh,
>
> if you have an 8-bit image you can apply the current threshold with
>   imp = IJ.getImage();
>   IJ.run(imp, "Convert to Mask", "");
>
I tried this before I posted.  What I get is the following command:
IJ.run(imp, "Convert to Mask", "method=Default background=Dark black")

If I leave out the arguments in my script, then the attached pop-up menu
will appear.
If I use:
IJ.run(imp, "Convert to Mask", "background=Dark black")
without the method parameter, it will not pop up the menu, but it will
use one of the methods to auto-threshold (probably the most recent or
default selection). I can see that the binary image produced does not
match theoverlay from the thresholds.

I tried to record Image>Threshold>Apply Threshold, and it threw the
following exception:
java.lang.RuntimeException: java.util.concurrent.ExecutionException:
java.lang.ClassCastException:
net.imagej.ops.commands.threshold.GlobalThresholder cannot be cast to
net.imagej.ops.OpEnvironment
     at
net.imagej.legacy.LegacyService.runLegacyCompatibleCommand(LegacyService.java:291)
     at
net.imagej.legacy.DefaultLegacyHooks.interceptRunPlugIn(DefaultLegacyHooks.java:163)
     at ij.IJ.runPlugIn(IJ.java)
     at ij.Executer.runCommand(Executer.java:137)
     at ij.Executer.run(Executer.java:63)
     at java.lang.Thread.run(Thread.java:748)
Caused by: java.util.concurrent.ExecutionException:
java.lang.ClassCastException:
net.imagej.ops.commands.threshold.GlobalThresholder cannot be cast to
net.imagej.ops.OpEnvironment
     at java.util.concurrent.FutureTask.report(FutureTask.java:122)
     at java.util.concurrent.FutureTask.get(FutureTask.java:192)
     at
net.imagej.legacy.LegacyService.runLegacyCompatibleCommand(LegacyService.java:287)
     ... 5 more
Caused by: java.lang.ClassCastException:
net.imagej.ops.commands.threshold.GlobalThresholder cannot be cast to
net.imagej.ops.OpEnvironment

Best regards
--aryeh





> (here it is written the Javascript or Python way)
>
> You can find out with Plugins>Macros>Record; set the Recorder to
> 'JavaScript'.
>
> Michael
> ________________________________________________________________
>
> On 27/09/2017 20:20, Aryeh Weiss wrote:
>> After I run:
>>
>> ip.setThreshold(stats.mean-multiplier*stats.stdDev,
>> 2**imp.getBitDepth(), ImageProcessor.RED_LUT)
>>
>> I have the thresholds associated with the image. I even see the
>> correct overlay.
>> However, I cannot figure how to apply these thresholds to the image
>> in order to create a binary image.
>>
>> IJ.run(imp, "Convert to Mask", " background=Dark black")
>>
>> applies one of the automatic threshholding methods, (even though I
>> removed that option from the argument list).
>>
>> I tried also, ip.setBinaryThreshold(), but it does not appear to do
>> what I want (I am not quite sure what it does)
>>
>> How are thresholds used to create a binary image?
>>
>> Thanks again in advance
>> --aryeh
>>
>
--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051


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

screenshot.png (83K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: how to apply theshholds to image - correction

Aryeh Weiss
I have more carefully examined the images, and Convert to Mask is in
fact using my thresholds.

The reasons I sometimes got the pop-up is that I was applying Convert to
mask to a stack. The thresholding method is requested for the case where
the checkbox for calculating the threshold for each slice is selected.

I wonder if there is a way to apply the thresholds with using the global
call to "Convert to mask".

--aryeh


On 28/09/2017 5:19, Aryeh Weiss wrote:

> Hi Michael
>
> Thanks again for your quick reply.
>
>
> On 27/09/2017 23:24, Michael Schmid wrote:
>> Hi Aryeh,
>>
>> if you have an 8-bit image you can apply the current threshold with
>>   imp = IJ.getImage();
>>   IJ.run(imp, "Convert to Mask", "");
>>
> I tried this before I posted.  What I get is the following command:
> IJ.run(imp, "Convert to Mask", "method=Default background=Dark black")
>
> If I leave out the arguments in my script, then the attached pop-up
> menu will appear.
> If I use:
> IJ.run(imp, "Convert to Mask", "background=Dark black")
> without the method parameter, it will not pop up the menu, but it will
> use one of the methods to auto-threshold (probably the most recent or
> default selection). I can see that the binary image produced does not
> match theoverlay from the thresholds.
>
> I tried to record Image>Threshold>Apply Threshold, and it threw the
> following exception:
> java.lang.RuntimeException: java.util.concurrent.ExecutionException:
> java.lang.ClassCastException:
> net.imagej.ops.commands.threshold.GlobalThresholder cannot be cast to
> net.imagej.ops.OpEnvironment
>     at
> net.imagej.legacy.LegacyService.runLegacyCompatibleCommand(LegacyService.java:291)
>     at
> net.imagej.legacy.DefaultLegacyHooks.interceptRunPlugIn(DefaultLegacyHooks.java:163)
>     at ij.IJ.runPlugIn(IJ.java)
>     at ij.Executer.runCommand(Executer.java:137)
>     at ij.Executer.run(Executer.java:63)
>     at java.lang.Thread.run(Thread.java:748)
> Caused by: java.util.concurrent.ExecutionException:
> java.lang.ClassCastException:
> net.imagej.ops.commands.threshold.GlobalThresholder cannot be cast to
> net.imagej.ops.OpEnvironment
>     at java.util.concurrent.FutureTask.report(FutureTask.java:122)
>     at java.util.concurrent.FutureTask.get(FutureTask.java:192)
>     at
> net.imagej.legacy.LegacyService.runLegacyCompatibleCommand(LegacyService.java:287)
>     ... 5 more
> Caused by: java.lang.ClassCastException:
> net.imagej.ops.commands.threshold.GlobalThresholder cannot be cast to
> net.imagej.ops.OpEnvironment
>
> Best regards
> --aryeh
>
>
>
>
>
>> (here it is written the Javascript or Python way)
>>
>> You can find out with Plugins>Macros>Record; set the Recorder to
>> 'JavaScript'.
>>
>> Michael
>> ________________________________________________________________
>>
>> On 27/09/2017 20:20, Aryeh Weiss wrote:
>>> After I run:
>>>
>>> ip.setThreshold(stats.mean-multiplier*stats.stdDev,
>>> 2**imp.getBitDepth(), ImageProcessor.RED_LUT)
>>>
>>> I have the thresholds associated with the image. I even see the
>>> correct overlay.
>>> However, I cannot figure how to apply these thresholds to the image
>>> in order to create a binary image.
>>>
>>> IJ.run(imp, "Convert to Mask", " background=Dark black")
>>>
>>> applies one of the automatic threshholding methods, (even though I
>>> removed that option from the argument list).
>>>
>>> I tried also, ip.setBinaryThreshold(), but it does not appear to do
>>> what I want (I am not quite sure what it does)
>>>
>>> How are thresholds used to create a binary image?
>>>
>>> Thanks again in advance
>>> --aryeh
>>>
>>
>

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how to apply theshholds ot image

MChapman
In reply to this post by Aryeh Weiss
Aryeh,

I think I ran into the same issue as you (wanting to use my own thresholding
values instead of the automatic thresholds).

While using the macro recorder, in the threshold menu, click on "set" and
specify you values.  This will expose another function in the recorder that
will let you set the values in the script.

Mike




--
Sent from: http://imagej.1557.x6.nabble.com/

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: how to apply theshholds ot image

Aryeh Weiss
Thank you for your reply.
My problem was not how to set the thresholds, for which I used the
setThreshold method in ImageProcessor.
However, I mistakenly thought that "Convert to Mask" was not using those
thresholds -- turns out I was wrong bout that.

I still wonder if there is a way to apply the thresholds without using
the global IJ.run to run the "Convert to Mask" command. Something like
ImageProcessor.applyThresholds() .

--aryeh

On 28/09/2017 15:25, MChapman wrote:

> Aryeh,
>
> I think I ran into the same issue as you (wanting to use my own thresholding
> values instead of the automatic thresholds).
>
> While using the macro recorder, in the threshold menu, click on "set" and
> specify you values.  This will expose another function in the recorder that
> will let you set the values in the script.
>
> Mike
>
>
>

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051

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