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
Binary ImageNow 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
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)
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)
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)
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.
Similar Reads
Binary Registers Data For computers, it is as difficult to understand words and numbers as humans can, computers need a specific language to understand it. To make the complicated data understood by computers, binary coding is used. In binary, data is represented with the combination of two digits, either 0 or 1. To stor
9 min read
Binary Division Binary division is a mathematical operation that involves dividing two binary numbers, which are numbers composed of only 0's and 1's. Binary division is similar to decimal division, except that the base of the number system is 2 instead of 10.In this article, we will learn about Binary Numbers, Bin
10 min read
What is Binary Code? Two States the digital systems, and computers are written in its basic language. Binary code It is a digital encoding of an analog signal wherein it uses a two-symbol system, â0â and â1â, to represent text, computer processor instructions, or any other data. A bit short for "binary digit", is the ba
9 min read
Binary Number System The Binary Number System, also known as the base-2 system, uses only two digits, '0' and '1', to represent numbers. It forms the fundamental basis for how computers process and store data.For example, the binary number (11001)â corresponds to the decimal number 25.The word binary is derived from the
6 min read
Binary Multiplication Binary Multiplication is a mathematical operation that involves multiplying two binary numbers, which are numbers composed of only 0s and 1s. Binary multiplication is similar to decimal multiplication, except that the base of the number system is 2 instead of 10. Binary multiplication involves multi
8 min read