VTK读取序列DCM格式医学图像
生活随笔
收集整理的這篇文章主要介紹了
VTK读取序列DCM格式医学图像
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
通常處理醫學圖像,使用VTK庫,VTK庫在官網下載,并經過Cmake,編譯并配置好環境變量后使用,下文提供使用VTK讀取三維圖像并顯示的代碼,經過調試可運行。
// RAWREAD.cpp : 定義控制臺應用程序的入口點。 //#include "stdafx.h"#include<vtkRenderWindow.h> #include<vtkRenderWindowInteractor.h> #include<vtkDICOMImageReader.h> #include<vtkMarchingCubes.h> #include<vtkPolyDataMapper.h> #include<vtkStripper.h> #include<vtkActor.h> #include<vtkProperty.h> #include<vtkCamera.h> #include<vtkOutlineFilter.h> #include<vtkOBJExporter.h> #include<vtkRenderer.h> #include<vtkMetaImageReader.h> #include<vtkInteractorStyleTrackballCamera.h>#include<iostream> #include<string.h>//需要進行初始化,否則會報錯#include <vtkAutoInit.h> #include<vtkRenderingVolumeOpenGL2ObjectFactory.h> #include<vtkRenderingOpenGL2ObjectFactory.h>#include <vtkAutoInit.h>VTK_MODULE_INIT(vtkRenderingOpenGL2) VTK_MODULE_INIT(vtkInteractionStyle) VTK_MODULE_INIT(vtkRenderingFreeType)int main(void) {vtkObjectFactory::RegisterFactory(vtkRenderingOpenGL2ObjectFactory::New());vtkObjectFactory::RegisterFactory(vtkRenderingVolumeOpenGL2ObjectFactory::New());vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();//WINDOW;renWin->AddRenderer(ren);vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();//wininteratcor;iren->SetRenderWindow(renWin);vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<vtkDICOMImageReader>::New();reader->SetDirectoryName("D:/CT_Brain");reader->SetDataByteOrderToLittleEndian();reader->Update();cout << "讀取數據完畢" << endl;cout << "The width is" << reader->GetWidth() << endl;cout << "The height is" << reader->GetHeight() << endl;cout << "The depth is" << reader->GetPixelSpacing() << endl;cout << "The Output port is" << reader->GetOutputPort() << endl;vtkSmartPointer<vtkMarchingCubes> marchingcube = vtkSmartPointer<vtkMarchingCubes>::New();marchingcube->SetInputConnection(reader->GetOutputPort());//獲得讀取的數據的點集;marchingcube->SetValue(0, 200);//Setting the threshold;marchingcube->ComputeNormalsOn();//計算表面法向量;vtkSmartPointer<vtkStripper> Stripper = vtkSmartPointer<vtkStripper>::New();Stripper->SetInputConnection(marchingcube->GetOutputPort());//獲取三角片vtkSmartPointer<vtkPolyDataMapper> Mapper = vtkSmartPointer<vtkPolyDataMapper>::New();//將三角片映射為幾何數據;Mapper->SetInputConnection(Stripper->GetOutputPort());Mapper->ScalarVisibilityOff();//vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();//Created a actor;actor->SetMapper(Mapper);//獲得皮膚幾何數據actor->GetProperty()->SetDiffuseColor(1, .49, .25);//設置皮膚顏色;actor->GetProperty()->SetSpecular(0.3);//反射率;actor->GetProperty()->SetOpacity(1.0);//透明度;actor->GetProperty()->SetSpecularPower(20);//反射光強度;actor->GetProperty()->SetColor(1, 0, 0);//設置角的顏色;actor->GetProperty()->SetRepresentationToWireframe();//線框;//vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();//Setting the Camera;//camera->SetViewUp(0, 0, -1);//設置相機向上方向;//camera->SetPosition(0, 1, 0);//位置:世界坐標系,相機位置;//camera->SetFocalPoint(0, 0, 0);//焦點,世界坐標系,控制相機方向;//camera->ComputeViewPlaneNormal();//重置視平面方向,基于當前的位置和焦點;vtkSmartPointer<vtkOutlineFilter> outfilterline = vtkSmartPointer<vtkOutlineFilter>::New();outfilterline->SetInputConnection(reader->GetOutputPort());vtkSmartPointer<vtkPolyDataMapper> outmapper = vtkSmartPointer<vtkPolyDataMapper>::New();outmapper->SetInputConnection(outfilterline->GetOutputPort());vtkSmartPointer<vtkActor> OutlineActor = vtkSmartPointer<vtkActor>::New();OutlineActor->SetMapper(outmapper);OutlineActor->GetProperty()->SetColor(0, 0, 0);//線框顏色ren->AddActor(actor);ren->AddActor(OutlineActor);//ren->SetActiveCamera(camera);//設置渲染器的相機;ren->ResetCamera();ren->ResetCameraClippingRange();//camera->Dolly(1.5);//使用Dolly()方法延伸著視平面法向移動相機;ren->SetBackground(1, 1, 1);//設置背景顏色;renWin->SetSize(1000, 600);vtkInteractorStyleTrackballCamera *style = vtkInteractorStyleTrackballCamera::New();iren->SetInteractorStyle(style);renWin->Render();iren->Initialize();iren->Start();vtkSmartPointer<vtkOBJExporter> porter = vtkSmartPointer<vtkOBJExporter>::New();porter->SetFilePrefix("D:/polywrite.obj");//重建圖像輸出porter->SetInput(renWin);porter->Write();return EXIT_SUCCESS;}運行結果:
?
?序列醫學圖像:
總結
以上是生活随笔為你收集整理的VTK读取序列DCM格式医学图像的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ProxySQL+MGR实现读写分离和主
- 下一篇: 微信小程序学习日记7