Page 475 - AI Ver 3.0 class 10_Flipbook
P. 475

To print the image in grayscale the change in imshow() function will be using cmap parameter:
                 img = cv2.imread('D:/Flower.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
                    [1]:  import cv2 # import OpenCV
                          from matplotlib import pyplot as plt # import matplotlib
                          import numpy as np # import numpy
                          img = cv2.imread('D:/Flower.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
                          plt.title('Flowers') #Display this title on the top of the image
                          plt.axis('off')
                          plt.show()



















                 Image Processing Operations

                 Let us learn about some of the functions we can perform over images.

                    [1]:  img = cv2.imread('D:/RGB.png')
                          print(img.shape)
                          (565, 598, 3)

                      It means that the image has a height of 480 pixels, width of 480 pixels and 3 means RGB combination of
                    colours.
                    [1]:  img = cv2.imread('D:/RGB.png')
                          print (img.min())
                          print (img.max())
                          0
                          255

                                                                                    Advance Python (Practical)  473
   470   471   472   473   474   475   476   477   478   479   480