After a few more search, I found an implementation which should be correct.

function fx = dxm(f)

fx = zeros(size(f));

fx(:, 2:end-1) = f(:,2:end-1) – f(:, 1:end-2);

fx(:, 1) = f(:, 1);

fx(:, end) = -f(:, end-1);

end

function fy = dym(f)

fy = zeros(size(f));

fy(2:end-1,:) = f(2:end-1,:) – f(1:end-2,:);

fy(1,:) = f(1,:);

fy(end,:) = -f(end-1,:);

end

Thanks again for your effort.

]]>Following is my code:

function test

u = im2double(imread(‘imgs/Bishapur.jpg’));

if size(u, 3) == 3

u = rgb2gray(u);

end

grad = @(u) cat(3,dxp(u),dyp(u));

div = @(V) dxm(V(:,:,1)) + dym(V(:,:,2));

gradu = grad(u);

divv = div(gradu);

diff = sum(gradu(:).*gradu(:)) + sum(u(:).*divv(:)) ;

msg = sprintf(‘diff: %f’, diff);

disp(msg);

end

function fx = dxp(f)

fx = [f(:,2:end) f(:,end)] – f;

end

function fy = dyp(f)

fy = [f(2:end,:); f(end,:)] – f;

end

function fx = dxm(f)

fx = f – [f(:,1) f(:,1:end-1)];

end

function fy = dym(f)

fy = f – [f(1,:); f(1:end-1,:)];

end

Any chance to find lecture notes of your following courses:

1. Mathematical Image Processing I.

2. Mathematical Image Processing II.

3. Inverse and Ill Poised Problems.

4. Inverse Problems and Applications in Image Processing.

It seems you have a great way to simplify ideas and many people will enjoy those.

Thank You.

P. S.

Have you ever thought on creating a course at Coursera?

They lack courses on those subjects.

Thank You.

]]>Liked your results.

It would be nice if you could share the MATLAB code.

Thank You.

]]>