function [Tops, im] = findTops(imBW, startingPoint, numOfSticksToFind,im)
    Tops = [];
    [r c]  = size(imBW);
    for i = 1:numOfSticksToFind
        %hledani tycky
        actPoint = flip(startingPoint);
        
        %hledani kolíku, pohybujeme se horizontálně doprava
        line =[0 0];
        if actPoint(2)< c
            while ~(line(end)==0 && line(end-1)==1) 
                line(end+1) = imBW(actPoint(1),actPoint(2));
                if (actPoint(2) + 1)>=c
                    break;
                else
                    actPoint(2) = actPoint(2)+1;
                   
                end
                im(actPoint(1), actPoint(2),:) = [255 0 0]; 
            end
        else
            return;
        end
        rightEdge = actPoint(2);
      
        P = find(line==1);
        L = find(line==1);
       if ~isempty(P) && ~isempty(L) 
        P = P(end);
        L = L(1);
        radii = round((P-L)/2);
        center = [actPoint(1), actPoint(2)-radii-1]; %střed kolíku
        actPoint = [center(1), center(2)];
        centerOfStick = actPoint;
       else
           centerOfStick = actPoint;
       end

        %going up
        k = 0; %po k krocich je treba znovu najit stred
        while centerOfStick ~= 0 
              actPoint(1) = actPoint(1)-1;
              if actPoint(1) <= 0
                  break;
              end
              im(actPoint(1), actPoint(2),:) = [0 255 0]; 
            if(imBW(actPoint(1), actPoint(2))~= 1 || k == 10)
                centerOfStick = hledaniStreduTycky(actPoint,radii,imBW);
                k = 0;
                if centerOfStick == 0 
                   % centerOfStick = hledaniKrajeAStreduTycky(actPoint,im);
                    top = actPoint;
                else
                    actPoint = centerOfStick;
                   im(actPoint(1), actPoint(2),:) = [0 255 0]; 
                end
            end
            k= k+1;

        end
        if exist('top','var')
            Tops(i,1) = top(1);
            Tops(i,2) = top(2);
        end
        if ~isempty(P)
        startingPoint(1) = startingPoint(1) + P;
        end
    end

end