Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
ConvertToConcentrationTest.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 
13 #include <iostream>
14 #include "mitkTestingMacros.h"
15 
16 #include "itkImage.h"
17 #include "itkImageRegionIterator.h"
18 
19 #include "itkBinaryFunctorImageFilter.h"
20 
21 #include "mitkConvertToConcentrationFunctor.h"
22 
23 
24 int ConvertToConcentrationTest(int argc , char* argv[])
25 {
26  // always start with this!
27  MITK_TEST_BEGIN("ConvertToConcentration");
28 
29  //Initialization Parameters
30  double RelaxationTime = 1.2;
31  double RecoveryTime = 0.125;
32  double Relaxivity = 4.3;
33 
34 
35 
36  //Test1: Functor calculation
37  mitk::ConvertToConcentrationFunctor<double,double,double> testFunctor;
38  testFunctor.initialize(RelaxationTime, Relaxivity, RecoveryTime);
39 
40 
41  double s0 = 197.0;
42  double sCM = 278.0;
43  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(0.009,testFunctor(sCM,s0), 1e-6, true)==true,"Check Functor Calculation with Input Value and baseline: 1");
44  s0 = 157.0;
45  sCM = 207.0;
46  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(0.0069,testFunctor(sCM,s0), 1e-6, true)==true,"Check Functor Calculation with Input Value and baseline: 2");
47  s0 = 195.0;
48  sCM = 270.0;
49  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(0.0084,testFunctor(sCM,s0), 1e-6, true)==true,"Check Functor Calculation with Input Value and baseline: 3");
50  s0 = 177.0;
51  sCM = 308.0;
52  MITK_TEST_CONDITION_REQUIRED(mitk::Equal(0.0164,testFunctor(sCM,s0), 1e-6, true)==true,"Check Functor Calculation with Input Value and baseline: 4");
53 
54  //Test2: Filter usage with Functor
55 
56  typedef itk::Image<double,3> ImageType;
57  typedef mitk::ConvertToConcentrationFunctor <double, double, double> ConversionFunctorType;
58  typedef itk::BinaryFunctorImageFilter<ImageType, ImageType, ImageType, ConversionFunctorType> FilterType;
59 
60  //Definition of testimages
61  ImageType::Pointer image = ImageType::New();
62  ImageType::Pointer BaselineImage = ImageType::New();
63  ImageType::IndexType start;
64  start[0] = 0; // first index on X
65  start[1] = 0; // first index on Y
66  start[2] = 0; // first index on Z
67  ImageType::SizeType size;
68  size[0] = 2; // size along X
69  size[1] = 2; // size along Y
70  size[2] = 2; // size along Z
71  ImageType::RegionType region;
72  region.SetSize( size );
73  region.SetIndex( start );
74  image->SetRegions( region );
75  image->Allocate();
76  BaselineImage->SetRegions( region );
77  BaselineImage->Allocate();
78  itk::ImageRegionIterator<ImageType> it = itk::ImageRegionIterator<ImageType>(image,image->GetLargestPossibleRegion());
79  itk::ImageRegionIterator<ImageType> Bit = itk::ImageRegionIterator<ImageType>(BaselineImage,BaselineImage->GetLargestPossibleRegion());
80  int count = 0;
81  while (!it.IsAtEnd()&& !Bit.IsAtEnd())
82  {
83  Bit.Set(150);
84  it.Set(count*50+150);
85  ++it;
86  ++Bit;
87  ++count;
88  }
89  //Filterinitialization
90  FilterType::Pointer ConversionFilter = FilterType::New();
91  ConversionFilter->SetFunctor(testFunctor);
92  ConversionFilter->SetInput1(image);
93  ConversionFilter->SetInput2(BaselineImage);
94 
95  ConversionFilter->Update();
96  ImageType::Pointer convertedImage = ImageType::New();
97  convertedImage = ConversionFilter->GetOutput();
98 
99  MITK_TEST_EQUAL(image->GetImageDimension(),convertedImage->GetImageDimension(),"Check dimensions of result image");
100 
101  itk::Index<3> idx;
102  idx[0]=0;
103  idx[1]=0;
104  idx[2]=0;
105  MITK_TEST_EQUAL(0,convertedImage->GetPixel(idx),"Check pixel of converted image index <0,0,0>");
106  idx[0]=1;
107  idx[1]=0;
108  idx[2]=0;
109  MITK_TEST_EQUAL(0.0072,convertedImage->GetPixel(idx),"Check pixel of converted image index <1,0,0>");
110  idx[0]=0;
111  idx[1]=1;
112  idx[2]=0;
113  MITK_TEST_EQUAL(0.0147,convertedImage->GetPixel(idx),"Check pixel of converted image index <0,1,0>");
114  idx[0]=1;
115  idx[1]=1;
116  idx[2]=0;
117  MITK_TEST_EQUAL(0.0225,convertedImage->GetPixel(idx),"Check pixel of converted image index <1,1,0>");
118  idx[0]=0;
119  idx[1]=0;
120  idx[2]=1;
121  MITK_TEST_EQUAL(0.0307 ,convertedImage->GetPixel(idx),"Check pixel of converted image index <0,0,1>");
122  idx[0]=1;
123  idx[1]=0;
124  idx[2]=1;
125  MITK_TEST_EQUAL(0.0392,convertedImage->GetPixel(idx),"Check pixel of converted image index <1,0,1>");
126  idx[0]=0;
127  idx[1]=1;
128  idx[2]=1;
129  MITK_TEST_EQUAL(0.0480,convertedImage->GetPixel(idx),"Check pixel of converted image index <0,1,1>");
130  idx[0]=1;
131  idx[1]=1;
132  idx[2]=1;
133  MITK_TEST_EQUAL(0.0574,convertedImage->GetPixel(idx),"Check pixel of converted image index <1,1,1>");
134 
135 
136 
137  MITK_TEST_END()
138 }
itk::Image< unsigned char, 3 > ImageType
#define MITK_TEST_CONDITION_REQUIRED(COND, MSG)
section GeneralTestsDeprecatedOldTestingStyle Deprecated macros All tests with MITK_TEST_BEGIN()
int ConvertToConcentrationTest(int argc, char *argv[])
mitk::Image::Pointer image
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
and MITK_TEST_END()