How to use voxels of different sizes to measure the volume of a 3D object using Matlab?

Hi Dear Community members,
i want to measure the volume of a cone using voxels. i am new in this field of voxels. Using the first link, a sphre of radius 8 has been voxelized. After voxelization, how can we count the total number of voxels. how to fix the size of voxels?
Using this method of author, how can we voxelize the cone to measure its volume. The attached file has xyz - coordiantes for the cone.
Thanks in advance for all cooperation and guidance.
% This scrypt illustrates the use of VoxelPlotter function to visualize
% voxel data stored in a 3d matrix
clear all
close all
clc
%Generating sinthetic input
gridesize=16;
R=8;
VoxelMat=zeros(gridesize,gridesize,gridesize);
for i=1:gridesize
for j=1:gridesize
for k=1:gridesize
if (i-gridesize/2)^2+(j-gridesize/2)^2+(k-gridesize/2)^2<R^2
VoxelMat(i,j,k)=1;
end
end
end
end
[vol_handle]=VoxelPlotter(VoxelMat,1);
view(3);
daspect([1,1,1]);
set(gca,'xlim',[0 gridesize], 'ylim',[0 gridesize], 'zlim',[0 gridesize]);

 Akzeptierte Antwort

Bruno Luong
Bruno Luong am 3 Sep. 2020
Bearbeitet: Bruno Luong am 4 Sep. 2020
Vol estimate = 1.2692e+06
xyz = load('Cone_20000_points.txt');
[minxyz,maxxyz] = bounds(xyz,1);
N = 30*ones(1,3); % resolution, select with care
ijk = min(max(ceil((xyz-minxyz)./(maxxyz-minxyz).*N),1),N);
C = accumarray(ijk,1);
b = C > 0;
p = mean(C(b))
if p < 2 % Sanity check
warning('Your bin is too small, inaccurate result');
end
Vol = sum(b,'all') * prod((maxxyz-minxyz)./N)

11 Kommentare

Thanks Dear Bruno for all your great cooperation as usual.
Please tell me what was the size of the voxel here. Also, how many voxels were counted in total? What will p represent. Please if you dont mind, explain to me the code. i will be vey thankful. can i conclude that : " b " represent the number of voxels. "prod((maxxyz-minxyz)./(N-1)" represent the size of voxel.
sum(b,'all') gives the number of voxels intesrsecting with the object
prod((maxxyz-minxyz)./N) is the volume (not size) of the voxel
Thank you for guiding! How will we know what is the size of the voxel? if i want to measure the volume using different size of voxel, how will we change the size of the voxel.
The sizes in x/y/z directions are
(maxxyz-minxyz)./N
PS: I edit the code I think the correct sizes is devided by N, not by N-1.
voxel means cube. Its length, width and heigh will be same e.g.5x5x5 or 10x10x10
In this case, if i use : (maxxyz-minxyz)./N --> it will give me voxel size like: 5 x5x6. am i right?
are the resolution and voxel size depending on each other?
I want to voxel size as 10, How will i fix it.
How to show the total count of all voxels used.
Please guide me.
Let as exercice for you. I have done enough already no?
Great Dear Bruno, yes i am thinking over it. I know, i am taking a lot of time from you.
i used below code to count number of voxels and size of voxels. Bruno, could you please look at it:6
number_of_voxels = numel(b) % To count number of voxels using above code.
% number_of_voxels = 27000
size_of_voxel = (maxxyz - minxyz)./N
% size_of_voxel= 5.1 5.1 5.93 ==> prod()~= 153
But if i measure volume using above values i.e. 27000 * 153 = 4139568 which is wrong.
Where you get this
number_of_voxels = numel(b) % To count number of voxels using above code.
from???? If you change the calculation of my code then it's normal you get wrong result.
Greetings Bruno, sorry for late reply. i was out of station.
Yes true, i got wrong results. Could you pleasue give me some tips how to count the number of voxels and how to measure the size of voxel.
i could not still figure out, how to measure the total number of voxels used. Please anyone can help me?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Produkte

Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by