We are using phase correlation to find pattern on image and what we get is 15% of results is spurious. Ours pattern has 32x32 pixels and image for research has 32x512 pixels. So we put Pattern to 32x512 pixels image to the left side and the rest of image is filled by zero pixels. Next we apply FFT to pattern and the image without applying a window function. Then we make Hadamard product, normalized it and do inverse FFT of resulting matrix. Sometimes we get false peak almost on the middle of plot where edge effects and circularity of correlation should be neglected.

The question:

What else could be the cause of false peak ?


what was searched and what we got: what was searched and what we got

real research image 32x512 (before greyscale) research image

real pattern in (in greyscale) real pattern

correlation result correlation result

Best Regards

Dawid D

  • $\begingroup$ I'm working in frequency domain and I can't find how is defined phase correlation in spatial domain so i don't fully understand the math behind the code. @lennon310 can you explicitly write the equations ? Thank you very much for your help. $\endgroup$
    – user7583
    Commented Jan 17, 2014 at 8:10
  • $\begingroup$ @deadline, my code works on spatial domain. It's a normalized cross correlation, you can check this paper for reference: scribblethink.org/Work/nvisionInterface/nip.pdf Thanks $\endgroup$
    – lennon310
    Commented Jan 17, 2014 at 15:51

1 Answer 1


I suspect your problem occurs due to some scaling issues. Basically you need to normalize your research image to the pattern template by subtracting the mean value of the template. And it is better calculate the ratio of correlation to the standard deviation of both images.

I don't know which programming language you are using. I wrote a Matlab code for you to better get what I meant above (note that I did not use zero padding since I work on the spatial domain, I don't think it is the issue that caused your spurious correlation too):

file1='https://lh3.googleusercontent.com/-GQSrln7qnO8/UtCT8elB_FI/AAAAAAAAEaw/bh7aKyyMRIo/s512/subimage.png'; % Research image
file2='https://lh5.googleusercontent.com/-YaDK_1QvqIQ/UtCT6-rNkNI/AAAAAAAAEao/41MOQJ_bXxU/s512/pattern_grey.png';   % Template pattern image

I2=I2(:,1:32); %% No padding  

It=double(I2);  % template
Ii=double(I1);  % image

Ii_mean = conv2(Ii,ones(size(It))./numel(It),'same');
It_mean = mean(It(:));
corr_1 = conv2(Ii,rot90(It-It_mean,2),'same')./numel(It);
corr_2 = Ii_mean.*sum(It(:)-It_mean);
conv_std = sqrt(conv2(Ii.^2,ones(size(It))./numel(It),'same')-Ii_mean.^2);
It_std = std(It(:));
S = (corr_1-corr_2)./(conv_std.*It_std);


What you get:

enter image description here

You can observe the correlation peak at 17th row, 450th column, which is the position of your pattern in original image.

You can also use Matlab built-in function normxcorr2(It,Ii);, just note that this function results in the correlation map with the sum of the lengths of two images, while my code provides you the correlation map the same size of your research image.

  • $\begingroup$ I think he does need to do zero padding if he wants to do FFT based convolution. You got away with not having it by using conv2 instead. $\endgroup$
    – Aaron
    Commented Jan 13, 2014 at 17:20
  • $\begingroup$ @Aaron thanks Aaron. Yes I found that zero padding may not a big issue, it is probably mainly due to the scaling problem. I deleted that part in my answer. Thanks $\endgroup$
    – lennon310
    Commented Jan 13, 2014 at 17:43
  • $\begingroup$ @lennon310 Thank you for your answer. We are using ImageJ so whole ours code is in Java. We are implementing division by standard driviation in the sumtable schema because there is a lot of calculations. I only doesn't understand corr_2 line there will by zero always becouse sum of element with subtrac mean value will always zero. Can an you explain please, why are you multiplying mean value of image by sum of template value with subtract mean value? $\endgroup$
    – Dawid D
    Commented Jan 17, 2014 at 15:15
  • $\begingroup$ @DawidD thank you very much for pointing out! You are right we don't need corr_2 since it is always zero. My code is just a normalized cross correlation (scribblethink.org/Work/nvisionInterface/nip.pdf), and there is no corr_2 either. Thank you:) $\endgroup$
    – lennon310
    Commented Jan 17, 2014 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.