Hi:
I am trying to extract the skull model from series of Dicom files.
I used vtkDICOMImageReader and vtkMarchingCubes.
Here is the result
I wish only get the skull model like the example Headbone
https://kitware.github.io/vtk-examples/site/Python/VisualizationAlgorithms/HeadBone/
- I tried to tune the parameters in
marchingCubes.SetValue(0, 10)
but there is no good result. - I do not know why there is abnormal particles flying around.
The dicom files are download from 3D-slicer and the link is attached.
Here is my code
#!/usr/bin/env python
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonCore import (
VTK_VERSION_NUMBER,
vtkVersion
)
from vtkmodules.vtkCommonDataModel import vtkImageData
from vtkmodules.vtkFiltersCore import (
vtkFlyingEdges3D,
vtkMarchingCubes,
vtkStripper
)
from vtkmodules.vtkFiltersSources import vtkSphereSource
from vtkmodules.vtkIOImage import vtkDICOMImageReader
from vtkmodules.vtkImagingHybrid import vtkVoxelModeller
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkPolyDataMapper,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkRenderer,
vtkCamera,
vtkInteractorStyle
)
from vtkmodules.util.numpy_support import vtk_to_numpy
import numpy as np
# the dicom files directory
dicom_dir = "C:\\Users\\perph\\PycharmProjects\\vtk\\MR-head\\Dicom"
reader = vtkDICOMImageReader()
reader.SetDirectoryName(dicom_dir)
reader.Update()
marchingCubes = vtkMarchingCubes()
marchingCubes.SetInputConnection(reader.GetOutputPort())
marchingCubes.SetValue(0, 10)
Stripper = vtkStripper()
Stripper.SetInputConnection(marchingCubes.GetOutputPort())
mapper = vtkPolyDataMapper()
mapper.SetInputConnection(Stripper.GetOutputPort())
actor = vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetDiffuseColor(1, .90, .25)
actor.GetProperty().SetSpecular(.1)
actor.GetProperty().SetSpecularPower(100)
renderer = vtkRenderer()
aCamera = vtkCamera()
aCamera.SetViewUp(0, 0, -1)
aCamera.SetPosition(0, 1, 0)
aCamera.SetFocalPoint(0, 0, 0)
aCamera.ComputeViewPlaneNormal()
rewin = vtkRenderWindow()
interactor = vtkRenderWindowInteractor()
renderer.SetActiveCamera(aCamera)
aCamera.Dolly(1.5)
# style = vtkInteractorStyleTrackballCamera()
# interactor.SetInteractorStyle(style)
rewin.AddRenderer(renderer)
interactor.SetRenderWindow(rewin)
renderer.AddActor(actor)
renderer.ResetCamera()
interactor.Initialize()
interactor.Start()
Thanks very much