How to get HSV and LAB color space?

ぃ、小莉子 提交于 2019-12-05 23:17:58

OpenCV brings the output of all the color spaces in the range (0, 255) Note: This is Mat type dependent, assuming 8UC3 here.

So, to bring HSV to its range :

H(HSV original) = H(OpenCV) * 2.0
S(HSV original) = S(OpenCV) * 100/255.0

V(HSV original) = V(OpenCV) * 100/255.0

similarly for Lab color space :

L(Lab original) = L(OpenCV) * 100/255.0

a(Lab original) = a(OpenCV) - 128

b(Lab original) = b(OpenCV) - 128

Reference

Adding a check, real color conversion, python code:

image_rgb = np.zeros((300, 300, 3), np.uint8)
image[:] = (255, 255, 255)

img_hsv = cv2.cvtColor(image_rgb, cv2.COLOR_RGB2HSV)
h = img_hsv[100, 100, 0]
s = img_hsv[100, 100, 1]
v = img_hsv[100, 100, 2]
print h , s , v
>>> 0 0 255
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!