#include <iostream>
int main( int argc, char * argv[] )
{
if( argc != 5 )
{
std::cerr << "Usage: "
<< std::endl
<< argv[0]
<< " inputImageFile outputImageFile nNewWidth nNewHeight"
<< std::endl;
return EXIT_FAILURE;
}
using T_InputPixel = unsigned char;
using T_WritePixel = unsigned char;
T_Reader::Pointer pReader = T_Reader::New();
pReader->SetFileName( argv[1] );
pReader->Update();
T_Transform::Pointer _pTransform = T_Transform::New();
_pTransform->SetIdentity();
T_Interpolator::Pointer _pInterpolator = T_Interpolator::New();
_pInterpolator->SetSplineOrder(3);
T_ResampleFilter::Pointer _pResizeFilter = T_ResampleFilter::New();
_pResizeFilter->SetTransform(_pTransform);
_pResizeFilter->SetInterpolator(_pInterpolator);
const double vfOutputOrigin[2] = { 0.0, 0.0 };
_pResizeFilter->SetOutputOrigin(vfOutputOrigin);
unsigned int nNewWidth = atoi(argv[3]);
unsigned int nNewHeight = atoi(argv[4]);
pReader->GetOutput()->GetLargestPossibleRegion();
unsigned int nOldWidth = vnInputSize[0];
unsigned int nOldHeight = vnInputSize[1];
const T_Image::SpacingType& vfInputSpacing =
pReader->GetOutput()->GetSpacing();
double vfOutputSpacing[2];
vfOutputSpacing[0] = vfInputSpacing[0] * (double) nOldWidth / (double) nNewWidth;
vfOutputSpacing[1] = vfInputSpacing[1] * (double) nOldHeight / (double) nNewHeight;
_pResizeFilter->SetOutputSpacing(vfOutputSpacing);
_pResizeFilter->
SetSize(vnOutputSize);
_pResizeFilter->SetInput(pReader->GetOutput());
T_Writer::Pointer pWriter = T_Writer::New();
pWriter->SetFileName(argv[2]);
pWriter->SetInput(_pResizeFilter->GetOutput());
pWriter->Update();
return EXIT_SUCCESS;
}