M-File Help: isimilarity | View code for isimilarity |
Locate template in image
s = isimilarity(T, im) is an image where each pixel is the ZNCC similarity of the template T (MxM) to the MxM neighbourhood surrounding the corresonding input pixel in im. s is same size as im.
s = isimilarity(T, im, metric) as above but the similarity metric is specified by the function metric which can be any of @sad, @ssd, @ncc, @zsad, @zssd.
Load an image of Wally/Waldo (the template)
T = iread('wally.png', 'double');
then load an image of the crowd where he is hiding
crowd = iread('wheres-wally.png', 'double');
Now search for him using the ZNCC matching measure
S = isimilarity(T, crowd, @zncc);
and display the similarity
idisp(S, 'colormap', 'jet', 'bar')
The magnitude at each pixel indicates how well the template centred on that point matches the surrounding pixels. The locations of the maxima are
[~,p] = peak2(S, 1, 'npeaks', 5);
Now we can display the original scene
idisp(crowd)
and highlight the most likely places that Wally/Waldo is hiding
plot_circle(p, 30, 'fillcolor', 'b', 'alpha', 0.3, ...
'edgecolor', 'none')
plot_point(p, 'sequence', 'bold', 'textsize', 24, ...
'textcolor', 'k', 'Marker', 'none')
imatch, sad, ssd, ncc, zsad, zssd, zncc
© 1990-2012 Peter Corke.