如何从3D体积获得横截面?

时间:2017-07-21 04:45:46

标签: matlab image-processing multidimensional-array interpolation slice

我想从示例中的3D卷中获取2D切片(略微修改)How do I resolve this issue with 3D image visualization?,如下所示:

% create input image
imageSizeX = 10;
imageSizeY = 10;
imageSizeZ = 10

% generate 3D grid using voxel size = 0.5
[Xq, Yq, Zq] = ndgrid(1:0.5:imageSizeX-1, 1:0.5:imageSizeY-1, 1:0.5:imageSizeZ-1);

% obtain coordinates of all internal vertices, faces, and edges
allCoords = [Xq(:), Yq(:), Zq(:)]; % i need this bit for something very important but not shown in the question.


% Re-generate 3D grid using voxel size = 1
[columnsInImage, rowsInImage, pagesInImage] = ndgrid(1: imageSizeX-1, 1: imageSizeY-1, 1: imageSizeZ-1);

% create the sphere in the image.
centerY  = imageSizeY/2;
centerX  = imageSizeX/2;
centerZ  = imageSizeZ/2;
diameter = 4;
radius   = diameter/2;

sphereVoxels = flipud((rowsInImage - centerY).^2 ...
    + (columnsInImage - centerX).^2 + (pagesInImage - centerZ).^2 <= radius.^2);


% change image from logical to numeric labels.
Img   = double(sphereVoxels);
for ii = 1:numel(Img)
    if Img(ii) == 0
        Img(ii) = 2;  % intermediate phase voxels
    end 
 end



% specify the desired angle
angle = 30;                     

% specify desired pixel height and width of solid
width  = imageSizeX;    
height = imageSizeY;
page   = imageSizeZ;

% Find the row point at which theta will be created
y = centerY - ( radius*cos(angle * pi/180) ) 


% determine top of the solid bar
y0 = max(1, y-height); 


% label everything from y0 to y to be = 3 (solid)
Img(1:width, y0:y, 1:page)=3;

%%%%%% Plot the surfaces
[X, Y, Z, C] = build_voxels(Img > 0);
hSurface = patch(X, Y, Z, Img(C),...
                 'AmbientStrength', 0.5, ...
                 'BackFaceLighting', 'unlit', ...
                 'EdgeColor', 'none', ...
                 'FaceLighting', 'flat');

colormap([1 0 0; 1 1 0]);
axis equal;
axis tight;
view(45, 45);
grid on;
xlabel('x-axis (voxels)');
ylabel('y-axis (voxels)');
zlabel('z-axis (voxels)');
light('Position', get(gca, 'CameraPosition'), 'Style', 'local');
zoom on;
hold on;


Vq   = griddata(columnsInImage, rowsInImage, pagesInImage, Img, Xq, Yq, Zq);
figure
h1   = slice(permute(Xq, [2 1 3]),permute(Yq, [2 1 3]),permute(Zq, [2 1 3]), Vq, 5,2,5);

当我运行代码时,我收到一条错误消息:

&#34;数据点位置的数量应等于数据点值的数量。 griddata中的错误&gt; useScatteredInterp(第188行) F = scatteredInterpolant(inargs {1}(:),inargs {2}(:),inargs {3}(:),...&#34;

我想相信这是因为columnsInImage的大小和pagesInImage的大小分别不等于size(P,1)size(P,3)

尽管如此,我还尝试使用如下矢量:

figure
h1         = slice(Img(:,1), Img(:,2), Img(:,3), Img, 5,2,5);

但我仍然会收到错误消息:

&#34;使用griddedInterpolant时出错 网格是由不严格单调增加的网格向量创建的。 interp3出错(第142行)             F = griddedInterpolant(X,Y,Z,V,方法,extrap);&#34;

拜托,伙计们,我需要有关如何解决这些问题的建议/想法。非常感谢提前!..

0 个答案:

没有答案
相关问题