Code covered by the BSD License  

Highlights from
Generalized Normalized Cross Correlation

5.0

5.0 | 2 ratings Rate this file 63 Downloads (last 30 days) File Size: 5.3 KB File ID: #29005
image thumbnail

Generalized Normalized Cross Correlation

by Dirk Padfield

 

11 Oct 2010 (Updated 19 Apr 2012)

Computes the correct NCC at all locations regardless of the relative size of A and TEMPLATE

| Watch this File

File Information
Description

normxcorr2_general computes the normalized cross-correlation of matrices TEMPLATE and A. The resulting matrix C contains correlation coefficients and its values may range from -1.0 to 1.0.

Limitations of normxcorr2:
The documentation of normxcorr2 states that, "The matrix A must be larger than the matrix TEMPLATE for the normalization to be meaningful." It is implemented following the details of the paper "Fast Normalized Cross-Correlation", by J. P. Lewis, Industrial Light & Magic. This approach assumes the template is small relative to the image and proceeds to calculate the normalization across the entire template. This leads to correct computations wherever the template is wholly overlapping with the image, but the computation is incorrect in the borders of the output (the border size is proportional to the template size). This problem is therefore worse for larger templates to the point that, when the template is the same size as the image, the only correct value is at the center pixel (where the images are fully overlapping). Thus, if normxcorr2 is used for such things as registering images of the same size, the result will be incorrect.

The new normxcorr2_general:
normxcorr2_general is more general than normxcorr2 in that it gives correct results everywhere regardless of the relative size of A and TEMPLATE. It accomplishes this by computing the normalized correlation only in the overlap regions between the two matrices. Thus, the result is correct for all locations of correlation. The result is the same as if the NCC were carried out in the spatial domain (which would take a long time to compute for large matrices).

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
03 Mar 2011 J. Kristian Sveen  
30 Jan 2012 John Bowen

Seems to work well. Seems faster than normxcorr2_mex for larger arrays, which is no longer on Matlab Central but is around on the internet.

23 Feb 2012 Florian

Please indicate that the Image Processing Toolbox is required as it uses functions thereof (at least iptchecknargin).

Please login to add a comment or rating.
Updates
13 Oct 2011

Added a new optional parameter. requiredNumberOfOverlapPixels sets to 0 all locations in C computed from positions where A and T overlap less than requiredNumberOfOverlapPixels.

19 Apr 2012

Made the code independent of the image processing toolbox (IPT). Note that the IPT is needed to run the example since normxcorr2 is part of that toolbox. However, normxcorr2_general does not require the IPT.

Tag Activity for this File
Tag Applied By Date/Time
image processing Dirk Padfield 12 Oct 2010 11:50:36
normxcorr2 Dirk Padfield 12 Oct 2010 11:50:36
ncc Dirk Padfield 12 Oct 2010 11:50:36
cc Dirk Padfield 12 Oct 2010 11:50:36
normalized crosscorrelation Dirk Padfield 12 Oct 2010 11:50:36
crosscorrelation Dirk Padfield 12 Oct 2010 11:50:36
correlation Dirk Padfield 12 Oct 2010 11:50:36
cc Pete 12 Apr 2011 13:04:34
cc Korea Aerospace university 18 May 2011 09:05:41

Contact us at files@mathworks.com