Calculate the difference between adjacent pixels

5 visualizzazioni (ultimi 30 giorni)
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,

Risposta accettata

jonas
jonas il 30 Set 2018

Try this instead

abs(diff(imageArray,1,2)) 
  7 Commenti
Matlab Student
Matlab Student il 3 Ott 2018
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 il 3 Ott 2018
Just change the dimension argument from 2 to 1 :)
abs(diff(imageArray,1,1))

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by