function gc = graddir(I)
%GRADDIR Calculates the summation of cardinal gradient magnitudes of a postal image block.
%   [GC] = GRADDIR(I) sums the cardinal gradient magnitudes to enable 
%   classification of I.  
%
%   Gradient vectors are obtained with the DIFF and ATAN2 functions.  
%
%   I is the matrix of pixel values of a grayscale image block.  
%
%   See also DIFF, ATAN2, FEATURES

%   Author(s): K. R. Varshney
%   School of Electrical and Computer Engineering, Cornell University
%   $Date: 2002/08/15 $

sizeI = size(I);

I = double(I);

h=diff(I);
h=h(:,1:end-1);

v=diff(I');
v=v(:,1:end-1)';

theta = atan2(v,h);

mag = (h.^2 + v.^2).^.5;

gc = sum(sum(((theta>=(-13*pi/24) & theta<(-11*pi/24)) | (theta>=(-pi/24) & theta<(pi/24)) | (theta>=(11*pi/24) & theta<(13*pi/24)) | (theta<(-23*pi/24)) | (theta>=(23*pi/24))).*mag));
