image matching using 2 for loops(template matching in a sliding window manner)
Show older comments
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
Doug Hull
on 26 Feb 2013
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?
XyzPersonnel
on 26 Feb 2013
XyzPersonnel
on 26 Feb 2013
Image Analyst
on 26 Feb 2013
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.
Answers (1)
Image Analyst
on 26 Feb 2013
0 votes
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
Categories
Find more on Template Matching in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!