We will start by using OpenCV techniques with the grayscale image:
- Start by importing the matplotlib (mpimg and pyplot), numpy, and openCV libraries as follows:
In[1]: import matplotlib.image as mpimg
In[2]: import matplotlib.pyplot as plt
In[3]: import numpy as np
In[4]: import cv2
- Next, read the image and convert it into a grayscale image:
In[5]: image_color = mpimg.imread('Image_4.12.jpg')
In[6]: image_gray = cv2.cvtColor(image_color, cv2.COLOR_BGR2GRAY)
In[7]: plt.imshow(image_gray, cmap = 'gray')
We have already seen what the image looks like; it is the grayscale conversion of the color image:
Fig 4.13: Color image to grayscaleÂ
- Now we will check the shape of the image, which is (515, 763):
In[8]: image_gray.shape
Out[8]: (515, 763)
- Now we will apply a filter to identify the white pixels of the image:
In[9]: image_copy = np.copy(image_gray)
# any value that is not white colour
In[10]: image_copy[ (image_copy...