Binarization of Digital Images Using Otsu Method in MATLAB


In digital image processing, the process of transforming a color image or a grayscale image into a binary image is referred to as binarization of the image. In a binary image, the image pixels are represented using binary values i.e., 0 and 1, where 0 represents the black pixel and 1 represents the white pixel.

Binarization is an efficient technique to simplify the image analysis and it also helps in extracting important characteristics of the image.

Process of Binarization of Digital Images

The process of binarization of a digital image is based on the use of a threshold value to manipulate the pixels of the original image to obtain a binary image.

In this process, the pixels of the image having a pixel value above the threshold value are set to 1 i.e., white and the pixels with a value less than the threshold value are set to 0 i.e., black.

Purpose of Binarization of Digital Images

Binarization of digital images can have several purposes. Some common uses of binarization in digital image processing are described below −

  • Image Segmentation − Binarization divides the original image into separate regions depending on the specified properties, this makes the process of image segmentation simpler.

  • Object Detection − Binarization also simplifies the process of object detection and recognition.

  • Property Extraction − Binarization can also be applied to a digital image to extract its properties and features such as patterns, edges, etc.

  • Image Compression − A digital image can be easily compressed through the binarization, as it is quite easier to encode a binary image.

  • Optical Character Recognition − Binarization converts digital images into binary image, which can be used to implement OCR algorithms to recognize characters optically.

Thresholding Techniques for Binarization of Digital Images

Depending on the properties of a digital image and desired output, the following are some common thresholding techniques used for binarization of digital images −

  • Global Thresholding − When a single threshold value is applied to the entire image for its binarization, then such a thresholding technique is termed as global thresholding.

  • Adaptive Thresholding − In this thresholding technique, different threshold values are applied to the image based on the local properties of regions of the image.

  • Otsu's Method − It is a thresholding technique in which an optimal thresholding value is determined automatically to perform binarization.

In this article, we will discuss binarization of digital image using the Otsu Method in MATLAB.

Binarization of Digital Images Using Otsu Method

In MATLAB, binarization of digital image using Otsu method is an image processing technique that automatically calculate an optimal threshold value.

MATLAB provides a built-in function 'graythresh' to compute the optimal threshold value to perform the binarization of the digital image.

The step-by-step process to perform binarization of a digital image using Otsu method in MATLAB is explained below −

  • Step (1) − Read the input image.

  • Step (2) − Convert the input image to grayscale.

  • Step (3) − Calculate the Otsu's threshold value using the 'graythresh' function.

  • Step (4) − Perform binarization of the image using the 'imbinarize' function.

  • Step (5) − Display the output binary image.

Hence, the binarization of a digital image using Otsu method is a straightforward process.

Example

Now, let us discuss the implementation of a MATLAB program to perform binarization of a digital image using Otsu method.

% Read the input image
img = imread('path_to_grayscale_image.jpg');

% Convert the input image to grayscale image
grayimg = rgb2gray(img);

% Calculate the Otsu threshold value
th = graythresh(grayimg);

% Perform the Binarization of the image using the threshold value
binaryimg = imbinarize(grayimg, th);

% Display the original image and the binarized image
figure;
subplot(1, 2, 1); imshow(img); title('Original Image');
subplot(1, 2, 2); imshow(binaryimg); title('Otsu Binarized Image');

Output

Code Explanation

In this MATLAB program, we start by reading the input digital image using the 'imread' function and store it in a variable 'img'. Then, we convert the RGB image to grayscale using the 'rgb2gray' function and store in a variable 'grayimg'.

Next, we compute the Otsu threshold value using the 'graythresh' function and store it in a variable 'th'. After that we use this threshold value 'th' to perform binarization of the image, for this we use the 'imbinarize' function.

Finally, we display the input digital image and the binary image side by side using the 'imshow' function.

Conclusion

In MATLAB, we can use the built-in function 'graythresh' to calculate the threshold value for binarization of a digital image. We have explained the concept in the above sections of this article. You can try the above given MATLAB code with your own image, just by replacing the image address in 'imread' function with your image's address.

Updated on: 05-Sep-2023

88 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements