MATLAB: Calculating a partial derivative in an 3D image

digital signal processingimage processingmathematics

I have a 3D image (I) and I want to calculate the partial derivatives d(I)/dxdy, d(I)/dxdz, d(I)/dydz. I know that matlab has the functions imgradient, but I don't know how to calculate this.
Thanks for all the support.

Best Answer

You could use diff, e.g.,
dIdxdy = diff( diff(I,1,1), 1,2);
Or, for maximum flexibility, you could use convolution. For example, if you want central differences,
dx=[1;0;-1];
dy=dx.';
dIdxdy=convn( convn(I,dx,'same') ,dy,'same');