Thresholding a label map generated by a plugin



Hello everyone!

I am basically using a Hough transform plugin to detect some droplets. As output, I get a labeled map which has 0 as background and the detected circles have their labels as intensities.

I want to convert this into binary to perform particle analysis on the same but the thresholding doesn’t work.

centroid_map = WindowManager.getImage("Centroid map")
IJ.setThreshold(centroid_map, 0.5, 65536);, "Convert to Mask", "");

This method when I perform manually selects all the circles but when I convert to mask, eats away a few circles. Additionally, the particle analyzer simply says “No particles detected, threshold 255-255 may not be correct.”

The image

Any help/ suggestions?


In my experience, ImageJ has a problem thresholding 16-bit images. As a result, I did the following to convert it to a mask using the contrast tool instead:

setMinAndMax(0, 1);
run(“Make Binary”);

Hope this helps,
Ben Smith


Thank you Ben! Actually, this seems to be the only workaround now. And yes, I also recently experienced this issue of ImageJ not thresholding 16-bit images correctly. I follow the same idea of converting to 8-bit and then doing the thresholding which seems to work fine.

Thanks a lot once again!


This is only true for the interactive thresholding, because the (8-bit) threshold overlay can differ from the actual value of the current threshold in 16-bit images.

See also:

If you use the macro recorder (in Javascript or Java mode) to get the required code while setting the threshold manually in the Threshold dialog, it will record setRawThreshold here. The following Groovy script works as expected and keeps all the circles:

#@ ImagePlus centroid_map

import ij.IJ
import ij.Prefs

IJ.setRawThreshold(centroid_map, 1, 65535, null);
Prefs.blackBackground = true;, "Convert to Mask", "");