OpenCV HLS color space range

blue picture blue · Oct 28, 2015 · Viewed 8.3k times · Source

Look my code, why the second line in console is 170 10 121.

H is 170, S is 10, but why L is 121. Because L must be less than 100:

enter image description here

Answer

Miki picture Miki · Oct 28, 2015

As you can see in the OpenCV documentation

In case of 8-bit and 16-bit images, R, G, and B are converted to the floating-point format and scaled to fit the 0 to 1 range.

If H<0 then H=H+360. On output 0 <= L <= 1, 0 <= S <= 1, 0 <= H <= 360.

The values are then converted to the destination data type:

  • 8-bit images: S,L are scaled in [0,255], H=H/2, so H range is in [0-180]
  • 32-bit (float) images: value are left as is.

So, in the end, for CV_8U images you'll have values in:

H in [0,180]
S,L in [0,255]