0

我需要在 3d 卷上滑动一个窗口。滑动仅在 3d 体积的一层上,即对于每个 x,y 具有一个特定的 z。这就是我想要循环执行的操作:对于每个 x、y、z,例如:

px =9; py =9; pz =12;

a = rand(50,50,50);
[x y z] = meshgrid(1:50,1:50,1:50);
r = 3;

%-------------loop starts here: 
% creating  a shaped window, for example sphere of radius r
inds = find((x-px).^2 + (y-py).^2 + (z-pz).^2 <= r.^2);
% getting the relevant indices, here, it is the sphere around px,py,pz
[i,j,k] = ind2sub(size(a),inds);
% adjust the center of the sphere to be at (0,0,0) instead of (px,py,pz)
adj_inds = bsxfun(@minus,[i,j,k],[px,py,pz]);

% Computing for each sphere some kind of median point
cx = sum(a(inds).*adj_inds(:,1))./sum(a(inds));
cy = sum(a(inds).*adj_inds(:,2))./sum(a(inds));
cz = sum(a(inds).*adj_inds(:,3))./sum(a(inds));

%Saving the result: the distance between the new point and the center of the sphere.
res(yc,xc) = sqrt(sum([cx,cy,cz].^2));
%-------------

现在,所有这些都应该发生很多次,(〜300000),循环需要很长时间,卷积返回3d体积(对于每个x,y,z),而我只需要为每个(x,y)和一个列表执行此操作z的。请帮忙...谢谢matlabit

4

0 回答 0