25 #include "rtkTestConfiguration.h" 28 template <
class TImage>
29 #if FAST_TESTS_NO_CHECKS 32 typename TImage::Pointer itkNotUsed(ref),
33 double itkNotUsed(ErrorPerPixelTolerance),
34 double itkNotUsed(PSNRTolerance),
35 double itkNotUsed(RefValueForPSNR))
40 typename TImage::Pointer ref,
41 double ErrorPerPixelTolerance,
43 double RefValueForPSNR)
46 ImageIteratorType itTest(recon, recon->GetBufferedRegion());
47 ImageIteratorType itRef(ref, ref->GetBufferedRegion());
49 using ErrorType = double;
50 ErrorType TestError = 0.;
51 ErrorType EnerError = 0.;
56 while (!itRef.IsAtEnd())
58 typename TImage::PixelType TestVal = itTest.Get();
59 typename TImage::PixelType RefVal = itRef.Get();
61 EnerError += std::pow(ErrorType(RefVal - TestVal), 2.);
66 ErrorType ErrorPerPixel = TestError / ref->GetBufferedRegion().GetNumberOfPixels();
67 std::cout <<
"\nError per Pixel = " << ErrorPerPixel << std::endl;
69 ErrorType MSE = EnerError / ref->GetBufferedRegion().GetNumberOfPixels();
70 std::cout <<
"MSE = " << MSE << std::endl;
72 ErrorType PSNR = 20 * log10(RefValueForPSNR) - 10 * log10(MSE);
73 std::cout <<
"PSNR = " << PSNR <<
"dB" << std::endl;
75 ErrorType QI = (RefValueForPSNR - ErrorPerPixel) / RefValueForPSNR;
76 std::cout <<
"QI = " << QI << std::endl;
94 if (!(ErrorPerPixel < ErrorPerPixelTolerance))
96 std::cerr <<
"Test Failed, Error per pixel not valid! " << ErrorPerPixel <<
" instead of " << ErrorPerPixelTolerance
100 if (!(PSNR > PSNRTolerance))
102 std::cerr <<
"Test Failed, PSNR not valid! " << PSNR <<
" instead of " << PSNRTolerance << std::endl;
106 #endif // FAST_TESTS_NO_CHECKS 108 template <
class TImage>
109 #if FAST_TESTS_NO_CHECKS 112 typename TImage::Pointer itkNotUsed(ref),
113 double itkNotUsed(ErrorPerPixelTolerance),
114 double itkNotUsed(PSNRTolerance),
115 double itkNotUsed(RefValueForPSNR))
120 typename TImage::Pointer ref,
121 double ErrorPerPixelTolerance,
122 double PSNRTolerance,
123 double RefValueForPSNR)
126 ImageIteratorType itTest(recon, recon->GetBufferedRegion());
127 ImageIteratorType itRef(ref, ref->GetBufferedRegion());
129 using ErrorType = double;
130 ErrorType TestError = 0.;
131 ErrorType EnerError = 0.;
136 while (!itRef.IsAtEnd())
138 typename TImage::PixelType TestVal = itTest.Get();
139 typename TImage::PixelType RefVal = itRef.Get();
140 TestError += (RefVal - TestVal).GetNorm();
141 EnerError += (RefVal - TestVal).GetSquaredNorm();
146 ErrorType ErrorPerPixel = TestError / ref->GetBufferedRegion().GetNumberOfPixels();
147 std::cout <<
"\nError per Pixel = " << ErrorPerPixel << std::endl;
149 ErrorType MSE = EnerError / ref->GetBufferedRegion().GetNumberOfPixels();
150 std::cout <<
"MSE = " << MSE << std::endl;
152 ErrorType PSNR = 20 * log10(RefValueForPSNR) - 10 * log10(MSE);
153 std::cout <<
"PSNR = " << PSNR <<
"dB" << std::endl;
155 ErrorType QI = (RefValueForPSNR - ErrorPerPixel) / RefValueForPSNR;
156 std::cout <<
"QI = " << QI << std::endl;
174 if (!(ErrorPerPixel < ErrorPerPixelTolerance))
176 std::cerr <<
"Test Failed, Error per pixel not valid! " << ErrorPerPixel <<
" instead of " << ErrorPerPixelTolerance
180 if (!(PSNR > PSNRTolerance))
182 std::cerr <<
"Test Failed, PSNR not valid! " << PSNR <<
" instead of " << PSNRTolerance << std::endl;
186 #endif // FAST_TESTS_NO_CHECKS 189 template <
class TImage>
190 #if FAST_TESTS_NO_CHECKS 193 typename TImage::Pointer itkNotUsed(ref),
194 double itkNotUsed(ErrorPerPixelTolerance),
195 double itkNotUsed(PSNRTolerance),
196 double itkNotUsed(RefValueForPSNR))
201 typename TImage::Pointer ref,
202 double ErrorPerPixelTolerance,
203 double PSNRTolerance,
204 double RefValueForPSNR)
206 if (!(recon->GetVectorLength() == ref->GetVectorLength()))
208 std::cerr <<
"Test Failed, image's vector length is " << recon->GetVectorLength() <<
" instead of " 209 << ref->GetVectorLength() << std::endl;
214 ImageIteratorType itTest(recon, recon->GetBufferedRegion());
215 ImageIteratorType itRef(ref, ref->GetBufferedRegion());
217 using ErrorType = double;
218 ErrorType TestError = 0.;
219 ErrorType EnerError = 0.;
224 while (!itRef.IsAtEnd())
226 typename TImage::PixelType TestVec = itTest.Get();
227 typename TImage::PixelType RefVec = itRef.Get();
228 double accumulatedError = 0;
229 for (
unsigned int channel = 0; channel < ref->GetVectorLength(); channel++)
231 accumulatedError += (RefVec[channel] - TestVec[channel]) * (RefVec[channel] - TestVec[channel]);
233 TestError += sqrt(accumulatedError);
234 EnerError += accumulatedError;
239 ErrorType ErrorPerPixel = TestError / ref->GetBufferedRegion().GetNumberOfPixels();
240 std::cout <<
"\nError per Pixel = " << ErrorPerPixel << std::endl;
242 ErrorType MSE = EnerError / ref->GetBufferedRegion().GetNumberOfPixels();
243 std::cout <<
"MSE = " << MSE << std::endl;
245 ErrorType PSNR = 20 * log10(RefValueForPSNR) - 10 * log10(MSE);
246 std::cout <<
"PSNR = " << PSNR <<
"dB" << std::endl;
248 ErrorType QI = (RefValueForPSNR - ErrorPerPixel) / RefValueForPSNR;
249 std::cout <<
"QI = " << QI << std::endl;
267 if (!(ErrorPerPixel < ErrorPerPixelTolerance))
269 std::cerr <<
"Test Failed, Error per pixel not valid! " << ErrorPerPixel <<
" instead of " << ErrorPerPixelTolerance
273 if (!(PSNR > PSNRTolerance))
275 std::cerr <<
"Test Failed, PSNR not valid! " << PSNR <<
" instead of " << PSNRTolerance << std::endl;
279 #endif // FAST_TESTS_NO_CHECKS 298 const double e = 1e-10;
302 std::cerr <<
"Unequal number of projections in the two geometries" << std::endl;
307 std::cerr <<
"Geometries don't have the same cylindrical detector radius" << std::endl;
311 for (
unsigned int i = 0; i < nproj; i++)
331 std::cerr <<
"Geometry of projection #" << i <<
" is unvalid." << std::endl;
338 template <
class TImage1,
class TImage2>
339 #if FAST_TESTS_NO_CHECKS 342 typename TImage1::Pointer itkNotUsed(im1B),
343 typename TImage2::Pointer itkNotUsed(im2A),
344 typename TImage2::Pointer itkNotUsed(im2B))
349 typename TImage1::Pointer im1B,
350 typename TImage2::Pointer im2A,
351 typename TImage2::Pointer im2B)
355 Image1IteratorType itIm1A(im1A, im1A->GetLargestPossibleRegion());
356 Image1IteratorType itIm1B(im1B, im1B->GetLargestPossibleRegion());
357 Image2IteratorType itIm2A(im2A, im2A->GetLargestPossibleRegion());
358 Image2IteratorType itIm2B(im2B, im2B->GetLargestPossibleRegion());
360 typename TImage2::PixelType scalarProductT1, scalarProductT2;
364 while (!itIm1A.IsAtEnd())
366 scalarProductT1 += itIm1A.Get() * itIm1B.Get();
371 while (!itIm2A.IsAtEnd())
373 scalarProductT2 += itIm2A.Get() * itIm2B.Get();
379 double ratio = scalarProductT1 / scalarProductT2;
380 std::cout <<
"1 - ratio = " << 1 - ratio << std::endl;
409 std::cerr <<
"Test Failed, ratio not valid! " << ratio <<
" instead of 1 +/- 0.001" << std::endl;
415 template <
class TImage1,
class TImage2>
416 #if FAST_TESTS_NO_CHECKS 419 typename TImage1::Pointer im1B,
420 typename TImage2::Pointer im2A,
421 typename TImage2::Pointer im2B)
426 typename TImage1::Pointer im1B,
427 typename TImage2::Pointer im2A,
428 typename TImage2::Pointer im2B)
432 Image1IteratorType itIm1A(im1A, im1A->GetLargestPossibleRegion());
433 Image1IteratorType itIm1B(im1B, im1B->GetLargestPossibleRegion());
434 Image2IteratorType itIm2A(im2A, im2A->GetLargestPossibleRegion());
435 Image2IteratorType itIm2B(im2B, im2B->GetLargestPossibleRegion());
442 while (!itIm1A.IsAtEnd())
444 for (
unsigned int component = 0; component < vectorLength; component++)
445 scalarProductT1 += itIm1A.Get()[component] * itIm1B.Get()[component];
450 while (!itIm2A.IsAtEnd())
452 for (
unsigned int component = 0; component < vectorLength; component++)
453 scalarProductT2 += itIm2A.Get()[component] * itIm2B.Get()[component];
459 double ratio = scalarProductT1 / scalarProductT2;
460 std::cout <<
"1 - ratio = " << 1 - ratio << std::endl;
489 std::cerr <<
"Test Failed, ratio not valid! " << ratio <<
" instead of 1 +/- 0.001" << std::endl;
void CheckVectorScalarProducts(typename TImage1::Pointer im1A, typename TImage1::Pointer im1B, typename TImage2::Pointer im2A, typename TImage2::Pointer im2B)
const std::vector< double > & GetSourceOffsetsY() const
void CheckVectorImageQuality(typename TImage::Pointer recon, typename TImage::Pointer ref, double ErrorPerPixelTolerance, double PSNRTolerance, double RefValueForPSNR)
static double ConvertAngleBetween0And2PIRadians(const double a)
void CheckGeometries(const rtk::ThreeDCircularProjectionGeometry *g1, const rtk::ThreeDCircularProjectionGeometry *g2)
const std::vector< double > & GetInPlaneAngles() const
typename TPixelType::ValueType ValueType
Projection geometry for a source and a 2-D flat panel.
const std::vector< double > & GetGantryAngles() const
const std::vector< double > & GetSourceToIsocenterDistances() const
const std::vector< double > & GetProjectionOffsetsY() const
const std::vector< double > & GetProjectionOffsetsX() const
void CheckScalarProducts(typename TImage1::Pointer im1A, typename TImage1::Pointer im1B, typename TImage2::Pointer im2A, typename TImage2::Pointer im2B)
const std::vector< double > & GetSourceOffsetsX() const
const std::vector< double > & GetCollimationUInf() const
const std::vector< double > & GetSourceToDetectorDistances() const
const std::vector< double > & GetOutOfPlaneAngles() const
const std::vector< double > & GetCollimationVInf() const
const std::vector< double > & GetCollimationVSup() const
const std::vector< double > & GetCollimationUSup() const
void CheckImageQuality(typename TImage::Pointer recon, typename TImage::Pointer ref, double ErrorPerPixelTolerance, double PSNRTolerance, double RefValueForPSNR)
void CheckVariableLengthVectorImageQuality(typename TImage::Pointer recon, typename TImage::Pointer ref, double ErrorPerPixelTolerance, double PSNRTolerance, double RefValueForPSNR)
virtual double GetRadiusCylindricalDetector() const