http://imagej.273.s1.nabble.com/setting-auto-threshold-in-a-macro-tp3687423p3687427.html
> On Jul 29, 2010, at 2:54 PM, Crowell Elizabeth wrote:
>
>
>> Rasband, Wayne (NIH/NIMH) [E] a écrit :
>>
>>> On Jul 29, 2010, at 1:44 PM, Crowell Elizabeth wrote:
>>>
>>>
>>>
>>>> Hello group members,
>>>>
>>>> I have yet another question for you.
>>>> I am trying to write a macro (attached) that will select particles of a
>>>> defined size in my images (in this case, nuclei). I make a projection
>>>> of my stack, try to auto threshold it with a dark background, make it
>>>> binary, and run analyze particles.
>>>>
>>>> When I adjust the threshold manually, clicking the auto button with the
>>>> "dark background" box checked gives me exactly the result desired.
>>>> Therefore I think my images are of sufficient quality to let me
>>>> threshold them automatically.
>>>>
>>>> However, the auto threshold function is not functioning properly in the
>>>> macro. The thresholding is not restrictive enough (it takes a wide
>>>> spectrum of gray values around the particles that just represent
>>>> noise). When I put in a wait function and run the macro while batchmode
>>>> = false, I can see that in the threshold window, the "dark background"
>>>> box is never checked. If I run the macro with the waitForUser line, the
>>>> image is thresholded correctly initially, and then changes to an
>>>> incorrect, non-restrictive threshold when the dialog box appears. So
>>>> there is something really fishy going on!
>>>>
>>>> How can I instruct ImageJ to adjust the threshold automatically with a
>>>> dark background? Apparently, the line "setAutoThreshold("Default
>>>> dark");" is not sufficient.
>>>>
>>>> Thank you in advance for your help,
>>>>
>>>>
>>> What version of ImageJ are you using? There are two recent setAutoThreshold() bug fixes listed in the release notes (
http://rsbweb.nih.gov/ij/notes.html).
>>>
>>> v1.44c:
>>> Fixed a bug in the setAutoThreshold() macro function that caused the threshold level to be one less than the level set by the "Threshold" widget when "Dark background" was enabled.
>>>
>>> v1.43u:
>>> Fixed a bug that caused the setAutoThreshold() macro function to not work correctly with 16 and 32 bit images that were not using the default display range.
>>>
>>> -wayne
>>>
>>>
>> Now I am using version 1.44d, but I still have the bugs. I also added
>> back the lines I had commented that convert the image to 8-bit before
>> thresholding. There is still the exact same behavior. If it helps, I
>> have posted an example problematic image at the site below. Only 2 out
>> of 6 images are properly thresholded by the macro.
>>
>>
http://www.woofiles.com/dl-201950-Zdk2DrwO-MAX1038w3DAPI.tif>>
>
> The ImageJ 1.44e8 daily build fixes a bug that caused setAutoThreshold("Default dark") to sometimes not generate the expected threshold for an image with a sharp peak in its histogram.
>
> -wayne
>
>
> -wayne
>
----------------------------------------------------------------------