-
Notifications
You must be signed in to change notification settings - Fork 276
/
tutorial44_a_note_about_color_spaces.py
71 lines (40 loc) · 1.39 KB
/
tutorial44_a_note_about_color_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#Video Playlist: https://www.youtube.com/playlist?list=PLHae9ggVvqPgyRQQOtENr6hK0m1UquGaG
"""
Color spaces
RGB - Red, Green, Blue
HSV - Hue, Saturation, Value
LAB - Lightness, A (Green to red), B (Blue to Yellow)
"""
import cv2
from skimage import io
#Needs 8 bit, not float.
color_opencv = cv2.imread('images/Osteosarcoma_01.tif', 1)
gray_opencv = cv2.imread('images/Osteosarcoma_01.tif', 0)
color_skimage = io.imread('images/Osteosarcoma_01.tif', as_gray=False)
gray_skimage = io.imread('images/Osteosarcoma_01.tif', as_gray=True)
B, G, R = cv2.split(color_opencv)
cv2.imshow("Original", color_opencv)
cv2.imshow("B", B)
cv2.imshow("G", G)
cv2.imshow("R", R)
cv2.waitKey(0)
cv2.destroyAllWindows()
##########################################################
hsv_image = cv2.cvtColor(color_skimage, cv2.COLOR_BGR2HSV)
h, s, v = cv2.split(hsv_image)
cv2.imshow("Original", color_opencv)
cv2.imshow("h", h)
cv2.imshow("s", s)
cv2.imshow("v", v)
cv2.waitKey(0)
cv2.destroyAllWindows()
#####################################
lab_image = cv2.cvtColor(color_skimage, cv2.COLOR_BGR2LAB)
L, A, B = cv2.split(lab_image)
cv2.imshow("Original", color_opencv)
cv2.imshow("L", L)
cv2.imshow("A", A)
cv2.imshow("B", B)
cv2.waitKey(0)
cv2.destroyAllWindows()
############################################