Thresholding a label map generated by a plugin

fiji
imagej
segmentation
python

#1

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);
IJ.run(centroid_map, "Convert to Mask", "");
centroid_map.show()

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 https://cloud.mpi-cbg.de/index.php/s/ruVDeuaFVp7KiCS

Any help/ suggestions?


#2

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(“8-bit”);
run(“Make Binary”);

Hope this helps,
Ben Smith


#3

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!


#4

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;
IJ.run(centroid_map, "Convert to Mask", "");