Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Template matchine with binary image

8 views
Skip to first unread message

Prasanna

unread,
Nov 9, 2009, 4:25:19 AM11/9/09
to
Hi all,
I am having a binary image "I" which is 480*640 size.
And my templates are "temp1"(size 146*149 binary) and temp2 (size 96*96 binary).

Now I want to match these 2 templates with image "I" and identify the matching locations in the image "I".

Please some one send me the MATLAB code for this. Because I'm not familiar with the this section.

ImageAnalyst

unread,
Nov 9, 2009, 8:14:43 AM11/9/09
to

-------------------------------------------------------------------------------------------------------
I'm not sure how long it will take, but if your templates are in the
image (i.e. the version of the template in the image is not scaled or
rotated) you can use the xcorr2() function in the Signal Processing
Toolbox to do a cross correlation of the images. This is a simple one-
liner solution - actually a little more because you'd have to search
the resulting array for the max using the find() function or similar
alternate ways. If you don't have that toolbox, you can easily write
it yourself in a few lines (4 nested for loops in the spatial domain).

Prasanna

unread,
Nov 9, 2009, 1:39:04 PM11/9/09
to
Thanks 4 replying. Below display the template matching code that I wrote. I did this using several demos those are in the MATLAB 2008a version. Here "someblobsI" means the binary image. "Icropped" means the template(which is also binary). no rotations and scalings happenning to both image and the template. Is this code relevant to my application or should I change something here?


C = real(ifft2(fft2(someblobsI) .* fft2(rot90(Icropped,2),480,640)));

figure, imshow(C,[]);
max(C(:))

thresh = 1000 ; % Use a threshold that's a little less than max.
figure, imshow(C > thresh); % identification

regards
Prasanna

0 new messages