Matrix of eight nearest neighbors

4 views (last 30 days)
Marlene
Marlene on 6 Jan 2012
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?

Answers (3)

Titus Edelhofer
Titus Edelhofer on 6 Jan 2012
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
Image Analyst on 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 Comments
Titus Edelhofer
Titus Edelhofer on 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
Sean de Wolski on 6 Jan 2012
Yes it's a five point stencil:
http://en.wikipedia.org/wiki/Five-point_stencil

Sign in to comment.


Marlene
Marlene on 13 Jan 2012
% Neighbor locations (footprint)
neigb= conndef(2,'maximal');
OR
neigb= [-1 0; 1 0; 0 -1;0 1;-1 -1;-1 1;1 -1;1 1];
  1 Comment
Titus Edelhofer
Titus Edelhofer on 13 Jan 2012
Yepp, that's what I thought it should be when writing my answer above ... ;-).

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!