I was working on the Normalized Cross Correlation for Template Matching in Spatial domain. While the method is slow, it works good enough for my purpose. But I saw a weird thing in there. Let me explain the situation below:
91 91 91 91 9 9
91 91 91 91 9 9
8 6 7 8
pattern image source image.
Now, when NCC goes through this: It finds the mean of the template image as 91 and underlying source image also as 91 and then it subtracts the intensity value from the pixel which essentially takes all terms in the formula to zero resulting in an undefined correlation value and no matches are found even when there is a perfect match.! How to get around this situation? I am using the following formula: from the excellent source by J. P. Lewis
Also, when I modified the formula to subtract (mean/2) from every pixel intensity, it seemed to work fine but I am concerned as to how much vulnerable to Illumination this new correlation coefficient is.
Edit: Conditions even worsened when I took a 1 X 1 pattern image and had multiple occurrences in source image. Using the above modified version I was unable to find appropriate matches. I would love to look into various work arounds many of you might have been using. Thanks.!