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;
}
using InputPixelType = unsigned char;
using MiddlePixelType = unsigned char;
using OutputPixelType = unsigned char;
const char * inputFilename = argv[1];
const char * outputFilename = argv[2];
reader->SetFileName(inputFilename);
writer->SetFileName(outputFilename);
using ExtractFilterType =
extractFilter->SetDirectionCollapseToSubmatrix();
reader->Update();
const InputImageType * inputImage = reader->GetOutput();
size[2] = 1;
const unsigned int sliceNumber = std::stoi(argv[3]);
start[2] = sliceNumber;
desiredRegion.SetIndex(start);
extractFilter->SetExtractionRegion(desiredRegion);
using PasteFilterType =
using MedianFilterType =
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();
}
catch (const itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}