Gaussian and Laplacian pyramids
A Gaussian pyramid keeps smaller, blurrier copies of an image. A Laplacian pyramid keeps the detail lost between those copies, plus the smallest copy needed to rebuild the image.
Watch the thin stripes inside the rectangle. Shrinking removes their contrast while the larger shapes remain recognizable.
G0 is the original. pyrDown blurs it and halves both dimensions to make G1, then repeats to make G2. These smaller images form the Gaussian pyramid; the fine stripes fade away.
Enlarge the next smaller Gaussian image to the current size, then subtract it from the current image. L0 stores the fine stripes and sharp edges; L1 stores broader corrections. Each row is shown at a common display size. Save G2 as the coarse base.
Start with the saved G2. Expand it and add L1 to recover G1; expand again and add L0 to recover G0. Enlarging alone leaves a blur. Adding the stored signed detail bands restores every original sample in this floating-point example.
To reconstruct, start at the smallest level: expand, add its saved detail band, and repeat until the original size is restored.
Computed 32 × 24 example using the OpenCV pyramid kernel, checked against native pyrDown/pyrUp. Detail-band colour is amplified 3× for visibility; the stored values keep their signs and are never clipped.
Try it on an image
Experiment at pixel level
Inspect a Gaussian level or signed Laplacian residual. Residual display uses mid-gray for zero; native values keep the sign.
The engine loads on your first run. Your images stay in this browser.
Scroll over either image to zoom at the pointer. Use the scrollbars to pan both views over the same relative area. Zoom is relative to the input; pixel coordinates belong to each image. Warps can change scene correspondence.
Pixel inspector RGBA · native values · matched scale · 9 × 9 output pixels
Select a pixel
Select a pixel
When to use it
For motion estimation, a 16-pixel displacement becomes 4 pixels after two reductions, making a coarse search easier. For image blending, combine broad brightness changes at coarse scales and fine edges at finer scales, then reconstruct.
How it works
- 01Blur and halve both dimensions repeatedly to make the Gaussian levels G0, G1 and G2.
- 02At each transition, expand the smaller level and subtract it from the larger one. Save the signed difference as a Laplacian detail band, and keep the smallest Gaussian level.
- 03To reconstruct, start at the smallest level: expand, add its saved detail band, and repeat until the original size is restored.
Lk = Gk − expand(Gk+1); reconstruct: Gk = expand(Gk+1) + Lk
What to tune
Choose enough levels to make the largest expected displacement small at the coarsest scale. Keep the same expansion operator and matching dimensions when forming and reconstructing the detail bands.
Where it breaks down
pyrUp alone cannot recover discarded detail. Reconstruction needs the smallest Gaussian image and every saved detail band. Use floating-point matrices for subtraction and addition: an unsigned 8-bit subtraction clips negative corrections. Match expansion to the exact next level size, especially for odd dimensions. A Laplacian pyramid is built from differences between scales; it is not a call to the Laplacian derivative filter.
TypeScript API
Open an entry for its exact overloads, parameter descriptions, result ownership and pinned upstream source.
All of these calls execute on the CPU. Native objects need explicit disposal. See matrices and ownership and build compatibility.
Related methods
Gaussian blur
Replace each pixel with a weighted average that gives nearby pixels more influence.
Box filtering
Average a rectangular neighbourhood with equal weight at every position.
Median filtering
Choose the middle value of a pixel neighbourhood instead of averaging its intensities.
Bilateral filtering
Smooth nearby pixels only when their colours are also similar.