Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 564
Adham shafik Avatar asked Nov 30 '25 04:11

Adham shafik


1 Answers

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...

like image 98
fcsc Avatar answered Dec 01 '25 23:12

fcsc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!