23 #include <itkImageRegionConstIteratorWithIndex.h>
24 #include <itkRandomImageSource.h>
31 template <
typename TPixel,
unsigned int VDimension>
34 typedef typename itk::Image<TPixel, VDimension>
ImageType;
37 itk::Size<VDimension> regionSize;
38 regionSize.Fill(size);
41 randomImageSource->SetNumberOfThreads(1);
42 randomImageSource->SetSize(regionSize);
43 randomImageSource->Update();
45 return randomImageSource->GetOutput();
55 template <
typename TPixel,
unsigned int VDimension>
59 typedef typename itk::VectorImage<TPixel, VDimension>
ImageType;
62 typename ImageType::RegionType imageRegion;
63 typename ImageType::RegionType::SizeType regionSize;
64 regionSize.Fill(size);
66 typename ImageType::RegionType::IndexType regionIndex;
68 imageRegion.SetSize(regionSize);
69 imageRegion.SetIndex(regionIndex);
71 typename ImageType::SpacingType imageSpacing;
72 imageSpacing.Fill(1.0f);
75 imageOrigin.Fill(0.0f);
79 itkImage->SetVectorLength(value.GetNumberOfElements());
80 itkImage->SetRegions(imageRegion);
81 itkImage->SetOrigin(imageOrigin);
82 itkImage->SetSpacing(imageSpacing);
85 itkImage->FillBuffer(value);
96 template <
typename TPixel,
unsigned int VDimension>
99 typedef typename itk::Image<TPixel, VDimension>
ImageType;
102 typename ImageType::RegionType imageRegion;
103 typename ImageType::RegionType::SizeType regionSize;
104 regionSize.Fill(size);
106 typename ImageType::RegionType::IndexType regionIndex;
108 imageRegion.SetSize(regionSize);
109 imageRegion.SetIndex(regionIndex);
111 typename ImageType::SpacingType imageSpacing;
112 imageSpacing.Fill(1.0f);
115 imageOrigin.Fill(0.0f);
119 itkImage->SetRegions(imageRegion);
120 itkImage->SetOrigin(imageOrigin);
121 itkImage->SetSpacing(imageSpacing);
122 itkImage->Allocate();
124 itkImage->FillBuffer(value);
132 template <
typename ImageType>
135 bool return_value =
true;
137 typename ImageType::RegionType itkRegion = itkImage->GetLargestPossibleRegion();
138 typename ImageType::SizeType itkImageSize = itkRegion.GetSize();
141 for (
unsigned int idx = 0; idx < mitkImage->GetDimension(); idx++)
143 return_value &= (itkImageSize[idx] == mitkImage->GetDimension(idx));
148 bool ptype_compare = (mitkImage->GetPixelType() == mitk::MakePixelType<ImageType>());
149 return_value &= ptype_compare;
155 bool origin_compare =
true;
156 for (
unsigned int idx = 0; idx < 3; idx++)
158 origin_compare &= (itkImage->GetOrigin()[idx] == origin[idx]);
160 return_value &= origin_compare;
170 template <
typename TPixel,
unsigned int VDimension>
173 std::stringstream msg;
174 msg <<
"Current type: (Random Image, " << VDimension <<
"D):" <<
typeid(TPixel).name() <<
"\n";
175 std::cout << msg.str();
177 bool assert_value =
true;
179 typedef typename itk::Image<TPixel, VDimension>
ImageType;
182 ImagePointer itkImage = CreateTestImageRandom<TPixel, VDimension>(5);
186 itk::ImageRegionConstIteratorWithIndex<ImageType> iter(itkImage, itkImage->GetLargestPossibleRegion());
191 bool difference =
false;
192 while (!iter.IsAtEnd())
194 TPixel ref = iter.Get();
197 difference |= (ref != val);
200 std::cout << iter.GetIndex() <<
":" << ref <<
" ? " << val <<
"\n";
205 assert_value = Assert_ImageMetaData_AreEqual<ImageType>(itkImage, output_import);
207 MITK_TEST_CONDITION(assert_value && (!difference),
"Pixel values are same in voxel-wise comparison.");
214 template <
typename TPixel,
unsigned int VDimension>
217 std::stringstream msg;
218 msg <<
"Current type: " << VDimension <<
"D):" <<
typeid(TPixel).name() <<
"\n";
219 std::cout << msg.str();
221 bool assert_value =
true;
223 typedef typename itk::Image<TPixel, VDimension>
ImageType;
230 itk::ImageRegionConstIteratorWithIndex<ImageType> iter(itkImage, itkImage->GetLargestPossibleRegion());
235 bool difference =
false;
236 while (!iter.IsAtEnd())
238 TPixel ref = iter.Get();
241 difference |= (ref != val);
244 std::cout << iter.GetIndex() <<
":" << ref <<
" ? " << val <<
"\n";
250 assert_value = Assert_ImageMetaData_AreEqual<ImageType>(itkImage, output_import);
252 MITK_TEST_CONDITION(assert_value && (!difference),
"Pixel values are same in voxel-wise comparison.");
257 typedef itk::VectorImage<short, 3>
ImageType;
260 value.SetElement(0, 1);
261 value.SetElement(0, 2);
272 MITK_TEST_CONDITION(pixelType == pixelType2,
"ImportItkImage and CastToMitkImage produce same pixel types")
277 MITK_TEST_CONDITION(pixelType == mitk::MakePixelType<ImageType>(2),
"MITK pixel type equals ITK pixel type")
279 typedef itk::VectorImage<int, 3> IntImageType;
282 MITK_TEST_CONDITION(!(pixelType == mitk::MakePixelType<IntImageType>(2)),
"MITK pixel type != ITK pixel type")
293 Assert_ItkImageImportSucceded_ReturnsTrue<short, 3>();
294 Assert_ItkImageImportSucceded_ReturnsTrue<float, 3>();
295 Assert_ItkImageImportSucceded_ReturnsTrue<unsigned char, 3>();
296 Assert_ItkImageImportSucceded_ReturnsTrue<int, 3>();
298 Assert_ItkImageImportRandomValuesSucceded_ReturnsTrue<short, 3>();
299 Assert_ItkImageImportRandomValuesSucceded_ReturnsTrue<float, 3>();
300 Assert_ItkImageImportRandomValuesSucceded_ReturnsTrue<unsigned char, 3>();
301 Assert_ItkImageImportRandomValuesSucceded_ReturnsTrue<int, 3>();
303 Assert_ItkImageImportRandomValuesSucceded_ReturnsTrue<short, 4>();
304 Assert_ItkImageImportRandomValuesSucceded_ReturnsTrue<float, 4>();
305 Assert_ItkImageImportRandomValuesSucceded_ReturnsTrue<unsigned char, 4>();
306 Assert_ItkImageImportRandomValuesSucceded_ReturnsTrue<int, 4>();
const Point3D GetOrigin() const
Get the origin, e.g. the upper-left corner of the plane.
itk::SmartPointer< Self > Pointer
Gives locked and index-based read access for a particular image part. The class provides several set-...
const TPixel & GetPixelByIndex(const itk::Index< VDimension > &idx) const
itk::VectorImage< TPixel, VDimension >::Pointer CreateTestVectorImageFixedValue(vcl_size_t size, const itk::VariableLengthVector< TPixel > &value)
itk::Image< unsigned char, 3 > ImageType
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
itk::ImageIOBase::IOPixelType GetPixelType() const
Image::Pointer ImportItkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, const BaseGeometry *geometry=nullptr, bool update=true)
Imports an itk::Image (with a specific type) as an mitk::Image.Instantiates instance of ITKImageImpor...
void Assert_ItkImageImportSucceded_ReturnsTrue()
itk::Image< TPixel, VDimension >::Pointer CreateTestImageRandom(short int size)
int mitkImportItkImageTest(int, char *[])
#define MITK_TEST_CONDITION(COND, MSG)
itk::Image< TPixel, VDimension >::Pointer CreateTestImageFixedValue(vcl_size_t size, TPixel value)
#define MITK_ASSERT_EQUAL(EXPECTED, ACTUAL, MSG)
Testing macro to test if two objects are equal.
int GetComponentType() const
Get the component type (the scalar (!) type). Each element may contain m_NumberOfComponents (more tha...
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
bool Assert_ImageMetaData_AreEqual(typename ImageType::Pointer itkImage, mitk::Image::Pointer mitkImage)
void Assert_ItkVectorImageImportAndCast_ReturnsTrue()
BaseGeometry Describes the geometry of a data object.
Class for defining the data type of pixels.
void Assert_ItkImageImportRandomValuesSucceded_ReturnsTrue()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.