I'm new to this place, so please forgive me if I'm asking a question already answered here.
I would like to calculate the area of a 3D-object given in MATLAB by a 3D-matrix with values 1
for the object and 0
for the background.
I tried with convhulln(K)
, which calculates a convex hull to the object, and afterwards summing up the areas of the different triangles. But since my object is in general not convex, this gives an underestimation of the area.
Another option I tried is just calculating the area of the voxels of the object "exposed" to the background. This works nice, but overestimates the area, since the voxelwise representation is only an approximation of the real object.
Is it possible to triangulate the surface of the 3D-object in a non-convex way, so that the area can be calculated by summing up the areas of the individual triangles?
Any help is welcome!
Yes, you can triangulate the surface of the object using the isosurface() function in MATLAB. Since your object is 1 and background is 0, you could do this to triangulate the surface:
FV = isosurface(yourMatrix, 0.5);
FV will be a struct that contains the faces and vertices of triangles of the surface. Since the area of a triangle can be calculated as half the magnitude of the cross-product of two of its sides, the total area of the surfaces can be computed as something like:
V = FV.vertices;
F = FV.faces;
A = V(F(:, 2), :) - V(F(:, 1), :);
B = V(F(:, 3), :) - V(F(:, 1), :);
C = cross(A, B, 2);
area = 1/2 * sum(sqrt(sum(C.^2, 2)));
The above code assumes that each element of your matrix represents a unit cube within the object. If this is not the case, you may scale A
and B
appropriately.