Skip to content

Instantly share code, notes, and snippets.

@somada141
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somada141/3d426b181ce202933950 to your computer and use it in GitHub Desktop.
Save somada141/3d426b181ce202933950 to your computer and use it in GitHub Desktop.
Create an orthogonal slice view through a 3D vtkImageData object #python #vtk #imagedata #dicom #visualization
# Assuming that we have an object of type 'vtkImageData' under the name of
# 'image'
# Create a new vtkImageSliceMapper
mapper = vtk.vtkImageSliceMapper()
# Set 'image' as the input dataset
mapper.SetInput(image)
# Set the orthogonal slice orientation to be perpendicular to the 'X' axis. Use
# 'SetOrientationToY' and 'SetOrientationToZ' for the Y and Z axes.
# Alternatively you can use the 'SetOrientation' method with a 'int' parameter
# of '1', '2', or '3' for the X, Y, or Z axis respectively
mapper.SetOrientationToX()
# Set the slice index to be visualized. Here we set it to the middle slice along
# the X axis
mapper.SetSliceNumber(image.GetDimensions()[0]//2)
# Create a new 'vtkImageActor'
actor = vtk.vtkImageActor()
# Set the mapper
actor.SetMapper(mapper)
# Set the image opacity to 50%
actor.GetProperty().SetOpacity(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment