VTK将窗口图像渲染为numpy数组

编程入门 行业动态 更新时间:2024-10-26 19:26:26
本文介绍了VTK将窗口图像渲染为numpy数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在VTK中,我可以使用以下代码片段将渲染窗口另存为图像.但是,实际上,我想直接将其作为一个numpy数组获取(无需编写然后读取).

In VTK I am able to use the following snippet to save the render window as an image. However, actually I want to get it directly as a numpy array (without writing then reading).

im = vtkWindowToImageFilter() writer = vtkPNGWriter() im.SetInput(renderWindow) im.Update() writer.SetInputConnection(im.GetOutputPort()) writer.SetFileName("file.png") writer.Write()

做到这一点的最佳方法是什么?

What is the best way to do this?

推荐答案

我相信没有必要涉及vtkXWriter(其中X是某种格式),除非您需要X格式的数据.在定义了要从中导出其内容作为图像的窗口之后,您可以继续获取VTK图像并对其进行处理.

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) ...

更多推荐

VTK将窗口图像渲染为numpy数组

本文发布于:2023-07-20 17:54:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1169731.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   图像   窗口   VTK   numpy

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!