Matrix of eight nearest neighbors

조회 수: 8 (최근 30일)
Marlene
Marlene 2012년 1월 6일
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?

답변 (3개)

Titus Edelhofer
Titus Edelhofer 2012년 1월 6일
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 2012년 1월 6일
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
Titus Edelhofer
Titus Edelhofer 2012년 1월 6일
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 2012년 1월 6일
Yes it's a five point stencil:
http://en.wikipedia.org/wiki/Five-point_stencil

댓글을 달려면 로그인하십시오.


Marlene
Marlene 2012년 1월 13일
% 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
Titus Edelhofer
Titus Edelhofer 2012년 1월 13일
Yepp, that's what I thought it should be when writing my answer above ... ;-).

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by