What is multi-Otsu thresholding?
Multi-Otsu thresholding is an extension of Otsu’s thresholding method, which is used to segment an image into multiple classes or regions based on pixel intensity values. While Otsu’s method finds a single threshold to divide the image into two classes (typically foreground and background), multi-Otsu thresholding extends this to divide the image into more than two classes or regions, effectively segmenting the image into multiple levels of intensity. This is particularly useful when we have an image with multiple objects or regions with distinct intensity levels.
In multi-Otsu thresholding, the image is divided into
The threshold_multiotsu() method
The syntax of the threshold_multiotsu() method is given below:
In Skimage, the threshold_multiotsu() method takes 4 parameters:
image: The first parameter is a grayscale input image.classes: The second parameter is the number ofclasses to be thresholded. The default value of these classes is 3. This is an optional parameter.nbins: The third parameter is the number of bins used to calculate the histogram. This is also an optional parameter.hist: The fourth parameter is the histogram from which to determine the threshold. If nohistis provided, then this function computes it from the image. This is also an optional parameter.
Note: The
threshold_multiotsu()method only takes a grayscale image. If we have a color image, then we convert it to grayscale using thergb2gray()method before applying the multi thresholding algorithm.
Let’s understand multi-Otsu thresholding with the help of the following examples.
Example with 3 classes
In the following example, we use three classes, which means the input image is thresholded into three classes:
Code explanation
Lines 1–6: We import the required libraries.
Line 9: We load a
cameraimage that is available in Skimage.Line 13: We generate thresholds using the
threshold_multiotsu()method and assign the thresholds to thethresholdValuesvariable.Line 15: We generate a number of regions based on the
thresholdValuesand assign them to thenumber OfRegionsvariable.Lines 18–34: We display the original image, a histogram of the original image (with
3classes), and the thresholded image.
Example with 4 classes
In the following example, we use four classes, which means the input image is thresholded into four classes:
Code explanation
Lines 1–6: We import the required libraries.
Line 9: We load a
cameraimage that is available in Skimage.Line 13: We generate thresholds using the
threshold_multiotsu()method and assign the thresholds to thethresholdValuesvariable.Line 15: We generate a number of regions based on the
thresholdValuesand assign them to thenumber OfRegionsvariable.Lines 18–34: We display the original image, a histogram of the original image (with
4classes), and the thresholded image.
Free Resources