outImg,outThreshold = | otsuThresholdImg (inImg) |
scalar = | otsuThresholdImg (inImg,outBinImg) |
outImg,outThreshold = | otsuThresholdImg (inImg,histogram) |
scalar = | otsuThresholdImg (inImg,histogram,outBinImg) |
Compute the Otsu threshold of an input image, and binarize the image using this threshold.
Otsu's method is used to automatically perform the binarization of an input image. It assumes that the image is bi-modal (pixel intensities can be distinguished in 2 classes: background pixels and foreground pixels). It then calculates the optimal threshold that separates these 2 classes, by minimizing their intra-class variance. In this implementation, the alternate method (maximizing the inter-classes variance) is used. It has the advantage to be faster than the first method.
On output, binarized image values are given by:
with the threshold computed from Otsu's method.
Input and output images must have same size and buffer type.
Here is an example of automatic otsu image thresholding applied to a 8-bits grey level image (on ouput, computed threshold equals 118) :