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;
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();
}
catch (const itk::ExceptionObject & excep)
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
}
using CastFilterType =
caster->SetInput(inputImage);
using GaussianFilterType =
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);
using ResampleFilterType =
transform->SetIdentity();
resampler->SetTransform(transform);
using InterpolatorType =
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());
writer->SetInput(resampler->GetOutput());
writer->SetFileName(argv[2]);
try
{
writer->Update();
}
catch (const itk::ExceptionObject & excep)
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
}
std::cout << "Resampling Done !" << std::endl;
return EXIT_SUCCESS;
}