function varargout = oprava5(varargin)
% OPRAVA5 MATLAB code for oprava5.fig
%      OPRAVA5, by itself, creates a new OPRAVA5 or raises the existing
%      singleton*.
%
%      H = OPRAVA5 returns the handle to a new OPRAVA5 or the handle to
%      the existing singleton*.
%
%      OPRAVA5('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in OPRAVA5.M with the given input arguments.
%
%      OPRAVA5('Property','Value',...) creates a new OPRAVA5 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before oprava5_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to oprava5_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help oprava5

% Last Modified by GUIDE v2.5 29-Apr-2013 17:28:10

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @oprava5_OpeningFcn, ...
                   'gui_OutputFcn',  @oprava5_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before oprava5 is made visible.
function oprava5_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to oprava5 (see VARARGIN)

% Choose default command line output for oprava5
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes oprava5 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = oprava5_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

%% po spuštění
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

global cislo_nahled;
global kolonky cesta zapis_excel;
global poradi vstup_formular vstup;

cislo_nahled = 1;
kolonky = 1;
poradi = 1;

global registr_ref_znak;
for i = 1:150
    for k = 1:36
        registr_ref_znak{k,i} = zeros(2,2);
    end
end
%%
[a,pocet_souboru] = size(vstup_formular);

if  pocet_souboru > 4 &&  strcmp(char(vstup_formular(end-3)), '.') == 1
    pocet_souboru = 1;
end

set(handles.prohlizeny_soubor,'String',strcat(['SOUBOR: ',num2str(cislo_nahled),'/',num2str(pocet_souboru)])); 

if length(vstup_formular) > 1
    [a,b,c] = size(vstup_formular);

    prvni_formular = char(vstup_formular);
    % pokud je vybrán jen jeden obraz
    if  b > 4 &&  strcmp(char(vstup_formular(end-3)), '.') == 1
        % pokud je vybráno víc obrazů
    else
        prvni_formular = char(vstup_formular(1));
    end
    vstup = im2double(imread(strcat(cesta,prvni_formular)));
    
    [a,b,c] = size(vstup);
    if (c > 2)
        vstup = rgb2gray(vstup);
    end
    
    vstup = vstup / max(max(vstup));
    imshow(vstup,'InitialMagnification','fit');
end

%%
[num,txt,raw] = xlsread('Vysledky.xls');
zapis_excel = raw;

%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% editační okna
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function rozpoznany_Callback(hObject, eventdata, handles)
% hObject    handle to rozpoznany (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of rozpoznany as text
%        str2double(get(hObject,'String')) returns contents of rozpoznany as a double


% --- Executes during object creation, after setting all properties.
function rozpoznany_CreateFcn(hObject, eventdata, handles)
% hObject    handle to rozpoznany (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function navrh1_Callback(hObject, eventdata, handles)
% hObject    handle to navrh1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of navrh1 as text
%        str2double(get(hObject,'String')) returns contents of navrh1 as a double


% --- Executes during object creation, after setting all properties.
function navrh1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to navrh1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function navrh2_Callback(hObject, eventdata, handles)
% hObject    handle to navrh2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of navrh2 as text
%        str2double(get(hObject,'String')) returns contents of navrh2 as a double


% --- Executes during object creation, after setting all properties.
function navrh2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to navrh2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function navrh3_Callback(hObject, eventdata, handles)
% hObject    handle to navrh3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of navrh3 as text
%        str2double(get(hObject,'String')) returns contents of navrh3 as a double


% --- Executes during object creation, after setting all properties.
function navrh3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to navrh3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function navrh4_Callback(hObject, eventdata, handles)
% hObject    handle to navrh4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of navrh4 as text
%        str2double(get(hObject,'String')) returns contents of navrh4 as a double


% --- Executes during object creation, after setting all properties.
function navrh4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to navrh4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function info_Callback(hObject, eventdata, handles)
% hObject    handle to info (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of info as text
%        str2double(get(hObject,'String')) returns contents of info as a double


% --- Executes during object creation, after setting all properties.
function info_CreateFcn(hObject, eventdata, handles)
% hObject    handle to info (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function vlastni_Callback(hObject, eventdata, handles)
% hObject    handle to vlastni (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of vlastni as text
%        str2double(get(hObject,'String')) returns contents of vlastni as a double


% --- Executes during object creation, after setting all properties.
function vlastni_CreateFcn(hObject, eventdata, handles)
% hObject    handle to vlastni (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% editační okna konec
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% tlačítko oprava
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in tlcitko.
function tlcitko_Callback(hObject, eventdata, handles)
% hObject    handle to tlcitko (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% global vstup vstup_formular
global cesta cislo_nahled;
global kolonky pocet_kolonek;
global poradi zapis_excel;
global vyst vyst_out zobraz_vyber_navrhu;

global navrhy_cislo navrhy_pismeno registr_ref_znak;
global navrhy_obraz_cislo navrhy_obraz_pismeno;

if isempty(cesta) == 1
    set(handles.info,'String','Nejprve spuste test');   
    set(findobj('tag','info'),'BackgroundColor', 'red');
    return;
end
set(findobj('tag','info'),'BackgroundColor', 'white');

if poradi == 1
    % vypnu tlačítka
    set(handles.nahoru,'enable','off');   
    set(handles.dolu,'enable','off');   
    set(handles.pred,'enable','off');   
    set(handles.po,'enable','off');   
    set(handles.zvrit,'enable','off');   
    set(handles.pushbutton77,'enable','off');   
    set(handles.panelak,'Visible','off');   

    load data\navrh.mat
    load data\obrazy.mat

    % načtení informačního souboru ze stejné složky jako obrazy
    % hledá podle koncovky .mat, v jedné složce může být jeden
    koren = cd(cesta);
    slozka = dir(cesta);
    delka_slozka = length(slozka);
    mat = zeros(1,delka_slozka);
    for i = 1: delka_slozka
        jmeno = slozka(i).name;
        if length(jmeno) > 4
            mat(i) = strcmp(jmeno(end-3:end),'.mat');
        end
    end
    % nahrání .mat
    if sum(mat) == 1
        jmeno = slozka(find(mat,'1')).name;    
        load (jmeno);
        cd(koren);
    else
        set(handles.info,'String','V adresáři může být jen jeden soubor ve formátu .mat');   
        cd(koren);
        clc;
        return;
    end

    obraz = obrazek_3_mezi_znacky_oprava{cislo_nahled};
        %% Přepočet na originální velikost
        rozmer_a = celkova_velikost(1);
        rozmer_b = celkova_velikost(2);

        [x_obraz y_obraz] = size(obraz);

        koeficient =  sqrt(x_obraz^2 + y_obraz^2)/sqrt(rozmer_a^2 + rozmer_b^2);   
        %%

    if get(handles.pismo,'Value') == 1
        if 4*kolonky > length(souradnice_kolonky)
            kolonky = 1;
        end
        navrh = navrhy_pismeno{cislo_nahled,kolonky};

        x1 = round(souradnice_kolonky(4*kolonky-3)*koeficient);
        x2 = round(souradnice_kolonky(4*kolonky-2)*koeficient);
        y1 = round(souradnice_kolonky(4*kolonky-1)*koeficient);
        y2 = round(souradnice_kolonky(4*kolonky)*koeficient);

    elseif get(handles.cislo,'Value') == 1
        if 4*kolonky > length(souradnice_cara)
            kolonky = 1;
        end
        navrh = navrhy_cislo{cislo_nahled,kolonky};

        x1 = round(souradnice_cara(4*kolonky-3)*koeficient);
        x2 = round(souradnice_cara(4*kolonky-2)*koeficient);
        y1 = round(souradnice_cara(4*kolonky-1)*koeficient);
        y2 = round(souradnice_cara(4*kolonky)*koeficient);    
    end

    obraz = obraz(x1:x2,y1:y2);
    imshow(obraz);

    % počet kolonek
    pocet_kolonek = length(souradnice_kolonky)/4;
    
    vyst = zeros(1,4);

    %% minimální rozdíl mezi návrhy znaků
    min_rozd = 0.2;%%
    k = 1;
    [a b] = size(navrh);
    while k < a
        i = 2;
        vyst(round(k/2),1) = navrh(k+1,1);
        while navrh(k,1) - navrh(k,i) < min_rozd || i > 4
            vyst(round(k/2),i) = navrh(k+1,i);
            i = i+1;
            if i == 5 
                break;
            end
        end
        k=k+2;
    end
%     vyst
    
    set(handles.rozpoznany, 'Value', 0);
    set(handles.navrh1, 'Value', 0);
    set(handles.navrh2, 'Value', 0);
    set(handles.navrh3, 'Value', 0);
    
    vyst_out = zeros(1, 1);
    zobraz_vyber_navrhu = zeros(1, round(a/2));
    % vyřazení vyst kde je jen jedna hodnota
     for i_vyst = 1 : round(a/2)
         vyst_out(i_vyst) = length(find(vyst(i_vyst,:) > 0));
         if vyst_out(i_vyst) == 1
             zobraz_vyber_navrhu(i_vyst) = vyst(i_vyst,1);
         end
     end
     vyst_out =  find(vyst_out > 1);
end % konec if poradi == 1

if get(handles.pismo,'Value') == 1
    pismenka = ['-ABCDEFGHIJKLMNOPQRSTUVWXYZ'];
elseif get(handles.cislo,'Value') == 1
    pismenka = ['-0123456789'];   
end

rozmer_vyst = length(vyst_out);
if poradi > (rozmer_vyst + 1)
    set(findobj('tag','info'),'string', 'Toto je poslední soubor');
end

% na poprvé přeskočí, výběr až na podruhé
if poradi > 1
    poradi_vyst_out = vyst_out(poradi-1);
    vyber_navrhu = [get(handles.rozpoznany, 'Value');
                                  get(handles.navrh1, 'Value');
                                  get(handles.navrh2, 'Value');
                                  get(handles.navrh3, 'Value')];

    if sum(vyber_navrhu) == 0
        set(handles.info,'String','Zadán znak z edit okna');   
        if isempty(get(handles.vlastni, 'String')) == 1;
            set(handles.info,'String','Není vyplněno edit okno'); 
%             poradi = poradi - 1;
            return;
        end
        if length(get(handles.vlastni, 'String')) > 1;
            set(handles.info,'String','Jsou vepsány dva znaky'); 
            return;
        end
        if get(handles.pismo,'Value') == 1
            zobraz_vyber_navrhu(poradi_vyst_out) =  abs(get(handles.vlastni, 'String')) - 96;    
        elseif get(handles.cislo,'Value') == 1
            zobraz_vyber_navrhu(poradi_vyst_out) =  abs(get(handles.vlastni, 'String')) - 47;    
        end
    else
        set(handles.info,'String','Zadán znak stiskem tlačítka');
        zobraz_vyber_navrhu(poradi_vyst_out)  = vyst(poradi_vyst_out,find(vyber_navrhu==1));
    end
    %% přidávání referenčních znaků
    if get(handles.pismo,'Value') == 1
        o = navrhy_obraz_pismeno{cislo_nahled,kolonky};
        umisteni = zobraz_vyber_navrhu(poradi_vyst_out) + 10;
    elseif get(handles.cislo,'Value') == 1         
        o = navrhy_obraz_cislo{cislo_nahled,kolonky};
        umisteni = zobraz_vyber_navrhu(poradi_vyst_out);
    end
    oa = o{poradi_vyst_out};

    prazdne = 1;
    while sum(sum(registr_ref_znak{umisteni,prazdne})) > 1
        prazdne = prazdne + 1;
    end
    
    registr_ref_znak{umisteni,prazdne} = oa;
            
end

if poradi == (rozmer_vyst +1)
    set(findobj('tag','info'),'string', 'Toto je poslední');
    zobraz_vyber_navrhu = pismenka(zobraz_vyber_navrhu+1);

    % zapnu tlačítka
    set(handles.nahoru,'enable','on');   
    set(handles.dolu,'enable','on');   
    set(handles.pred,'enable','on');   
    set(handles.po,'enable','on');   
    set(handles.zvrit,'enable','on');   
    set(handles.pushbutton77,'enable','on');   
    set(handles.panelak,'Visible','on');   
    
    poradi = 1;
    
    % zapisování a úprava v excelu
    [num,txt,raw] = xlsread('Vysledky.xls');
    if get(handles.pismo,'Value') == 1
        csiplo = 0;
        stary_retezec = char(txt(cislo_nahled + 1,kolonky + 1));
    elseif get(handles.cislo,'Value') == 1    
        csiplo = pocet_kolonek;
        stary_retezec = (raw(cislo_nahled + 1,kolonky + csiplo + 1));
    end
    
    zapis_excel(cislo_nahled+1,kolonky + csiplo + 1) = cellstr(zobraz_vyber_navrhu);
    set(findobj('tag','tlcitko'),'string', 'Oprava');
    return;
end

if poradi >= 1 && poradi < (rozmer_vyst + 1)
    set(findobj('tag','tlcitko'),'string', strcat(num2str(vyst_out(poradi)),'. znak'));
set(handles.text_rozpoznani, 'string', strcat(['Rozpoznaný znak číslo ',num2str(vyst_out(poradi))]));

    rozpoznany = vyst(vyst_out(poradi),1);
    navrh1 = vyst(vyst_out(poradi),2);
    navrh2 = vyst(vyst_out(poradi),3);
    navrh3 = vyst(vyst_out(poradi),4);

    % nastavení tlačítek
    set(findobj('tag','rozpoznany'),'string',pismenka(rozpoznany+1));
    if navrh1 == 0
        set(findobj('tag','navrh1'),'string', '-');
        set(handles.navrh1,'enable','off');   
    else
        set(findobj('tag','navrh1'),'string', pismenka(navrh1+1));
        set(handles.navrh1,'enable','on');   
    end

    if navrh2 == 0
        set(findobj('tag','navrh2'),'string', '-');
        set(handles.navrh2,'enable','off');   
    else
        set(findobj('tag','navrh2'),'string', pismenka(navrh2+1));
        set(handles.navrh2,'enable','on'); 
    end

    if navrh3 == 0
        set(findobj('tag','navrh3'),'string', '-');
        set(handles.navrh3,'enable','off');   
    else
        set(findobj('tag','navrh3'),'string', pismenka(navrh3+1));
        set(handles.navrh3,'enable','on');   
    end
    
end
% nulování tlačítek
set(handles.rozpoznany, 'Value', 0);
set(handles.navrh1, 'Value', 0);
set(handles.navrh2, 'Value', 0);
set(handles.navrh3, 'Value', 0);

poradi = poradi + 1;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% uložit
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in zvrit.
function zvrit_Callback(hObject, eventdata, handles)
% hObject    handle to zvrit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global zapis_excel registr_ref_znak;

xlswrite('Vysledky.xls', (zapis_excel), 1, 'A1');

% uložení do databáze referenčních znaků
load 'data\databaze.mat'
zapis_pozice = length(databaze);
for i = 1 : 36
    radek_stejnych = registr_ref_znak(i,1:end);
    konec = 0;
    k = 1;
    pozice = zapis_pozice;
    while konec == 0
        kontrola = radek_stejnych{k};
        k = k + 1;
        if sum(sum(kontrola)) == 0
            konec = 1;
        else
            pozice = pozice + 1;
            databaze{i,pozice} = kontrola;
        end
    end
end

% přerovnání databáze vzorových znaků
vystup = databaze;
maximum_i = 1;
for k =  1:36
    radek = vystup(k,1:end);
    delka = length(radek);
    pomocna = 0;
    for i = 1:delka
        prerovnan{i} = [];
          if sum(sum(radek{i})) > 0
              pomocna(i) = 1;
          end
    end

    pozice = find(pomocna == 1);
    for i = 1:length(pozice)
        prerovnan{i} = radek{pozice(i)}; 
    end
    if maximum_i < i
        maximum_i = i;
    end

    for i = 1:delka
        vystup{k,i} = prerovnan{i};
    end
end
databaze = vystup(1:36,1:maximum_i);

save('data\databaze.mat', 'databaze');

disp('uloženo');
    set(findobj('tag','info'),'string', 'ULOŽENO');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% další
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in po.
function po_Callback(hObject, eventdata, handles)
% hObject    handle to po (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global vstup vstup_formular cesta cislo_nahled;
global  poradi; 
% global zobraz_vyber_navrhu
poradi = 1;

% inkrementace
cislo_nahled = cislo_nahled + 1;

% počet souborů
[a,pocet_souboru] = size(vstup_formular);

% pokud je vybrán jen jeden obraz
if  pocet_souboru > 4 &&  strcmp(char(vstup_formular(end-3)), '.') == 1
    set(findobj('tag','info'),'string', 'Byl vybrán jen jeden soubor');
    cislo_nahled = cislo_nahled - 1;
elseif pocet_souboru > 1
    % pokud je vybráno více obrazů
    if cislo_nahled > pocet_souboru
        set(findobj('tag','info'),'string', 'Toto je poslední soubor');
        cislo_nahled = cislo_nahled - 1;
    elseif cislo_nahled == pocet_souboru
        vstup = im2double(imread(strcat(cesta,char(vstup_formular(pocet_souboru))))); 
        [a,b,c] = size(vstup);
        if (c > 2)
            vstup = rgb2gray(vstup);
        end
        imshow(vstup,'InitialMagnification','fit');
        set(findobj('tag','info'),'string', char(vstup_formular(cislo_nahled)));
        set(handles.prohlizeny_soubor,'String',strcat(['SOUBOR: ',num2str(cislo_nahled),'/',num2str(pocet_souboru)]));
    else
        vstup = im2double(imread(strcat(cesta,char(vstup_formular(cislo_nahled)))));
        [a,b,c] = size(vstup);
        if (c > 2)
            vstup = rgb2gray(vstup);
        end
        imshow(vstup,'InitialMagnification','fit');
        set(findobj('tag','info'),'string', char(vstup_formular(cislo_nahled)));
        set(handles.prohlizeny_soubor,'String',strcat(['SOUBOR: ',num2str(cislo_nahled),'/',num2str(pocet_souboru)]));
    end
else
    set(findobj('tag','info'),'string', 'Nebyl vložen soubor');
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% předchozí
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in pred.
function pred_Callback(hObject, eventdata, handles)
% hObject    handle to pred (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global vstup vstup_formular cesta cislo_nahled;
global zobraz_vyber_navrhu poradi; 
poradi = 1;

% dekrementace
cislo_nahled = cislo_nahled - 1;

% počet souborů
[a,pocet_souboru] = size(vstup_formular);

% pokud je vybrán jen jeden obraz
if  pocet_souboru > 4 &&  strcmp(char(vstup_formular(end-3)), '.') == 1
    set(findobj('tag','info'),'string', 'Byl vybrán jen jeden soubor');
    cislo_nahled = cislo_nahled + 1;
elseif pocet_souboru > 1
    % pokud je vybráno více obrazů
    if cislo_nahled < 1
        set(findobj('tag','info'),'string', 'Toto je první soubor');
        cislo_nahled = cislo_nahled + 1;
    elseif cislo_nahled == 1
        vstup = im2double(imread(strcat(cesta,char(vstup_formular(1)))));
        [a,b,c] = size(vstup);
        if (c > 2)
            vstup = rgb2gray(vstup);
        end
        imshow(vstup,'InitialMagnification','fit');
        set(findobj('tag','info'),'string', char(vstup_formular(cislo_nahled)));
        set(handles.prohlizeny_soubor,'String',strcat(['SOUBOR: ',num2str(cislo_nahled),'/',num2str(pocet_souboru)])); 
    else
        vstup = im2double(imread(strcat(cesta,char(vstup_formular(cislo_nahled)))));
        [a,b,c] = size(vstup);
        if (c > 2)
            vstup = rgb2gray(vstup);
        end
        imshow(vstup,'InitialMagnification','fit');
        set(findobj('tag','info'),'string', char(vstup_formular(cislo_nahled)));  
        set(handles.prohlizeny_soubor,'String',strcat(['SOUBOR: ',num2str(cislo_nahled),'/',num2str(pocet_souboru)])); 
    end
else
    set(findobj('tag','info'),'string', 'Nebyl vložen soubor');
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% pohyb po stránce dolu
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in dolu.
function dolu_Callback(hObject, eventdata, handles)
% hObject    handle to dolu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global kolonky cislo_nahled;
load data\navrh.mat

if get(handles.pismo,'Value') == 1
    b = size(navrhy_pismeno);
elseif get(handles.cislo,'Value') == 1
    b = size(navrhy_cislo);
end

if b(2) == 1
    set(findobj('tag','info'),'string', 'V souboru je jenom jedno místo pro opravu.');
    return;
end

if  kolonky < b(2)
    kolonky = kolonky + 1;
    set(findobj('tag','info'),'string', strcat(num2str(kolonky),'. pozice'));
else
    set(findobj('tag','info'),'string', strcat(num2str(kolonky),'. pozice'));
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% pohyb po stránce nahoru
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in nahoru.
function nahoru_Callback(hObject, eventdata, handles)
% hObject    handle to nahoru (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global kolonky;
load data\navrh.mat

if get(handles.pismo,'Value') == 1
    b = size(navrhy_pismeno);
elseif get(handles.cislo,'Value') == 1
    b = size(navrhy_cislo);
end

if b(2) == 1
    set(findobj('tag','info'),'string', 'V souboru je jenom jedno místo pro opravu.');
    return;
end

if  kolonky >1
    kolonky = kolonky - 1;
    set(findobj('tag','info'),'string', strcat(num2str(kolonky),'. pozice'));
else
    set(findobj('tag','info'),'string',strcat(num2str(kolonky),'. pozice'));
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% zavřít
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in pushbutton77.
function pushbutton77_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton77 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close;
