%1=hrot je OK, 2 hrot nie je OK
function[Vysledok]= bend_spike(Im_crop)
konst=57.29577951; %radian to degrees
[rows,cols]=size(Im_crop);
percento=0.2;
Hrot=imcrop(Im_crop,[(cols-round(cols*percento)) (0) (cols) (rows)]);
pocet1=0;pocet2=0;
x1_buff=0;x2_buff=0;
for y=1:11; % prvych 10 stlpcov priemeruje, a vypocita kraje ihly
    for x=2:rows %aby nehladal pri dalsej podmienke 0 ty element
        if((Hrot(x,y)>Hrot(x-1,y)) && x<rows/2)
            x1_buff=x1_buff+x;pocet1=pocet1+1;
        end
        if((Hrot(x,y)<Hrot(x-1,y)) && x>rows/2)
            x2_buff=x2_buff+x;pocet2=pocet2+1;
        end
    end
    x=2;
end
x1_buff=round(x1_buff/pocet1); % x1_buff reprezentuj horny hranicu ihly
x2_buff=round(x2_buff/pocet2); % x2_buff reprezentuj dolnu hranicu ihly
figure(3)
imshow(Hrot);
hold on;
plot([0 cols],[x1_buff x1_buff]);
plot([0 cols],[x2_buff x2_buff]);
[x,y,x1,y1]=search2(Hrot);
[rows,cols]=size(Hrot);
pocet1=0;pocet2=0;
for stlpce=1:cols; 
    for riadky=2:(rows)
        if (riadky<(x1_buff+5)&&riadky>(x1_buff)&&Hrot(riadky,stlpce)>0)
            pocet1=pocet1+1;
        end
        if(riadky<(x2_buff)&&riadky>(x2_buff-5)&&Hrot(riadky,stlpce)>0)
            pocet2=pocet2+1;
        end
    end
    if((pocet1)==1) 
        y1_rampa_final=stlpce;
    end
    if((pocet2)==1)
        y2_rampa_final=stlpce;
    end
    riadky=2;
    pocet2=0;
    pocet1=0;
end
plot([y1_rampa_final y1],[x1_buff x1]);
plot([y2_rampa_final y1],[x2_buff x1]);
x=abs(x1-x1_buff);
y=abs(y1_rampa_final-y1);
angle1=(atan(x/y))*konst;
Vysledok=2; %defaultne som nastavil hodnotu chybnu
if(angle1<30) % nadefinoval som uhol medzi rampou a telou ihly
    Vysledok=1; % ak je uhol mensie, tak je ihla OK
end
y_2=abs(y2_rampa_final-y1);
angle2=(atan(x/y_2))*konst;
if(angle2<30) % nadefinoval som uhol medzi rampou a telou ihly
    Vysledok=1;
end
end