From handcrafted to learned features
Why SIFT, HOG, Haar and LBP were engineered, what a convolution layer learns instead, and when the handcrafted pipeline still wins.
For decades, if you wanted a machine to recognise a pedestrian, match a landmark between two photographs, or find a face, you wrote down by hand what a feature should look like. SIFT computed histograms of gradient orientations around keypoints; HOG computed the same histograms on a dense grid; Haar features compared rectangular patches of brightness; LBP encoded each pixel as a binary comparison with its neighbours. These descriptors were not learned. They were engineered — designed, tuned and defended in papers.
Then in 2012 a deep network called AlexNet cut the ImageNet error rate by a wide margin, and within a few years almost every step those descriptors performed by hand was being learned from data instead. The surprising part was not that learning won on a benchmark. It was how much of the hand-engineering turned out to be unnecessary.
A feature is a hypothesis about what matters
A handcrafted descriptor encodes a human hypothesis: "locally, image structure is captured by the direction and strength of brightness change, so let me histogram gradients in a grid of cells and normalise." A learned feature replaces that hypothesis with a question the data answers: let the network choose the filters, and let gradient descent decide which measurements reduce the loss.
The widget below puts the two pipelines side by side on the same patch. In the handcrafted view you watch gradients become per-cell orientation histograms and then one normalized vector; in the learned view four kernels convolve the patch into feature maps and a pooled embedding. Translate the patch and compare how each representation holds up.
Toggle between the two pipelines, then translate the patch. Both descriptors and their cosine similarity to the unshifted patch are recomputed from the pixels.
one 8-bin orientation histogram per cell
descriptor (72-D)
- dimensionality
- 72
- L2 norm
- 1.000
- cosine to unshifted
- 1.000
- pipeline
- cells x hist
Per-cell histograms are tied to absolute cell positions, so translating the patch pushes gradients across cell borders and the descriptor drifts.
| property | handcrafted | learned |
|---|---|---|
| Where invariance comes from | Normalization written by hand (size, orientation, illumination) | Learned from data; pooling adds translation invariance |
| Data needed | None to define the descriptor — it is analytic | Large labeled corpora, or a pretrained backbone |
| Inference compute | A few arithmetic ops per pixel | A deep conv stack, though layers can be frozen |
| Interpretability | Each dimension means a gradient direction in a cell | Distributed codes; needs probing to read |
| Geometry-heavy tasks | Still preferred: explicit, exact, deterministic | Good for matching; geometry is still solved classically |
Illustrative, not trained: the four kernels are hand-picked and global average pooling is an idealised invariance step. Real CNNs learn filters by backpropagation at every layer, producing the edge-to-object hierarchy, and real embeddings are shaped by the task loss. The handcrafted histogram, the convolution and the pooled embedding shown here are exactly the operations those systems scale up.
What handcrafted features encode
The classical descriptors differ in detail but share one move: pick a simple local measurement, aggregate it over a region, and normalize so the result survives the changes you do not care about.
- SIFT measures gradient orientation at scale-space keypoints, bins the orientations in a 4×4 neighbourhood into a 128-dimensional vector, and subtracts the dominant orientation so the descriptor rotates with the patch.
- HOG drops the keypoint detector and computes the same kind of histogram on a dense grid of cells, contrast-normalizing overlapping blocks; it was the standard pedestrian detector for a decade.
- Haar features are differences of rectangular sums — cheap edge and centre-surround measurements computed instantly with an integral image — and a boosted cascade of them powered real-time face detection.
- LBP compares each pixel with its neighbours and emits a short binary code, an illumination-robust texture measure.
The common formula is a magnitude-weighted orientation histogram. For cell and orientation bin ,
followed by a normalization (L2, or block contrast normalization in HOG) that removes overall brightness changes. Every choice here — cell size, bin count, which normalizer — is a design decision made by a person.
Descriptors were already half-learned
It is tempting to call the classical era "no learning", but the classifier on top of the descriptor was always trained — an SVM on HOG vectors, a boosted cascade on Haar features. The bag-of-visual-words pipeline went further: it clustered local descriptors with k-means to build a visual vocabulary and represented each image as a histogram over that vocabulary. The front end was handcrafted, but the back end already learned. The change in 2012 was to learn the front end too.
What changed: learn the filters
A convolution layer is the same operation a handcrafted filter performs, with the numbers left free. For an input image and filters ,
In SIFT or HOG the kernel is a fixed gradient operator and the weights inside it are chosen by the author. In a CNN the are parameters initialised at random and updated by backpropagation to reduce a task loss. Stack several layers and each layer composes the previous one's features, so the network can build measurements that no one wrote down.
AlexNet trained roughly 60 million parameters over 1.2 million labelled images and 1000 classes, and its learned filters beat every handcrafted pipeline on the benchmark. The lesson generalised: given enough data and compute, the measurement itself becomes a learned parameter.
What a CNN's filters look like at depth
The filters are not arbitrary. When you visualise what a trained image network has learned, a consistent hierarchy appears:
- First layers resemble oriented edge and colour-blob detectors — Gabor-like filters that look strikingly like a learned SIFT or HOG front end.
- Middle layers combine edges into corners, junctions and simple textures.
- Deeper layers respond to object parts and motifs: wheels, eyes, windows.
- Late layers become class-selective, firing for whole objects and categories.
Nobody specified that hierarchy; it falls out of composing trainable filters and training them end to end. The handcrafted descriptors spent years trying to capture the first two levels by hand; the network learned all four.
Transfer learning: a pretrained CNN as a descriptor
The most practical bridge from classical to learned features is also the simplest. Take a CNN trained on a large dataset, remove its classification head, and use the activations it produces as your descriptor:
- Run the input through the frozen convolutional stack.
- Read a feature map (per location) or globally pool it into an embedding (per image).
- L2-normalize and compare with cosine similarity or a nearest-neighbour search — exactly as you would compare SIFT vectors.
Razavian and colleagues showed in 2014 that these off-the-shelf ImageNet features, used without any fine-tuning, already rivalled or beat handcrafted pipelines across many recognition tasks. That is the operational meaning of "a CNN is a drop-in replacement for SIFT": the frozen network is a fixed function from pixels to a vector, and the vector behaves like a descriptor. If your task is close to the pretraining data, freezing is enough; if there is a large domain gap and enough data, fine-tuning adapts the filters too.
Learned is not automatically better
A pretrained backbone is a bet that your images resemble its training data. On X-rays, microscopy, satellite radar or other specialised modalities the bet fails, and a frozen natural-image network can underperform a simple engineered descriptor. Learned features also inherit their training distribution's biases and are sensitive to input perturbations. Evaluate the transfer; do not assume it.
When classical still wins
Learned features dominate large-scale natural-image recognition, but the classical toolbox has not gone away. It is still the right choice when:
- Data is scarce or the modality is unusual. No large pretraining corpus exists, and a handcrafted descriptor needs no labels to define.
- Compute, latency or power is tight. A gradient histogram or Haar sum is a handful of operations per pixel, with no GPU and no model weights to ship.
- You need interpretability or guarantees. Each dimension of a SIFT/HOG vector has a stated meaning; a regulated system may require features a human can audit rather than a distributed code.
- The task is geometry, not semantics. Camera calibration, epipolar geometry, absolute pose, photogrammetry and structure-from-motion are solved by explicit geometric algorithms. Classical detectors and descriptors with RANSAC remain robust and deterministic, and matching precision at the sub-pixel level still favours them.
In practice the two combine: a learned detector and descriptor propose matches, and classical geometric verification decides which are consistent.
Descriptors and learned embeddings
Strip away the terminology and both objects are the same thing: a vector in a space where distance means similarity. Matching is a nearest-neighbour query in both cases, and cosine or Euclidean distance is the metric either way.
The difference is where the invariance lives. In a handcrafted descriptor, invariance to rotation or illumination is inserted by a person, step by step. In a learned embedding, invariance is whatever the training objective forced the representation to have — contrastive or triplet losses pull similar inputs together and push others apart, so the geometry of the space is learned, not specified. The bag-of-visual-words histogram is the historical halfway house: a learned vocabulary over handcrafted descriptors. A modern embedding is its end-to-end descendant.
Illustrative vs real
The widget uses four fixed, hand-picked kernels, not trained weights, and global average pooling as an idealised invariance step. Real convolutional networks learn every layer's filters by backpropagation, and real embeddings are shaped by the task loss over millions of examples. The operations shown — gradient histogram, convolution, pooled vector, cosine similarity — are exactly the ones those systems scale up.
Check yourself
Eduspheria wiki · Applied AI, Classical computer vision
0 / 6 answered
Where next: the same classical-to-learned story plays out in language — we start with the fixed statistics of n-gram language models before moving to learned representations.