How can I use a loop to subtract a pixel's gray level to it´s neighbor pixel's gray level?

 Accepted Answer

I = im2double(imread('cameraman.tif'));
Ix = diff(I')';
Iy = diff(I);

5 Comments

diff works on every pixel in the image so you do not need a loop. That's one of the major advantages of Matlab.
That is a good function. thank you, that helps me a lot.
Can I do diff function to one file to both x- and y-direction? Or can I make one file from Ix and Iy? I mean that I do diff function and get one file.
Can I use diff function to subtract pixel from 2-pixel away from it? So it not neigbour pixel anymore.

Sign in to comment.

More Answers (0)

Asked:

on 13 Feb 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!