使用vtk python显示三维图像

2024-07-08 16:01:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用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()

Tags: thename图像imagetablewindowreaderfile
2条回答

vtkImageActor将图像显示为二维对象。如果要渲染三维体积,则需要使用vtkVolume对象

此示例显示如何在VTK中进行体积渲染: https://github.com/Kitware/VTK/blob/master/Examples/VolumeRendering/Python/SimpleRayCast.py

对于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)

相关问题 更多 >

    热门问题