
% rozeznavani znaku 1
% prizpusobeny filtr

function sfa7_1


% rozeznavani znaku v textu

close all

stranka=double(255-imread("sample.jpg"));
stranka=stranka(60:560,300:800);
dim=size(stranka)

max(max(stranka))
figure(1,'units','normalized','position',[0,1,0.5,0.8])
imshow(stranka,[]);


pismeno=stranka(72:92,40:60);
dim2=size(pismeno)
s1=floor(dim(1)/2-dim2(1)/2); s2=floor(dim(2)/2-dim2(2)/2);
figure(2)
imshow(pismeno,[]);

h=zeros(dim);
h(s1:s1+dim2(1)-1,s2:s2+dim2(2)-1)=pismeno;
matched=conj(ft2(h,1));
figure(3);
imshow(abs(matched),[])

g=ft2(stranka,1);
g2=g.*matched;
vystup=abs(ift2(g2,1));
maximum=max(max(vystup));
vystup2=vystup.*(vystup>0.9*maximum);
figure(4,'units','normalized','position',[0,1,0.5,0.8])
imshow(vystup2,[]);


figure(5,'units','normalized','position',[0,1,0.5,0.8])
konvol=abs(ift2(ft2(vystup2,1).*ft2(h,1),1));
maximum=max(max(konvol));
imshow(konvol,[0,0.5*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

