Notes

Color Space (RGB, HSV)

A digital image is not just a grid of brightness values: each pixel also carries colour information. A color space is the scheme used to represent that colour numerically, and choosing the right scheme can make a vision task far simpler.

Two useful ways to describe colour
In RGB, each pixel has three channel values: red, green, and blue. Combining their intensities produces the visible colour: high red and green with little blue appears yellow, while equal high values appear white. RGB matches how cameras, screens, and many image files store colour, so it is the standard starting point for computer vision.

HSV represents the same visual information differently:

  • Hue: the basic colour, such as red, green, or blue.
  • Saturation: how vivid the colour is; low saturation produces greyish colours.
  • Value: brightness, from dark to bright.

This separation is valuable because colour identity is less tangled with lighting. For example, a system detecting ripe red tomatoes can threshold a range of red hue values while allowing brightness to vary between shade and direct sunlight. HSV is also useful for tracking coloured markers in video, inspecting product labels, or isolating skin-colour-like regions as one input to face-analysis pipelines.

Why conversion matters
A colour-based rule built directly in RGB can fail when illumination changes: a red object’s R, G, and B values all shift as the scene gets darker or warmer. Converting RGB to HSV gives a pipeline more meaningful controls for selecting colour, rejecting dull background pixels, or adjusting for brightness. Libraries such as OpenCV provide cv2.cvtColor for this conversion. One practical trap: OpenCV images loaded with imread use BGR channel order by default, so the appropriate conversion is cv2.COLOR_BGR2HSV, not RGB-to-HSV. Using the wrong order silently produces incorrect colours and unreliable masks.

A color space is a numerical representation of color used to encode image pixels. RGB represents colors through red, green, and blue channel intensities, while HSV represents hue, saturation, and brightness-like value. Converting between color spaces exposes different visual properties, enabling robust preprocessing, color-based segmentation, and feature extraction under varying lighting conditions.

Think of a colour space as a map for colours. Just as a street map gives every place an address, a colour space gives every visible colour a set of numbers that a computer can understand.

RGB describes colours by mixing red, green, and blue light—like the tiny lights in a phone or TV screen. HSV describes colour more like people do: its basic shade, how vivid it is, and how light or dark it appears.

Using the right colour map helps AI notice useful patterns, such as separating ripe red fruit from green leaves. In unsupervised learning, where AI looks for groups without being told their names, colour spaces can help it discover clusters of similarly coloured pixels.