imcorrcoef - template matching by normalized correlation |
C = imcorrcoef(Img, template) |
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. |
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. |
// // Let's detect the letter "B" in a license plate // img = gray_imread(SIPDIR+'images/plate.jpg'); xbasc(), imshow(img); template = gray_imread(SIPDIR+'images/template.jpg'); xbasc(), imshow(template); C = imcorrcoef(img, template); xbasc(); imshow(img+2*(C==maxi(C)),[]); // letter is detected!! |
Ricardo Fabbri <rfabbri@if.sc.usp.br> |
The latest version of the Scilab Image Processing toolbox can be found at |
http://siptoolbox.sourceforge.net |
imconv, mkfilter, edge |