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;
}
const unsigned int Dimension = 2;
typedef unsigned char PixelComponentType;
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;
FilterType::Pointer nearestFilter = FilterType::New();
FilterType::Pointer linearFilter = FilterType::New();
ImageType, double > NearestInterpolatorType;
NearestInterpolatorType::Pointer interpolatorNearest = NearestInterpolatorType::New();
ImageType, double > LinearInterpolatorType;
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 );
ImageType::PointType origin;
origin[0] = 0.4;
origin[1] = 0.4;
nearestFilter->SetOutputOrigin( origin );
linearFilter->SetOutputOrigin( origin );
ImageType::DirectionType direction;
direction.SetIdentity();
nearestFilter->SetOutputDirection( direction );
linearFilter->SetOutputDirection( direction );
ImageType::SizeType size;
size[0] = 300;
size[1] = 300;
nearestFilter->SetSize( size );
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;
}