Page 262 - AI Ver 1.0 Class 10
P. 262
Step 2 Display a 2D image using the imread()function of cv2. Thus, the complete code that appears in
Jupyter Notebook will be:
Did you notice that the colour of the image above is not presented properly? This is because OpenCV represents
the images in BGR (Blue Green Red) combination instead of RGB (Red Green Blue) so the blue color in images
dominates. We will use the following code in imshow()function for converting from BGR to RGB:
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
So, the new code with the new display will be:
To print the image in grayscale the change in imshow() function will be using cmap parameter:
img = cv2.imread(‘D:\Buddy.jpg’,0) #Load the image file with 0 parameter
#To open in grayscale mode
Plt.imshow(img, cmap = ‘gray’) #cmap=gray specifies color mapping as gray
260 Touchpad Artificial Intelligence-X

