how to find the differnce between all the neighbouring elements in an array???

i have a 64*64 array i need to find the differnce between all the adjacent elements in the array. for instance, if i take a particular element i need to subtract it from the neighhbouring elemnts

Respuestas (2)

If you want to add all the differences of the center pixel within it's 8-neighborhood, you can construct a filter and apply it to the image:
F = -ones(3); F(2,2) = 1;
Y = conv2(I, F)

5 comentarios

i dont need the sum, i would lik to get all the differences of the center pixel within it's 8-neighborhood
Image Analyst
Image Analyst el 18 de En. de 2013
Editada: Image Analyst el 18 de En. de 2013
Then see Matt's answer. You specify which direction you want, out of 8 possible directions. You can get them one direction at a time if that's what you want. Just be aware that convolution "flips" the window so the direction is 180 from what you might think.
sorry its not 8 neighbourhood but 4 neighbourhood
Same answer. Use kernels:
[0 -1 0; 0 1 0; 0 0 0]
[0 0 0; 0 1 0; 0 -1 0]
[0 0 0; -1 1 0; 0 0 0]
[0 0 0; 0 1 -1; 0 0 0]
for the 4 different directions.
If you only want the 4 vertical/horizontal neighbours, it's probably easier (and faster??) to use DIFF.

Iniciar sesión para comentar.

Matt J
Matt J el 18 de En. de 2013
Editada: Matt J el 18 de En. de 2013
The diff() command will give you horizontal and vertical differences. Convolution can give you differences along any direction, e.g.,
conv2(A,[0 0 0; 0 1 0; 0 0 -1]) %differences between A(i,j) and A(i-1,j-1)

Categorías

Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 18 de En. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by