how to calculate voxel image volume ?
20 views (last 30 days)
Show older comments
Moussa DIEDHIOU
on 31 Aug 2022
Moved: Image Analyst
on 1 Sep 2022
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
on 31 Aug 2022
is it https://www.mathworks.com/help/vision/ref/pcmapndt.html that you are using?
Accepted Answer
More Answers (1)
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
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)
volshow(counts, 'BackgroundColor', [0.8 0.8 0.8]);
See Also
Categories
Find more on 3-D Volumetric Image Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!