VTK render window image to numpy array VTK render window image to numpy array numpy numpy

VTK render window image to numpy array


I believe there is no need to involve vtkXWriter (where X is some format), except if you need the data in the X format. After you define the window from which you want to export its contents as an image, you can proceed to get a VTK image and work with that.

from vtk.util.numpy_support import vtk_to_numpy...vtk_rw = vtk.vtkRenderWindow()...vtk_win_im = vtk.vtkWindowToImageFilter()vtk_win_im.SetInput(vtk_rw)vtk_win_im.Update()vtk_image = vtk_win_im.GetOutput()width, height, _ = vtk_image.GetDimensions()vtk_array = vtk_image.GetPointData().GetScalars()components = vtk_array.GetNumberOfComponents()arr = vtk_to_numpy(vtk_array).reshape(height, width, components)...