MATLAB: How can i get the divergence of vector field of a gray scale image?

divergenceimage processing

How can i get the divergence of vector field of a gray scale image??

Best Answer

In this example the vector field is computed as the gradient in x and y direction:
function D = imdiv(I)
Ix = diff([I I(:, end)]')';
Iy = diff([I; I(end, :)]);
[X Y] = meshgrid(1:size(I, 2), 1:size(I, 1));
D = divergence(X, Y, Ix, Iy);
Related Question