Wiki
Core13 min read

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.

input patch (24x24)
gradient magnitude

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.

Handcrafted versus learned features
propertyhandcraftedlearned
Where invariance comes fromNormalization written by hand (size, orientation, illumination)Learned from data; pooling adds translation invariance
Data neededNone to define the descriptor — it is analyticLarge labeled corpora, or a pretrained backbone
Inference computeA few arithmetic ops per pixelA deep conv stack, though layers can be frozen
InterpretabilityEach dimension means a gradient direction in a cellDistributed codes; needs probing to read
Geometry-heavy tasksStill preferred: explicit, exact, deterministicGood 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 cc and orientation bin bb,

hc[b]=∑p∈c∥∇I(p)∥ 1 ⁣[θ(p)∈bin b],h_c[b] = \sum_{p \in c} \lVert \nabla I(p) \rVert \, \mathbb{1}\!\left[\theta(p) \in \text{bin } b\right],

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 II and filters WkW_k,

Fk(x,y)=σ ⁣(∑i,jWk(i,j) I(x+i, y+j)+bk).F_k(x,y) = \sigma\!\left(\sum_{i,j} W_k(i,j)\, I(x+i,\, y+j) + b_k \right).

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 WkW_k 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:

  1. Run the input through the frozen convolutional stack.
  2. Read a feature map (per location) or globally pool it into an embedding (per image).
  3. 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

  1. 1A SIFT-style descriptor uses a 4×4 grid of spatial cells with an 8-bin orientation histogram per cell. How many dimensions does the descriptor have?
    Numeric answer
  2. 2When the filters of the first convolution layer of a CNN trained on natural images are visualised, they most resemble…
    Multiple choice
  3. 3Global average pooling of a convolutional feature map discards where activations occurred, which gives the resulting embedding translation invariance.
    True / false
  4. 4Which 2012 network, trained on 1.2 million ImageNet images, showed that learned convolutional filters decisively beat handcrafted pipelines?
    Short answer
  5. 5An image patch has rows [[0, 0, 10], [0, 0, 10], [0, 0, 10]]. Applying the vertical Sobel kernel [[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], what is the centre-pixel response?
    Numeric answer
  6. 6For which task would a classical handcrafted pipeline still commonly be preferred over a pretrained CNN?
    Multiple choice

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.