Matrix of eight nearest neighbors
Mostrar comentarios más antiguos
Hi all,
This matrix
neigb=[-1 0; 1 0; 0 -1; 0 1];
represents the four nearest neighbors.
How is the matrix of eight neighbors?
Respuestas (3)
Titus Edelhofer
el 6 de En. de 2012
0 votos
Hi Marlene,
this should not be that difficult, I guess? One of the next four neighbors you would get by adding the line [-1 -1] to your variable neigb.
Titus
Image Analyst
el 6 de En. de 2012
I don't understand that in an image processing context. In image processing a four-connected structuring element would look like
0 1 0
1 x 1
0 1 0
while an 8-connected one would be
1 1 1
1 x 1
1 1 1
You gave
-1 0
1 0
0 -1
0 1
4 comentarios
Titus Edelhofer
el 6 de En. de 2012
I understand this as follows: -1 0 means one to the left on the same y (this would correspond to index (2,1) of your first matrix).
Image Analyst
el 6 de En. de 2012
I know it's used in the form I listed in all of the image processing routines in the Image Processing Toolbox. Where is the form you and Marlene used?
Titus Edelhofer
el 6 de En. de 2012
I know this from numerical analysis, when you implement e.g. finite differences (in 1D the central difference is f(x+h)-f(x-h), so it would be the neighbors [-1; 1]. The discrete laplacian uses (often) the four neighbors Marlene used, i.e., f(x+h, y+h), f(x+h, y-h), f(x-h, y+h), f(x-h, y-h). Starting from x=[x,y] you add the neighbors matrix.
Sean de Wolski
el 6 de En. de 2012
Yes it's a five point stencil:
http://en.wikipedia.org/wiki/Five-point_stencil
Marlene
el 13 de En. de 2012
1 comentario
Titus Edelhofer
el 13 de En. de 2012
Yepp, that's what I thought it should be when writing my answer above ... ;-).
Categorías
Más información sobre Nearest Neighbors 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!