直管を画像に埋め込む(ITKライブラリ)

ITKライブラリを使用して、5本の直管を作成し、画像データに埋め込みます。

5本の直管画像

プログラムでは、まず、5本の直管を点列データ(座標+半径)を与えてそれぞれ作成し、次にitk::SpatialObjectToImageFilter関数で画像データに変換します。画像データは101×126×500の3次元の画像データで、出力形式はInsight Meta-Imageファイル(mha)となっています。上図は、出力されたmhaファイルをParaViewで読み込み、ボリュームレンダリングで表示したものです。

5TubeSpatialObject.cxx

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
 
 
 
 
 
 
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
!
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
!
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
!
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
!
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
 
#include "itkGroupSpatialObject.h"
#include "itkImageFileWriter.h"
#include "itkSpatialObjectToImageFilter.h"
#include "itkTubeSpatialObject.h"
 
int main(int argc, char *argv[])
{
  typedef unsigned char PixelType;
  const unsigned int Dimension = 3;
 
  typedef itk::Image< PixelType, Dimension > ImageType;
 
  typedef itk::TubeSpatialObject< Dimension > TubeType;
  typedef itk::SmartPointer< TubeType >       TubePointer;
  typedef TubeType::TubePointType             TubePointType;
  typedef TubeType::PointListType             TubePointListType;
  typedef itk::GroupSpatialObject<Dimension>  GroupType;
  typedef itk::SmartPointer< GroupType >      GroupPointer;
 
  typedef itk::SpatialObjectToImageFilter<
    GroupType, ImageType > SpatialObjectImageFilterType;
 
  TubePointer tube1 = TubeType::New();
  tube1->GetProperty()->SetName("Tube1");
  tube1->SetId(1);
 
  TubePointListType list;
  for( unsigned int i = 0; i < 11; ++i )
    {
    double dx = -0.012 * i;
    double dy = 0.4 * i;
    double dz = 0.0135 * i;
    double radius = 0.1;
    TubePointType p;
    p.SetPosition(1.68 + dx, 0.0 + dy, 0.727 + dz);
    p.SetRadius(radius);
    list.push_back(p);
    }
 
  tube1->SetPoints(list);
  tube1->ComputeBoundingBox();
  list.clear();
 
  TubePointer tube2 = TubeType::New();
  tube2->GetProperty()->SetName("Tube2");
  tube2->SetId(2);
 
  for( unsigned int i = 0; i < 11; ++i )
    {
    double dx = 0.5 * i;
    double dy = 0.004  * i;
    double dz =-0.005  * i;
    double radius = 0.1;
    TubePointType p;
    p.SetPosition(0.0 + dx, 2.36 + dy, 1.13 + dz);
    p.SetRadius(radius);
    list.push_back(p);
    }
 
  tube2->SetPoints(list);
  tube2->ComputeBoundingBox();
  list.clear();
 
  TubePointer tube3 = TubeType::New();
  tube3->GetProperty()->SetName("Tube3");
  tube3->SetId(3);
 
  for( unsigned int i = 0; i < 11; ++i )
    {
    double dx =-0.192 * i;
    double dy = 0.048  * i;
    double dz =-0.008  * i;
    double radius = 0.2;
    TubePointType p;
    p.SetPosition(5.0 + dx, 3.52 + dy, 1.29 + dz);
    p.SetRadius(radius);
    list.push_back(p);
    }
 
  tube3->SetPoints(list);
  tube3->ComputeBoundingBox();
  list.clear();
 
  TubePointer tube4 = TubeType::New();
  tube4->GetProperty()->SetName("Tube4");
  tube4->SetId(3);
 
  for( unsigned int i = 0; i < 11; ++i )
    {
    double dx = 0.3 * i;
    double dy = 0.336  * i;
    double dz =-0.004  * i;
    double radius = 0.2;
    TubePointType p;
    p.SetPosition(2.0 + dx, 0.0 + dy, 1.55 + dz);
    p.SetRadius(radius);
    list.push_back(p);
    }
 
  tube4->SetPoints(list);
  tube4->ComputeBoundingBox();
  list.clear();
 
  TubePointer tube5 = TubeType::New();
  tube5->GetProperty()->SetName("Tube5");
  tube5->SetId(3);
 
  for( unsigned int i = 0; i < 11; ++i )
    {
    double dx = 0.02 * i;
    double dy =-0.4  * i;
    double dz =-0.011  * i;
    double radius = 0.4;
    TubePointType p;
    p.SetPosition(2.44 + dx, 4.0 + dy, 2.19 + dz);
    p.SetRadius(radius);
    list.push_back(p);
    }
 
  tube5->SetPoints(list);
  tube5->ComputeBoundingBox();
  list.clear();
 
  GroupPointer tubeNet = GroupType::New();
  tubeNet->GetProperty()->SetName("tube network");
  tubeNet->AddSpatialObject(tube1);
  tubeNet->AddSpatialObject(tube2);
  tubeNet->AddSpatialObject(tube3);
  tubeNet->AddSpatialObject(tube4);
  tubeNet->AddSpatialObject(tube5);
 
  SpatialObjectImageFilterType::Pointer imageFilter =
    SpatialObjectImageFilterType::New();
 
  ImageType::SizeType size;
  size[0] = 126;
  size[1] = 101;
  size[2] = 500;
  imageFilter->SetSize(size);
 
  ImageType::SpacingType spacing;
  spacing[0] = 5.0 / (size[0] - 1);
  spacing[1] = 4.0 / (size[1] - 1);
  spacing[2] = 3.07 / (size[2] - 1);
  imageFilter->SetSpacing(spacing);
 
  imageFilter->SetInsideValue(1);
  imageFilter->SetInput(tubeNet);
  imageFilter->SetChildrenDepth(1);
  imageFilter->Update();
  tubeNet->GetMaximumDepth();
 
  typedef itk::ImageFileWriter< ImageType > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("tube.mha");
  writer->SetInput(imageFilter->GetOutput());
  writer->Update();
 
  return EXIT_SUCCESS;
}

ダウンロードとビルド

ソースコードとCMakeLists.txtファイル:

#ref(): File not found: "5TubeSpatialObject.zip" at page "直管を画像に埋め込む(ITKライブラリ)"


添付ファイル: file5tube_image.png 1392件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2013-07-11 (木) 08:23:32 (1861d)