IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit

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

IPSDKIPLFILTERING_API image::ImagePtr ipsdk::imaproc::filter::normalizedCrossCorrelation2dImg (const image::ImageConstPtr &pInImg2d, const KernelXYConstPtr &pInKnlXY)
 wrapper function for Computes the Normalized Cross Correlation between an image and a kernel More...
 
IPSDKIPLFILTERING_API void ipsdk::imaproc::filter::normalizedCrossCorrelation2dImg (const image::ImageConstPtr &pInImg2d, const KernelXYConstPtr &pInKnlXY, const image::ImagePtr &pOutRealImg)
 wrapper function for Computes the Normalized Cross Correlation between an image and a kernel More...
 
IPSDKIPLFILTERING_API image::ImagePtr ipsdk::imaproc::filter::normalizedCrossCorrelation2dImg (const image::ImageConstPtr &pInImg2d, const image::ImageConstPtr &pInKnlImg2d)
 wrapper function for Computes the Normalized Cross Correlation between an image and a kernel More...
 
IPSDKIPLFILTERING_API void ipsdk::imaproc::filter::normalizedCrossCorrelation2dImg (const image::ImageConstPtr &pInImg2d, const image::ImageConstPtr &pInKnlImg2d, const image::ImagePtr &pOutRealImg)
 wrapper function for Computes the Normalized Cross Correlation between an image and a kernel More...
 

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.

Attributes description

Attribute description for algorithm :

Name ToolTip Default Initializer
ipsdk::imaproc::attr::InImg2d [Input] 2d image for operation X
ipsdk::imaproc::attr::InKnlXY [Input] kernel xy for processing operation X
ipsdk::imaproc::attr::OutRealImg [Output] image for processing operation (data contained in image buffer are reals) ipsdk::imaproc::duplicateInOut (_pOutRealImg, _pInImg2d, ipsdk::image::eImageBufferType::eIBT_Real32)

Global Rule description

Global rule description for algorithm :
ipsdk::imaproc::matchSize (_pInImg2d,_pOutRealImg)

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

Associated library

IPSDKIPLFiltering

Header file

Code Example

// Compute the NCC
ImagePtr pOutNCCImg = normalizedCrossCorrelation2dImg(pImg, pKernel);
See also
NormalizedCrossCorrelation2dImgLvl1
NormalizedCrossCorrelation2dImgLvl2
NormalizedCrossCorrelation2dImgLvl3

Function Documentation

◆ normalizedCrossCorrelation2dImg() [1/4]

IPSDKIPLFILTERING_API image::ImagePtr ipsdk::imaproc::filter::normalizedCrossCorrelation2dImg ( const image::ImageConstPtr pInImg2d,
const KernelXYConstPtr pInKnlXY 
)

wrapper function for Computes the Normalized Cross Correlation between an image and a kernel

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ normalizedCrossCorrelation2dImg() [2/4]

IPSDKIPLFILTERING_API void ipsdk::imaproc::filter::normalizedCrossCorrelation2dImg ( const image::ImageConstPtr pInImg2d,
const KernelXYConstPtr pInKnlXY,
const image::ImagePtr pOutRealImg 
)

wrapper function for Computes the Normalized Cross Correlation between an image and a kernel

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ normalizedCrossCorrelation2dImg() [3/4]

IPSDKIPLFILTERING_API image::ImagePtr ipsdk::imaproc::filter::normalizedCrossCorrelation2dImg ( const image::ImageConstPtr pInImg2d,
const image::ImageConstPtr pInKnlImg2d 
)

wrapper function for Computes the Normalized Cross Correlation between an image and a kernel

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ normalizedCrossCorrelation2dImg() [4/4]

IPSDKIPLFILTERING_API void ipsdk::imaproc::filter::normalizedCrossCorrelation2dImg ( const image::ImageConstPtr pInImg2d,
const image::ImageConstPtr pInKnlImg2d,
const image::ImagePtr pOutRealImg 
)

wrapper function for Computes the Normalized Cross Correlation between an image and a kernel

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure