Beginner level · Module 5: Feature Extraction · Lesson 1 of 3
Feature Vectors and Colour Histograms
Learners turn each image into a fixed-length vector of numbers, starting with colour histograms in HSV that summarise an image's colours.
In this lesson you will
- Explain feature vectors
- Compute normalised colour histograms
Key concepts
feature vectorfixed lengthcv2.calcHistHSV histogramnormalisation
The lesson
Classical classifiers need every image described by the same number of values: a feature vector. Raw pixels are a poor choice because they change completely if the object moves slightly.
A colour histogram counts how many pixels fall into each colour range. Computed on the hue and saturation channels of HSV (for example 16 × 8 bins with cv2.calcHist), it describes colour while being fairly robust to lighting. Flatten it into a 128-value vector and normalise it so that image size does not matter.
Colour histograms ignore where colours are, so a red tomato and a red cloth look alike. They work best when colour is the main difference between categories, as with ripe and unripe fruit.
Step by step
- Compute an HSV histogram for one ripe and one unripe mango.
- Flatten and normalise both histograms.
- Plot them and compare.
- Compute the distance between pairs of images with cv2.compareHist.
Practice activity
Compute and compare colour histograms for the project categories.
Expected result: Histogram plots and distances that show which categories colour can separate.
Check your understanding
-
Why are raw pixels poor features?
Show answer
They change completely when the object moves or changes size.
-
What does a colour histogram ignore?
Show answer
Where in the image the colours are.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.