Skip to content

integral

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

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

ARGUMENTSsrc, sum, sdepth
FUNCTIONintegral
RETURN TYPEvoid
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

imgproc_transform

Calculates the integral of an image.

The function calculates one or more integral images for the source image as follows:

\texttt{sum} (X,Y) =  \sum _{x<X,y<Y}  \texttt{image} (x,y)
\texttt{sqsum} (X,Y) =  \sum _{x<X,y<Y}  \texttt{image} (x,y)^2
\texttt{tilted} (X,Y) =  \sum _{y<Y,abs(x-X+1) \leq Y-y-1}  \texttt{image} (x,y)

Using these integral images, you can calculate sum, mean, and standard deviation over a specific up-right or rotated rectangular region of the image in a constant time, for example:

\sum _{x_1 \leq x < x_2,  \, y_1  \leq y < y_2}  \texttt{image} (x,y) =  \texttt{sum} (x_2,y_2)- \texttt{sum} (x_1,y_2)- \texttt{sum} (x_2,y_1)+ \texttt{sum} (x_1,y_1)

It makes possible to do a fast blurring or fast block correlation with a variable window size, for example. In case of multi-channel images, sums for each channel are accumulated independently.

As a practical example, the next figure shows the calculation of the integral of a straight rectangle Rect(4,4,3,2) and of a tilted rectangle Rect(5,1,2,3) . The selected pixels in the original image are shown, as well as the relative pixels in the integral images sum and tilted .

integral calculation example

integral(src: Mat, sum: Mat, sdepth: number): void;
2 available overloads
integral(src: Mat, sum: Mat): void;
integral(src: Mat, sum: Mat, sdepth: number): void;
src

input image as W \times H, 8-bit or floating-point (32f or 64f).

sum

Output destination, filled by the native operation. integral image as (W+1)\times (H+1) , 32-bit integer or floating-point (32f or 64f).

sdepth

desired depth of the integral and the tilted integral images, CV_32S, CV_32F, or CV_64F.

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.