View the segmented object and corresponding 3D bounding box together

조회 수: 18 (최근 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?

채택된 답변

Uday Pradhan
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.
  댓글 수: 1
Vinit Nagda
Vinit Nagda 2021년 5월 28일
Hello Uday,
Thank you very much for your response. Your code serves the purpose I want to achieve.
However, I have one doubt concerning the isovalue parameter that you specify in the isosurface function.
I have a labelled volume data and all the objects are labelled with unique integer number. I set the isolvalue to the label value of one object to see that specific object and its corresponding bounding box. However, the result is that all the objects in the subset volume are displayed. How does the isovalue parameter works?
Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by