如何在MATLAB中获取像素邻居?

3m *_*asr 3 matlab computer-vision

我需要获得像素邻居以获得一系列边界点,所以我的计划是: -

  1. 找到边界像素.
  2. 找到它的邻居(它也应该是一个边界像素).
  3. 递归执行此操作直到我到达起始像素.

如何在MATLAB中获得像素邻居?

小智 6

您始终可以定义位移矢量

d = [ 1 0; -1 0; 1 1; 0 1; -1 1; 1 -1; 0 -1; -1 -1]; 
Run Code Online (Sandbox Code Playgroud)

然后位置的邻居loc =[i j]

neighbors = d+repmat(loc,[8 1]);
Run Code Online (Sandbox Code Playgroud)

希望对你有用......