| Image Processing Toolbox |     ![]()  | 
Normalized two-dimensional cross-correlation
Syntax
Description
C = normxcorr2(TEMPLATE,A) computes the normalized cross-correlation of the matrices TEMPLATE and A. The matrix A must be larger than the matrix TEMPLATE for the normalization to be meaningful. The values of TEMPLATE cannot all be the same. The resulting matrix, C, contains the correlation coefficients, which may range in value from -1.0 to 1.0.
Class Support
The input matrices can be of class uint8, uint16, or double.
Algorithm
normxcorr2 uses the following general procedure:
Example
T = .2*ones(11); % make light gray plus on dark gray background T(6,3:9) = .6; T(3:9,6) = .6; BW = T>0.5; % make white plus on black background imshow(BW), title('Binary') figure, imshow(T), title('Template') % make new image that offsets template T T_offset = .2*ones(21); offset = [3 5]; % shift by 3 rows, 5 columns T_offset( (1:size(T,1))+offset(1), (1:size(T,2))+offset(2) ) = T; figure, imshow(T_offset), title('Offset Template') % cross-correlate BW and T_offset to recover offset cc = normxcorr2(BW,T_offset); [max_cc, imax] = max(abs(cc(:))); [ypeak, xpeak] = ind2sub(size(cc),imax(1)); corr_offset = [ (ypeak-size(T,1)) (xpeak-size(T,2)) ]; isequal(corr_offset,offset) % 1 means offset was recovered
See Also
References
[1]  J. P. Lewis, "Fast Normalized Cross-Correlation", Industrial Light & Magic. 
<http://www.idiom.com/~zilla/Papers/nvisionInterface/nip.html>
[2] Robert M. Haralick and Linda G. Shapiro, Computer and Robot Vision, Volume II, Addison-Wesley, 1992, pp. 316-317.
   | nlfilter | ntsc2rgb | ![]()  |