TL;DR
An image pyramid is a stack of versions of one picture. Level 0 is the original. Each next level is blurred and then shrunk to half the width and height, so the top of the stack is a tiny copy of the whole scene. Programs use it to find things of different sizes, and to search coarse to fine, because a small copy is cheap to scan.
Builds on: Digital Image, Convolution, Gaussian (Normal) Distribution, Nyquist–Shannon Sampling Theorem · Leads to: Local Image Features, Object Detection, Feature Pyramid Networks for Object Detection
Where it's used
Multi-scale detection. Early face and object detectors ran a fixed-size window over a pyramid of resized copies of the photo. A window 24 pixels wide can only fit objects about 24 pixels wide. A copy shrunk by two makes a 48-pixel object fit that window, so one detector covers many sizes.
Matching across zoom levels. Photo-stitching and image-search systems compare Local Image Features in two pictures taken at different distances. They match at a coarse level first, which finds the rough alignment cheaply, then refine at full resolution.
Blending and compression. Burt and Adelson's Laplacian pyramid blends two photos seamlessly by mixing each level separately. Coarse shapes blend over a wide area and fine edges over a narrow one, so a seam is hard to see.
Feature pyramids in modern networks. Feature Pyramid Networks (2017) build the same stack out of a convolutional network's feature maps instead of pixels. Feature Pyramid Networks for Object Detection shows how this lets one detector find objects of all sizes in a single pass.
How it works
Take one row of eight pixels that alternates dark and bright: 0, 8, 0, 8, 0, 8, 0, 8. Build the next level, which should have four pixels.
flowchart LR A["Level 0: 8 pixels"] --> B["Blur with weights 1, 2, 1 over 4"] --> C["Keep every second pixel"] --> D["Level 1: 4 pixels"]
- Shrink naively. Keep every second pixel: positions 0, 2, 4, 6. You get 0, 0, 0, 0. Check: the row's average is 4, but the shrunken row is black. The pattern has been lost.
- Blur first. Replace each pixel by a weighted average of itself and its two neighbours, with weights 1, 2, 1 divided by 4. For the bright pixel at position 1, the neighbours are both 0, so the value is (0 + 2·8 + 0) / 4 = 4. At the ends, copy the edge pixel as its own neighbour. The result is 2, 4, 4, 4, 4, 4, 4, 6. Check: the middle values all sit at 4, the average.
- Shrink. Keep positions 0, 2, 4, 6 of the blurred row. You get 2, 4, 4, 4. Check: half the pixels, and the grey level of the original average.
- Repeat for level 2. Blur 2, 4, 4, 4 with the same weights and copying at the ends. You get 2.5, 3.5, 4, 4. Keep positions 0 and 2: 2.5, 4. Check: the level has two values from four.
- Stack the levels. Level 0 has 8 pixels, level 1 has 4, level 2 has 2. In two dimensions the same work is done along rows, then along columns, so each level has a quarter of the pixels of the one below.
The blur is what makes step 2 work. It is a low-pass filter: it keeps slow changes and weakens fast ones.
- blur response
The math
The formula is the one-dimensional walkthrough written in two dimensions, with a bell-shaped set of weights in place of 1, 2, 1. Real systems use a longer kernel such as the five-tap binomial , which is close to a Gaussian.
Step 1 in symbols: the blur
For a row , with weights on the left neighbour, the pixel and the right neighbour, and the end pixel copied at each edge:
Step 2 in symbols: keep every second sample
Step 3 in symbols: the recursion
Let stand for the blur and for keeping every second sample. Then each level is
Why the blur must come first
Measured in original pixels, a pattern that repeats every pixels has frequency in cycles per pixel. The blur multiplies each such pattern by
For the checkerboard, , so . The blur removes it exactly, which is why the blurred row in step 2 is flat at 4 in the middle. After keeping every second sample, the new grid can only hold frequencies up to cycle per original pixel. For , . The blur keeps it, but damps it, so it survives without folding back.
Sizes
If the photo has pixels, level has about pixels. Adding up the levels gives , which approaches . A full pyramid costs about a third more memory than the image alone.
Worked examples
Start with the row . Blur with weights , copying the end pixel at each edge.
- Pixel 0: the neighbours are a copy of itself (0) and pixel 1 (0). .
- Pixel 1: left neighbour 0, itself 0, right neighbour 8. .
- Pixel 2: left neighbour 0, itself 8, right neighbour 8. .
- Pixel 3: left neighbour 8, itself 8, copied right neighbour 8. The value is 8.
- The blurred row is . Keep positions 0 and 2: the level-1 row is .
- Interpretation: the sharp step from 0 to 8 has become a ramp. The bright sample at position 2 reads 6, not 8, because its dark neighbour pulled it down.
Start with the row .
- Blur. Pixels 0 and 1 are 0. Pixel 2: . Pixel 3: . Pixel 4 and the pixels after it: 8. The blurred row is .
- Keep positions 0, 2, 4, 6. Level 1 is .
- Blur level 1 again. Pixel 0: . Pixel 1: . Pixel 2: . Pixel 3: 8. The blurred row is .
- Keep positions 0 and 2. Level 2 is .
- Interpretation: eight values have become two. The edge has spread over more pixels at each level, and the coarse level still shows a dark-to-bright change, now as 0.5 and 6.5.
Take a photo of pixels.
- Level 0 has pixels.
- Level 1 has pixels.
- Level 2 has pixels.
- Level 3 has pixels.
- Levels 0 to 3 together hold pixels. Divided by the original count, that is , close to .
- Scale: a face 96 pixels wide in the photo is 96 / 4 = 24 pixels wide at level 2. A 24-pixel window fits it there.
Try it: a face is 48 pixels wide in the original photo. At which level does a 24-pixel window fit it? Answer: level 1, because 48 / 2 = 24.
Common mistakes and tradeoffs
It is tempting to think that shrinking by keeping every second pixel is enough. In fact it aliases: the checkerboard in the walkthrough vanishes into black. Blur first, because the blur removes the detail that the smaller grid cannot represent.
It is tempting to think a pyramid is the same as resizing the photo with a smooth interpolation such as Bilinear Interpolation. In fact interpolation does not remove the high frequencies, so aliasing remains. A pyramid also builds each level from the one before, so the whole stack costs about a third more memory, while resizing from the original again for every scale costs a full pass each time.
It is tempting to think a pyramid makes a detector scale invariant by itself. In fact it only gives the detector each scale it searches. The detector must still recognise the object at that scale, and an object whose size falls between two levels is only seen at a factor of two off, which is coarse.
Use a pyramid when you need to search at many scales, match coarse to fine, blend images, or compress images in layers. Do not use it when a modern network already shrinks its own feature maps with strided convolution or pooling, as Max Pooling does. Feature pyramids inside the network reuse those maps and avoid rescaling the input for every scale. A Laplacian pyramid stores the detail that each blur removes, so the original image can be rebuilt exactly; a Gaussian pyramid does not.
History
In the 1970s and early 1980s, picture-processing researchers used hierarchical image structures to speed up search. In 1983 Peter Burt and Edward Adelson published the Laplacian pyramid as a compact image code. Their construction made the blurred, shrunken stack the standard way to hold an image at several scales, and it spread into compression and blending.
In 2004 David Lowe's SIFT features searched for keypoints across a scale space organised into octaves. Each octave halves the image, which is the same idea as a pyramid level. In 2017 Lin and colleagues' Feature Pyramid Networks moved the pyramid inside a convolutional network, building it from feature maps instead of pixels. That is how most modern detectors handle objects of many sizes. The idea caught on because it is simple and uses the same convolution found everywhere else in the pipeline.
Recap
- An image pyramid is a stack of levels. Each level is blurred and then shrunk by two in each direction.
- The blur is a low-pass filter, a weighted average with bell-like weights. It must come before shrinking, or the pattern aliases, as the Nyquist–Shannon Sampling Theorem predicts.
- Each level has a quarter of the pixels of the one below. The whole stack costs about 4/3 of the original image.
- Searching a stack of scales lets one fixed-size window find objects of many sizes.
- Read next: Local Image Features for matching points across scales, Object Detection for the task that uses scales, and Feature Pyramid Networks for Object Detection for the pyramid built inside a network.