int
main(int argc, char * argv[])
{
if (argc != 3)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0];
std::cerr << " <InputFileName> <OutputFileName>";
std::cerr << std::endl;
return EXIT_FAILURE;
}
const char * inputFileName = argv[1];
const char * outputFileName = argv[2];
const int xDiv = 6;
const int yDiv = 4;
const int zDiv = 1;
using PixelType = unsigned char;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(inputFileName);
reader->UpdateOutputInformation();
MedianType::Pointer median = MedianType::New();
median->SetInput(reader->GetOutput());
median->SetRadius(2);
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFileName);
for (int z = 0; z < zDiv; z++)
{
start[2] = fullSize[2] * double(z) / zDiv;
end[2] = fullSize[2] * (z + 1.0) / zDiv;
size[2] = end[2] - start[2];
for (int y = 0; y < yDiv; y++)
{
start[1] = fullSize[1] * double(y) / yDiv;
end[1] = fullSize[1] * (y + 1.0) / yDiv;
size[1] = end[1] - start[1];
for (int x = 0; x < xDiv; x++)
{
start[0] = fullSize[0] * double(x) / xDiv;
end[0] = fullSize[0] * (x + 1.0) / xDiv;
size[0] = end[0] - start[0];
region.SetSize(size);
median->GetOutput()->SetRequestedRegion(region);
median->Update();
ImageType::Pointer result = median->GetOutput();
result->DisconnectPipeline();
writer->SetInput(result);
ioRegion.
SetSize(0, region.GetSize()[0]);
ioRegion.
SetSize(1, region.GetSize()[1]);
ioRegion.
SetSize(2, region.GetSize()[2]);
writer->SetIORegion(ioRegion);
try
{
writer->Update();
}
catch (itk::ExceptionObject & error)
{
std::cerr << "Exception for chunk: " << x << ' ' << y << ' ' << z << error << std::endl;
return EXIT_FAILURE;
}
}
}
}
return EXIT_SUCCESS;
}