三维图像切面提取

切片(Slice)或切面是三维图像比较常用的概念,尤其在医学图像中。通过提取切面可以方便地浏览和分析图像内部组织结构。VTK中vtkImageReSlice类可以实现图像切面的提取。在实际开发中,四视图中冠状视面、矢状面和横断面(显示过图像内部一点且平行于XY、YZ、XZ平面的平面),需要用到此类。

示例说明

CMakeLists.txt文件代码如下:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(ImageResliceExample)
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
ADD_EXECUTABLE(ImageResliceExample  ImageResliceExample.cpp)
TARGET_LINK_LIBRARIES(ImageResliceExample ${VTK_LIBRARIES})    

ImageResliceExample.cpp文件代码如下:

#include <vtkSmartPointer.h>
#include <vtkImageReader2.h>
#include <vtkMatrix4x4.h>
#include <vtkImageReslice.h>
#include <vtkLookupTable.h>
#include <vtkImageMapToColors.h>
#include <vtkImageActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleImage.h>
#include <vtkCommand.h>
#include <vtkImageData.h>
#include <vtkMetaImageReader.h>
#include <vtkImageCast.h>class vtkImageInteractionCallback : public vtkCommand
{
public:static vtkImageInteractionCallback *New(){return new vtkImageInteractionCallback; }vtkImageInteractionCallback() {this->Slicing = 0;this->ImageReslice = 0;this->Interactor = 0; }void SetImageReslice(vtkImageReslice *reslice) {this->ImageReslice = reslice; }void SetImageMapToColors(vtkImageMapToColors *mapToColors){this->mapToColors = mapToColors;}vtkImageReslice *GetImageReslice() {return this->ImageReslice;}void SetInteractor(vtkRenderWindowInteractor *interactor) {this->Interactor = interactor;}vtkRenderWindowInteractor *GetInteractor() {return this->Interactor; }virtual void Execute(vtkObject *, unsigned long event, void *){vtkRenderWindowInteractor *interactor = this->GetInteractor();int lastPos[2];interactor->GetLastEventPosition(lastPos);int currPos[2];interactor->GetEventPosition(currPos);if (event == vtkCommand::LeftButtonPressEvent){this->Slicing = 1;}else if (event == vtkCommand::LeftButtonReleaseEvent){this->Slicing = 0;}else if (event == vtkCommand::MouseMoveEvent){if (this->Slicing){vtkImageReslice *reslice = this->ImageReslice;// Increment slice position by deltaY of mouseint deltaY = lastPos[1] - currPos[1];reslice->Update();double sliceSpacing = reslice->GetOutput()->GetSpacing()[2];vtkMatrix4x4 *matrix = reslice->GetResliceAxes();// move the center point that we are slicing throughdouble point[4];double center[4];point[0] = 0.0;point[1] = 0.0;point[2] = sliceSpacing * deltaY;point[3] = 1.0;matrix->MultiplyPoint(point, center);matrix->SetElement(0, 3, center[0]);matrix->SetElement(1, 3, center[1]);matrix->SetElement(2, 3, center[2]);mapToColors->Update();interactor->Render();}else{vtkInteractorStyle *style = vtkInteractorStyle::SafeDownCast(interactor->GetInteractorStyle());if (style){style->OnMouseMove();}}}}private:int Slicing;vtkImageReslice *ImageReslice;vtkRenderWindowInteractor *Interactor;vtkImageMapToColors *mapToColors;
};int main()
{vtkSmartPointer<vtkMetaImageReader> reader =vtkSmartPointer<vtkMetaImageReader>::New();reader->SetFileName ( "E:\\TestData\\brain.mhd" );reader->Update();int extent[6];double spacing[3];double origin[3];reader->GetOutput()->GetExtent(extent);reader->GetOutput()->GetSpacing(spacing);reader->GetOutput()->GetOrigin(origin);double center[3];center[0] = origin[0] + spacing[0] * 0.5 * (extent[0] + extent[1]);center[1] = origin[1] + spacing[1] * 0.5 * (extent[2] + extent[3]);center[2] = origin[2] + spacing[2] * 0.5 * (extent[4] + extent[5]);static double axialElements[16] = {1, 0, 0, 0,0, 1, 0, 0,0, 0, 1, 0,0, 0, 0, 1 };vtkSmartPointer<vtkMatrix4x4> resliceAxes =vtkSmartPointer<vtkMatrix4x4>::New();resliceAxes->DeepCopy(axialElements);resliceAxes->SetElement(0, 3, center[0]);resliceAxes->SetElement(1, 3, center[1]);resliceAxes->SetElement(2, 3, center[2]);vtkSmartPointer<vtkImageReslice> reslice =vtkSmartPointer<vtkImageReslice>::New();reslice->SetInputConnection(reader->GetOutputPort());reslice->SetOutputDimensionality(2);reslice->SetResliceAxes(resliceAxes);reslice->SetInterpolationModeToLinear();vtkSmartPointer<vtkLookupTable> colorTable =vtkSmartPointer<vtkLookupTable>::New();colorTable->SetRange(0, 1000); colorTable->SetValueRange(0.0, 1.0);colorTable->SetSaturationRange(0.0, 0.0);colorTable->SetRampToLinear();colorTable->Build();vtkSmartPointer<vtkImageMapToColors> colorMap =vtkSmartPointer<vtkImageMapToColors>::New();colorMap->SetLookupTable(colorTable);colorMap->SetInputConnection(reslice->GetOutputPort());colorMap->Update();vtkSmartPointer<vtkImageActor> imgActor =vtkSmartPointer<vtkImageActor>::New();imgActor->SetInputData(colorMap->GetOutput());vtkSmartPointer<vtkRenderer> renderer =vtkSmartPointer<vtkRenderer>::New();renderer->AddActor(imgActor);renderer->SetBackground(1, 1, 1);vtkSmartPointer<vtkRenderWindow> renderWindow =vtkSmartPointer<vtkRenderWindow>::New();renderWindow->SetSize(500, 500);renderWindow->AddRenderer(renderer);vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =vtkSmartPointer<vtkRenderWindowInteractor>::New();vtkSmartPointer<vtkInteractorStyleImage> imagestyle =vtkSmartPointer<vtkInteractorStyleImage>::New();renderWindowInteractor->SetInteractorStyle(imagestyle);renderWindowInteractor->SetRenderWindow(renderWindow);renderWindowInteractor->Initialize();vtkSmartPointer<vtkImageInteractionCallback> callback =vtkSmartPointer<vtkImageInteractionCallback>::New();callback->SetImageReslice(reslice);callback->SetInteractor(renderWindowInteractor);callback->SetImageMapToColors(colorMap);imagestyle->AddObserver(vtkCommand::MouseMoveEvent, callback);imagestyle->AddObserver(vtkCommand::LeftButtonPressEvent, callback);imagestyle->AddObserver(vtkCommand::LeftButtonReleaseEvent, callback);renderWindowInteractor->Start();return EXIT_SUCCESS;
}

运行结果:

按下鼠标左键,移动鼠标时的gif图片:

代码解释:

  1. 先通过vtkMetaImageReader读取一副三维图像,获取图像范围、原点和像素间隔,由这三个参数可以计算图像的中心位置。
  2. 接下来定义了切面的变换矩阵axialElements,该矩阵的前三列分别表示X、Y和Z方向矢量,第四列为切面坐标系原点。通过修改切面坐标系原点,可以得到不同位置的切面图像。
  3. 然后将读取的图像作为vtkImageReslice的输入,通过函数SetResliceAxes()设置变换矩阵resliceAxis。

VTK图像处理之vtkImageReslice相关推荐

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

    沿着轴方向切割体数据. vtkImageReslice 是几何图形过滤器中的瑞士军刀.他可以排列,旋转,翻转,缩放,重新采样,变形, 还有随意再任何效率与图像质量组合下,渲染图像.简单的操作,像排列, ...

  2. VTK图像处理颜色映射(一)

    颜色映射是标量算法的一种,是应用最为广泛的可视化算法,该算法的核心是将数据集的属性数据和颜色表中的颜色相互对应,并用所对应的颜色绘制标量数据. 颜色映射的过程主要包括以下步骤: 1)定义颜色表,在颜色 ...

  3. Python数据三维可视化-VTK

    Python科学计算三维可视化[完结]:https://www.cnblogs.com/yuyukun/p/12063595.html VTK 图形模型的主要作用是用图形描述几何体构成的场景,可视化流 ...

  4. VTK笔记-切面重建-使用交互器更新断层图的奇异现象的问题排查

    问题   VTK图像处理交流群(962611958)里有朋友提了一个问题:使用交互器操作轴面图像的中心点时,出现图像随着鼠标移动:大家都认为平移时出现图像的平移是不可能的,因为在使用vtkImageR ...

  5. VTK系列70_VTK对MHD格式文件单张切片的鼠标滑动提取显示

    实例11:基于VTK对MHD格式文件单张切片的鼠标滑动提取显示 #include "vtkAutoInit.h" VTK_MODULE_INIT(vtkRenderingOpenG ...

  6. 5、VTK在图像处理中的应用

    5.VTK在图像处理中的应用 图像是VTK中一个非常重要的数据.数字图像广泛应用于工业生产.生物医学.媒体娱乐.地质.气象等重要领域,数字图像处理具有重要的应用价值.我们在掌握了VTK的基本知识后,这 ...

  7. 三维数据平滑处理_VTK图像处理(二)--vtkPolyData数据处理

    前言 vtkPolyData数据是一种广泛使用的vtk数据结构,可以用来表示很多常用的数据结构,如点云数据.面片模型等.本文章先分析vtkPolyData数据的基本组成,创建方法和显示管线,结果介绍了 ...

  8. VTK系列45_图像进行理想低通滤波器处理(频域处理)

    实例45:理想低通滤波器(频域处理) #include "vtkAutoInit.h" VTK_MODULE_INIT(vtkRenderingOpenGL2); VTK_MODU ...

  9. VTK系列2_椎体的显示及旋转控制

    实例2:显示椎体及旋转 #include "vtkAutoInit.h" VTK_MODULE_INIT(vtkRenderingOpenGL2); VTK_MODULE_INIT ...

  10. VTK CT重建(一) MPR 多层面重建 四视图

    目录 概述: MPR,全称是multi-planar reformation / reconstruction,是常用的医学图像后处理技术 优化后的视频: vtkImageReslice 参考资料 概 ...

最新文章

  1. edgesForExtendedLayout
  2. ESFramework网络通信框架介绍之(2)――网络通信消息NetMessage
  3. 【Netty】Netty 核心组件 ( ChannelHandlerContext )
  4. 关于IDEA 的一些常用设置
  5. 洛谷P3902 递增
  6. 在SAP分析云里根据业务数据绘制词云(Word Cloud)
  7. .Net MVC Cache 缓存技术总结
  8. 小汤学编程之JavaEE学习day10——Spring
  9. Mac下安装MySQL(Mac 10.12)
  10. 关闭window 8.1 的skydrive
  11. 如何开发神经网络来预测电离层中的干扰
  12. 谷歌Chrome浏览器如何截图长图
  13. 对convertView和ViewHolder的理解
  14. stap中的entry函数
  15. ThreeJS - 动态更换fbx模型的某个子Mesh现有的纹理贴图为指定的纹理贴图
  16. android 高德地图sha1,Android调试高德SDK,如何获取SHA1?
  17. 高效能人士的七个习惯 与成功有约
  18. android 使用SAF框架操作外置sd卡
  19. 软件:推荐七款实用的画流程图工具
  20. .NET破解之PDF编辑器

热门文章

  1. 亿佰特Wifi模块、蓝牙模块和Zigbee模块协议在物联网智能家居上的应用指南
  2. 三角形的几何公式大全_初中数学几何公式、定理梳理大全,老师都收藏了
  3. win7修复计算机 正常启动不了怎么办,Win7系统无法正常启动怎么办
  4. 2021-09-09 一个python代码验证身份证号码
  5. aso优化师是什么_什么是ASO优化?
  6. ios 代理和委托的区别
  7. 原型工具axure7.0下载及汉化
  8. 2k21sports服务器暂时不可用,NBA2K20服务器不可用怎么解决 nba2k20进不去游戏解决办法...
  9. fiddler+mitmproxy+夜神模拟器安装
  10. (毕业设计资料)基于单片机51单片机智能药盒控制系统设计