Skip to course content
Free computer vision course

Computer Vision and Multimodal AI

Unit 02.02: Colour spaces and when each one helps

Colour spaces are different questions you can ask of the same pixels.

BGR, HSV and grayscale

BGR/RGB stores intensity per channel. HSV separates colour from brightness. Grayscale discards colour entirely.

The code converts one pixel three ways.

import cv2
import numpy as np

bgr = np.zeros((2, 2, 3), dtype="uint8")
bgr[:] = [40, 180, 220]   # BGR: a warm yellow

hsv = cv2.cvtColor(bgr, cv2.COLOR_BGR2HSV)
gray = cv2.cvtColor(bgr, cv2.COLOR_BGR2GRAY)

print("BGR :", bgr[0, 0], " (blue, green, red)")
print("HSV :", hsv[0, 0], " (hue, saturation, value)")
print("GRAY:", gray[0, 0])

for space, use in [("BGR/RGB", "display, and model input"),
                   ("HSV", "picking a colour regardless of brightness"),
                   ("GRAY", "shape and texture, when colour is irrelevant")]:
    print(f"{space:9} {use}")

# HSV separates colour from brightness, which is why "find the yellow object"
# is a hue range in HSV and an awkward three-way condition in BGR.

HSV is the one worth reaching for deliberately. "Find the yellow object" is a hue range in HSV and an awkward three-way condition in BGR that breaks the moment the lighting changes.

Grayscale is not a lesser format; it is the right one when shape and texture carry the signal and colour is a distraction the model would otherwise learn from.

The mistake this prevents

The mistake is converting to grayscale to save memory. It is a modelling decision that discards a third of the information, and if colour distinguishes your classes it is the wrong one however much memory it saves.

Takeaway

Choose the colour space from the question. HSV for colour under varying light, grayscale when colour is noise, RGB when a pretrained model expects it.