I am trying to extract a STL file from a volume (3D-matrix). Since I am working with a DICOM volume, I want to adapt the matrix elements to the voxel size. Everything seems to work fine, but when I check the stl output size (for example in a CAD software), it seems that a slice, a "voxel", is missing in each direction. This can be (maybe) reasonable for a DICOM, where the slices are counted considering the respective center (and therefore, in a certain sense, one slice may be missing in the finale measure), but not in the following example I tried.
I leave here a simple code: my voxel size is 0.723x0.723x0.8; I created a 10x10x10 matrix, so I would expect a 7.23 x 7.23 x 8 mm stl. Instead, I get a 6.507 x 6.507 x 7.2 mm stl, so I think something goes wrong.
R=randi(3,10,10,10);
R(R>1)=0;
[F1,V1]=isosurface(R,0);
[F2,V2]=isocaps(R,0);
faces=[F1;F2+length(V1(:,1))];
vertices=[V1;V2];
S=makehgtform('scale',[0.723,0.723,0.8]);
new_vertices=vertices*S(1:3,1:3);
p=patch('Vertices',new_vertices,'Faces',faces,'FaceColor','blue');
view(3)
camlight headlight; lighting gouraud
str=strcat(['R','.stl']);
stlwrite(str,faces,new_vertices);
How can isosurface, isocaps or stlwrite be responsible for this?