Skip to content

meanStdDev

Core and matricesfunctionOpenCV 5.0.0
import { meanStdDev } from '@banou/opencv-wasm'

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

ARGUMENTSsrc, mean, stddev, mask
FUNCTIONmeanStdDev
RETURN TYPEvoid
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Calculates a mean and standard deviation of array elements.

The function cv::meanStdDev calculates the mean and the standard deviation M of array elements independently for each channel and returns it via the output parameters:

\begin{array}{l} N =  \sum _{I, \texttt{mask} (I)  \ne 0} 1 \\ \texttt{mean} _c =  \frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \texttt{src} (I)_c}{N} \\ \texttt{stddev} _c =  \sqrt{\frac{\sum_{ I: \; \texttt{mask}(I) \ne 0} \left ( \texttt{src} (I)_c -  \texttt{mean} _c \right )^2}{N}} \end{array}

When all the mask elements are 0's, the function returns mean=stddev=Scalar::all(0).

Note: The calculated standard deviation is only the diagonal of the complete normalized covariance matrix. If the full matrix is needed, you can reshape the multi-channel array M x N to the single-channel array M*N x mtx.channels() (only possible when the matrix is continuous) and then pass the matrix to calcCovarMatrix .

See: countNonZero, mean, norm, minMaxLoc, calcCovarMatrix

meanStdDev(src: Mat, mean: Mat, stddev: Mat, mask: Mat): void;
2 available overloads
meanStdDev(src: Mat, mean: Mat, stddev: Mat): void;
meanStdDev(src: Mat, mean: Mat, stddev: Mat, mask: Mat): void;
src

input array that should have from 1 to 4 channels so that the results can be stored in Scalar_ 's.

mean

Output destination, filled by the native operation. output parameter: calculated mean value.

stddev

Output destination, filled by the native operation. output parameter: calculated standard deviation.

mask

optional operation mask of type CV_8U, CV_8S or CV_Bool.

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.