-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGettingAndSettingGray.py
More file actions
37 lines (27 loc) · 910 Bytes
/
GettingAndSettingGray.py
File metadata and controls
37 lines (27 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import cv2
grayImg=cv2.imread('images/logo.png', cv2.IMREAD_GRAYSCALE)
dimensions=grayImg.shape
print(dimensions)
(h, w)=grayImg.shape
print("Dimensions of the image - Height: {}, Width: {}".format(h, w))
totalNumberOfPixels=grayImg.size
print("Total number of elements: {}".format(totalNumberOfPixels))
print("Total number of elements: {}".format(h*w))
imageDtype=grayImg.dtype
print("Image datatype: {}".format(imageDtype))
cv2.imshow("original image", grayImg)
cv2.waitKey(0)
i=grayImg[6, 40]
print("Pixel at (6,40) - Intensity: {}".format(i))
grayImg[6, 40]=0
i=grayImg[6, 40]
print("Pixel at (6,40) - Intensity: {}".format(i))
topLeftCorner=grayImg[0:50, 0:50]
cv2.imshow("top left corner original", topLeftCorner)
cv2.waitKey(0)
grayImg[20:70, 20:70]=topLeftCorner
cv2.imshow("modified image", grayImg)
cv2.waitKey(0)
grayImg[0:50, 0:50]=255
cv2.imshow("modified image", grayImg)
cv2.waitKey(0)