使用vtk python显示3D图像

问题描述 投票:0回答:2

我想使用vtk模块python显示3D图像。图像以.vti格式保存。我编写了以下简单代码,但无法正常工作。我该如何解决?

import vtk

file_name = 'Vug.vti'

# Read the source file.
reader = vtk.vtkNrrdReader()
reader.SetFileName(file_name)
reader.Update()  

# Map the image through the lookup table
color = vtk.vtkImageMapToColors()
#color.SetLookupTable(table)
color.SetInputConnection(reader.GetOutputPort())

# Display the image
actor = vtk.vtkImageActor()
actor.GetMapper().SetInputConnection(color.GetOutputPort())

renderer = vtk.vtkRenderer()
renderer.AddActor(actor)

window = vtk.vtkRenderWindow()
window.AddRenderer(renderer)

# Set up the interaction
interactor = vtk.vtkRenderWindowInteractor()
window.SetInteractor(interactor)
window.Render()

# Start interaction
interactor.Start()
python vtk
2个回答
0
投票

vtkImageActor将图像显示为2d对象。如果要渲染3D体积,则需要使用vtkVolume对象。

此示例显示了如何在VTK中批量渲染:https://github.com/Kitware/VTK/blob/master/Examples/VolumeRendering/Python/SimpleRayCast.py


0
投票

使用vtkplotter,这很简单:

from vtkplotter import load, datadir, show
vol = load(datadir + 'vase.vti') # returns vtkVolume
# set color and trasparency transfer functions along the scalar range
vol.color(["green", "pink", "blue"]).alpha([0, 0, 0.2, 0.5, 0.9])
show(vol)

更多示例here

© www.soinside.com 2019 - 2024. All rights reserved.