This method first estimates a cutoff, then calculates the distribution of pixels within the cutoff in order to determine the final threshold.
I have found this method to work quite well for fluorescence microscopy images in which most of the pixels are background and the background is approximately gaussian.
There are a couple parameters than can be used to tune the threshold.
Jake Hughey (2020). Simple Image Thresholding (https://www.mathworks.com/matlabcentral/fileexchange/44291-simple-image-thresholding), MATLAB Central File Exchange. Retrieved .
Slight refinement to only use pixels below the cutoff for calculating the threshold.
Updated the description.
Fixed bug caused by mode not accepting integers.
Inspired by: Ridler-Calvard image thresholding