function [a, b, c] = sfpe(image, Krow, Kcol)
% [a, b, c] = sfpe(image, Krow, Kcol)
% sloped facet parameter estimator (Haralick and Shapiro, p.375)
krow = round((Krow-1)/2);
kcol = round((Kcol-1)/2);
[m n] = size(image);
for ii = 1:krow
  for jj = 1:n
    a(ii,jj) = 0.0;
    b(ii,jj) = 0.0;
    c(ii,jj) = 0.0;
  end
end
for ii = 1+m-krow:m
  for jj = 1:n
    a(ii,jj) = 0.0;
    b(ii,jj) = 0.0;
    c(ii,jj) = 0.0;
  end
end
sumrc = Krow*Kcol;
sumc2 = 2*kcol*(kcol+1)*(2*kcol+1)/6.0;
sumr2 = 2*krow*(krow+1)*(2*krow+1)/6.0;
for ii = 1+krow:m-krow
  for jj = 1:kcol
    a(ii,jj) = 0.0;
    b(ii,jj) = 0.0;
    c(ii,jj) = 0.0;
  end
  for jj = 1+n-kcol:n
    a(ii,jj) = 0.0;
    b(ii,jj) = 0.0;
    c(ii,jj) = 0.0;
  end
  for jj = 1+kcol:n-kcol
    sumi = 0.0;
    sumri = 0.0;
    sumci = 0.0;
    for i2 = -krow:krow
      for j2 = -kcol:kcol
        sumi = sumi + image(ii,jj);
        sumri = sumri + i2*image(ii+i2,jj+j2);
        sumci = sumci + j2*image(ii+i2,jj+j2);
      end
    end
    a(ii,jj) = sumri/sumr2;
    b(ii,jj) = sumci/sumc2;
    c(ii,jj) = sumi/sumrc;
  end
end
