normxcorr2 for template matching: old error in documentation ?
Mostrar comentarios más antiguos
In the current r2015a online documentation's example of template matching using normxcorr2 ( mathworks.com/help/images/ref/normxcorr2.html ), the offset of correlation array, because of zero padding is assumed to be the size of template:
yoffSet = ypeak-size(onion,1);
xoffSet = xpeak-size(onion,2);
However, when I run through the example on my machine (r2011b), and extract the rectangle matching region of 'peppers' based on the above values ...
match = peppers(yoffSet:yoffSet+size(onion,1)-1, xoffSet:xoffSet+size(onion,2)-1);
... the resulting crop is not equal to 'onion'. It is in fact offset by 1*1 pixel. Don't know if this can be caused by my older Matlab version.
From what I can understand from normxcorr2 code and conv2 help, the padding is in fact of width (size(T)-1)/2 on each side for a template with an odd size (for an even template size, the padding is size(T)/2 on the left and top, and size(T)/2 - 1 on the right and bottom). These would be the correct offset values for the central pixel of template (when there is one, i.e. odd template size).
In the end, the offset for the top-left pixel of the template-matching region should rather be size(T) -1. Am I right ?
Respuesta aceptada
Más respuestas (1)
Emmanuel
el 13 de Oct. de 2015
1 comentario
Alex Taylor
el 13 de Oct. de 2015
Emmanuel,
That is correct. I will make sure that this error in the documentation is corrected. The correct positioning of imrect given the computed x and y translations (offsets) should be:
imrect(hAx,[xoffSet+1,yOffset+1,size(onion,2),size(onion,1)]);
Thanks for pointing this out.
Categorías
Más información sobre Template Matching en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!