Beginner level · Module 5: Feature Extraction · Lesson 2 of 3
Texture, Shape and HOG Features
Learners describe shape and texture with HOG (histograms of oriented gradients) and with contour measurements such as area, perimeter and roundness.
In this lesson you will
- Compute HOG features and visualise them
- Extract shape features from contours
Key concepts
HOGcells and orientation binsskimage.feature.hogcv2.findContoursarea, perimeter, circularity
The lesson
HOG divides an image into small cells and, in each cell, makes a histogram of gradient directions. The result describes shape and texture: the outline of a leaf, the stripes of a pattern. skimage.feature.hog computes it and can return a visualisation.
Images must be resized to the same size first so that every HOG vector has the same length.
Contours outline objects in a binary image (cv2.findContours). From the largest contour you can compute area, perimeter and circularity (4π × area / perimeter²; 1 for a circle). Simple shape numbers like these can separate round onions from elongated groundnuts.
Step by step
- Resize images to 128 × 128 and compute HOG features.
- Display the HOG visualisation for two categories.
- Threshold an image, find the largest contour and compute circularity.
- Compare the feature values across categories.
Practice activity
Build a feature table (HOG length, circularity, area) for 20 project images.
Expected result: A correct feature table and visualisations that show which features separate the categories.
Check your understanding
-
Why resize images before computing HOG?
Show answer
So that every image produces a feature vector of the same length.
-
What circularity value does a perfect circle have?
Show answer
1.
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.