I have a binary mask, I loaded it in 3D slicer as a segmentation file, and in Data module, I used “export visible segments to model”. Then in Models module, I can see the model volume is 55349.06 mm^3 (none smooth).
Then, I used my own vtk codes to calculate its volume:
mask = vtk.vtkNIFTIImageReader()
mask.SetFileName('origCT_nodule_0.nii.gz')
mask.Update()
nodule = vtk.vtkDiscreteMarchingCubes()
nodule.SetInputData(mask.GetOutput())
nodule.Update()
massProperties = vtk.vtkMassProperties()
massProperties.SetInputData(nodule.GetOutput())
massProperties.Update()
volume = massProperties.GetVolume()
print(volume)
However, the volume is 47789.92 mm^3. I visualized it to check what happened:
Oh, it seems this is an unclosed surface representation. I know 3D Slicer will close it first and then calculate its volume (as in the first screenshot). Then, I used vtkFillHolesFilter() to close the surface first:
fill_holes_filter = vtk.vtkFillHolesFilter()
fill_holes_filter.SetInputData(nodule.GetOutput())
fill_holes_filter.SetHoleSize(100.0)
fill_holes_filter.Update()
This time, the volume is 40265.35 mm^3. What happened???