社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

【Python】VTK: 三维图像处理和可视化利器

机器学习初学者 • 4 年前 • 1353 次点击  

VTK在Java, Tcl, Python中都有接口,本文介绍VTK在Python中的接口。

VTK (The Visualization Toolkit ) 是一款用于计算机3D成像、构建模型、图像处理、容积渲染、科学数据可视化等方面的免费软件系统,支持Linux, Windows, Mac, Web, mobile devices等平台;

一些常见使用场景👇👇

3D成像
图像处理1
图像处理2
构建模型
容积渲染

下面简单介绍VTK如何快速上手,

安装

pip install vtk

快速入门VTK

以一个小为例,

import vtkmodules.vtkInteractionStyle
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkFiltersSources import vtkCylinderSource
from vtkmodules.vtkRenderingCore import (vtkActor, vtkPolyDataMapper,
                                         vtkRenderWindow,
                                         vtkRenderWindowInteractor,
                                         vtkRenderer)
# 数据准备
colors = vtkNamedColors()
bkg = map(lambda x: x / 255.0, [26, 51, 102, 255])
colors.SetColor("BkgColor", *bkg)
cylinder = vtkCylinderSource()
cylinder.SetResolution(8)

# 映射
cylinderMapper = vtkPolyDataMapper()
cylinderMapper.SetInputConnection(cylinder.GetOutputPort())

# 添加绘制对象
cylinderActor = vtkActor()

#绘制对象添加映射器
cylinderActor.SetMapper(cylinderMapper)
cylinderActor.GetProperty().SetColor(colors.GetColor3d("Tomato"))
cylinderActor.RotateX(30.0)
cylinderActor.RotateY(-45.0)

# 添加绘制器
ren = vtkRenderer()

# 添加绘制窗口
renWin = vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# 绘制器添加对象
ren.AddActor(cylinderActor)
ren.SetBackground(colors.GetColor3d( "BkgColor"))
renWin.SetSize(300, 300)
renWin.SetWindowName('CylinderExample')

# 交互器初始化
iren.Initialize()
ren.ResetCamera()
ren.GetActiveCamera().Zoom(1.5)
renWin.Render()

# 交互器启动
iren.Start()

进一步学习👇👇
https://kitware.github.io/vtk-examples/site/Python/


-END-




    
往期精彩回顾




本站qq群554839127,加入微信群请扫码:

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/122587