What is the range of values in HSV, YCrCb and LAB color spaces in opencv python. For example in RGB, R -> 0-255, G -> 0-255 and B -> 0-255. What is the valid range for the mentioned color spaces.
Thanks
The OpenCV documentation covers this completely. 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:
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.
For e.g., HLS and HSV colorspaces normally give the H (hue) channel values in [0, 360)
to map 360 degrees of color on a color wheel. 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. 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; so that 0 maps to 0, 255 maps to 360 degrees, and linearly spaced in between.
All of the available color codes can be seen under the ColorConversionCodes in the docs.