function [output] = seg(input,level)

[m n] = size(input);
output = zeros(m,n);

for i = 2:m-1
  for j = 2:n-1
    if input(i,j) ~= level
        output(i,j) = 0;
    else
      if input(i,j)==input(i-1,j) & input(i,j)==input(i+1,j) & input(i,j)==input(i,j-1) & ...
         input(i,j)==input(i,j+1)
        output(i,j) = 0;
      else
	output(i,j) = 1;
      end
    end
  end
end




