swh:1:snp:e6d42e6731ce66e3c09de07ac49964c03139e990
Tip revision: ea44f4474e640ca632b40d75d03b57b037a4a7da authored by Konrad Werys on 18 March 2019, 12:43:10 UTC
unnecesary merge
unnecesary merge
Tip revision: ea44f44
itkCalculatorT1ImageFilter_test.cpp
/*!
* \file itkOxT1ImageFilter_test.cpp
* \author Konrad Werys
* \date 2018/08/13
*/
#include "CmakeConfigForTomato.h"
#ifdef USE_ITK
#include "OxTestItkImagesFactory.h"
#include "OxFunctionsT1Basic.h"
#include "OxFitterAmoebaVnl.h"
#include "OxSignCalculatorNoSign.h"
#include "OxSignCalculatorRealImag.h"
#include "OxStartPointCalculatorDefault3Dims.h"
#include "OxCalculatorT1Molli.h"
#include "itkCalculatorT1ImageFilter.h"
#include "itkTestingComparisonImageFilter.h"
#include "gtest/gtest.h"
TEST(itkCalculatorT1ImageFilter, calculate) {
typedef double TYPE;
typedef itk::Image <TYPE, 3> TImageIn;
typedef itk::Image <TYPE, 2> TImageOut;
typedef itk::CalculatorT1ImageFilter < TImageIn, TImageOut > CalculatorT1ImageFilterType;
typedef itk::Testing::ComparisonImageFilter<TImageIn, TImageIn> ComparisonImageFilter3dType;
typedef itk::Testing::ComparisonImageFilter<TImageOut, TImageOut> ComparisonImageFilter2dType;
std::vector< std::string > filePaths;
filePaths.push_back("testData/blood.yaml");
filePaths.push_back("testData/myocardium.yaml");
int nRows = 2;
int nCols = 3;
// test images
Ox::TestItkImagesFactory<TYPE> itkImagesFactory(nRows, nCols, filePaths);
TImageIn::Pointer imageMag = itkImagesFactory.generateImageMag();
TImageIn::Pointer imagePha = itkImagesFactory.generateImagePha();
TImageOut::Pointer imageMolliA = itkImagesFactory.generateImageResultsMolliA();
TImageOut::Pointer imageMolliB = itkImagesFactory.generateImageResultsMolliB();
TImageOut::Pointer imageMolliT1star = itkImagesFactory.generateImageResultsMolliT1star();
// init the necessary objects
Ox::FunctionsT1Basic<TYPE> functionsObject;
Ox::FitterAmoebaVnl<TYPE> fitterAmoebaVnl;
Ox::SignCalculatorRealImag<TYPE> signCalculator;
Ox::StartPointCalculatorDefault3Dims<TYPE> startPointCalculator;
Ox::CalculatorT1Molli<TYPE> calculatorT1Molli;
// configure calculator
calculatorT1Molli.setFunctionsT1(&functionsObject);
calculatorT1Molli.setFitter(&fitterAmoebaVnl);
calculatorT1Molli.setSignCalculator(&signCalculator);
calculatorT1Molli.setStartPointCalculator(&startPointCalculator);
calculatorT1Molli.setInvTimes(itkImagesFactory.getInvTimesPtr());
calculatorT1Molli.setNSamples(itkImagesFactory.getNSamples());
// configure calculator itk filter
CalculatorT1ImageFilterType::Pointer imageCalculatorItk = CalculatorT1ImageFilterType::New();
imageCalculatorItk->SetInputMagImage(imageMag);
imageCalculatorItk->SetInputPhaImage(imagePha);
imageCalculatorItk->SetCalculator(&calculatorT1Molli);
//imageCalculatorItk->SetNumberOfThreads(1);
imageCalculatorItk->Update();
ComparisonImageFilter2dType::Pointer diff = ComparisonImageFilter2dType::New();
diff->SetValidInput(imageMolliA.GetPointer());
diff->SetTestInput(imageCalculatorItk->GetAImage());
diff->UpdateLargestPossibleRegion();
EXPECT_LE(diff->GetMaximumDifference(), 1e-2);
diff->SetValidInput(imageMolliB.GetPointer());
diff->SetTestInput(imageCalculatorItk->GetBImage());
diff->UpdateLargestPossibleRegion();
EXPECT_LE(diff->GetMaximumDifference(), 1e-2);
diff->SetValidInput(imageMolliT1star.GetPointer());
diff->SetTestInput(imageCalculatorItk->GetT1starImage());
diff->UpdateLargestPossibleRegion();
EXPECT_LE(diff->GetMaximumDifference(), 1e-2);
}
TEST(itkCalculatorT1ImageFilter, calculate_no_phase_given) {
typedef double TYPE;
typedef itk::Image <TYPE, 3> TImageIn;
typedef itk::Image <TYPE, 2> TImageOut;
typedef itk::CalculatorT1ImageFilter < TImageIn, TImageOut > ImageCalculatorItkType;
typedef itk::Testing::ComparisonImageFilter<TImageIn, TImageIn> ComparisonImageFilter3dType;
typedef itk::Testing::ComparisonImageFilter<TImageOut, TImageOut> ComparisonImageFilter2dType;
std::vector< std::string > filePaths;
filePaths.push_back("testData/blood.yaml");
filePaths.push_back("testData/myocardium.yaml");
int nRows = 4;
int nCols = 5;
// test images
Ox::TestItkImagesFactory<TYPE> itkImagesFactory(nRows, nCols, filePaths);
TImageIn::Pointer imageMag = itkImagesFactory.generateImageMag();
//TImageIn::Pointer imagePha = itkImagesFactory.generateImagePha();
TImageOut::Pointer imageMolliA = itkImagesFactory.generateImageResultsMolliA();
TImageOut::Pointer imageMolliB = itkImagesFactory.generateImageResultsMolliB();
TImageOut::Pointer imageMolliT1star = itkImagesFactory.generateImageResultsMolliT1star();
// init the necessary objects
Ox::FunctionsT1Basic<TYPE> functionsObject;
Ox::FitterAmoebaVnl<TYPE> fitterAmoebaVnl;
Ox::SignCalculatorNoSign<TYPE> signCalculator;
Ox::StartPointCalculatorDefault3Dims<TYPE> startPointCalculator;
Ox::CalculatorT1Molli<TYPE> calculatorT1Molli;
// configure calculator
calculatorT1Molli.setFunctionsT1(&functionsObject);
calculatorT1Molli.setFitter(&fitterAmoebaVnl);
calculatorT1Molli.setSignCalculator(&signCalculator);
calculatorT1Molli.setStartPointCalculator(&startPointCalculator);
calculatorT1Molli.setInvTimes(itkImagesFactory.getInvTimesPtr());
calculatorT1Molli.setNSamples(itkImagesFactory.getNSamples());
// configure calculator itk filter
ImageCalculatorItkType::Pointer imageCalculatorItk = ImageCalculatorItkType::New();
imageCalculatorItk->SetInputMagImage(imageMag);
// imageCalculatorItk->SetInputPhaImage(imagePha);
imageCalculatorItk->SetCalculator(&calculatorT1Molli);
//imageCalculatorItk->SetNumberOfThreads(1);
imageCalculatorItk->Update();
ComparisonImageFilter2dType::Pointer diff = ComparisonImageFilter2dType::New();
diff->SetValidInput(imageMolliA.GetPointer());
diff->SetTestInput(imageCalculatorItk->GetAImage());
diff->UpdateLargestPossibleRegion();
EXPECT_LE(diff->GetMaximumDifference(), 1e-2);
diff->SetValidInput(imageMolliB.GetPointer());
diff->SetTestInput(imageCalculatorItk->GetBImage());
diff->UpdateLargestPossibleRegion();
EXPECT_LE(diff->GetMaximumDifference(), 1e-2);
diff->SetValidInput(imageMolliT1star.GetPointer());
diff->SetTestInput(imageCalculatorItk->GetT1starImage());
diff->UpdateLargestPossibleRegion();
EXPECT_LE(diff->GetMaximumDifference(), 1e-2);
}
#endif //USE_ITK