• vtk类之vtkImageReslice:基本算法,对体数据沿着轴进行切片


    沿着轴方向切割体数据。

    vtkImageReslice 是几何图形过滤器中的瑞士军刀。他可以排列,旋转,翻转,缩放,重新采样,变形, 还有随意再任何效率与图像质量组合下,渲染图像。简单的操作,像排列,重新采样和渲染高效功能,与被人所熟知的vtkImagePermute、 vtkImageResample 和 vtkImagePad一样。有一些任务,vtkImageReslice更适合做这些事情。

    1)对一个图像应用简单的旋转,缩放和平移。有一个更好的注意是,先使用vtkImageChangeInformation,把图像的坐标系原点更新到图像中心点,以便尺度和旋转发生中心而不是环绕图像的左下角。

    2)通过方法SetInformationInput对一个数据集重新采样,以匹配另一个数据集。例如,比较两个图像或者组合两幅图像。可以我不在同一个坐标系空间上的2幅图像,同时通过方法SetResliceTransform 应用线性或非线性变换。

    3)从一个体数据中提取图像切片卷。最方便的方法来执行此操作是使用 SetResliceAxesDirectionCosines() 指定切片的方向。方向余弦形式给出 x、 y 和 z 轴的输出向量。SetOutputDimensionality(2) 用于指定的方法想要输出一个切片,而不是一个卷。SetResliceAxesOrigin()方法,设置切片将经过的该origin空间点。你也可以同时使用ResliceAxes 和ResliceTransform ,为了从体数据中导出切片序列,你需要应用变换信息。transformation 

    应用实例:

    #-*- coding: UTF-8 -*-
    #-------------------------------------------------------------------------------
    # Name:        模块2
    # Purpose:
    #
    # Author:      ankier
    #
    # Created:     07-01-2013
    # Copyright:   (c) Ankier 2013
    # Licence:     <your licence>
    #-------------------------------------------------------------------------------
    
    from ActorFactory import ActorFactory
    from vtk import *
    from glo import *
    
    class ResliceActorFactory(ActorFactory):
        def __init__(self):
            ActorFactory.__init__(self)
            #定义一块板子
            self.__PlaneSource = vtkPlaneSource()
            self.__PlaneSource.SetOrigin(-50, -50, 0)
            self.__PlaneSource.SetPoint1(50, -50 , 0)
            self.__PlaneSource.SetPoint2(-50 , 50 , 0) 
            self.__PlaneSource.SetXResolution(50)
            self.__PlaneSource.SetYResolution(50)
            
            self.__Input = None
            
            #定义图像切片类
            self.__ImageReslice = vtkImageReslice()
            
            globalInstance = Global.GetInstance()
            
            
            transform = globalInstance.GetOrthoViewFrame().GetOrthoPlanesFactory().GetAxialPlane()._Transform
            print transform
            self.__ImageReslice.SetResliceTransform(transform)
            self.__ImageReslice.InterpolateOn()
            self.__ImageReslice.SetOptimization(2)
            self.__ImageReslice.SetBackgroundLevel(1023)
            self.__ImageReslice.SetInterpolationModeToLinear()
            self.__ImageReslice.SetOutputDimensionality(2)
            
            
            self.__LookupTable = vtkLookupTable()     
            self.__LookupTable.SetNumberOfTableValues(256)
            self.__LookupTable.Build()
            for i in range(256):
                self.__LookupTable.SetTableValue(i, i/255.0, i/255.0, i/255.0)
            
            
            self.__MapToColor = vtkImageMapToColors()
            self.__MapToColor.SetLookupTable(self.__LookupTable)
            self.__MapToColor.SetInputConnection(self.__ImageReslice.GetOutputPort())
            
            #设置板子的纹理映射类
            self.__TexturePlane= vtkTextureMapToPlane()
            self.__TexturePlane.SetInput(self.__PlaneSource.GetOutput())
            
            #设置纹理类。
            self.__Texture = vtkTexture()
            self.__Texture.InterpolateOn()
            self.__Texture.RepeatOff() # only necessary if interpolation is on
            
            #设置Poly Data,从纹理映射器重,得到被filter的输出数据
            self.__PolyDataMapper = vtkPolyDataMapper()
            self.__PolyDataMapper.SetInput(self.__TexturePlane.GetOutput())
            
        def UpdateData(self):
            (min,max) = self.__Input.GetScalarRange()   
            self.__LookupTable.SetTableRange(min,max)
            self.__ImageReslice.SetInput(self.__Input)
            self.__Texture.MapColorScalarsThroughLookupTableOff()
            self.__Texture.SetInput(self.__MapToColor.GetOutput())
        
        def SetInput(self, input):
            self.__Input = input
        
        def _MakeActors(self):
            self.UpdateData()
            actor = self._NewActor()
            actor.SetMapper(self.__PolyDataMapper)
            actor.SetTexture(self.__Texture)
            return [actor]
  • 相关阅读:
    linux常见的基本操作命令
    CentOS-7安装mongodb
    分布式CAP理论
    Spring-boot2.X整合Apache ActiveMQ5.X
    Apche ActiveMQ5.X介绍及CentOS7的安装
    初识Java消息服务JMS
    初始Apache-Shiro权限认证Web知识点
    Java定时任务总结
    Apache-Shiro自定义Realm实战
    Java 作业题1
  • 原文地址:https://www.cnblogs.com/ankier/p/2850192.html
Copyright © 2020-2023  润新知