int main( int argc, char ** argv )
{
if( argc <= 3 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " input3DImageFile output3DImageFile " << std::endl;
std::cerr << " sliceNumber " << std::endl;
return EXIT_FAILURE;
}
typedef unsigned char InputPixelType;
typedef unsigned char MiddlePixelType;
typedef unsigned char OutputPixelType;
const char * inputFilename = argv[1];
const char * outputFilename = argv[2];
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
reader->SetFileName( inputFilename );
writer->SetFileName( outputFilename );
ExtractFilterType;
ExtractFilterType::Pointer extractFilter = ExtractFilterType::New();
extractFilter->SetDirectionCollapseToSubmatrix();
reader->Update();
const InputImageType * inputImage = reader->GetOutput();
InputImageType::RegionType inputRegion = inputImage->GetBufferedRegion();
size[2] = 1;
const unsigned int sliceNumber = atoi( argv[3] );
start[2] = sliceNumber;
InputImageType::RegionType desiredRegion;
desiredRegion.SetSize( size );
desiredRegion.SetIndex( start );
extractFilter->SetExtractionRegion( desiredRegion );
OutputImageType > PasteFilterType;
PasteFilterType::Pointer pasteFilter = PasteFilterType::New();
MiddleImageType > MedianFilterType;
MedianFilterType::Pointer medianFilter = MedianFilterType::New();
extractFilter->SetInput( inputImage );
medianFilter->SetInput( extractFilter->GetOutput() );
pasteFilter->SetSourceImage( medianFilter->GetOutput() );
pasteFilter->SetDestinationImage( inputImage );
pasteFilter->SetDestinationIndex( start );
indexRadius[0] = 1;
indexRadius[1] = 1;
indexRadius[2] = 0;
medianFilter->SetRadius( indexRadius );
medianFilter->UpdateLargestPossibleRegion();
const MiddleImageType * medianImage = medianFilter->GetOutput();
pasteFilter->SetSourceRegion( medianImage->GetBufferedRegion() );
writer->SetInput( pasteFilter->GetOutput() );
try
{
writer->Update();
}
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}