【发布时间】:2013-04-29 10:23:02
【问题描述】:
我有一个线性索引数组,对于每个线性索引,我想找到半径为5-pixels 的相邻像素的线性索引。我找到了以下代码,它为8-connected neighborhood 完成了这项工作。但是,如何实现它以找到120 neighbors 的线性索引,用于5-pixel 邻域。
%# target_array: array where pixels are marked
%# idx: linear index of a marked pixel
[M,N] = size(target_array)
neighbor_offsets=[-M-1 -M -M+1 1 M+1 M M-1 -1];
neighbors = bsxfun(@plus, idx, neighbor_offsets);
【问题讨论】:
-
你能在你的代码中定义
M和idx吗? -
@Dan:我已经编辑了问题以定义
M和idx
标签: matlab indexing computer-vision