Medical Imaging Interaction Toolkit  2018.4.99-6a3ea89d
Medical Imaging Interaction Toolkit
mitkTestDynamicImageGenerator.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
15 #include "mitkImageCast.h"
17 
18 namespace mitk
19 {
20  typedef itk::Image<double, 3> FrameITKImageType;
21  typedef itk::Image<double, 4> DynamicITKImageType;
22  typedef itk::Image<unsigned char, 3> MaskITKImageType;
23 
24  TestImageType::Pointer GenerateTestImage(int factor)
25  {
26  TestImageType::Pointer image = TestImageType::New();
27 
28  TestImageType::IndexType start;
29  start[0] = 0; // first index on X
30  start[1] = 0; // first index on Y
31 
32  TestImageType::SizeType size;
33  size[0] = 3; // size along X
34  size[1] = 3; // size along Y
35 
36  TestImageType::RegionType region;
37  region.SetSize(size);
38  region.SetIndex(start);
39 
40  image->SetRegions(region);
41  image->Allocate();
42 
43  itk::ImageRegionIterator<TestImageType> it = itk::ImageRegionIterator<TestImageType>(image,
44  image->GetLargestPossibleRegion());
45 
46  int count = 1;
47 
48  while (!it.IsAtEnd())
49  {
50  it.Set(count * factor);
51  ++it;
52  ++count;
53  }
54 
55  return image;
56  }
57 
58  TestMaskType::Pointer GenerateTestMask()
59  {
60  TestMaskType::Pointer image = TestMaskType::New();
61 
62  TestMaskType::IndexType start;
63  start[0] = 0; // first index on X
64  start[1] = 0; // first index on Y
65 
66  TestMaskType::SizeType size;
67  size[0] = 3; // size along X
68  size[1] = 3; // size along Y
69 
70  TestMaskType::RegionType region;
71  region.SetSize(size);
72  region.SetIndex(start);
73 
74  image->SetRegions(region);
75  image->Allocate();
76 
77  itk::ImageRegionIterator<TestMaskType> it = itk::ImageRegionIterator<TestMaskType>(image,
78  image->GetLargestPossibleRegion());
79 
80  int count = 1;
81 
82  while (!it.IsAtEnd())
83  {
84  if (count > 1 && count < 5)
85  {
86  it.Set(1);
87  }
88  else
89  {
90  it.Set(0);
91  }
92 
93  ++it;
94  ++count;
95  }
96 
97  return image;
98  }
99 
101  {
102  FrameITKImageType::Pointer image = FrameITKImageType::New();
103 
104  FrameITKImageType::IndexType start;
105  start[0] = 0; // first index on X
106  start[1] = 0; // first index on Y
107  start[2] = 0; // first index on Z
108 
109  FrameITKImageType::SizeType size;
110  size[0] = 3; // size along X
111  size[1] = 3; // size along Y
112  size[2] = 3; // size along Z
113 
114  FrameITKImageType::RegionType region;
115  region.SetSize(size);
116  region.SetIndex(start);
117 
118  image->SetRegions(region);
119  image->Allocate();
120 
121  itk::ImageRegionIterator<FrameITKImageType> it = itk::ImageRegionIterator<FrameITKImageType>(image,
122  image->GetLargestPossibleRegion());
123 
124  int count = 0;
125 
126  while (!it.IsAtEnd())
127  {
128  double slope = count % (size[0] * size[1]);
129  double offset = itk::Math::Floor<double, double>(count / (size[0] * size[1])) * 10;
130 
131  it.Set(slope * timePoint + offset);
132  ++it;
133  ++count;
134  }
135 
137  mitkImage->InitializeByItk(image.GetPointer());
138  mitkImage->SetVolume(image->GetBufferPointer());
139 
140  return mitkImage;
141  }
142 
144  {
145  MaskITKImageType::Pointer image = MaskITKImageType::New();
146 
147  MaskITKImageType::IndexType start;
148  start[0] = 0; // first index on X
149  start[1] = 0; // first index on Y
150  start[2] = 0; // first index on Z
151 
152  MaskITKImageType::SizeType size;
153  size[0] = 3; // size along X
154  size[1] = 3; // size along Y
155  size[2] = 3; // size along Z
156 
157  MaskITKImageType::RegionType region;
158  region.SetSize(size);
159  region.SetIndex(start);
160 
161  image->SetRegions(region);
162  image->Allocate();
163 
164  itk::ImageRegionIterator<MaskITKImageType> it = itk::ImageRegionIterator<MaskITKImageType>(image,
165  image->GetLargestPossibleRegion());
166 
167  int count = 0;
168 
169  while (!it.IsAtEnd())
170  {
171  if (count < 14)
172  {
173  it.Set(1);
174  }
175  else
176  {
177  it.Set(0);
178  }
179 
180  ++it;
181  ++count;
182  }
183 
185  mitkImage->InitializeByItk(image.GetPointer());
186  mitkImage->SetVolume(image->GetBufferPointer());
187 
188  return mitkImage;
189  }
190 
191 
193  {
194  auto filter = mitk::TemporalJoinImagesFilter::New();
195 
197  for (int i = 0; i < 10; ++i)
198  {
199  filter->SetInput(i, GenerateTestFrame(1 + (5.0 * i)));
200  bounds.push_back(1 + (5.0 * (i + 1)));
201  }
202 
203  filter->SetFirstMinTimeBound(1.);
204  filter->SetMaxTimeBounds(bounds);
205 
206  filter->Update();
207 
208  return filter->GetOutput();
209  }
210 
211 }
212 
Image::Pointer MITKTESTINGHELPER_EXPORT GenerateTestMaskMITK()
itk::Image< unsigned char, 3 > MaskITKImageType
DataCollection - Class to facilitate loading/accessing structured data.
TestImageType::Pointer MITKTESTINGHELPER_EXPORT GenerateTestImage(int factor=1)
static Vector3D offset
std::vector< mitk::TimePointType > TimeBoundsVectorType
Image::Pointer MITKTESTINGHELPER_EXPORT GenerateDynamicTestImageMITK()
mitk::Image::Pointer image
Image::Pointer MITKTESTINGHELPER_EXPORT GenerateTestFrame(double timePoint)
static Pointer New()
itk::Image< double, 3 > FrameITKImageType
itk::Image< double, 4 > DynamicITKImageType
TestMaskType::Pointer MITKTESTINGHELPER_EXPORT GenerateTestMask()