Matrix of eight nearest neighbors
Afficher commentaires plus anciens
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?
Réponses (3)
Titus Edelhofer
le 6 Jan 2012
0 votes
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
le 6 Jan 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 commentaires
Titus Edelhofer
le 6 Jan 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
le 6 Jan 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
le 6 Jan 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
le 6 Jan 2012
Yes it's a five point stencil:
http://en.wikipedia.org/wiki/Five-point_stencil
Marlene
le 13 Jan 2012
1 commentaire
Titus Edelhofer
le 13 Jan 2012
Yepp, that's what I thought it should be when writing my answer above ... ;-).
Catégories
En savoir plus sur Nearest Neighbors dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!