Calculate the difference between adjacent pixels

조회 수: 9 (최근 30일)
Matlab Student
Matlab Student 2018년 9월 30일
댓글: jonas 2018년 10월 3일
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,

채택된 답변

jonas
jonas 2018년 9월 30일

Try this instead

abs(diff(imageArray,1,2)) 
  댓글 수: 7
Matlab Student
Matlab Student 2018년 10월 3일
Good Morning Jonas,
May I ask how can I calculate the same in the vertical direction? I mean how to calculate the difference between vertically adjacent pixels?
Thanks in advance,
jonas
jonas 2018년 10월 3일
Just change the dimension argument from 2 to 1 :)
abs(diff(imageArray,1,1))

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by