Slice 3D Volume into 2D Image along the specific axis

Hello everone,
I'm trying to perform in image-analysis.
Suppose I have faces data of the volume (Faces) corresponding with Coordinate (Coords) which attached in this topic.
By using the following code,
%% Plot 3D Image
fv.faces = Faces;
fv.vertices = Coords;
patch(fv,'FaceColor', [0.8 0.8 1.0], ...
'EdgeColor', 'b', ...
'FaceLighting', 'gouraud', ...
'AmbientStrength', 0.15);
camlight('headlight');
material('dull');
axis equal; axis tight;
xlabel('x');ylabel('y');zlabel('z');
view([30,30,30])
I obtained the plotted result as (with some of disappeared volume in the red circle)
Now, I want to slices this volume along the Z-axis to obtain the picture in XY-plane filled with black color.
I'm try to construct with the code as
%% Plot 2D sliced images
colors = [0 0 0];
close all;
spc = max(Coords(:,3))-min(Coords(:,3));
RangeZ = 5; % Define number of slices in Z-axis
for i = 1 : RangeZ
Coordi = DOMAIN.NODES;
Coordi(:,3) = Coordi(:,3) / RangeZ + spc/RangeZ*(i-1);
S.Vertices = Coordi;
S.Faces = Faces;
S.FaceVertexCData = colors;
S.FaceColor = 'flat';
S.EdgeColor = 'red';
S.LineWidth = 1;
figure
patch(S);
view([30,30,30])
xlabel('x');ylabel('y');zlabel('z');
axis([min(Coordi(:,1)) max(Coordi(:,1)) min(Coordi(:,2)) max(Coordi(:,2)) min(Coordi(:,3)) max(Coordi(:,3))]);
end
However, the results that shown below in the left side are not sliced (Just plot the whole volume in different range of Z-axis).
I want to slices the above volume along Z- axis as depicted in the right side ( I drawn the picture by myself for easy to understand).
>>>>>>>>>>
>>>>>>>>>>
I've been struggle with this problem for a very long time.
Any suggestions, Ideas are very very appreciated.
Thanks in advances.

4 Comments

Have you tried using the slice function?
Thank you very much for replying this topic.
The slice function that you mentioned is also one of the option that I considered to perform as well.
However, from the informations or datas that I obtained, I dont have any idea how to input into the slice function.
slices this volume along the Z-axis to obtain the picture in XY-plane filled with black color.
may be use view(2) after crop by Coordi(:,3) = Coordi(:,3) / RangeZ + spc/RangeZ*(i-1);
Thank you for replying this topic.
I have tried to use the code that you mentioned before
Coordi(:,3) = Coordi(:,3) / RangeZ + spc/RangeZ*(i-1);
view(2)
However, the result is still plotted the whole volume, not the specific range of Z-axis.

Sign in to comment.

Answers (1)

Actually you did it in the first plot, just add the following line in 2D sliced images plots.
And use the original axis ranges.
patch(S);
view([30,30,30])
axis equal; axis tight; % Add this line
xlabel('x');ylabel('y');zlabel('z');
axis([min(Coords(:,1)) max(Coords(:,1)) min(Coords(:,2)) max(Coords(:,2)) min(Coords(:,3)) max(Coords(:,3))]); % Use the original xyz limts

Categories

Asked:

on 10 Feb 2022

Edited:

on 15 Feb 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!