Code covered by the BSD License  

Highlights from
Fast/Robust Template Matching

4.0

4.0 | 6 ratings Rate this file 158 Downloads (last 30 days) File Size: 13.45 KB File ID: #24925
image thumbnail

Fast/Robust Template Matching

by Dirk-Jan Kroon

 

04 Aug 2009 (Updated 22 Feb 2011)

Template Matching with SSD Block Matching and Normalized CC, (color) 2D and 3D

| Watch this File

File Information
Description

TEMPLATE_MATCHING is a CPU efficient function which calculates matching score images between template and (color) 2D image or 3D image volume.

It calculates:
- The sum of squared difference (SSD Block Matching), robust template matching.
- The normalized cross correlation (NCC), independent of illumination, only dependent on texture

The user can combine the two images, to get template matching which works robust with his application.

Both matching methods are implemented using FFT based correlation.

Try the examples.

Please report: bugs, successes and other comment.

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
05 Sep 2009 Masoud

Perfect. It is fast and robust.
Thank you

11 Oct 2009 Tony

The function 'normxcorr2' available in matlab is faster than the code you submitted. Please profile it and see for yourself. But thanks for sharing the code.

29 Mar 2010 Dirk-Jan Kroon

*Tony
The submitted function supports 3D, SSD and color which is not in the function 'normxcorr2'. Also normxcorr2 is only a little bit faster when the template is only a few pixels in size...

09 Apr 2010 Steffen

I tried only the 3D normalized cross-correlation. It works very well. Thanks for sharing.

09 Dec 2010 Shahbaba2011

Thanx for sharing your code. How can I detect same template apping more than once in image.

13 Dec 2010 Marcos Belmonte

Hi, thanks for sharing your code, it's great. I have a 3D image with a sphere, and another sphere as a template. To locate the maximum cross correlation I write:
[I_SSD,I_NCC]=template_matching(T,I);
[x,y,z]=ind2sub(size(I_NCC),find(I_NCC==max(I_NCC(:))));
daspect([1 1 1]);
figure,isosurface(I,0); hold on; plot3(y,x,z,'r*'); title('MAX NCCC3D')

Is it correct?
I don't know if the real coordinates are displayed well because I don't understant very well the normalized cross-correlation in 3D.

Thanks very much.
Regards

27 Dec 2010 Marcos Belmonte

Hi, I have a problem with the NCCC three-dimensional, with the code I have written above, it plots a * in all the slices not only in the slices that match the template.
What should I do? Thanks in advance.

27 Dec 2010 Marcos Belmonte

The problem is that z is logical and I want it to be the number of the slice.

16 May 2011 Carlos

Hi, You used any paper to develop this code? Can you give me the name of this paper?

Thanks a lot

Please login to add a comment or rating.
Updates
05 Aug 2009

Fixed Range to 0..1

22 Feb 2011

Faster Multiple Template search

Tag Activity for this File
Tag Applied By Date/Time
template Dirk-Jan Kroon 04 Aug 2009 11:40:07
template matching Dirk-Jan Kroon 04 Aug 2009 11:40:08
matching Dirk-Jan Kroon 04 Aug 2009 11:40:08
crosscorrelation Dirk-Jan Kroon 04 Aug 2009 11:40:08
matching score Dirk-Jan Kroon 04 Aug 2009 11:40:08
normalized Dirk-Jan Kroon 04 Aug 2009 11:40:08
normalized crosscorrelation Dirk-Jan Kroon 04 Aug 2009 11:40:08
sum of squared differences Dirk-Jan Kroon 04 Aug 2009 11:40:08
sum of squared difference Dirk-Jan Kroon 04 Aug 2009 11:40:08
color Dirk-Jan Kroon 04 Aug 2009 11:40:08
2d Dirk-Jan Kroon 04 Aug 2009 11:40:08
3d Dirk-Jan Kroon 04 Aug 2009 11:40:08
block matching Dirk-Jan Kroon 04 Aug 2009 11:40:08
block matching Gökhan Kul 18 May 2010 07:45:00
input argument t is undefined error in template_matching at 56 t thiru 17 Nov 2010 08:49:17
i checked but it shows error thiru 17 Nov 2010 08:50:05
respected sir thiru 17 Nov 2010 08:50:05
ssd Thomas Steffen 02 Mar 2011 08:35:09

Contact us at files@mathworks.com