how to find the differnce between all the neighbouring elements in an array???
Mostrar comentarios más antiguos
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)
Thorsten
el 18 de En. de 2013
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
maria
el 18 de En. de 2013
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.
maria
el 18 de En. de 2013
Image Analyst
el 18 de En. de 2013
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.
Matt J
el 18 de En. de 2013
If you only want the 4 vertical/horizontal neighbours, it's probably easier (and faster??) to use DIFF.
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.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!