13 #ifndef mitkImageGenerator_h
14 #define mitkImageGenerator_h
18 #include <itkImageRegionIterator.h>
19 #include <itkMersenneTwisterRandomVariateGenerator.h>
36 template <
typename TPixelType>
44 typedef itk::Image<TPixelType, 3> ImageType;
45 typename ImageType::RegionType imageRegion;
46 imageRegion.SetSize(0, dimX);
47 imageRegion.SetSize(1, dimY);
48 imageRegion.SetSize(2, dimZ);
49 typename ImageType::SpacingType spacing;
50 spacing[0] = spacingX;
51 spacing[1] = spacingY;
52 spacing[2] = spacingZ;
56 itk::Matrix<double, 3, 3> directionMatrix;
57 directionMatrix.SetIdentity();
59 typename ImageType::Pointer image = ImageType::New();
60 image->SetSpacing(spacing);
61 image->SetOrigin(origin);
62 image->SetDirection(directionMatrix);
63 image->SetLargestPossibleRegion(imageRegion);
64 image->SetBufferedRegion(imageRegion);
65 image->SetRequestedRegion(imageRegion);
67 image->FillBuffer(0.0);
69 typedef itk::ImageRegionIterator<ImageType> IteratorOutputType;
70 IteratorOutputType it(image, imageRegion);
82 mitkImage->InitializeByItk(image.GetPointer());
83 mitkImage->SetVolume(image->GetBufferPointer());
92 template <
typename TPixelType>
99 output->SetGeometry(reference->GetGeometry());
100 output->Initialize(output_type, reference->GetDimension(), reference->GetDimensions());
103 TPixelType *imageBuffer =
nullptr;
107 imageBuffer =
static_cast<TPixelType *
>(writeAccess.
GetData());
111 MITK_ERROR <<
"Write access not granted on mitk::Image.";
115 for (
unsigned int i = 0; i < output->GetVolumeData(0)->GetSize(); i++)
117 imageBuffer[i] = fill_value;
126 template <
typename TPixelType>
129 unsigned int dimZ = 1,
130 unsigned int dimT = 1,
134 const double randomMax = 1000.0f,
135 const double randMin = 0.0f)
143 auto dimensions =
new unsigned int[4];
144 unsigned int numberOfDimensions = 0;
145 unsigned int bufferSize = 0;
152 numberOfDimensions = 2;
153 dimensions[0] = dimX;
154 dimensions[1] = dimY;
155 bufferSize = dimX * dimY;
159 numberOfDimensions = 3;
160 dimensions[0] = dimX;
161 dimensions[1] = dimY;
162 dimensions[2] = dimZ;
163 bufferSize = dimX * dimY * dimZ;
168 numberOfDimensions = 4;
169 dimensions[0] = dimX;
170 dimensions[1] = dimY;
171 dimensions[2] = dimZ;
172 dimensions[3] = dimT;
173 bufferSize = dimX * dimY * dimZ * dimT;
175 output->Initialize(type, numberOfDimensions, dimensions);
177 spacing[0] = spacingX;
178 spacing[1] = spacingY;
179 spacing[2] = spacingZ;
180 output->SetSpacing(spacing);
183 TPixelType *imageBuffer =
nullptr;
187 imageBuffer =
static_cast<TPixelType *
>(writeAccess.
GetData());
191 MITK_ERROR <<
"Write access not granted on mitk::Image.";
195 itk::Statistics::MersenneTwisterRandomVariateGenerator::Pointer randomGenerator =
196 itk::Statistics::MersenneTwisterRandomVariateGenerator::New();
197 randomGenerator->Initialize();
200 for (
unsigned int i = 0; i < bufferSize; i++)
207 imageBuffer[i] = (TPixelType)randomGenerator->GetIntegerVariate((
int)randomMax);
214 imageBuffer[i] = (TPixelType)randomGenerator->GetUniformVariate(randMin, randomMax);
219 imageBuffer[i] = (
unsigned char)((
int)randomGenerator->GetIntegerVariate((
int)randomMax)) % 256;
223 imageBuffer[i] = (
unsigned short)((
int)randomGenerator->GetIntegerVariate((
int)randomMax)) % 65536;