22 CPPUNIT_TEST_SUITE(mitkCropImageFilterTestSuite);
24 CPPUNIT_TEST_SUITE_END();
29 const unsigned int NUM_ITERATIONS = 5;
30 const unsigned int DATA_DIM = 25;
42 std::default_random_engine randGen(r());
43 std::uniform_int_distribution<int> randDistr(0, (DATA_DIM / 2) - 1);
45 float* data =
new float[DATA_DIM*DATA_DIM*DATA_DIM];
47 for (
unsigned int i = 0; i < DATA_DIM*DATA_DIM*DATA_DIM; ++i)
53 unsigned int dimension[3]{ DATA_DIM, DATA_DIM, DATA_DIM };
54 inputImage->Initialize(mitk::MakeScalarPixelType<float>(), 3, dimension);
55 inputImage->SetImportVolume(data, 0, 0, mitk::Image::ImportMemoryManagementType::CopyMemory);
57 for (
unsigned int iteration = 0; iteration < NUM_ITERATIONS; ++iteration)
59 unsigned int XPixelsCropStart = randDistr(randGen);
60 unsigned int YPixelsCropStart = randDistr(randGen);
61 unsigned int ZPixelsCropStart = randDistr(randGen);
62 unsigned int XPixelsCropEnd = randDistr(randGen);
63 unsigned int YPixelsCropEnd = randDistr(randGen);
64 unsigned int ZPixelsCropEnd = randDistr(randGen);
66 unsigned int newXDim = DATA_DIM - XPixelsCropStart - XPixelsCropEnd;
67 unsigned int newYDim = DATA_DIM - YPixelsCropStart - YPixelsCropEnd;
68 unsigned int newZDim = DATA_DIM - ZPixelsCropStart - ZPixelsCropEnd;
70 m_CropImageFilter->SetInput(inputImage);
72 m_CropImageFilter->SetXPixelsCropStart(XPixelsCropStart);
73 m_CropImageFilter->SetYPixelsCropStart(YPixelsCropStart);
74 m_CropImageFilter->SetZPixelsCropStart(ZPixelsCropStart);
75 m_CropImageFilter->SetXPixelsCropEnd(XPixelsCropEnd);
76 m_CropImageFilter->SetYPixelsCropEnd(YPixelsCropEnd);
77 m_CropImageFilter->SetZPixelsCropEnd(ZPixelsCropEnd);
79 m_CropImageFilter->Update();
83 const float* outputData = (
const float*)readAccess.GetData();
85 CPPUNIT_ASSERT_MESSAGE(std::string(
"expected x size to be " + std::to_string(newXDim) +
" but was " + std::to_string(outputImage->GetDimension(0))), newXDim == outputImage->GetDimension(0));
86 CPPUNIT_ASSERT_MESSAGE(std::string(
"expected y size to be " + std::to_string(newYDim) +
" but was " + std::to_string(outputImage->GetDimension(1))), newYDim == outputImage->GetDimension(1));
87 CPPUNIT_ASSERT_MESSAGE(std::string(
"expected z size to be " + std::to_string(newZDim) +
" but was " + std::to_string(outputImage->GetDimension(2))), newZDim == outputImage->GetDimension(2));
89 for (
unsigned int z = 0; z < newZDim; ++z)
91 for (
unsigned int y = 0; y < newYDim; ++y)
93 for (
unsigned int x = 0; x < newXDim; ++x)
95 unsigned int origPos = (x + XPixelsCropStart) + (y + YPixelsCropStart) * DATA_DIM + (z + ZPixelsCropStart) * DATA_DIM * DATA_DIM;
96 unsigned int outPos = x + y * newXDim + z * newXDim * newYDim;
97 CPPUNIT_ASSERT_MESSAGE(std::string(
"expected " + std::to_string(data[origPos])
98 +
" but was " + std::to_string(outputData[outPos])),
99 std::abs((
float)outputData[outPos] - (
float)data[origPos]) <
mitk::eps);
110 for (
int repetition = 0; repetition < 20; ++repetition)
112 MITK_INFO <<
"[" << (repetition + 1) <<
"/20]";
117 void tearDown()
override 119 m_CropImageFilter =
nullptr;
MITK_TEST_SUITE_REGISTRATION(mitkImageToItk)
Follow Up Storage - Class to facilitate loading/accessing structured follow-up data.
#define MITK_TEST(TESTMETHOD)
Adds a test to the current test suite.
Test fixture for parameterized tests.
MITKCORE_EXPORT const ScalarType eps
ImageReadAccessor class to get locked read access for a particular image part.