Thread Subject: Template matchine with binary image

Subject: Template matchine with binary image

From: Prasanna

Date: 9 Nov, 2009 09:25:19

Message: 1 of 3

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.

Subject: Template matchine with binary image

From: ImageAnalyst

Date: 9 Nov, 2009 13:14:43

Message: 2 of 3

On Nov 9, 4:25 am, "Prasanna " <pmgunaward...@gmail.com> wrote:
> 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.

-------------------------------------------------------------------------------------------------------
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).

Subject: Template matchine with binary image

From: Prasanna

Date: 9 Nov, 2009 18:39:04

Message: 3 of 3

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

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
please send me ... Prasanna 9 Nov, 2009 04:29:02
rssFeed for this Thread

Contact us at files@mathworks.com