且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获得HSV和LAB颜色空间?

更新时间:2023-01-27 11:21:22

OpenCV带来范围(0,255)范围内所有颜色空间的输出. .

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

因此,要使HSV达到其范围:

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

与Lab颜色空间类似:

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

参考

添加支票,真实颜色转换, python代码:

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