function s = sector(a)
% s = sector(a)
%     Returns labeled sector number for Canny edge detector (see R. Jain,
%     Machine Vision, McGraw-Hill, p.171)
%     a: input array of orientations in interval [0,2*pi]
[m,n] = size(a);
s = zeros(m,n);
for ii = 1:m
  for jj = 1:n
    aij = a(ii,jj);
    if (aij>=0) & (aij<pi/8)
      s(ii,jj) = 0;
    end
    if (aij>=pi/8) & (aij<(3*pi/8))
      s(ii,jj) = 3;
    end
    if (aij>=(3*pi/8)) & (aij<(5*pi/8))
      s(ii,jj) = 2;
    end
    if (aij>=(5*pi/8)) & (aij<(7*pi/8))
      s(ii,jj) = 1;
    end
    if (aij>=(7*pi/8)) & (aij<(9*pi/8))
      s(ii,jj) = 0;
    end
    if (aij>=(9*pi/8)) & (aij<(11*pi/8))
      s(ii,jj) = 3;
    end
    if (aij>=(11*pi/8)) & (aij<(13*pi/8))
      s(ii,jj) = 2;
    end
    if (aij>=(13*pi/8)) & (aij<(15*pi/8))
      s(ii,jj) = 1;
    end
    if (aij>=(15*pi/8)) & (aij<(2*pi))
      s(ii,jj) = 0;
    end
  end
end
