int main( int argc, char * argv[] )
{
if( argc < 4 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] <<
" inputImageFile outputImageFile_NearestNeighbor" <<
" outputImageFile_Linear " << std::endl;
return EXIT_FAILURE;
}
using PixelComponentType = unsigned char;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writerNearest = WriterType::New();
WriterType::Pointer writerLinear = WriterType::New();
reader->SetFileName( argv[1] );
writerNearest->SetFileName( argv[2] );
writerLinear->SetFileName( argv[3] );
ImageType, ImageType >;
FilterType::Pointer nearestFilter = FilterType::New();
FilterType::Pointer linearFilter = FilterType::New();
ImageType, double >;
NearestInterpolatorType::Pointer interpolatorNearest = NearestInterpolatorType::New();
ImageType, double >;
LinearInterpolatorType::Pointer interpolatorLinear = LinearInterpolatorType::New();
nearestFilter->SetInterpolator( interpolatorNearest );
linearFilter->SetInterpolator( interpolatorLinear );
TransformType::Pointer transform = TransformType::New();
nearestFilter->SetTransform( transform );
linearFilter->SetTransform( transform );
PixelType defaultValue;
defaultValue.Fill(50);
nearestFilter->SetDefaultPixelValue( defaultValue );
linearFilter->SetDefaultPixelValue( defaultValue );
ImageType::SpacingType spacing;
spacing[0] = .35;
spacing[1] = .35;
nearestFilter->SetOutputSpacing( spacing );
linearFilter->SetOutputSpacing( spacing );
origin[0] = 0.4;
origin[1] = 0.4;
nearestFilter->SetOutputOrigin( origin );
linearFilter->SetOutputOrigin( origin );
nearestFilter->SetOutputDirection( direction );
linearFilter->SetOutputDirection( direction );
size[0] = 300;
size[1] = 300;
linearFilter->SetSize( size );
nearestFilter->SetInput( reader->GetOutput() );
linearFilter->SetInput( reader->GetOutput() );
writerNearest->SetInput( nearestFilter->GetOutput() );
writerLinear->SetInput( linearFilter->GetOutput() );
try
{
writerNearest->Update();
}
{
std::cerr << "Exception thrown " << std::endl;
std::cerr << excp << std::endl;
}
try
{
writerLinear->Update();
}
{
std::cerr << "Exception thrown " << std::endl;
std::cerr << excp << std::endl;
}
return EXIT_SUCCESS;
}