function [output] = marking(input)

[m n] = size(input);

K_MAX = 0;
for i = 2 : m-1
  j=2;
  while j <= n-1
     if input(i,j) == 1
        % No parent
        if input(i-1,j-1) == 0 & input(i-1,j) == 0 & input(i-1,j+1) == 0 & input(i,j-1) == 0
           K_MAX = K_MAX + 1;
           input(i,j) = K_MAX;
           k = K_MAX;
        else % Parent
           k = max( [input(i-1,j-1) input(i-1,j) input(i-1,j+1) input(i,j-1)] );
           input(i,j) = k;
        end
     end
   j=j+1;
   end
end

output = input;

