基于matlab的三维体积滑动窗口

基于matlab的三维体积滑动窗口,matlab,3d,computer-vision,convolution,sliding-window,Matlab,3d,Computer Vision,Convolution,Sliding Window,我需要在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 i

我需要在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));
%-------------
px=9;py=9;pz=12;
a=兰特(50,50,50);
[x y z]=网格网格(1:50,1:50,1:50);
r=3;
%-------------循环从这里开始:
%创建成型窗口,例如半径为r的球体

inds=find((x-px)。^2+(y-py)。^2+(z-pz)。^2您是否尝试过使用列处理,使用
colfilt
函数?嗯,我不太确定如何将我的三维体积转换为colfilt的二维输入。我想我可以分层处理它,因为我的滑动窗口不是方形的,而是球形(或圆柱体),因此,每一层看起来都不同。。