-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path107openCVChannel.py
More file actions
42 lines (32 loc) · 1.07 KB
/
107openCVChannel.py
File metadata and controls
42 lines (32 loc) · 1.07 KB
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
38
39
40
41
42
import cv2
import numpy as np
print("OpenCV version:")
print(cv2.__version__)
img = cv2.imread("nomadProgramerIcon.png")
print("width: {} pixels".format(img.shape[1]))
print("height: {} pixels".format(img.shape[0]))
print("channels: {}".format(img.shape[2]))
(height, width) = img.shape[:2]
center = (width // 2, height // 2)
cv2.imshow("nomadProgramer", img)
(Blue, Green, Red) = cv2.split(img)
cv2.imshow("Red Channel", Red)
cv2.imshow("Green Channel", Green)
cv2.imshow("Blue Channel", Blue)
cv2.waitKey(0)
zeros = np.zeros(img.shape[:2], dtype = "uint8")
cv2.imshow("Red", cv2.merge([zeros, zeros, Red]))
cv2.imshow("Green", cv2.merge([zeros, Green, zeros]))
cv2.imshow("Blue", cv2.merge([Blue, zeros, zeros]))
cv2.waitKey(0)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow("Gray Filter", gray)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
cv2.imshow("HSV Filter", hsv)
lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
cv2.imshow("LAB Filter", lab)
cv2.waitKey(0)
BGR = cv2.merge([Blue, Green, Red])
cv2.imshow("Blue, Green and Red", BGR)
cv2.waitKey(0)
cv2.destroyAllWindows()