Box filtering
Average a rectangular neighbourhood with equal weight at every position.
The same scene stays here while the working view changes.
The orange 3 × 3 window surrounds one output location. Every sample has the same weight, 1/9.
Every sample has the same weight, 1/9. One output value is 130.1; the window then moves across the image.
The whole image has now been processed. The highlighted input value 156 becomes 130.1.
Divide by the area when normalization is enabled.
Computed teaching example on a 24 × 16 image. Small kernels and simplified settings keep each change visible; use the image laboratory for native OpenCV.
Try it on an image
Experiment at pixel level
Average the colour image with a square box.
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
Compute local means, local variance, and inexpensive smoothing over large windows.
How it works
- 01Select a rectangular window.
- 02Sum its samples with equal weights.
- 03Divide by the area when normalization is enabled.
mean = Σ window / number of samples
What to tune
ksize chooses the neighbourhood; normalize selects an average or a sum; ddepth controls overflow and precision.
Where it breaks down
Equal weights can leave block-shaped blur and suppress edges. sqrBoxFilter averages squared values, useful with a local mean for variance.
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.
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.
Custom correlation kernels
Apply your own linear filter to every pixel neighbourhood.