Skip to content

computeECC

Motion and trackingfunctionOpenCV 5.0.0
import { computeECC } from '@banou/opencv-wasm'

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

Computes the Enhanced Correlation Coefficient (ECC) value between two images

The Enhanced Correlation Coefficient (ECC) is a normalized measure of similarity between two images [EP08]. The result lies in the range [-1, 1], where 1 corresponds to perfect similarity (modulo affine shift and scale), 0 indicates no correlation, and -1 indicates perfect negative correlation.

For single-channel images, the ECC is defined as:


\mathrm{ECC}(I, T) = \frac{\sum_{x} (I(x) - \mu_I)(T(x) - \mu_T)}
{\sqrt{\sum_{x} (I(x) - \mu_I)^2} \cdot \sqrt{\sum_{x} (T(x) - \mu_T)^2}}

For multi-channel images (e.g., 3-channel RGB), the formula generalizes to:


\mathrm{ECC}(I, T) =
\frac{\sum_{x} \sum_{c=1}^{C} (I_c(x) - \mu_{I_c})(T_c(x) - \mu_{T_c})}
{\sqrt{\sum_{x} \sum_{c=1}^{C} (I_c(x) - \mu_{I_c})^2} \cdot
 \sqrt{\sum_{x} \sum_{c=1}^{C} (T_c(x) - \mu_{T_c})^2}}

Where:

  • I_c(x), T_c(x) are the values of channel c at spatial location x,
  • \mu_{I_c}, \mu_{T_c} are the mean values of channel c over the masked region (if provided),
  • C is the number of channels (only 1 and 3 are currently supported),
  • The sums run over all pixels x in the image domain (optionally restricted by mask).

See: findTransformECC

computeECC(templateImage: Mat, inputImage: Mat, inputMask: Mat): number;
2 available overloads
computeECC(templateImage: Mat, inputImage: Mat): number;
computeECC(templateImage: Mat, inputImage: Mat, inputMask: Mat): number;
templateImage

Input template image; must have either 1 or 3 channels and be of type CV_8U, CV_16U, CV_32F, or CV_64F.

inputImage

Input image to be compared with the template; must have the same type and number of channels as templateImage.

inputMask

Optional single-channel mask to specify the valid region of interest in inputImage and templateImage.

Returns

The ECC similarity coefficient in the range [-1, 1].

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.