📄 itkbsplineresampleimagefiltertest.cxx
字号:
upSampler->Update();
ImageTypePtr2D outImage2 = upSampler->GetOutput();
PrintImageData(outImage2);
bool sameResults = false;
if( splineOrder == 5 )
{
sameResults = VerifyResultsHigherOrderSpline(outImage2, ExpectedResults);
}
else if( splineOrder == 3 )
{
sameResults = VerifyResults3rdOrderSpline(outImage2, ExpectedResults);
}
else if( splineOrder == 1 )
{
sameResults = VerifyResultsLowerOrderSpline(outImage2, ExpectedResults);
}
else if( splineOrder == 0 )
{
sameResults = VerifyResultsLowerOrderSpline(outImage2, ExpectedResults);
}
if (!sameResults)
{
flag = 1;
std::cout << "*** Error: unexpected value in Standard L2 - resampler with order " << splineOrder <<
" spline." << std::endl;
std::cout << "" << std::endl;
}
else
{
std::cout << "Tests for Standard L2 - resampler with order " << splineOrder << " spline PASSED " << std::endl;
std::cout << "" << std::endl;
}
return flag;
}
int test2D_Centered_l2_NthOrderSpline_filter(unsigned int splineOrder)
{
int flag = 0;
// Allocate a simple test image
ImageTypePtr2D image = ImageType2D::New();
set2DData(image);
double ExpectedResults[] = {0.124139, 0.606412, 1.322693, 1.803619,
0.580514, 1.719005, 2.834988, 3.584282,
1.244998, 2.731395, 3.214231, 3.538417,
1.691146, 3.411135, 3.468862, 3.507621};
// L2 norm resampler.
typedef itk::BSplineCenteredResampleImageFilterBase<ImageType2D, ImageType2D> ResamplerType;
typedef itk::BSplineDownsampleImageFilter<ImageType2D,ImageType2D,ResamplerType> DownsamplerType2D;
typedef itk::BSplineUpsampleImageFilter<ImageType2D,ImageType2D,ResamplerType> UpsamplerType2D;
DownsamplerType2D::Pointer downSampler = DownsamplerType2D::New();
FilterWatcher downWatcher(downSampler, "test2D_Centered_l2_filter");
UpsamplerType2D::Pointer upSampler = UpsamplerType2D::New();
FilterWatcher upWatcher(upSampler, "test2D_Centered_l2_filter");
downSampler->SetSplineOrder(splineOrder);
upSampler->SetSplineOrder(splineOrder);
downSampler->SetInput(image);
downSampler->Update();
ImageTypePtr2D outImage1 = downSampler->GetOutput();
PrintImageData(outImage1);
upSampler->SetInput( outImage1 );
upSampler->Update();
ImageTypePtr2D outImage2 = upSampler->GetOutput();
PrintImageData(outImage2);
bool sameResults = false;
if( splineOrder == 4 )
{
sameResults = VerifyResultsHigherOrderSpline(outImage2, ExpectedResults);
}
else if( splineOrder == 3 )
{
sameResults = VerifyResults3rdOrderSpline(outImage2, ExpectedResults);
}
else if( splineOrder == 2 )
{
sameResults = VerifyResults2ndOrderSpline(outImage2, ExpectedResults);
}
else if (splineOrder == 1 )
{
sameResults = VerifyResultsLowerOrderSpline(outImage2, ExpectedResults);
}
else if (splineOrder == 0 )
{
sameResults = VerifyResultsLowerOrderSpline(outImage2, ExpectedResults);
}
if (!sameResults)
{
flag = 1;
std::cout << "*** Error: unexpected value in Centered l2 - resampler with order " << splineOrder <<
" spline." << std::endl;
std::cout << "" << std::endl;
}
else
{
std::cout << "Tests for Centered l2 - resampler with order " << splineOrder << " spline PASSED " << std::endl;
std::cout << "" << std::endl;
}
return flag;
}
int testIntInputDoubleOutput()
{
int flag = 0;
// Note this only tests the downsampling using Int input and double output.
// TODO: Modify to test upsampling also.
// Allocate a simple test image
IntImageTypePtr2D image = IntImageType2D::New();
setInt2DData(image);
double ExpectedResults[] = {0.124139, 0.606412, 1.322693, 1.803619,
0.580514, 1.719005, 2.834988, 3.584282,
1.244998, 2.731395, 3.214231, 3.538417,
1.691146, 3.411135, 3.468862, 3.507621};
// L2 norm resampler.
typedef itk::BSplineCenteredResampleImageFilterBase<IntImageType2D, ImageType2D> ResamplerType;
typedef itk::BSplineDownsampleImageFilter<IntImageType2D,ImageType2D,ResamplerType> DownsamplerType2D;
typedef itk::BSplineCenteredResampleImageFilterBase<ImageType2D, ImageType2D> ResamplerType2;
typedef itk::BSplineUpsampleImageFilter<ImageType2D,ImageType2D,ResamplerType2> UpsamplerType2D;
DownsamplerType2D::Pointer downSampler = DownsamplerType2D::New();
UpsamplerType2D::Pointer upSampler = UpsamplerType2D::New();
int splineOrder = 3;
downSampler->SetSplineOrder(splineOrder);
upSampler->SetSplineOrder(splineOrder);
downSampler->SetInput(image);
downSampler->Update();
ImageTypePtr2D outImage1 = downSampler->GetOutput();
PrintImageData(outImage1);
// interp->Print( std::cout );
// PrintImageData(image);
// upSampler->SetInput( downSampler->GetOutput() );
upSampler->SetInput( outImage1 );
upSampler->Update();
ImageTypePtr2D outImage2 = upSampler->GetOutput();
PrintImageData(outImage2);
bool sameResults = VerifyResults3rdOrderSpline(outImage2, ExpectedResults);
if (!sameResults)
{
flag = 1;
std::cout << "*** Error: unexpected value in Centered l2 - resampler (integer input, double output)" << std::endl;
}
else
{
std::cout << "Tests for Centered l2 - resampler (integer input, double output) PASSED" << std::endl;
}
return flag;
}
//Test for Centered_L2 filter with Nth order spline
int test2D_Centered_L2_NthOrderSpline_filter(unsigned int splineOrder)
{
int flag = 0;
// Allocate a simple test image
ImageTypePtr2D image = ImageType2D::New();
set2DData(image);
double ExpectedResults[] = {0.119494, 0.600647, 1.323863, 1.802788,
0.574571, 1.712082, 2.837723, 3.583139,
1.245641, 2.733425, 3.217399, 3.537894,
1.690034, 3.409774, 3.468826, 3.507932};
// L2 norm resampler.
typedef itk::BSplineCenteredL2ResampleImageFilterBase<ImageType2D, ImageType2D> ResamplerType;
typedef itk::BSplineDownsampleImageFilter<ImageType2D,ImageType2D,ResamplerType> DownsamplerType2D;
typedef itk::BSplineUpsampleImageFilter<ImageType2D,ImageType2D,ResamplerType> UpsamplerType2D;
DownsamplerType2D::Pointer downSampler = DownsamplerType2D::New();
FilterWatcher downWatcher(downSampler, "test2D_Centered_L2_filter");
UpsamplerType2D::Pointer upSampler = UpsamplerType2D::New();
FilterWatcher upWatcher(upSampler, "test2D_Centered_L2_filter");
//int splineOrder = 2;
downSampler->SetSplineOrder(splineOrder);
upSampler->SetSplineOrder(splineOrder);
downSampler->SetInput(image);
downSampler->Update();
ImageTypePtr2D outImage1 = downSampler->GetOutput();
PrintImageData(outImage1);
// interp->Print( std::cout );
// PrintImageData(image);
// upSampler->SetInput( downSampler->GetOutput() );
upSampler->SetInput( outImage1 );
upSampler->Update();
ImageTypePtr2D outImage2 = upSampler->GetOutput();
PrintImageData(outImage2);
bool sameResults = false;
if( splineOrder == 4 )
{
sameResults = VerifyResultsHigherOrderSpline(outImage2, ExpectedResults);
}
else if( splineOrder == 3 )
{
sameResults = VerifyResults3rdOrderSpline(outImage2, ExpectedResults);
}
else if( splineOrder == 2 )
{
sameResults = VerifyResults2ndOrderSpline(outImage2, ExpectedResults);
}
else if (splineOrder == 1 )
{
sameResults = VerifyResultsLowerOrderSpline(outImage2, ExpectedResults);
}
else if (splineOrder == 0 )
{
sameResults = VerifyResultsLowerOrderSpline(outImage2, ExpectedResults);
}
if (!sameResults)
{
flag = 1;
std::cout << "*** Error: unexpected value in Centered L2 - resampler with order " << splineOrder <<
" spline." << std::endl;
std::cout << "" << std::endl;
}
else
{
std::cout << "Tests for Centered L2 - resampler with order " << splineOrder << " spline PASSED " << std::endl;
std::cout << "" << std::endl;
}
return flag;
}
int
itkBSplineResampleImageFilterTest(
int itkNotUsed(argc),
char * itkNotUsed(argv) [] )
{
int flag = 0;
int dummyflag = 0;
std::cout << "Testing B Spline up and down sampling methods: \n";
flag += testIntInputDoubleOutput();
//Test for Standard l2 BSplines for different orders (3,2,1,0)
flag += test2D_Standard_l2_NthOrderSpline_filter( 3 );
flag += test2D_Standard_l2_NthOrderSpline_filter( 2 );
flag += test2D_Standard_l2_NthOrderSpline_filter( 0 );
//The error for spline order 1 is much higher than allowable threshold
//Hence, a different reference set is needed for comparison. Therefore, a
//dummy flag is used to test that the code compiles. The accuracy of this
//filter remains to be tested
dummyflag += test2D_Standard_l2_NthOrderSpline_filter( 1 );
//Test for Centered l2 BSplines for different orders (4-1)
flag += test2D_Centered_l2_NthOrderSpline_filter( 4 );
flag += test2D_Centered_l2_NthOrderSpline_filter( 3 );
flag += test2D_Centered_l2_NthOrderSpline_filter( 2 );
flag += test2D_Centered_l2_NthOrderSpline_filter( 1 );
//Test for Standard L2 BSplines for different orders (5,3,1,0)
flag += test2D_Standard_L2_NthOrderSpline_filter( 5 );
flag += test2D_Standard_L2_NthOrderSpline_filter( 3 );
flag += test2D_Standard_L2_NthOrderSpline_filter( 1 );
flag += test2D_Standard_L2_NthOrderSpline_filter( 0 );
//Test for Centered L2 BSplines for different orders (4-1)
flag += test2D_Centered_L2_NthOrderSpline_filter( 4 );
flag += test2D_Centered_L2_NthOrderSpline_filter( 3 );
flag += test2D_Centered_L2_NthOrderSpline_filter( 2 );
flag += test2D_Centered_L2_NthOrderSpline_filter( 1 );
//Test for the exceptions for unsupported spline orders
bool passed = false;
try
{
std::cout << "Test when Standard_l2 spline order is unsupported" << std::endl;
dummyflag += test2D_Standard_l2_NthOrderSpline_filter( 6 );
}
catch( itk::ExceptionObject& err )
{
std::cout << "Caught expected error." << std::endl;
std::cout << err << std::endl;
passed = true;
}
if (!passed)
std::cout << "*** " << flag << " expected exception was not caught." << std::endl;
passed = false;
try
{
std::cout << "Test when Centered_l2 spline order is unsupported" << std::endl;
dummyflag += test2D_Centered_l2_NthOrderSpline_filter( 6 );
}
catch( itk::ExceptionObject& err )
{
std::cout << "Caught expected error." << std::endl;
std::cout << err << std::endl;
passed = true;
}
if (!passed)
std::cout << "*** " << flag << " expected exception was not caught." << std::endl;
passed = false;
try
{
std::cout << "Test when Standard_L2 spline order is unsupported" << std::endl;
dummyflag += test2D_Standard_L2_NthOrderSpline_filter( 6 );
}
catch( itk::ExceptionObject& err )
{
std::cout << "Caught expected error." << std::endl;
std::cout << err << std::endl;
passed = true;
}
if (!passed)
std::cout << "*** " << flag << " expected exception was not caught." << std::endl;
passed = false;
try
{
std::cout << "Test when Centered_L2 spline order is unsupported" << std::endl;
dummyflag += test2D_Centered_L2_NthOrderSpline_filter( 6 );
}
catch( itk::ExceptionObject& err )
{
std::cout << "Caught expected error." << std::endl;
std::cout << err << std::endl;
passed = true;
}
if (!passed)
std::cout << "*** " << flag << " expected exception was not caught." << std::endl;
std::cout << "dummyflag: " << dummyflag << std::endl;
// Return results of test
if (flag != 0) {
std::cout << "*** " << flag << " tests failed" << std::endl;
return EXIT_FAILURE; }
else {
std::cout << "All tests successfully passed" << std::endl;
return EXIT_SUCCESS; }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -