
% rozeznavani znaku 2
% multiplexovany prizpusobeny filtr

function sfa7_2



close all

% nactu vstupni data
abc=double(imread("abc.jpg"));
dim=size(abc)
figure(1)
imshow(abc,[])

% slozim dva vertikalne posunute vzory
% normalizuji, protoze 'B' je intenzivnejsi nez 'A' 
a=abc(110:200,40:130);a=a/norm(a);
b=abc(110:200,150:240);b=b/norm(b);
pismena=[a;b];
dim2=size(pismena)
s1=floor(dim(1)/2-dim2(1)/2); s2=floor(dim(2)/2-dim2(2)/2);
figure(2)
imshow(pismena,[])

% vlozim do stredu odezvy
h=zeros(dim);
h(s1:s1+dim2(1)-1,s2:s2+dim2(2)-1)=pismena;

% multiplexovany filtr
matched=conj(ft2(h,1));
figure(3);
imshow(abs(matched),[])

% vystup
g=ft2(abc,1);
g2=g.*matched;
vystup=abs(ift2(g2,1));
maximum=max(max(vystup));
vystup2=vystup.*(vystup>0.8*maximum); % prahovani
figure(5)
imshow(vystup2+abc/max(max(abc))*maximum,[]);

end



function G=ft2(g,del)
 G=fftshift(fft2(fftshift(g)))*del*del;
end


function g=ift2(G,delf)
 g=ifftshift(ifft2(ifftshift(G)))*(delf*size(G,1))^2;
end

