17 #ifndef ImageGenerator_H_HEADER_INCLUDED
18 #define ImageGenerator_H_HEADER_INCLUDED
22 #include <itkImageRegionIterator.h>
23 #include <itkMersenneTwisterRandomVariateGenerator.h>
40 template <
typename TPixelType>
48 typedef itk::Image<TPixelType, 3>
ImageType;
49 typename ImageType::RegionType imageRegion;
50 imageRegion.SetSize(0, dimX);
51 imageRegion.SetSize(1, dimY);
52 imageRegion.SetSize(2, dimZ);
53 typename ImageType::SpacingType spacing;
54 spacing[0] = spacingX;
55 spacing[1] = spacingY;
56 spacing[2] = spacingZ;
60 itk::Matrix<double, 3, 3> directionMatrix;
61 directionMatrix.SetIdentity();
64 image->SetSpacing(spacing);
65 image->SetOrigin(origin);
66 image->SetDirection(directionMatrix);
67 image->SetLargestPossibleRegion(imageRegion);
68 image->SetBufferedRegion(imageRegion);
69 image->SetRequestedRegion(imageRegion);
71 image->FillBuffer(0.0);
73 typedef itk::ImageRegionIterator<ImageType> IteratorOutputType;
74 IteratorOutputType it(image, imageRegion);
86 mitkImage->InitializeByItk(image.GetPointer());
87 mitkImage->SetVolume(image->GetBufferPointer());
96 template <
typename TPixelType>
103 output->SetGeometry(reference->GetGeometry());
104 output->Initialize(output_type, reference->GetDimension(), reference->GetDimensions());
107 TPixelType *imageBuffer = NULL;
111 imageBuffer =
static_cast<TPixelType *
>(writeAccess.
GetData());
115 MITK_ERROR <<
"Write access not granted on mitk::Image.";
119 for (
unsigned int i = 0; i < output->GetVolumeData(0)->GetSize(); i++)
121 imageBuffer[i] = fill_value;
130 template <
typename TPixelType>
133 unsigned int dimZ = 1,
134 unsigned int dimT = 1,
138 const double randomMax = 1000.0f,
139 const double randMin = 0.0f)
147 auto dimensions =
new unsigned int[4];
148 unsigned int numberOfDimensions = 0;
149 unsigned int bufferSize = 0;
156 numberOfDimensions = 2;
157 dimensions[0] = dimX;
158 dimensions[1] = dimY;
159 bufferSize = dimX * dimY;
163 numberOfDimensions = 3;
164 dimensions[0] = dimX;
165 dimensions[1] = dimY;
166 dimensions[2] = dimZ;
167 bufferSize = dimX * dimY * dimZ;
172 numberOfDimensions = 4;
173 dimensions[0] = dimX;
174 dimensions[1] = dimY;
175 dimensions[2] = dimZ;
176 dimensions[3] = dimT;
177 bufferSize = dimX * dimY * dimZ * dimT;
179 output->Initialize(type, numberOfDimensions, dimensions);
181 spacing[0] = spacingX;
182 spacing[1] = spacingY;
183 spacing[2] = spacingZ;
184 output->SetSpacing(spacing);
187 TPixelType *imageBuffer =
nullptr;
191 imageBuffer =
static_cast<TPixelType *
>(writeAccess.
GetData());
195 MITK_ERROR <<
"Write access not granted on mitk::Image.";
201 randomGenerator->Initialize();
204 for (
unsigned int i = 0; i < bufferSize; i++)
211 imageBuffer[i] = (TPixelType)randomGenerator->GetIntegerVariate((
int)randomMax);
218 imageBuffer[i] = (TPixelType)randomGenerator->GetUniformVariate(randMin, randomMax);
223 imageBuffer[i] = (
unsigned char)((
int)randomGenerator->GetIntegerVariate((
int)randomMax)) % 256;
itk::SmartPointer< Self > Pointer
DataCollection - Class to facilitate loading/accessing structured data.
void * GetData()
Gives full data access.
static mitk::Image::Pointer GenerateGradientImage(unsigned int dimX, unsigned int dimY, unsigned int dimZ, float spacingX=1, float spacingY=1, float spacingZ=1)
Generates gradient image with the defined size and spacing.
generator for synthetic MITK images This is a helper class to generate synthetic MITK images (random ...
map::core::discrete::Elements< 3 >::InternalImageType ImageType
static mitk::Image::Pointer GenerateRandomImage(unsigned int dimX, unsigned int dimY, unsigned int dimZ=1, unsigned int dimT=1, mitk::ScalarType spacingX=1, mitk::ScalarType spacingY=1, mitk::ScalarType spacingZ=1, const double randomMax=1000.0f, const double randMin=0.0f)
Generates random image with the defined size and spacing.
int GetComponentType() const
Get the component type (the scalar (!) type). Each element may contain m_NumberOfComponents (more tha...
static mitk::Image::Pointer GenerateImageFromReference(mitk::Image::Pointer reference, TPixelType fill_value)
Generates an image of a same geometry as the one given as reference.
ImageWriteAccessor class to get locked write-access for a particular image part.
Class for defining the data type of pixels.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.