#include <iostream>
int
main(int argc, char * argv[])
{
if (argc != 6)
{
std::cerr << "Usage: " << argv[0]
<< " inputImageFile spacingFraction sigmaFraction outputImageFileLabelImageInterpolator "
"outputImageFileNearestNeighborInterpolator"
<< std::endl;
return EXIT_FAILURE;
}
const char * const inputImageFile = argv[1];
const double spacingFraction = std::stod(argv[2]);
const double sigmaFraction = std::stod(argv[3]);
const char * const outputImageFileLabelImageInterpolator = argv[4];
const char * const outputImageFileNearestNeighborInterpolator = argv[5];
using PixelType = unsigned char;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(inputImageFile);
reader->Update();
ResampleFilterType::Pointer resizeFilter = ResampleFilterType::New();
resizeFilter->SetInput(reader->GetOutput());
const ImageType::SpacingType inputSpacing{ reader->GetOutput()->GetSpacing() };
ImageType::SpacingType outputSpacing;
for (
unsigned int dim = 0; dim <
Dimension; ++dim)
{
outputSpacing[dim] = inputSpacing[dim] * spacingFraction;
}
resizeFilter->SetOutputSpacing(outputSpacing);
for (
unsigned int dim = 0; dim <
Dimension; ++dim)
{
outputSize[dim] = inputSize[dim] * inputSpacing[dim] / spacingFraction;
}
GaussianInterpolatorType::Pointer gaussianInterpolator = GaussianInterpolatorType::New();
GaussianInterpolatorType::ArrayType sigma;
for (
unsigned int dim = 0; dim <
Dimension; ++dim)
{
sigma[dim] = outputSpacing[dim] * sigmaFraction;
}
gaussianInterpolator->SetSigma(sigma);
gaussianInterpolator->SetAlpha(3.0);
resizeFilter->SetInterpolator(gaussianInterpolator);
WriterType::Pointer writer = WriterType::New();
writer->SetInput(resizeFilter->GetOutput());
writer->SetFileName(outputImageFileLabelImageInterpolator);
try
{
writer->Update();
}
catch (itk::ExceptionObject & error)
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
NearestNeighborInterpolatorType::Pointer nearestNeighborInterpolator = NearestNeighborInterpolatorType::New();
resizeFilter->SetInterpolator(nearestNeighborInterpolator);
writer->SetFileName(outputImageFileNearestNeighborInterpolator);
try
{
writer->Update();
}
catch (itk::ExceptionObject & error)
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}