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;
}
const unsigned int Dimension = 3;
typedef unsigned char InputPixelType;
typedef float InternalPixelType;
typedef unsigned char OutputPixelType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
const double factorX = atof( argv[3] );
const double factorY = atof( argv[4] );
const double factorZ = atof( argv[5] );
try
{
reader->Update();
}
{
std::cerr << "Exception catched !" << std::endl;
std::cerr << excep << std::endl;
}
InputImageType::ConstPointer inputImage = reader->GetOutput();
InternalImageType > CastFilterType;
CastFilterType::Pointer caster = CastFilterType::New();
caster->SetInput( inputImage );
InternalImageType,
InternalImageType > GaussianFilterType;
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;
ResampleFilterType::Pointer resampler = ResampleFilterType::New();
TransformType::Pointer transform = TransformType::New();
transform->SetIdentity();
resampler->SetTransform( transform );
InternalImageType, double > InterpolatorType;
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() );
InputImageType::SizeType inputSize =
inputImage->GetLargestPossibleRegion().GetSize();
InputImageType::SizeType size;
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;
}