我有点困惑,非常感谢一些帮助。
我已经阅读了许多有关查找相邻像素的帖子,这非常有帮助:
http://blogs.mathworks.com/steve/2008/02/25/neighbor-indexing-2/
但是,我无法将其应用于大小(A)=[8 340 340 15] 的 4D 矩阵(A)。它代表 8 组 3D 图像(每组 15 个切片),我想获取其中的邻居。我不确定要使用哪个大小来计算偏移量。这是我尝试过的代码,但我认为它不起作用,因为偏移量应该适用于 4 维?没有循环怎么办?
%A is a 4D matrix with 0 or 1 values
Aidx = find(A);
% loop here?
[~,M,~,~] =size(A);
neighbor_offsets = [-1, M, 1, -M]';
neighbors_idx = bsxfun(@plus, Aidx', neighbor_offsets(:));
neighbors = B(neighbors_idx);
谢谢,齐格