MATLAB: Calculate the difference between adjacent pixels

image processing

Hello Team,
I have written this Matlab code to calculate the absolute difference between horizontally adjacent pixels.
imageArray = imread('index.jpg');
information = imfinfo('index.jpg')
for j = 1:1:information.Height – 1
for i = 1:1:information.Width – 2
D_hor(i,j) = abs(imageArray(i,j) – imageArray(i+1, j))
i = i +1
end
j = j+1
end
Once I started verifying the code using a simple Matrix, it displayed incorrect results.
Can you please help me?
Regards,

Best Answer

Try this instead

abs(diff(imageArray,1,2))