简体   繁体   English

opencv python中每个通道的HSV,YCrCb和LAB颜色空间中的像素值范围是多少

[英]What is the range of pixel values in HSV , YCrCb, and LAB color spaces for each channel in opencv python

What is the range of values in HSV, YCrCb and LAB color spaces in opencv python. opencv python中HSV,YCrCb和LAB颜色空间的值范围是多少? For example in RGB, R -> 0-255, G -> 0-255 and B -> 0-255. 例如在RGB中,R-> 0-255,G-> 0-255和B-> 0-255。 What is the valid range for the mentioned color spaces. 提到的颜色空间的有效范围是多少?

Thanks 谢谢

The OpenCV documentation covers this completely. OpenCV文档完全涵盖了这一点。 Just to recap for your specific questions though, for an 8-bit image, converting from a BGR image with the following conversion codes will give you the following maximum values for each channel: 只是为了解决您的特定问题,对于8位图像,使用以下转换代码从BGR图像进行转换将为您提供每个通道的以下最大值:

  • COLOR_BGR2HSV --> [180, 255, 255]
  • COLOR_BGR2Lab --> [255, 255 255]
  • COLOR_BGR2YCrCb --> [255, 255 255]

There's an additional option for the various color transformations that do not get mapped to the full 255 values, generally by appending _FULL to the conversion code, so that they use the full range. 对于不映射到完整255个值的各种颜色转换,还有一个附加选项,通常是通过在转换代码后附加_FULL来使它们使用完整范围。

For eg, HLS and HSV colorspaces normally give the H (hue) channel values in [0, 360) to map 360 degrees of color on a color wheel. 例如,HLS和HSV色彩空间通常在[0, 360) 0,360)中给出H(色相)通道值,以将360度色彩映射到色轮上。 However, you cannot fit those values in a uint8 type, so instead OpenCV divides this value by 2 with COLOR_BGR2HSV or COLOR_BGR2HLS so that it fits, but this means you can only specify 180 separate hues in a uint8 image. 但是,您无法将这些值拟合为uint8类型,因此OpenCV将该值用COLOR_BGR2HSVCOLOR_BGR2HLS除以2以使其适合,但这意味着您只能在uint8图像中指定180个单独的色相。 But you could fit 255 distinct values, so instead, there exists the options COLOR_BGR2HSV_FULL and COLOR_BGR2HLS_FULL (and the inverses) to specify to use the full 255 range for the hue channel; 但是您可以容纳255个不同的值,因此,存在选项COLOR_BGR2HSV_FULLCOLOR_BGR2HLS_FULL (以及COLOR_BGR2HSV_FULL COLOR_BGR2HLS_FULL )可以指定将整个255范围用于色相通道。 so that 0 maps to 0, 255 maps to 360 degrees, and linearly spaced in between. 因此0映射到0,255映射到360度,并且两者之间呈线性间隔。

All of the available color codes can be seen under the ColorConversionCodes in the docs. 所有可用的颜色代码都可以在文档的ColorConversionCodes下看到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM