What's the best way to automatically figure out the best threshold for converting a grayscale image to black and white? I can figure out pretty good threshold values by hand, but I would like to automate choosing the threshold value.
Edit: I've been reading a bit about this problem, and by looking at the histogram for the image can help, e.g. if the image has a bi-modal histogram then choosing a threshold between the modes seems to be reasonably. However, for multi-modal, or flat histograms, it appears more complicated. So I think I have some more reading to do. Thanks to everyone who replied!
0.5 usually ends up loosing a lot of information unless the original image is extremely bright. In fact, any absolute threshold will mess up one kind of images or another.
A better method would be to make a histogram of luminosities and choose a threshold near the mode. This should work better on most images than any absolute threshold.
I would look into an adaptive thresholding algorithm. One such, which is not very hard to implement is Otsus method.
It works by assuming that you have foreground pixels and background pixels and attempts to find the best separation of them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With