-
Notifications
You must be signed in to change notification settings - Fork 0
/
spaces.py
40 lines (24 loc) · 897 Bytes
/
spaces.py
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
import cv2 as cv
import matplotlib.pyplot as plt
img = cv.imread(r"C:\Users\monta\Desktop\Opencv\photos\ali.jpg")
#cv.imshow("Image", img)
plt.imshow(img)
plt.show() # the difference between these to methods opencv displays bgr images matplotlib has no idea about bgr it will dispaly it as an rgb "
# converting the image to gray scale
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
cv.imshow("Gray", gray)
# BGR to HSV
hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
cv.imshow("HSV", hsv)
# BGR to RGB
rgb = cv.cvtColor(img, cv.COLOR_BGR2RGB)
cv.imshow("RGB", rgb)
plt.imshow(rgb)
plt.show() # !!! matplotlib works with RGB !!!
# BGR to L*a*b
lab = cv.cvtColor(img, cv.COLOR_BGR2LAB)
cv.imshow("lab", lab)
# you cannot convert grayscale to hsv directly: grayscale to bgr and then bgr to hsv
hsv_bgr = cv.cvtColor(hsv, cv.COLOR_HSV2BGR)
cv.imshow("hsv --> bgr", hsv_bgr)
cv.waitKey(0)