Horje
Binary Image

Digital image processing makes the use of algorithms that help us to extract essential features from the images. The aim of the digital image processing is to enhance image quality so that we can extract useful information which can be used later for further detailed studies. Pixel is the smallest unit in the image that has some color value. Regions of Interest are those areas on the image on which we can perform many operations related to any digital image processing.

What is Binary Image?

There are three categories of images out of which Binary image is mostly used in Image Processing. There are two colors present in binary images: black and white. Black denotes background and white denotes regions of interest. There are two pixel values : 0 is used to denote black while 1 is used to denote white.

How to Create a Binary Image?

To create a Binary image we use the thresholding. In thresholding, we define the threshold for the pixel value where we compare the image pixel value with the threshold value. The steps are as follows:

  • If the image is colored or in RGB format change it to grayscale image
  • Define a threshold value.
  • For each pixel present in the image, if the pixel value lies below the threshold value set that pixel value to 0 else 1.
  • The result is a binary image.

Operations on Binary Images

We can perform several Boolean operations like AND, OR, NOT and XOR. Other than those operations we can perform some advanced operations like Morphological Operations. This type of operations focus on the shape of the images. The task of morphological operations is to process the shapes of the foregrounds. Some are as follows

1. Dilation

Dilation is a technique that is used to add borders around the regions of interest or the objects whose pixel value is 1. This technique is used to fill the gaps or small holes that might be present between two or more objects. It first detects the objects and expands by adding the pixels of value 1.

Let us consider an image

flower-(1)
download-(6)

Binary Image

Now we are using OpenCV, a computer vision library to dilate our image. The code is as follows

Python
import cv2
import numpy as np
from google.colab.patches import cv2_imshow
# Load the binary image
image_path = '/content/flower.jpg'  # Replace with your image path
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
# Threshold the image to ensure it's binary
_, binary_image = cv2.threshold(image, 127, 255, cv2.THRESH_BINARY)

# Define the structuring element (kernel)
kernel_size = (5,5)  # Change the size as needed
kernel = np.ones(kernel_size, np.uint8)
#cv2_imshow(binary_image)
# Apply dilation
dilated_image = cv2.dilate(binary_image, kernel, iterations=1)


cv2_imshow(dilated_image)

The image after dilation is as follows

download-(5)

As we can see the folds present on the flower has been filled a compared to the original Binary image

2. Erosion

This operation works completely opposite of Dilation. The aim of this operation is to remove the additional pixels around the images. This technique is useful when we want to remove the noises from the image. The code is as follows:

Python
image_path = '/content/flower.jpg'  # Replace with your image path
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
# Threshold the image to ensure it's binary
_, binary_image = cv2.threshold(image, 90, 255, cv2.THRESH_BINARY)

# Define the structuring element (kernel)
kernel_size = (5,5)  # Change the size as needed
kernel = np.ones(kernel_size, np.uint8)
eroded = cv2.erode(binary_image, kernel, iterations=1)
cv2_imshow(eroded)
download-(7)

In erosion we can see that the background has become more prominent and that the dots that were present at the center of the flower has been removed.

3. Opening

This technique is basically combination of the above two techniques that is dilation and erosion. In this, erosion operation is performed then the dilation operation. It is used to smooth the curves along the boundaries by removing the additional pixels and fill up the necessary gaps using the dilation technique.

Python
image_path = '/content/flower.jpg'  # Replace with your image path
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
# Threshold the image to ensure it's binary
_, binary_image = cv2.threshold(image, 90, 255, cv2.THRESH_BINARY)

# Define the structuring element (kernel)
kernel_size = (5,5)  # Change the size as needed
kernel = np.ones(kernel_size, np.uint8)
opened = cv2.morphologyEx(binary_image, cv2.MORPH_OPEN, kernel)
cv2_imshow(opened)
download-(9)

As you can see that because of erosion technique being applied first, the background has become prominent and that excess pixels has been removed. Then with the help of dilation the lines present on the petals have been filled up.

4. Closing

Closing is just the opposite of Opening. In Closing dilation operation is first performed followed by erosion. This technique is useful to remove the small holes and the excess noise present.

Python
image_path = '/content/flower.jpg'  # Replace with your image path
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
# Threshold the image to ensure it's binary
_, binary_image = cv2.threshold(image, 90, 255, cv2.THRESH_BINARY)

# Define the structuring element (kernel)
kernel_size = (5,5)  # Change the size as needed
kernel = np.ones(kernel_size, np.uint8)
opened = cv2.morphologyEx(binary_image, cv2.MORPH_CLOSE, kernel)
cv2_imshow(opened)
download-(11)

In this we can see that all the gaps have been filled up. Then to make the petals prominent, erosion technique has been applied.

Advantages and Disadvantages of Binary Images

Advantages

  • It is broadly used because of its simplicity in computations.
  • Binary images require less computational time because for object the pixel value is 1 and for background it is 0.
  • It requires less memory because of black and white pixels.
  • We can reduce the noise present in the images using erosion operation.
  • We can extract essential features from the images quite easily.

Disadvantages

  • The binary images are often sensitive to thresholds.
  • Often there is loss of information. This is because small objects which do not satisfy the threshold criteria, is converted to black.
  • It is not useful in textual information as the morphological operations can remove the significant information.
  • Using Binary images for 3 dimensional purposes can be challenging.

Applications of Binary Images

  • Binary Images are widely used in Medical fields as it helps to conduct segmentation.
  • They are used in Optical Character Recognition(OCR) as it helps to separate textual data from the foreground.
  • Binary Images are useful as it helps to detect the patterns present in the image.
  • Since Binary images are simple to process they are used in object detection problems.
  • Binary Images are also used in real time embedded systems.
  • Since it has two color codes, these images are preferred in Deep Learning Models.
  • Binary images is used in biometric systems especially for iris recognition.

Conclusion

Binary Images are simple but they are powerful in the world of Image Processing. This is because one can extract useful information despite less color codes and can highlight regions of interest effectively.

Frequently Asked Questions on Binary Image-FAQ’S

Explain the difference between Binary image and grayscale image?

Binary images consist of pixels that have values either 0 or 1. Grayscale images on the other hand comprises different shades of grey ranging between values 0 to 255.

What techniques can we use to handle noise in images?

To handle the noise in images we can use morphological operations like erosion, closing and opening to remove the noise.

What are some advanced operations other than morphological operations?

Some other techniques include:

  • Hit-or-Miss Transform: To detect shapes of objects.
  • Thinning: Reduce the regions of interest to skeleton form.
  • Thickening: Expand objects without merging.
  • Pruning: Remove small thin lines or branches without distorting the shape of the object.



Reffered: https://www.geeksforgeeks.org


Electronics Engineering

Related
Applications of Full Wave Rectifier Applications of Full Wave Rectifier
Difference Between VLSI and Embedded Systems Difference Between VLSI and Embedded Systems
Arduino - PIR Sensor Arduino - PIR Sensor
What is a Serial Communications Interface (SCI)? What is a Serial Communications Interface (SCI)?
Applications of Logic Gates Applications of Logic Gates

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
24