<< imconv SIP - Scilab Image Processing Toolbox imfinfo >>

SIP - Scilab Image Processing Toolbox >> SIP - Scilab Image Processing Toolbox > imcorrcoef

imcorrcoef

Template matching by normalized correlation

Calling Sequence

C = imcorrcoef(Img, template)

Parameters

Img
M x N Grayscale image in any range.
template
n x n matrix, n odd. A small object to be found in the image.
C
The correlation coefficient image. Its highest value occurs where the template matches exactly.

Description

Function imcorrcoef performs template matching by 2D correlation of a grayscale image and a template. This means the template is compared to the image pixel-by-pixel, for every possible translation of the template. The result is normalized to range from -1 to +1. You may also use the absolute value of this measure.

This is an expensive calculation, and should be used only for small templates. The object to be detected must appear in the image with very little variation of rotation and scale. This is useful if you can restrict the image capture to avoid those problems.

Examples

//
// Let's detect the letter "B" in a license plate
//
img = gray_imread(SIPDIR+'images/plate.gif');
clf; imshow(img);
template = gray_imread(SIPDIR+'images/template.jpg');
clf; imshow(template);

C = imcorrcoef(img, template);

clf;
imshow(img+2*(C==max(C)),[]);  // letter is detected!!

Authors

Availability

The latest version of the Scilab Image Processing toolbox can be found at

http://siptoolbox.sourceforge.net

See Also


<< imconv SIP - Scilab Image Processing Toolbox imfinfo >>