I have generated a segmentation mask for a CT volume and and saved it as a nifti format. This image volume consists of below set of categories.
0: Background (None of the following organs)
1: Liver
2: Bladder
3: Lungs
4: Kidneys
5: Bone
6: Brain
In order to extract the surface mesh which belongs to the liver (i.e. 1) from this label mask I simply applied the vtkImageThreshold filter followed by vtkDiscreteMarchingCubes filter.
But I’m not able to extract the liver surface mesh and the resulted output image you can see below.
Please help me on this matter. Thank you very much for your time and consideration.
binary_mask_file = './mask-0.nii'
mask_reader = vtk.vtkNIFTIImageReader()
mask_reader.SetFileName(binary_mask_file)
mask_reader.Update()
threshold = vtk.vtkImageThreshold()
threshold.SetInputConnection(mask_reader.GetOutputPort())
threshold.ThresholdByLower(5)
threshold.ThresholdByUpper(2)
threshold.ReplaceInOn()
threshold.SetInValue(0)
threshold.ReplaceOutOn()
threshold.SetOutValue(1)
threshold.Update()
dmc = vtk.vtkDiscreteMarchingCubes()
dmc.SetInputConnection(threshold.GetOutputPort())
dmc.GenerateValues(1, 1, 1)
dmc.Update()
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(dmc.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Add the actors to the renderer, set the background and size
ren.AddActor(actor)
ren.SetBackground(1.0, 1.0, 1.0)
renWin.SetSize(600, 600)
iren.Initialize()
# We'll zoom in a little by accessing the camera and invoking a "Zoom"
# method on it.
ren.ResetCamera()
#ren.GetActiveCamera().Zoom(1.5)
renWin.Render()
# Start the event loop.
iren.Start()