View the segmented object and corresponding 3D bounding box together
조회 수: 11 (최근 30일)
이전 댓글 표시
I have a labelled volumetric matrix data and I can view the segmented objects in volumetric data in the VolumeViewer App. Then, using 'regionprops3' function, I get the 'BoundingBox' property of each object. How can I view the object and its corresponding bounding box together?
댓글 수: 0
채택된 답변
Uday Pradhan
2021년 5월 28일
편집: Uday Pradhan
2021년 5월 28일
Hi Vinit,
You could use the drawcuboid function to construct your cuboidal bounding box around a volume. I am attaching an example script below, I hope it will help you get started:
%% Script taken from : https://nl.mathworks.com/help/matlab/visualize/visualizing-volume-data.html
load mri D % load data
D = squeeze(D); % remove singleton dimension
limits = [NaN NaN NaN NaN NaN 10];
[x, y, z, D] = subvolume(D, limits); % extract a subset of the volume data
[fo,vo] = isosurface(x,y,z,D,5); % isosurface for the outside of the volume
[fe,ve,ce] = isocaps(x,y,z,D,5); % isocaps for the end caps of the volume
f = figure
hold on;
p1 = patch('Faces', fo, 'Vertices', vo); % draw the outside of the volume
p1.FaceColor = 'red';
p1.EdgeColor = 'none';
p2 = patch('Faces', fe, 'Vertices', ve, ... % draw the end caps of the volume
'FaceVertexCData', ce);
p2.FaceColor = 'interp';
p2.EdgeColor = 'none';
view(-40,24)
daspect([1 1 0.3]) % set the axes aspect ratio
colormap(gray(100))
box on
camlight(40,40) % create two lights
camlight(-20,-10)
lighting gouraud
roi = drawcuboid(gca,'Position',[15 15 0 95 120 10],'InteractionsAllowed','none');
%Turn InteractionsAllowed to all if you want to manually adjust size of the
%box
Result:
Please check the Position argument accepts the cuboid information in the form of a 1 by 6 vector defined as [xmin ymin zmin w h d] where (xmin ymin zmin) is the lower left vertex of the cuboid. So you need to be careful about the 1 by 6 bounding box information given by regionprops3 as they might not be what drawcuboid expects. Note: regionprops3 returns Smallest cuboid containing the region, returned as a 1-by-6 vector of the form [ulf_x ulf_y ulf_z width_x width_y width_z]. ulf_x, ulf_y, and ulf_z specify the upper-left front corner of the cuboid. width_x, width_y, and width_z specify the width of the cuboid along each dimension.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 3-D Volumetric Image Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!