5
$\begingroup$

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.

$\endgroup$
2
  • 1
    $\begingroup$ 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). $\endgroup$
    – Peter K.
    Commented Sep 13, 2017 at 16:05
  • $\begingroup$ 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. $\endgroup$
    – Miranda
    Commented Sep 13, 2017 at 16:11

1 Answer 1

1
$\begingroup$

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 the image which best matches you image is centered at [-1, -1] and you only have part of it in your image.

This is really an extreme case.

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

$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$
    – Miranda
    Commented Sep 13, 2017 at 16:28
  • $\begingroup$ Can you please add some clarifications to your answer based on my questions in the comment? $\endgroup$
    – Miranda
    Commented Apr 4, 2021 at 16:32

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.