how to calculate voxel image volume ?

15 views (last 30 days)
Hi,
I am nex in matlab coding.
I am using voxel image function to drow voxels on a point cloud.
the code is runing and it gives a good plot. But the problem is that i do not know how to estimate the volume of my voxelized object ?
anyone can help ?
I already use volume function or [C,V] like alphashape or convexhull, but it doesn't work.
Thank's
  2 Comments
Walter Roberson
Walter Roberson on 31 Aug 2022
is it https://www.mathworks.com/help/vision/ref/pcmapndt.html that you are using?
Moussa DIEDHIOU
Moussa DIEDHIOU on 31 Aug 2022
Hi,
the code is :
ptclouds = load('exemple.xyz');
Pts = ptclouds(:,1:3);
vs = [0.5, 0.5, 0.5]; % voxel size
vxl = voxel_image(Pts, vs);
Thank's

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 31 Aug 2022
Try regionprops3 or just sum the binarized image to count the voxels.
  3 Comments
Walter Roberson
Walter Roberson on 31 Aug 2022
Image Analyst is not available through email.
Moussa DIEDHIOU
Moussa DIEDHIOU on 31 Aug 2022
yes. Thank you for your help

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 31 Aug 2022
discretize() each coordinate axis separately, getting an index number for each point. Use accumarray() with the combined indices, and count 1. Afterwards the volume is nnz() of the count times the volume of each voxel.
  3 Comments
Walter Roberson
Walter Roberson on 31 Aug 2022
N = 500;
data = randn(N,3) .* [20 10 15];
ptc = pointCloud(data);
%pcshow does not work in MATLAB Answers
xyz = ptc.Location;
scatter3(xyz(:,1), xyz(:,2), xyz(:,3)); %instead of pcshow for Answers
minxyz = floor(min(xyz,[],1));
maxxyz = ceil(max(xyz,[],1));
dx = .5; dy = .25; dz = .5;
xidx = 1 + floor((xyz(:,1) - minxyz(1))/dx);
yidx = 1 + floor((xyz(:,2) - minxyz(2))/dy);
zidx = 1 + floor((xyz(:,3) - minxyz(3))/dz);
counts = accumarray([xidx, yidx, zidx], 1);
volume = nnz(counts) .* (dx .* dy .* dz)
volume = 31.2500
volshow(counts, 'BackgroundColor', [0.8 0.8 0.8]);
Moussa DIEDHIOU
Moussa DIEDHIOU on 1 Sep 2022
Moved: Image Analyst on 1 Sep 2022
It works ! Thank you so so much for your help Roberson.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!