vtkimage to numpy

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

image = *.GetOutput() #只要得到的数据类型为vtkimage即可
rows, cols, _ = image.GetDimensions()
scalars = image.GetPointData().GetScalars()
arr = vtk_to_numpy(scalars)
arr = arr.reshape(rows, cols, -1)

你可能感兴趣的:(笔记,python)