我有一个线性索引数组,对于每个线性索引,我想找到半径为 的相邻像素的线性索引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);