#include "itksys/SystemTools.hxx"
#include <sstream>
int main(int argc, char * argv[])
{
if( argc < 2 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " InputImageFile [radius]" << std::endl;
return EXIT_FAILURE;
}
std::string inputFilename = argv[1];
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( inputFilename );
FilterType::Pointer medianFilter = FilterType::New();
FilterType::InputSizeType radius;
radius.Fill(2);
if (argc > 2)
{
radius.Fill(atoi(argv[2]));
}
reader->Update();
processSize[0] =
reader->GetOutput()->GetLargestPossibleRegion().
GetSize()[0] / 2;
processSize[1] =
reader->GetOutput()->GetLargestPossibleRegion().
GetSize()[1] / 2;
processIndex[0] = processSize[0] / 2;
processIndex[1] = processSize[1] / 2;
medianFilter->SetRadius(radius);
medianFilter->SetInput( reader->GetOutput() );
medianFilter->GetOutput()->SetRequestedRegion( processRegion );
PasteType::Pointer pasteFilter = PasteType::New();
pasteFilter->SetSourceImage(medianFilter->GetOutput());
pasteFilter->SetSourceRegion(medianFilter->GetOutput()->GetRequestedRegion());
pasteFilter->SetDestinationImage(reader->GetOutput());
pasteFilter->SetDestinationIndex(processIndex);
SubtractType::Pointer diff = SubtractType::New();
diff->SetInput1(reader->GetOutput());
diff->SetInput2(pasteFilter->GetOutput());
reader->GetOutput(),true,
itksys::SystemTools::GetFilenameName(inputFilename));
std::stringstream desc;
desc << "Median/PasteImageFilter, radius = " << radius;
pasteFilter->GetOutput(),
true,
desc.str());
std::stringstream desc2;
desc2 << "Original - Median/Paste";
diff->GetOutput(),
true,
desc2.str());
return EXIT_SUCCESS;
}