How do isosurface and isocaps affect the size of stlwrite's output?

1 view (last 30 days)
I have a volume read from a DICOM, representing a femur. I made this volume binary - 1 bone, 0 background - and I tried to create the corresponding STL with stlwrite (from Exchange). I exported the STL from 3DSlicer too, to ensure the real size of the part, that must be 117.2 mm, with a possible error of about 0.8 mm
If I simply use isosurface, I get a 116.8 mm STL, but with the upper and lower face open.
So I added a background slice (all zeros) under and over my volume, to "close" the stack of slices, but in this way the output STL's size grows to 118.4, just as I have added two slices (they are 0.8 mm thick): is it correct? Shouldn't the dimensions remain the same, since I have added just background and not "material"?
So I tried to use isocaps(), and this closed my volume and leaves the size to 116.8 mm.
Beyond the size discrepancy (that may depend on an approximation done by the software). which solution is the "best" and the "less modifying" the original size?

Answers (2)

William Rose
William Rose on 26 Oct 2022
Edited: William Rose on 26 Oct 2022
[edit : fix spelling errors]
isocaps is the way to go. Adding the background slices, even if they are zeros, still counts as material, and that is why adding the ends with isocaps increases the length by 1.6 mm = 2x0.8 = 2 slice widths. The length of 116.8 mm, which you got with isocaps, is 0.4 mm less than the real length of 117.2, and this length is within the possible error of 0.8 mm. The length with the two added slices is slightly outside the allowable error range. So I recommend isocaps.
  1 Comment
Simone Cotta Ramusino
Simone Cotta Ramusino on 26 Oct 2022
Thanks for your reply, @William Rose.
But I realized I was not very precise: the labelmap (corresponding to the 3D segment) that I use in Matlab has 147 slices, 0.8 mm thick, so I should obtain a total of 117.6 mm and not 116.8 mm; does isosurface "count" the slices in a particular way? It is quite strange that the discrepancy is exactly of one slice (even if it is the max error admitted)
And why, according to you, isosurface counts even the bg slices? When I check the part's height I am taking into account just the bone, so even if I added, for example, 10 slices over and under, once the surface is closed, length should not change, should it?

Sign in to comment.


William Rose
William Rose on 27 Oct 2022
When you say "I get a 116.8 mm STL" and "this closed my volume and leaves the size to 116.8 mm", how exactly did you obtain those lengths?
The length of 116.8 mm is not surprising with 147 slices of width 0.8. If each voxel is represented by its center location, then the distance between (center of) top and bottom voxel is (n-1)*thickness=(147-1)*0.8=116.8.
isocaps() and isosurface() have a variety of options. You can use the output from them in various ways. Therefore I suspect you will need to share some data and code to get exact answers to your questions. If you do share code, please share the simplest possible bit of code that illustrates the problem you are having.
  3 Comments
Simone Cotta Ramusino
Simone Cotta Ramusino on 27 Oct 2022
Dont' worry @William Rose, your help is always appreciated.
Well, I told you, I can't completely understand two things:
1) If I add bg slices, I think they should not affect the stl output, since there is no material and isosurface should exclude them, as it does in x and y dimensions.
2) My example is not derived from a DICOM, so it does not consider the center of the slices; yet, when I check the stl output, it still counts one slice less (0.8 mm is missing).
3) Last, I just noticed that in the Matlab figure, the piece starts 0.8 mm higher, i.e. first slice is at 0.8, not at 0. I don't know if this has anything to do with it

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!