clear all
clc
%close all

F1=imread('image005.jpg');
F2=imread('image008.jpg');

F1=imread('zkouska.png');
F2=imread('zkouska2.png');

F1=imread('f.png');
F2=imread('f2.png');
%F2=imread('f2_5_0.png');

%F1=imread('z.png');
%F2=imread('z2.png');
F1=zeros(150,150);

gauss=1.3;

for kk=0:15
    
        %%%odsud
        posunx=kk;
        posuny=0;

        Fs=imread('f_s.png');
       %Fs=imread('cara.png');
        Fs=Fs(:,:,1);
        F1=zeros(size(F1,1),size(F1,2));
        
        posunxx=0.5*(size(F1,1)-size(Fs,1));
        posunyy=0.5*(size(F1,2)-size(Fs,2));
        F1(posunxx:(size(Fs,1)+posunxx-1),posunyy:(size(Fs,2)+posunyy-1))=Fs;
    
        F2=zeros(size(F1,1),size(F1,2));
        posunxx=posunx+0.5*(size(F1,1)-size(Fs,1));
        posunyy=posuny+0.5*(size(F1,2)-size(Fs,2));
        F2(posunxx:(size(Fs,1)+posunxx-1),posunyy:(size(Fs,2)+posunyy-1))=Fs;

        
        rozdilovy=uint8(zeros(size(F1,1),size(F1,2),3));
        rozdilovy(:,:,1)=F2;
        rozdilovy(:,:,3)=F1;%vykresli vysledny obraz do prostred platna 
        rozdilovy(:,:,2)=rozdilovy(:,:,3);

        [x,y]=LK(F1,F2,gauss);

        prah=1;
        xx=x(find(abs(x)>prah));
        yy=y(find(abs(y)>prah));

        xx=mean(mean(xx))
        yy=mean(mean(yy))

        %close all
        figure(1)
        subplot(2,2,1)
        imshow(x);
        subplot(2,2,2)
        imshow(y);
        subplot(2,2,3)
        imshow(F1);
        subplot(2,2,4)
        imshow(abs(rozdilovy));


        %%dosud


        na_pixl_X=xx/(posunx+1)
        na_pixl_Y=yy/(posuny+1)
        
        
        vysledeky(kk+1)=yy;
        vysledekx(kk+1)=xx;

figure(2)
quiver(x,y);

end

figure (1)
subplot(2,2,1);
plot(0:size(vysledeky,2)-1,vysledeky)
subplot(2,2,2);
plot(0:size(vysledekx,2)-1,vysledekx)







%%%%%%%%%%%%%%%%


% F=imread('3_1.png');
% %F=rgb2gray(F);
% 
% 
% maska=[1,2,1;2,0,2;1,2,1]
% %maska=[0,0,0;0,1,0;0,0,0];
% 
% G=convolution(F,maska)/12;
% G=uint8(G);
% 
% R=abs(G-F);
% 
% imshow(R)
% figure(2)
% imshow(G)




% kernel_size=7;
% k = (kernel_size-1)/2;
% sigma=1.5;
% 
% gaus_kernel=zeros(kernel_size,kernel_size);
% dgaus_kernel=zeros(kernel_size,kernel_size);
% for i=1:kernel_size
%     for j=1:kernel_size
%         gaus_kernel(i,j)=1/(2*pi*sigma^2)*exp(-(((i-k-1)^2+(j-k-1)^2)/(2*sigma^2)));
%         dgaus_kernel(i,j)=-(i-k-1)/(2*pi*sigma^3)*exp(-(((i-k-1)^2+(j-k-1)^2)/(2*sigma^2)));
%     end;
% end
% 
% 
% 
% surf(dgaus_kernel);