function [ pocet_hran, delka_hran, smer_hran ] = hrany(vektory_obrysu )
%COUNT_EDGES Summary of this function goes here
%   Detailed explanation goes he

%% Inicializace promennych
pocet_hran = 0; % zavedeni promenne pro pocet hran
g = []; % promenna pro (min,max) hodnoty hran
h = 1;  % smer hrany
j = 1;  % prvni hodnota hrany
smer_hran = []; %zavedeni promenne pro vektor hran

%% 
mask = zeros(1,7); % Maska, do ktere vstupuji hodnoty hran
n_lost = length(mask) + 1; % 
vektory_obrysu = vektory_obrysu/28; % prepocet hodnot
vektory_obrysu = [vektory_obrysu(end-(floor(length(mask)/2)):end) ...
    vektory_obrysu ...
    vektory_obrysu(length(vektory_obrysu(end-(floor(length(mask)/2)):end))+1 :length(mask)+1)];

for i = 1 : length(vektory_obrysu) - length(mask) + 1
    modus(i) = mode(vektory_obrysu(i : length(mask) + i - 1));    % modus hodnot z masky
    media(i) = median(vektory_obrysu(i : length(mask) + i - 1));    % modus hodnot z masky
    rozdil = abs(modus(i)-media(i));
    
    if rozdil == 0 && i > 2
        modus(i) = mode([modus(i-1) vektory_obrysu(i+1 : length(mask) + i - 1)]);
    end
end


modus = [modus 0]; % zavedeni modusu s pocatecni hodnotou 0
for i = 2 : length(modus) 
    if modus(i) ~= modus(i-1)
        g(h,:) = [j i]; % (min,max) indexy hran
        j = i; % zmena undexu j
        h = h+1; % zmena indexu h
    end
end
 
delka_hran = zeros(1, length(g)); % zavedeni rady pro delky hran
for i = 1 : size(g, 1)
    if (g(i,2) - g(i,1)) > 9 % nastaveni prahu pro velikost hrany
        delka_hran(i) = (g(i,2) - g(i,1)); % zjisteni delky hrany
        pocet_hran = pocet_hran + 1; % registrace hrany
        smer_hran(i) = modus(g(i,1)); % ulozeni vektoru hrany
        if ((smer_hran(i) == 1) || (smer_hran(i) == 3) || (smer_hran(i) == 7) || (smer_hran(i) == 9))
            delka_hran(i) = ceil(delka_hran(i) * sqrt(2)); % diagonalni vektory vynasobeny sqrt(2)
        end
    end   
end

delka_hran(delka_hran==0) = []; % smazani malych hran
if isempty(smer_hran)
    smer_hran = 0;
end
end
