Page 263 - AI Ver 1.0 Class 10
P. 263
Image Processing Operations
Let us learn about some of the functions we can perform over images.
● img = cv2.imread(‘buddy.jpg’)
print(img.shape)
The above code shows the output as:
(480, 480, 3)
It means that the image has a height of 480 pixels, width of 480 pixels and 3 means RGB combination of
colours.
● img = cv2.imread(‘buddy.jpg’)
print (img.min())
print (img.max())
The above code shows the output as:
0
255
It means that the above image has a minimum pixel value as 0 and maximum pixel value as 255.
• The pixel value by its row and column coordinates of an image can be accessed by using img[y
coordinate,x,coordinate,channels]. For the BGR image, it returns an array of Blue, Green, Red
values. For grayscale images, just corresponding intensity is returned. For example:
✶ [B,G,R]= img[25, 40]
print(‘R=’, R, ‘G=’, G, ‘B=’,B)
It will display the Blue, Green, Red colour code between 0 to 255 of pixel at 25 row and 40 column of
th
an image taken with imread().
✶ blue=img[25,40,0] #traps only blue code
green=img[25,40,1] #traps only green code
red=img[25,40,2] #traps only red code
Computer Vision 261

