IPSDK 4.1
IPSDK : Image Processing Software Development Kit
Normalized Cross-Correlation 2d
imagenormalizedCrossCorrelation2dImg (inImg2d,inKnlXY)
imagenormalizedCrossCorrelation2dImg (inImg2d,inKnlImg2d)

Detailed Description

Computes the Normalized Cross Correlation between an image and a kernel.

The two dimensional Normalized Cross-Correlation (NCC) between an image $ InImg2d $ and a template $ InKnlXY $ is a similarity measure, which is defined in spatial domain as follows :

\[ NCC(InImg2d(\textbf{x}), InKnlXY) = \frac{\sum \limits_{\textbf{i $ \in \aleph_{\textbf{x}}$}}{ \left( InImg2d(\textbf{x}) - \overline{InImg2d} \right) \left( InKnlXY(\textbf{x}+\textbf{i}) - \overline{InKnlXY} \right) }} {\sqrt{ \sum \limits_{\textbf{i $ \in \aleph_{\textbf{x}}$}} { \left( InImg2d(\textbf{x}) - \overline{InImg2d} \right)^2} \sum \limits_{\textbf{i $ \in \aleph_{\textbf{x}}$}} { \left( InKnlXY(\textbf{x}+\textbf{i}) - \overline{InKnlXY} \right)^2}}} \]

Where $ \textbf{x} = \left[ x, y \right]^T $ represents the coordinates of a pixel, $ \overline{InImg2d} $ is the mean of $ InImg2d $ in the neighbourhood defined by the kernel and $ \overline{InKnlXY} $ is the mean of $ InKnlXY $.

The kernel describes the template to match with the input image. Typically, it represents a region of interest of an altered version of the input image (deformation, noise, ...).

To improve the algorithm peformances, it is recommanded to extract a search area from the initial image to reduce the number of processed data. This area will be given to the algorithm as the input image $ InImg2d $.

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

NCC2d.png

As displayed by the colorbar, low values are represented in blue and high values are represented in red. The position of the maximum of the NCC indicates the location of the center of the patch in the image which matches the most with the template.

See also
http://en.wikipedia.org/wiki/Cross-correlation
Note
It is possible to call the NCC with an image provided as a template, nevertheless the algorithm still internally calculates and uses a kernel. These functions are ment to simplify the use of the function but it means that the data are copied in memory.

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLFiltering as filter

Code Example

# opening of input images
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
# create a processing kernel
inKnl = PyIPSDK.rectangularKernelXY(1, 2, [1, 1, 1,
1, 1, 1,
1, 0, 1,
1, 1, 1,
1, 1, 1],
True)
# normalized cross correlation 2d computation
outImg = filter.normalizedCrossCorrelation2dImg(inImg, inKnl)

Example of C++ code :

Example informations

Header file

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

Code Example

// Compute the NCC
ImagePtr pOutNCCImg = normalizedCrossCorrelation2dImg(pImg, pKernel);