% Partial derivatives in X and Y directions
function [Gx,Gy] = Gradient(A, p);

X = [-1 0 1]/2; % filter
Y = [1 0 -1]'/2; % filter

Gx = filter2(X,A); % correlation
Gy = filter2(Y,A);
[M,N] = size(A);
Gx(1:p+1,:) = 0;
Gx(M-p-1:M,:) = 0;
Gx(:,1:p+1) = 0;
Gx(:,N-p-1:N) = 0;
Gy(1:p+1,:) = 0;
Gy(M-p-1:M,:) = 0;
Gy(:,1:p+1) = 0;
Gy(:,N-p-1:N) = 0;

