Why do we have a negative range in normalized cross correlation formula

4 views (last 30 days)
i was implementing template matching prog and came across normalized cross correlation formula . my question is why we are having a negative range for the limits of template (s=-a to a and t =-b to b ) and how do we implement this thing in prog as array cant have negative indexing.
I HAVE ATTACHED THE FORMULA WITH IT
AND
I HAVE ALSO ATTACHED THE PADDING ASSOCIATED WITH IT

Answers (1)

Geoff Hayes
Geoff Hayes on 6 Oct 2014
Rakesh - you won't have negative indexing if you pad your array (using, for example, padarray) and then move your window only along the original image.
In your above image, if the green square is the top left corner of the unpadded image/grid, then its coordinate is (0,0). But once you pad the image with the 2 pixel wide border along the top and bottom (of the grid), the coordinate of the top-left corner now becomes (2,2). And that is where you would start the (sliding) window from - moving to the right until you reach the top-right corner of the grid, before it was padded.
If your original grid is 5x5, then with the additional padding, it becomes 9x9 (because a and b are both 2). We then start our window at (2,2) and move to the right until we reach (2,7). Move to the next row and continue as before. We do this until we reach the final corner of (7,7), which is the bottom right corner of our original grid.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!