简体   繁体   English

绘制由3d numpy数组表示的3d体积数据

[英]Plot 3d volumetric data represented by a 3D numpy array

I've seen that vtkplotter supports a wide range of volumetric image formats, but does it support plotting numpy arrays? 我已经看到vtkplotter支持各种体积图像格式,但它是否支持绘制numpy数组? I have an image in a .mhd format that I converted to .npz file and would like to plot it using the mentioned library. 我有.mhd格式的图像,我转换为.npz文件,并希望使用提到的库绘制它。 Is there a way to do so? 有办法吗?

import numpy as np
data = np.zeros((3,3,3))
# how to plot this?

If you know any other tools for visualizing volumetric data, suited for medical analysis, please tell so. 如果您知道任何其他可视化体积数据的工具,适合医学分析,请告知。 I've tried mayavi but it consumes so much memory that it crashes my computer. 我尝试了mayavi,但它耗费了大量内存,导致我的计算机崩溃。

You can use numpy_support to convert numpy arrays to vtkImageData (ie a VTK 3D image). 您可以使用numpy_support将numpy数组转换为vtkImageData(即VTK 3D图像)。

An example follows, there's a numpy warning about type conversion: I don't think it's relevant but I'm not a python guru... 下面是一个例子,关于类型转换有一个numpy警告:我不认为它是相关的,但我不是一个蟒蛇大师......

from vtk.util import numpy_support
import vtk
import numpy as np

data = np.zeros((3,3,3))

# vtkImageData is the vtk image volume type
imdata = vtk.vtkImageData()
# this is where the conversion happens
depthArray = numpy_support.numpy_to_vtk(data.ravel(), deep=True, array_type=vtk.VTK_DOUBLE)

# fill the vtk image data object
imdata.SetDimensions(data.shape)
imdata.SetSpacing([1,1,1])
imdata.SetOrigin([0,0,0])
imdata.GetPointData().SetScalars(depthArray)

# f.ex. save it as mhd file
writer = vtk.vtkMetaImageWriter()
writer.SetFileName("test.mhd")
writer.SetInputData(imdata)
writer.Write()

... and to visualize vtk volume data you can use Paraview. ...并且可视化vtk体积数据,您可以使用Paraview。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM