Skip to content

findTransformECC

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

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

example: samples/cpp/image_alignment.cpp An example using the image alignment ECC algorithm Finds the geometric transform (warp) between two images in terms of the ECC criterion [EP08] .

See: computeECC, estimateAffine2D, estimateAffinePartial2D, findHomography

findTransformECC(templateImage: Mat, inputImage: Mat, warpMatrix: Mat, motionType: number, criteria: TermCriteria, inputMask: Mat, gaussFiltSize: number): number;
templateImage

1 or 3 channel template image; CV_8U, CV_16U, CV_32F, CV_64F type.

inputImage

input image which should be warped with the final warpMatrix in order to provide an image similar to templateImage, same type as templateImage.

warpMatrix

Input/output value, modified by the native operation. floating-point 2\times 3 or 3\times 3 mapping matrix (warp).

motionType

parameter, specifying the type of motion:

  • MOTION_TRANSLATION sets a translational motion model; warpMatrix is 2\times 3 with the first 2\times 2 part being the unity matrix and the rest two parameters being estimated.
  • MOTION_EUCLIDEAN sets a Euclidean (rigid) transformation as motion model; three parameters are estimated; warpMatrix is 2\times 3.
  • MOTION_AFFINE sets an affine motion model (DEFAULT); six parameters are estimated; warpMatrix is 2\times 3.
  • MOTION_HOMOGRAPHY sets a homography as a motion model; eight parameters are estimated;`warpMatrix` is 3\times 3.
criteria

parameter, specifying the termination criteria of the ECC algorithm; criteria.epsilon defines the threshold of the increment in the correlation coefficient between two iterations (a negative criteria.epsilon makes criteria.maxcount the only termination criterion). Default values are shown in the declaration above.

inputMask

An optional single channel mask to indicate valid values of inputImage.

gaussFiltSize

An optional value indicating size of gaussian blur filter; (DEFAULT: 5)

The function estimates the optimum transformation (warpMatrix) with respect to ECC criterion ([EP08]), that is

\texttt{warpMatrix} = \arg\max_{W} \texttt{ECC}(\texttt{templateImage}(x,y),\texttt{inputImage}(x',y'))

where

\begin{bmatrix} x' \\ y' \end{bmatrix} = W \cdot \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}

(the equation holds with homogeneous coordinates for homography). It returns the final enhanced correlation coefficient, that is the correlation coefficient between the template image and the final warped input image. When a 3\times 3 matrix is given with motionType =0, 1 or 2, the third row is ignored.

Unlike findHomography and estimateRigidTransform, the function findTransformECC implements an area-based alignment that builds on intensity similarities. In essence, the function updates the initial transformation that roughly aligns the images. If this information is missing, the identity warp (unity matrix) is used as an initialization. Note that if images undergo strong displacements/rotations, an initial transformation that roughly aligns the images is necessary (e.g., a simple euclidean/similarity transform that allows for the images showing the same image content approximately). Use inverse warping in the second image to take an image close to the first one, i.e. use the flag WARP_INVERSE_MAP with warpAffine or warpPerspective. See also the OpenCV sample image_alignment.cpp that demonstrates the use of the function. Note that the function throws an exception if algorithm does not converges.

Returns

The number result.

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.