VTK笔记——医学图像配准(Landmark)

随着现代医学的迅速发展,医学影像学为临床诊断提供了多种模态的医学图像,如X射线,CT,MRI等,当然,他们各自有各自的诊断优势。不过,有时候,医生希望将不同图像信息进行适当的集成。然而不同模态的医学图像成像原理不同,风辨率,成像参数却不相同,因此在图像融合前必须进行图像匹配。

医学图像配准就是通过寻找一种(或一系列)的空间变换(旋转、偏移、缩放和变形等),使两幅图像的对应点达到空间位置和解剖结构上的完全一致。配准结果应使两幅图像上是所有的解剖点(精确匹配),或至少是所有具有诊断意义的点都达到匹配(粗略匹配)。

其中,基于标记点对应关系的配准方法已经得到了广泛的应用,即所谓的特征匹配,通常用于图像分割、特征提取和关键点(landmark)搜寻等场合。

vtkLandmarkTransform

vtkLandmarkTransform是一种比较经典的匹配算法,基于标记点,两个点集在配准后的平均距离最小,要求输入两个点数必须相等,序号一致的点集,做线性变换。它常用于粗略匹配,效率高。
下面简单的示范一下它是如何使用的?

1.源标记点集

  vtkSmartPointer<vtkPoints> sourcePoints =
    vtkSmartPointer<vtkPoints>::New();
  double sourcePoint1[3] = {1.0, 0.0, 0.0};
  sourcePoints->InsertNextPoint(sourcePoint1);
  double sourcePoint2[3] = {0.0, 1.0, 0.0};
  sourcePoints->InsertNextPoint(sourcePoint2);
  double sourcePoint3[3] = {0.0, 0.0, 1.0};
  sourcePoints->InsertNextPoint(sourcePoint3);

2.目标标记点集

  vtkSmartPointer<vtkPoints> targetPoints =
    vtkSmartPointer<vtkPoints>::New();
  double targetPoint1[3] = {0.0, 0.0, 1.1};
  targetPoints->InsertNextPoint(targetPoint1);
  double targetPoint2[3] = {0.0, 1.02, 0.0};
  targetPoints->InsertNextPoint(targetPoint2);
  double targetPoint3[3] = {-1.11, 0.0, 0.0};
  targetPoints->InsertNextPoint(targetPoint3);

3.设置Landmark

  vtkSmartPointer<vtkLandmarkTransform> landmarkTransform = 
    vtkSmartPointer<vtkLandmarkTransform>::New();
  landmarkTransform->SetSourceLandmarks(sourcePoints);
  landmarkTransform->SetTargetLandmarks(targetPoints);
  landmarkTransform->SetModeToRigidBody();
  landmarkTransform->Update();

4.获取线性变换

  vtkMatrix4x4* mat = landmarkTransform->GetMatrix();

效果

VTK笔记——医学图像配准(Landmark)_第1张图片

LandmarkTransform.cxx

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

int main(int, char *[])
{
 /*
 This demo creates a coordinate frame (+x, +y, +z) of vectors and a rotated,
 peturbed frame (+z, +y, -x) and aligns the rotated frame to the original as best as possible.
 */
 
 vtkSmartPointer<vtkPoints> sourcePoints =
   vtkSmartPointer<vtkPoints>::New();
 double sourcePoint1[3] = {1.0, 0.0, 0.0};
 sourcePoints->InsertNextPoint(sourcePoint1);
 double sourcePoint2[3] = {0.0, 1.0, 0.0};
 sourcePoints->InsertNextPoint(sourcePoint2);
 double sourcePoint3[3] = {0.0, 0.0, 1.0};
 sourcePoints->InsertNextPoint(sourcePoint3);
 
 vtkSmartPointer<vtkPoints> targetPoints =
   vtkSmartPointer<vtkPoints>::New();
 double targetPoint1[3] = {0.0, 0.0, 1.1};
 targetPoints->InsertNextPoint(targetPoint1);
 double targetPoint2[3] = {0.0, 1.02, 0.0};
 targetPoints->InsertNextPoint(targetPoint2);
 double targetPoint3[3] = {-1.11, 0.0, 0.0};
 targetPoints->InsertNextPoint(targetPoint3);
 
 // Setup the transform
 vtkSmartPointer<vtkLandmarkTransform> landmarkTransform = 
   vtkSmartPointer<vtkLandmarkTransform>::New();
 landmarkTransform->SetSourceLandmarks(sourcePoints);
 landmarkTransform->SetTargetLandmarks(targetPoints);
 landmarkTransform->SetModeToRigidBody();
 landmarkTransform->Update(); //should this be here?

 vtkSmartPointer<vtkPolyData> source =
   vtkSmartPointer<vtkPolyData>::New();
 source->SetPoints(sourcePoints);
 
 vtkSmartPointer<vtkPolyData> target =
   vtkSmartPointer<vtkPolyData>::New();
 target->SetPoints(targetPoints);
 
 vtkSmartPointer<vtkVertexGlyphFilter> sourceGlyphFilter =
   vtkSmartPointer<vtkVertexGlyphFilter>::New();
 sourceGlyphFilter->SetInputData(source);
 sourceGlyphFilter->Update();
 
 vtkSmartPointer<vtkVertexGlyphFilter> targetGlyphFilter =
   vtkSmartPointer<vtkVertexGlyphFilter>::New();
 targetGlyphFilter->SetInputData(target);
 targetGlyphFilter->Update();
   
 vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter =
   vtkSmartPointer<vtkTransformPolyDataFilter>::New();
 transformFilter->SetInputConnection(sourceGlyphFilter->GetOutputPort());
 transformFilter->SetTransform(landmarkTransform);
 transformFilter->Update();
   
 // Display the transformation matrix that was computed
 vtkMatrix4x4* mat = landmarkTransform->GetMatrix();
 std::cout << "Matrix: " << *mat << std::endl;

 // Visualize
 vtkSmartPointer<vtkPolyDataMapper> sourceMapper =
   vtkSmartPointer<vtkPolyDataMapper>::New();
 sourceMapper->SetInputConnection(sourceGlyphFilter->GetOutputPort());

 vtkSmartPointer<vtkActor> sourceActor =
   vtkSmartPointer<vtkActor>::New();
 sourceActor->SetMapper(sourceMapper);
 sourceActor->GetProperty()->SetColor(0,1,0);
 sourceActor->GetProperty()->SetPointSize(4);

 vtkSmartPointer<vtkPolyDataMapper> targetMapper =
   vtkSmartPointer<vtkPolyDataMapper>::New();
 targetMapper->SetInputConnection(targetGlyphFilter->GetOutputPort());

 vtkSmartPointer<vtkActor> targetActor =
   vtkSmartPointer<vtkActor>::New();
 targetActor->SetMapper(targetMapper);
 targetActor->GetProperty()->SetColor(1,0,0);
 targetActor->GetProperty()->SetPointSize(4);
 
 vtkSmartPointer<vtkPolyDataMapper> solutionMapper =
   vtkSmartPointer<vtkPolyDataMapper>::New();
 solutionMapper->SetInputConnection(transformFilter->GetOutputPort());

 vtkSmartPointer<vtkActor> solutionActor =
   vtkSmartPointer<vtkActor>::New();
 solutionActor->SetMapper(solutionMapper);
 solutionActor->GetProperty()->SetColor(0,0,1);
 solutionActor->GetProperty()->SetPointSize(3);
 
 // Create a renderer, render window, and interactor
 vtkSmartPointer<vtkRenderer> renderer =
   vtkSmartPointer<vtkRenderer>::New();
 vtkSmartPointer<vtkRenderWindow> renderWindow =
   vtkSmartPointer<vtkRenderWindow>::New();
 renderWindow->AddRenderer(renderer);
 vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
   vtkSmartPointer<vtkRenderWindowInteractor>::New();
 renderWindowInteractor->SetRenderWindow(renderWindow);

 // Add the actor to the scene
 renderer->AddActor(sourceActor);
 renderer->AddActor(targetActor);
 renderer->AddActor(solutionActor);
 renderer->SetBackground(.3, .6, .3); // Background color green

 // Render and interact
 renderWindow->Render();
 renderWindowInteractor->Start();
 
 return EXIT_SUCCESS;
}

Ref

VTKExamples/Cxx/Filtering/LandmarkTransform
VTK笔记——医学图像配准(Landmark)_第2张图片

你可能感兴趣的:(VTK笔记,vtk,配准,landmark,图像)