close all
clear all

% template=imread('pa_org_template.png'); 
% %template=imread('tesoura_org_template.png');
% A=imread('orgimage.png');
% %A=imread('TP2_img_01_01g.png'); %Just to try the gray level image


template=imread('pa_template.png');
%template=imread('tesoura_template.png');
A=imread('ordtools.png');



% cross-correlate BW and offsetTemplate to recover offset  
cc = normxcorr2(template,A); 
figure(1); imshow(cc)

[ypeak, xpeak] = find( cc > 0.80);
figure(2), imshow(A);
pause

figure(2);hold on;
plot(xpeak-size(template,2)/2, ypeak-size(template,1)/2, 'or');

step=4;

cc2=cc(1:step:end, 1:step:end);
x=1:size(cc2,2); y=1:size(cc2,1);
[X Y]=meshgrid(x,y);


figure(3), h=mesh(Y,X,cc2); %set(h,'EdgeColor', [0 0 0]); axis off; %grid off;
ylabel('cols'); xlabel('lines');
 