1 Code For Converting RGB, Grayscale, and HSI Image: Author: Atik Ishrak October 1, 2024
1 Code For Converting RGB, Grayscale, and HSI Image: Author: Atik Ishrak October 1, 2024
1 Code For Converting RGB, Grayscale, and HSI Image: Author: Atik Ishrak October 1, 2024
October 1, 2024
plt . show ()
1
1.1 Input
2
Listing 2: Python Script: Image Conversion
import matplotlib . pyplot as plt
import numpy as np
from PIL import Image
# Create an image with LSB set to zero ( bit plane 0 set to zero )
lsb_ zero_ima ge = image_array & ~1 # Set LSB to 0 using bitwise AND
# Create an image with MSB set to zero ( bit plane 7 set to zero )
msb_ zero_ima ge = image_array & ~(1 << 7) # Set MSB to 0 using bitwise AND
3
2.1 Input: Cameraman.tf
4
2.3 Output: Image setting the LSB to zero and then MSB to zero
5
3.1 Input: Cameraman.tf
6
Listing 4: Python Script: Image Conversion
import numpy as np
import matplotlib . pyplot as plt
from PIL import Image
# Use the reference CDF to find the mapping for histogram specification
mapping = np . zeros (256)
for i in range (256):
ref_val = np . abs ( r e f e r e n c e _ c d f _ n o r m a l i z e d - o r i g i n a l _ c d f _ n o r m a l i z e d [ i ]). argmin ()
mapping [ i ] = ref_val
# Load the original and reference images and convert them to grayscale
orig inal_ima ge = np . array ( Image . open ( " / content / sample_data / cameraman . tif " ). convert ( " L " ))
r ef er en c e_ im ag e = np . array ( Image . open ( " / content / sample_data / canoe . tif " ). convert ( " L " ))
# Replace with any reference image
# Original image
ax1 . imshow ( original_image , cmap = ’ gray ’)
ax1 . set_title ( " Original ␣ Image " )
ax1 . axis ( ’ off ’)
# Reference image
ax2 . imshow ( reference_image , cmap = ’ gray ’)
ax2 . set_title ( " Reference ␣ Image " )
ax2 . axis ( ’ off ’)
plt . show ()
7
4.1 Input: Origial Image (cameraman.tf ) and Reference Image (canoe.ttf )
Figure 3: Caption
8
from PIL import Image
plt . show ()
Figure 4: Caption
9
5.2 Output: FFT of cameraman.tf
# Perform Erosion
erosion = cv2 . erode ( image , kernel , iterations =1)
# Perform Dilation
dilation = cv2 . dilate ( image , kernel , iterations =1)
# Display Erosion
10
axes [0 , 0]. imshow ( erosion , cmap = ’ gray ’)
axes [0 , 0]. set_title ( ’ Erosion ’)
axes [0 , 0]. axis ( ’ off ’)
# Display Dilation
axes [0 , 1]. imshow ( dilation , cmap = ’ gray ’)
axes [0 , 1]. set_title ( ’ Dilation ’)
axes [0 , 1]. axis ( ’ off ’)
# Display Opening
axes [1 , 0]. imshow ( opening , cmap = ’ gray ’)
axes [1 , 0]. set_title ( ’ Opening ’)
axes [1 , 0]. axis ( ’ off ’)
# Display Closing
axes [1 , 1]. imshow ( closing , cmap = ’ gray ’)
axes [1 , 1]. set_title ( ’ Closing ’)
axes [1 , 1]. axis ( ’ off ’)
Figure 5: Caption
11
6.2 Output: Morphological Operation of the cameraman.tf
Figure 6: Caption
12