医影在线

搜索
查看: 770|回复: 1
打印 上一主题 下一主题

三维图像切片提取

[复制链接]
跳转到指定楼层
楼主
发表于 2014-7-31 09:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
三维图像切片提取切片是指三维图像中的一个切面对应的图像。切面可以是过图像内部一点且平行于XY、YZ、XZ平面的平面,也可以是任意的过三维图像内部一点任意方向的平面。通过提取切片可以方便的浏览和分析图像内部组织结构,是医学图像浏览软件中的一个重要的功能。在VTK中vtkImageReslice类实现图像切片提取功能。下面首先看一段切片提取的代码。
1:  vtkSmartPointer<vtkMetaImageReader> reader =
   2:     vtkSmartPointer<vtkMetaImageReader>::New();
   3:  reader->SetFileName ( " brain.mhd" );
   4:  reader->Update();
   5:   
   6:  int extent[6];
   7:  double spacing[3];
   8:  double origin[3];
   9:   
  10:  reader->GetOutput()->GetExtent(extent);
  11:  reader->GetOutput()->GetSpacing(spacing);
  12:  reader->GetOutput()->GetOrigin(origin);
  13:   
  14:  double center[3];
  15:  center[0] = origin[0] + spacing[0] * 0.5 * (extent[0] + extent[1]);
  16:  center[1] = origin[1] + spacing[1] * 0.5 * (extent[2] + extent[3]);
  17:  center[2] = origin[2] + spacing[2] * 0.5 * (extent[4] + extent[5]);
  18:   
  19:  static double axialElements[16] = {
  20:     1, 0, 0, 0,
  21:     0, 1, 0, 0,
  22:     0, 0, 1, 0,
  23:     0, 0, 0, 1 };
  24:   
  25:  vtkSmartPointer<vtkMatrix4x4> resliceAxes =
  26:     vtkSmartPointer<vtkMatrix4x4>::New();
  27:  resliceAxes->DeepCopy(axialElements);
  28:   
  29:  resliceAxes->SetElement(0, 3, center[0]);
  30:  resliceAxes->SetElement(1, 3, center[1]);
  31:  resliceAxes->SetElement(2, 3, center[2]);
  32:   
  33:   
  34:  vtkSmartPointer<vtkImageReslice> reslice =
  35:     vtkSmartPointer<vtkImageReslice>::New();
  36:  reslice->SetInputConnection(reader->GetOutputPort());
  37:  reslice->SetOutputDimensionality(2);
  38:  reslice->SetResliceAxes(resliceAxes);
  39:  reslice->SetInterpolationModeToLinear();
  40:   
  41:  vtkSmartPointer<vtkLookupTable> colorTable =
  42:     vtkSmartPointer<vtkLookupTable>::New();
  43:  colorTable->SetRange(0, 1000);
  44:  colorTable->SetValueRange(0.0, 1.0);
  45:  colorTable->SetSaturationRange(0.0, 0.0);
  46:  colorTable->SetRampToLinear();
  47:  colorTable->Build();
  48:   
  49:  vtkSmartPointer<vtkImageMapToColors> colorMap =
  50:     vtkSmartPointer<vtkImageMapToColors>::New();
  51:  colorMap->SetLookupTable(colorTable);
  52:  colorMap->SetInputConnection(reslice->GetOutputPort());
  53:   
  54:  vtkSmartPointer<vtkImageActor> imgActor =
  55:     vtkSmartPointer<vtkImageActor>::New();
  56:  imgActor->SetInput(colorMap->GetOutput());
  57:   
  58:  vtkSmartPointer<vtkRenderer> renderer =
  59:     vtkSmartPointer<vtkRenderer>::New();
  60:  renderer->AddActor(imgActor);
  61:  renderer->SetBackground(.4, .5, .6);
  62:   
  63:  vtkSmartPointer<vtkRenderWindow> renderWindow =
  64:     vtkSmartPointer<vtkRenderWindow>::New();
  65:  renderWindow->SetSize(500, 500);
  66:  renderWindow->AddRenderer(renderer);
  67:   
  68:  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
  69:     vtkSmartPointer<vtkRenderWindowInteractor>::New();
  70:  vtkSmartPointer<vtkInteractorStyleImage> imagestyle =
  71:     vtkSmartPointer<vtkInteractorStyleImage>::New();
  72:   
  73:  renderWindowInteractor->SetInteractorStyle(imagestyle);
  74:  renderWindowInteractor->SetRenderWindow(renderWindow);
  75:  renderWindowInteractor->Initialize();
  76:   
  77:  renderWindowInteractor->Start();

首先通过vtkMetaImageReader读取一副医学三维图像,并获取得到图像范围(extent),原点和像素间隔;由这三个参数可以计算图像的中心位置center;接下来定义了切面的变换矩阵axialElements,该矩阵的前三列分别表示x、y和z方向向量,第四列为中心点坐标;代码中的axialElements表示切面变换矩阵与当前坐标系一致,且切面为过中心点center,并平行于XY平面的平面。当前,定义该切面时,也可以是其他平面,甚至是任意平面,但是必须要过图像内部点。下面给出了一个常用的变换矩阵:

static double coronalElements[16] = {
1, 0, 0, 0,
0, 0, 1, 0,
0,-1, 0, 0,
0, 0, 0, 1 }; 提取平行于XZ平面的切片

static double sagittalElements[16] = {
0, 0,-1, 0,
1, 0, 0, 0,
0,-1, 0, 0,
0, 0, 0, 1 }; 提取平行于YZ平面的切片

static double obliqueElements[16] = {
1, 0, 0, 0,
0, 0.866025, -0.5, 0,
0, 0.5, 0.866025, 0,
0, 0, 0, 1 }; 提取斜切切片

注意使用这些变换矩阵的时候,需要将第四列替换为切片经过图像的一个点坐标,上例中将图像的中心添加到axialElements矩阵,并通过函数SetResliceAxes设置变换矩阵,SetOutputDimensionality(2)指定输出的图像为一个二维图像;而函数SetInterpolationModeToLinear()则指定了切面提取中的差值方式为线性差值,另外该类中还提供了其他的差值方式:
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 赞同赞同 反对反对
回复

使用道具 举报

2#
发表于 2014-7-31 16:38 | 只看该作者
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

快速回复 返回顶部 返回列表