Skip to content

boxFilter

Image processingfunctionOpenCV 5.0.0
import { boxFilter } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

Blurs an image using the box filter.

The function smooths an image using the kernel:

\texttt{K} =  \alpha \begin{bmatrix} 1 & 1 & 1 &  \cdots & 1 & 1  \\ 1 & 1 & 1 &  \cdots & 1 & 1  \\ \hdotsfor{6} \\ 1 & 1 & 1 &  \cdots & 1 & 1 \end{bmatrix}

where

\alpha = \begin{cases} \frac{1}{\texttt{ksize.width*ksize.height}} & \texttt{when } \texttt{normalize=true}  \\1 & \texttt{otherwise}\end{cases}

Unnormalized box filter is useful for computing various integral characteristics over each pixel neighborhood, such as covariance matrices of image derivatives (used in dense optical flow algorithms, and so on). If you need to compute pixel sums over variable-size windows, use #integral.

See: blur, bilateralFilter, GaussianBlur, medianBlur, integral

boxFilter(src: Mat, dst: Mat, ddepth: number, ksize: Size, anchor: Point, normalize: boolean, borderType: number): void;
4 available overloads
boxFilter(src: Mat, dst: Mat, ddepth: number, ksize: Size): void;
boxFilter(src: Mat, dst: Mat, ddepth: number, ksize: Size, anchor: Point): void;
boxFilter(src: Mat, dst: Mat, ddepth: number, ksize: Size, anchor: Point, normalize: boolean): void;
boxFilter(src: Mat, dst: Mat, ddepth: number, ksize: Size, anchor: Point, normalize: boolean, borderType: number): void;
src

input image.

dst

Output destination, filled by the native operation. output image of the same size and type as src.

ddepth

the output image depth (-1 to use src.depth()).

ksize

blurring kernel size.

anchor

anchor point; default value Point(-1,-1) means that the anchor is at the kernel center.

normalize

flag, specifying whether the kernel is normalized by its area or not.

borderType

border mode used to extrapolate pixels outside of the image, see #BorderTypes. #BORDER_WRAP is not supported.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.