# What does it mean when cross correlation between two images occur at negative coordinates

I am using Matlab normxcorr2 to calculate the cross correlation between several images, something like what has been done here: in Matlab documentation. There are some of the examples that I get negative values for xoffSet and yoffSet, but I am not sure what it means when these values are negative. Another issue, is practical since I need to give these xoffSet and yoffSet values as an input to coordinates of rectangle in an image, but since these are negative, the function throws an error. I googled it but no success in finding something that can explain such thing. I was thinking of just putting zero instead of negative values, but I'm not sure if that's a right approach. I would appreciate if someone can explain about the meaning of such negative values and how I can substitute such negative values with appropriate quantities.

• Welcome to DSP.SE! It sounds like the coordinates your call to peak is returning is in the padding area added by normxcorr2. Are you sure you are giving the yoffSet = ypeak-size(onion,1); call the correct image (i.e. your onion patch image). – Peter K. Sep 13 '17 at 16:05
• Thank you for your comment! Basically, to find yoffSet, and xoffSet, I need to subtract the first and second dimensions of the template image (the image with the smaller size), respectively, from ypeak and xpeak. So, the answer is yes. – Miranda Sep 13 '17 at 16:11

## 1 Answer

It means the best match to template happens outside the image.

For instance, let's say your template is 5 by 5.
And you got answer which is -1, -1. It means the part of teh image which best matches you image is centered at [-1, -1] and you only have part of it in your image.

This is really extreme case.

P. S.
If you share your data (2 Images) we'll be able to assist more.

• Thank you for your response Royi! Unfortunately, I cannot share my images. Can you clarify what you mean by outside the image? By image, do you mean the parent image for which we want to find the maximum correlation with a template? If so, how does it happen? And is there anyway to transform these negative values inside the image area? – Miranda Sep 13 '17 at 16:28