Encoding images in the HSV and HLS space

However, ever since the RGB color space was created, people have realized that it is actually quite a poor representation of human vision. Therefore, researchers have developed many alternative representations. One of them is called HSV (short for Hue, Saturation, and Valueand the other one is called HLS (Hue, Lightness, and Saturation). You might have seen these color spaces in color pickers and common image editing software. In these color spaces, the hue of the color is captured by a single hue channel, the colorfulness is captured by a saturation channel, and the lightness or brightness is captured by a lightness or value channel.

In OpenCV, an RGB image can easily be converted into the HSV color space using cv2.cvtColor:

In [5]: img_hsv = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2HSV)

The same is true for the HLS color space. In fact, OpenCV provides a whole range of additional color spaces, which are available via cv2.cvtColor. All we need to do is to replace the color flag with one of the following:

  • HLS using cv2.COLOR_BGR2HLS
  • LAB (lightness, green-red, and blue-yellow) using cv2.COLOR_BGR2LAB
  • YUV (overall luminance, blue luminance, and red luminance) using cv2.COLOR_BGR2YUV
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset