View the segmented object and corresponding 3D bounding box together

13 次查看(过去 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 个)

类别

Help CenterFile Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by