int main( int argc, char * argv[] )
{
if( argc < 6 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0]
<< " inputImageFile outputImageFile factorX factorY factorZ"
<< std::endl;
return EXIT_FAILURE;
}
using InputPixelType = unsigned char;
using InternalPixelType = float;
using OutputPixelType = unsigned char;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
const double factorX = std::stod( argv[3] );
const double factorY = std::stod( argv[4] );
const double factorZ = std::stod( argv[5] );
try
{
reader->Update();
}
{
std::cerr << "Exception catched !" << std::endl;
std::cerr << excep << std::endl;
}
InputImageType::ConstPointer inputImage = reader->GetOutput();
InternalImageType >;
CastFilterType::Pointer caster = CastFilterType::New();
caster->SetInput( inputImage );
InternalImageType,
InternalImageType >;
GaussianFilterType::Pointer smootherX = GaussianFilterType::New();
GaussianFilterType::Pointer smootherY = GaussianFilterType::New();
GaussianFilterType::Pointer smootherZ = GaussianFilterType::New();
smootherX->SetInput( caster->GetOutput() );
smootherY->SetInput( smootherX->GetOutput() );
smootherZ->SetInput( smootherY->GetOutput() );
const InputImageType::SpacingType& inputSpacing = inputImage->GetSpacing();
const double sigmaX = inputSpacing[0] * factorX;
const double sigmaY = inputSpacing[1] * factorY;
const double sigmaZ = inputSpacing[2] * factorZ;
smootherX->SetSigma( sigmaX );
smootherY->SetSigma( sigmaY );
smootherZ->SetSigma( sigmaZ );
smootherX->SetDirection( 0 );
smootherY->SetDirection( 1 );
smootherZ->SetDirection( 2 );
smootherX->SetNormalizeAcrossScale( false );
smootherY->SetNormalizeAcrossScale( false );
smootherZ->SetNormalizeAcrossScale( false );
InternalImageType, OutputImageType >;
ResampleFilterType::Pointer resampler = ResampleFilterType::New();
TransformType::Pointer transform = TransformType::New();
transform->SetIdentity();
resampler->SetTransform( transform );
InternalImageType, double >;
InterpolatorType::Pointer interpolator = InterpolatorType::New();
resampler->SetInterpolator( interpolator );
resampler->SetDefaultPixelValue( 0 );
OutputImageType::SpacingType spacing;
spacing[0] = inputSpacing[0] * factorX;
spacing[1] = inputSpacing[1] * factorY;
spacing[2] = inputSpacing[2] * factorZ;
resampler->SetOutputSpacing( spacing );
resampler->SetOutputOrigin( inputImage->GetOrigin() );
resampler->SetOutputDirection( inputImage->GetDirection() );
inputImage->GetLargestPossibleRegion().
GetSize();
size[0] =
static_cast< SizeValueType >( inputSize[0] / factorX );
size[1] =
static_cast< SizeValueType >( inputSize[1] / factorY );
size[2] =
static_cast< SizeValueType >( inputSize[2] / factorZ );
resampler->SetSize( size );
resampler->SetInput( smootherZ->GetOutput() );
WriterType::Pointer writer = WriterType::New();
writer->SetInput( resampler->GetOutput() );
writer->SetFileName( argv[2] );
try
{
writer->Update();
}
{
std::cerr << "Exception catched !" << std::endl;
std::cerr << excep << std::endl;
}
std::cout << "Resampling Done !" << std::endl;
return EXIT_SUCCESS;
}