Color Spaces and Thresholding

For the road images, we know that they’re all composed of red, green, and blue values or RGB. And in the previous medium article, we’ve used some combination of masking and color thresholds on these RGB values to pick out bright white lane pixels.

Binary Combo Image (Image by author)

And this lane detection can work well alongside gradient detection which relies on grayscale intensity measurements. However, RGB thresholding doesn’t work that well in images that include varying light conditions or when lanes are a different color like yellow. We can break any road image down into it’s separate RGB components which are often called channels.

Separate Images of R,G and B Channels (Image by author)

The brighter pixels indicate higher values of red, green, or blue, respectively. There are many other ways to represent the colors in an image besides just composed of red, green and blue values. These different color representations are often called color spaces. RGB is red, green, blue color space. We can think of this as a 3D space where any color can be represented by a 3D coordinate of R, G, and B values as shown in the image below:

3D RGB Color Space (Image by author)

There’s also HSV color space, for hue, saturation, and value. And there’s HLS, for hue, lightness, and saturation. These are some of the most commonly used color spaces in image analysis. For both of these, H has a range from 0 to 179 for degrees around the cylindrical color space.

HLS Binary Image (Image by author)
Separate Images of H,L and S Channels (Image by author)