image matching using 2 for loops(template matching in a sliding window manner)

I have to match two images.
The second image is a cropped part of the first image. I want to use two for loops to compare both images with the condition that setting a threshold level to a value, and thus storing the matched rows and columns and then displaying the matched part by making a rectangle on it.
The looping should be done in such a way that sliding the cropped image on the original image.

4 Comments

You need to tell us what you have tried. If it is exactly cropped from the original, then there should be a perfect match. Have you tried convolution and correlation functions?
yes it is exactly the cropped part from original. i did tried correlation but want to do through for loop
cn any 1 suggest how this can be achieved.
See my code, referenced below. You can't use the simple form of correlation or convolution and have it work reliably, you need to use "normalized" cross correlation, which is done by the normxcorr2. If you used correlation, then any bright portion of the image could have a brighter/higher value than when your template is properly aligned. That's why you have to normalize it - let me know if you don't understand why.

Sign in to comment.

Answers (1)

Using normxcorr2() is probably the easiest way. I've posted code for that many times, the latest being: http://www.mathworks.com/matlabcentral/answers/64649#comment_131900

Asked:

on 26 Feb 2013

Community Treasure Hunt

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

Start Hunting!