Path: news.mathworks.com!not-for-mail
From: "Peter Bone" <peterbone@hotmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Template Matching
Date: Fri, 4 Apr 2008 10:12:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 28
Message-ID: <ft4uti$a7o$1@fred.mathworks.com>
References: <fsnera$t69$1@fred.mathworks.com>
Reply-To: "Peter Bone" <peterbone@hotmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1207303922 10488 172.30.248.37 (4 Apr 2008 10:12:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 4 Apr 2008 10:12:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 870367
Xref: news.mathworks.com comp.soft-sys.matlab:461036


"akane ajibana" <androalpha_v7@yahoo.com> wrote in message
<fsnera$t69$1@fred.mathworks.com>...
> hi everyone..
> i have need help on template matching. i have an image that
> need to be match with 3 subimage(template images).can anyone
> teach me on the coding in Matlab

The images cannot be different sizes so you will have to pad
out the smaller image with zeros to make it the same size.
The images must also be square.

% fourier transform both images
fi = fft2(i);
fr = fft2(ref);

% perform phase correlation (amplitude is normalized)
fc = fi .* conj(fr);
fcn = fc ./ abs(fc); 
c = real(ifft2(fcn));

% find the peak in the correlation plane
[v index] = max(c(:));
[y x] = ind2sub(siz,index);
% invert quadrants due to fft shift
mid = siz(1) / 2;
y = y - sign(y-mid-0.5) * mid;
x = x - sign(x-mid-0.5) * mid;