Code covered by the BSD License  

Highlights from
WNCC - Weighted Normalized Cross Correlation

5.0 | 1 rating Rate this file 22 Downloads (last 30 days) File Size: 4.14 KB File ID: #33340 Version: 1.0
image thumbnail

WNCC - Weighted Normalized Cross Correlation


Andrew Diamond (view profile)


Performs pattern matching in an image via normalized cross correlation but with a weighted template

| Watch this File

File Information

Normalized Cross Correlation (NCC) is an excellent choice for finding a given pattern in an image given a known scale and orientation. Matlab's IP toolbox normxcorr2 function does this.
However there's no way to specify which pixels of the pattern are important. This is particularly problematic because the template (i.e. pattern) matrix inadvertently specifies a rectangular ROI. So if the pattern as it appears in the image has artifacts close enough to the pattern, it will be in range of the template window and so the response will be degraded. Assuming that the nature of the problem is such that such artifacts are not actually important to the pattern match, being able to de-weight pixels away from the pattern can mitigate this.
Note: This function is more expensive than normxcorr2. It uses 3 convolutions (technically correlation) between image and template sized matrices. The convolution implementation automatically switches between frequency and spatial domains and so the time is usually “reasonable” .
The WNCC formula (but not the implementation) is the same as NCC but it with weighted variance vs regular variance, i.e.
NCC = cov(x,y)/sqrt(cov(x,x)*cov(y,y))
WNCC = wcov(x,y,w)/sqrt(wcov(x,x,w)*wcov(y,y,w))
Where “wcov” is the weighted covariance w/r to the weights “w”
(see the comments in wncc for details)

In the example (picture) above, the “template” (i.e. pattern) is a cross. The “image” has such a pattern but within the rectangular region that contains it there are two bright artifacts that degrade the performance of NCC (bottom right). The “template weights” image shows that the WNCC matching will largely ignore anything not very close to a cross shaped ROI. In particular, this weighting will allow the artifacts to be ignored. The improved result (note colorbars) is shown in the WNCC image (bottom left).

Tested in 2008a, 2008b, 2008b, 2011a

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.6 (R2008a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
21 Oct 2011 Dave Holden

Works great. Thanks!

19 Oct 2011 Sven

Sven (view profile)

I haven't yet tried this but I've needed something similar in the past, so thank you for this submission.

Comment only

Contact us