Adham shafik
Adham shafik

Reputation: 1044

How to get pixel neighbors in MATLAB?

I need to get pixel neighbors in order to get a sequence of boundary points , so my plan is to :-

  1. Find a boundary pixel .
  2. Find its neighbor ( it should be a boundary pixel too ) .
  3. Recursively do this until i reach the starting pixel .

How can i get pixel neighbors in MATLAB ?

Upvotes: 3

Views: 6636

Answers (1)

fcsc
fcsc

Reputation: 111

You could always define a displacement vector

d = [ 1 0; -1 0; 1 1; 0 1; -1 1; 1 -1; 0 -1; -1 -1]; 

Then the neighbors of location loc =[i j] are

neighbors = d+repmat(loc,[8 1]);

Hope is useful to you...

Upvotes: 7

Related Questions