int main( int argc, char * argv[] )
{
if( argc < 5 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile outputImageFile lower upper " << std::endl;
return EXIT_FAILURE;
}
using InputPixelType = unsigned short;
using InternalPixelType = float;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
try
{
reader->Update();
}
{
std::cerr << "Exception caught!" << std::endl;
std::cerr << excep << std::endl;
}
InputImageType,
InternalImageType >;
IntensityFilterType::Pointer intensityWindowing = IntensityFilterType::New();
intensityWindowing->SetWindowMinimum( std::stoi( argv[3] ) );
intensityWindowing->SetWindowMaximum( std::stoi( argv[4] ) );
intensityWindowing->SetOutputMinimum( 0.0 );
intensityWindowing->SetOutputMaximum( 255.0 );
intensityWindowing->SetInput( reader->GetOutput() );
InternalImageType,
InternalImageType >;
GaussianFilterType::Pointer smootherX = GaussianFilterType::New();
GaussianFilterType::Pointer smootherY = GaussianFilterType::New();
smootherX->SetInput( intensityWindowing->GetOutput() );
smootherY->SetInput( smootherX->GetOutput() );
InputImageType::ConstPointer inputImage = reader->GetOutput();
const InputImageType::SpacingType& inputSpacing = inputImage->GetSpacing();
const double isoSpacing = std::sqrt( inputSpacing[2] * inputSpacing[0] );
smootherX->SetSigma( isoSpacing );
smootherY->SetSigma( isoSpacing );
smootherX->SetDirection( 0 );
smootherY->SetDirection( 1 );
using OutputPixelType = unsigned char;
InternalImageType, OutputImageType >;
ResampleFilterType::Pointer resampler = ResampleFilterType::New();
TransformType::Pointer transform = TransformType::New();
transform->SetIdentity();
resampler->SetTransform( transform );
InternalImageType, double >;
InterpolatorType::Pointer interpolator = InterpolatorType::New();
resampler->SetInterpolator( interpolator );
resampler->SetDefaultPixelValue( 255 );
OutputImageType::SpacingType spacing;
spacing[0] = isoSpacing;
spacing[1] = isoSpacing;
spacing[2] = isoSpacing;
resampler->SetOutputSpacing( spacing );
resampler->SetOutputOrigin( inputImage->GetOrigin() );
resampler->SetOutputDirection( inputImage->GetDirection() );
inputImage->GetLargestPossibleRegion().
GetSize();
const double dx = inputSize[0] * inputSpacing[0] / isoSpacing;
const double dy = inputSize[1] * inputSpacing[1] / isoSpacing;
const double dz = (inputSize[2] - 1 ) * inputSpacing[2] / isoSpacing;
resampler->SetSize( size );
resampler->SetInput( smootherY->GetOutput() );
resampler->Update();
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( argv[2] );
writer->SetInput( resampler->GetOutput() );
try
{
writer->Update();
}
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << excep << std::endl;
}
return EXIT_SUCCESS;
}