clc
clear all
close all
warning off all

[num txt] = xlsread('seznam_registrace2');

rozsah = size(txt);

cesta_koresp_sourad = 'c:\Users\Michal\Documents\VUTBR\Magistr\Diplomová práce\Programy\Hledání korespondenčních značek\Koresp_souradnice_nereg\';
cesta_sourad = 'c:\Users\Michal\Documents\VUTBR\Magistr\Diplomová práce\Programy\Hledání korespondenčních značek\Souřadnice_nereg\';

start = 1;
vse = 0;
for i = start:rozsah(2)
    for j = 2:rozsah(1)
        if length(cell2mat(txt(j,i))) == 0

            continue
        else
        vse = vse + 1;          

        end
    end
end
count = 0;
nul = 0;
m = 1;

for i = start:rozsah(2)
    for j = 3:rozsah(1)
        if length(cell2mat(txt(j,i))) == 0
            nul = nul + 1;
            continue
        else
            clc
            count = count+1;
            disp('Hotovo [%]')
            disp(count/vse*100)
            
            soubor1 = cell2mat(txt(2,i));
            soubor2 = cell2mat(txt(j,i))
            cesta_obr = cell2mat(txt(1,i));
            
            
            obr1 = imread([cesta_obr '' soubor1 '' '.jpg']);
            obr2 = imread([cesta_sourad '' soubor2 '' '.jpg']);

            obr1 = imresize(obr1,[1000 1500]);
            obr2 = imresize(obr2,[1000 1500]);
            
            load([cesta_koresp_sourad '' soubor1 '' '_korespondence.mat'])
            sourad1 = koresp_sourad_vse(m:m+1,:);        
            sourad2 = koresp_sourad_vse(m+2:m+3,:);
            D = koresp_sourad_vse(m+4,:);
            D(find (D==0))=[];
            sourad1(:,find (sourad1(1,:)==0))=[];
            sourad2(:,find (sourad2(1,:)==0))=[];
            m = m+5;
            obr_g22_cely = double(obr2)/double(max(max(obr2)));
            
%             sourad1(:,15) = [];
%             sourad2(:,15) = [];
%             D(15) = [];
            
            for k = 1:length(sourad1)
                s1 = sourad1(:,k);
                s2 = sourad2(:,k);
                
                vel_vyr = 60;
                obr_g11 = double(obr1(:,:,2))/double(max(max(obr1(:,:,2))));
                obr_g11(s1(1) - 5 : s1(1) + 5,s1(2)) = 1;
                obr_g11(s1(1),s1(2) - 5 : s1(2) + 5) = 1;
                obr_g11 = obr_g11(s1(1) - vel_vyr : s1(1) + vel_vyr,s1(2) - vel_vyr : s1(2) + vel_vyr);
                obr_g22 = double(obr2)/double(max(max(obr2)));
                obr_g22(s2(1) - 7 : s2(1) + 7,s2(2)) = 0;
                obr_g22(s2(1),s2(2) - 7 : s2(2) + 7) = 0;
                obr_g22 = obr_g22(s2(1) - vel_vyr : s2(1) + vel_vyr,s2(2) - vel_vyr : s2(2) + vel_vyr);
                


%                 obr_g22_cely(s2(1) - 5 : s2(1) + 5,s2(2)) = 1;
%                 obr_g22_cely(s2(1),s2(2) - 5 : s2(2) + 5) = 1;
%                 obr_g22_cely = obr_g22(s2(1) - vel_vyr : s2(1) + vel_vyr,s2(2) - 100 : s2(2) + vel_vyr);
                
                figure(1)
                subplot(2,2,1)
                imshow(obr_g11)
                subplot(2,2,2)
                imshow(obr_g22)
                subplot(2,2,3)
                plot(D)
                text(k,D(k),[' \leftarrow ' '' num2str(D(k))])
                
  
                pause()
                
            end
            
                
            
            
        end
    end
    

    
    m = 1;
end





