IPSDK 4.1.0.2
IPSDK : Image Processing Software Development Kit
Fast Cross-Correlation 2d
imagefastCrossCorrelation2dImg (inImg,inTemplateImg)

Detailed Description

2D Cross correlation calculated in the Fourier domain

This algorithm computes the two dimensional Cross-Correlation (CC) between an image $ InImg2d $ and a template $ InTemplateImg $. To speed up the process, the calculation is performed in the frequency domain as follows :

\[ CC = \mathcal{F}^{-1}\left((\mathcal{F}(InImg2d - \mu_{InImg2d}) \overline{\mathcal{F}(InTemplateImg - \mu_{InTemplateImg})}\right) \]

Where $ \overline{I} $ is the configate of $I$, $ \mathcal{F}(I) $ represents the Fourier transform of an image $I$, $\mu_{InImg2d}$ is the local mean intensity of the input image in the neighbourhood defined by the template, $\mu_{InTemplateImg}$ is the template global mean intensity and $ \mathcal{F}^{-1} $ the inverse Fourier tranform.

The algorithm needs 4 working images with Real32 data to compute the Fourier transforms. If the template image is smaller than the reference image, it is padded before calculating its Fourier transform and two additional working images are used to store the padded template image.

Please, note that the results are not strictly identical to the Normalized Cross-Correlation 2d and the maximum is located at the origin of the template whereas it is located at the template center coordinates for the NCC. Moreover, unless the image and the template sizes are small, its implementation can be much faster, as show the following figure:

CC2d_bench.png

The performances has been calculated on a desktop computer with Intel(R) Core(TM) i9-10980XE 3GHz, 128Go RAM, Windows 10 64 bits.

Here is an example of an image, a template to match and the resulting fast CC :

CC2d.png
See also
http://en.wikipedia.org/wiki/Cross-correlation

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLFiltering as filter

Code Example

# opening of input images
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
# normalized cross correlation 2d computation
outImg = filter.fastCrossCorrelation2dImg(inImg, templateImg)

Example of C++ code :

Example informations

Header file

#include <IPSDKIPL/IPSDKIPLFiltering/Processor/FastCrossCorrelation2dImg/FastCrossCorrelation2dImg.h>

Code Example

// Generate a random image
ImagePtr pInImg = loadTiffImageFile(inputImgPath);
// Compute the NCC
ImagePtr pOutImg = fastCrossCorrelation2dImg(pInImg, pTemplateImg);