Last active
August 29, 2015 14:08
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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