%   KRIZENI3     [sourad count] = krizeni3(obr_thin)
%   Funkce slouží k detekci křížení cév ve skeletizovaném obrazu
%
%   obr_thin - vstupní skeletizovaný obraz
%   sourad - nalezené souřadnice
%   count - počet nalezených souřadnic

function [sourad count] = krizeni3(obr_thin)
%detekovana krizeni
a = [0 1 0;1 1 1;0 0 0];
b = [0 1 0;1 1 1;0 1 0];
c = [1 0 0;0 1 0;1 0 1];
d = [1 0 1;0 1 0;0 0 1];
e = [0 0 0;1 1 1;0 1 0];
f = [0 0 1;0 1 0;1 0 1];
g = [1 0 1;0 1 0;1 0 1];
h = [1 0 1;0 1 0;1 0 0];
ch= [1 0 1;0 1 0;0 1 0];
n = [1 0 0;0 1 1;0 1 0];
k = [0 0 1;1 1 0;0 1 0];
l = [1 0 0;0 1 1;1 0 0];
m = [0 1 0;0 1 1;1 0 0];
o = [0 1 0;0 1 0;1 0 1];
p = [0 0 1;1 1 0;0 0 1];
q = [0 1 0;1 1 0;0 0 1];
%----------------------------------------------
vel = size(obr_thin);
sourad = zeros(2,300);
count = 0;
for i = 2:1: vel(1)-1
    for j = 2:1: vel(2)-1
        matice = obr_thin(i-1:i+1,j-1:j+1);
        if obr_thin(i,j)==1
           if floor(sum(sum(matice == a))/9) || floor(sum(sum(matice == b))/9)|| floor(sum(sum(matice == c))/9)||...
                   floor(sum(sum(matice == d))/9) || floor(sum(sum(matice == e))/9) || floor(sum(sum(matice == f))/9)||...
                   floor(sum(sum(matice == g))/9) || floor(sum(sum(matice == h))/9) || floor(sum(sum(matice == ch))/9)||...
                   floor(sum(sum(matice == n))/9) || floor(sum(sum(matice == k))/9)|| floor(sum(sum(matice == l))/9) ||...
                   floor(sum(sum(matice == m))/9)|| floor(sum(sum(matice == o))/9)|| floor(sum(sum(matice == p))/9) ||...
                   floor(sum(sum(matice == q))/9)
               
               
                      count = count + 1;

                      sourad(:,count) = [i,j];  
                 
               
            end
        end
    end
end
