Sometimes images seem like good candidates for thresholding, because of the content they contain. But not all algorithms work all the time. Consider the following image of a stamp, and its grayscale equivalent. It has a lot of extremely fine detail, and might be a candidate for localized thresholding?
Now consider the histogram of the grayscale image. There are three peaks in the histogram, one near the lower intensities representing the background of the stamp, and the overlapped bimodal peak at the opposite end, representing the stamp.
Below are the results of four thresholding algorithms applied to the image.
Here we can see the failure of both global Otsu, and local Bernsen. Otsu fails because of the trimodal nature of the histogram – the threshold value calculated is 108. The unlikely algorithms that succeed are Bernsen (local) and the percentile algorithm (global). The latter uses a fraction of foreground pixels set to 50%, making the threshold equal to 176.
Now if the contrast in the grayscale image is stretched to remove the background, and the intensities redistributed, a bimodal histogram is created.
If this contrasted stretched image is then thresholded using Otsu, a better binary image appears, with a threshold value of 126.