ExpErimEnt - 08
Aim: To study and perform the Bit-plane slicing of image.
Software Required: Google colaboratory.
Theory:
Bit-plane slicing is a technique used in digital image processing to analyze the
individual bits in the pixel values, where each pixel is represented by a binary
number, commonly using 8 bits for grayscale images or 24 bits for color images.
The process of bit-plane slicing involves separating and displaying each bit of the
pixel values as a separate image. It creates a set of binary images, each
corresponding to a single bit of the original pixel values. The most significant bit
(MSB) is the leftmost bit, representing the highest order bit; the least significant
bit (LSB) is the rightmost bit, representing the lowest order bit.
Code and Output:
import cv2
import numpy as np
import matplotlib.pyplot as plt
img=cv2.imread("/content/Arslan img.jpg",0)
#Iterate over each pixel and change pixel value to binary using np.
lst=[]
for i in range (img. shape [0]) :
for j in range (img. shape [1]) :
lst.append (np. binary_repr (img [1] [j] ,width=8)) # width = no. of bits
eight_bit_img = (np. array([int (i[0]) for i in lst] ,dtype = np. uint8) * 128).reshape (img.
shape [0], img. shape [1])
seven_bit_img = (np. array ([int (i[1]) for i in lst] ,dtype = np.uint8) * 64).reshape (img.
shape [0], img. shape [1])
six_bit_img = (np. array ([int (i[2]) for i in lst] ,dtype = np.uint8) * 32).reshape (img. shape
[0], img. shape [1])
five_bit_img = (np. array ([int (i[3]) for i in lst] ,dtype = np.uint8) * 16).reshape (img. shape
[0], img. shape [1])
four_bit_img = (np. array ([int (i[4]) for i in lst] ,dtype = np.uint8) * 8).reshape (img. shape
[0], img. shape [1])
three_bit_img = (np. array ([int (i[5]) for i in lst] ,dtype = np.uint8) * 4).reshape (img. shape
[0], img. shape [1])
two_bit_img = (np. array ([int (i[6]) for i in lst] ,dtype = np.uint8) * 2).reshape (img. shape
[0], img. shape [1])
one_bit_img = (np. array ([int (i[7]) for i in lst] ,dtype = np.uint8) * 1).reshape (img. shape
[0], img. shape [1])
# Plotting
fig = plt.figure(figsize=(16 , 10))
# Original Image
fig.add_subplot(3, 3, 1)
plt.imshow(img,cmap='gray')
plt.axis("off")
plt.title("Original Image")
fig.add_subplot(3, 3, 2)
plt.imshow(eight_bit_img,cmap='gray')
plt.axis("off")
plt.title("8 bit image")
fig.add_subplot(3, 3, 3)
plt.imshow(seven_bit_img,cmap='gray' )
plt.axis("off")
plt.title("7 bit image")
fig.add_subplot(3, 3, 4)
plt.imshow(six_bit_img ,cmap='gray')
plt.axis("off")
plt.title("6 bit image")
fig.add_subplot(3, 3, 5)
plt.imshow(five_bit_img,cmap='gray' )
plt.axis("off")
plt.title("5 bit image")
fig.add_subplot(3, 3, 6)
plt.imshow(four_bit_img,cmap='gray' )
plt.axis("off")
plt.title("4 bit image")
fig.add_subplot(3, 3, 7)
plt.imshow(three_bit_img,cmap='gray' )
plt.axis("off")
plt.title("3 bit image")
fig.add_subplot(3, 3, 8)
plt.imshow(two_bit_img ,cmap='gray')
plt.axis("off")
plt.title("2 bit image")
fig.add_subplot(3, 3, 9)
plt.imshow(one_bit_img ,cmap='gray')
plt.axis("off")
plt.title("1 bit image")
Result : We have studied and performed Bit-plane Slicing of image.