int
main(int argc, char ** argv)
{
if (argc < 3)
{
std::cerr << "Missing parameters. " << std::endl;
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile outputImageFile" << std::endl;
return EXIT_FAILURE;
}
using PixelType = float;
reader->SetFileName(argv[1]);
try
{
reader->Update();
}
catch (const itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
NeighborhoodIteratorType::RadiusType radius;
radius.Fill(1);
NeighborhoodIteratorType it(
radius, reader->GetOutput(), reader->GetOutput()->GetRequestedRegion());
output->SetRegions(reader->GetOutput()->GetRequestedRegion());
output->Allocate();
IteratorType out(output, reader->GetOutput()->GetRequestedRegion());
NeighborhoodIteratorType::OffsetType offset1 = { { -1, -1 } };
NeighborhoodIteratorType::OffsetType offset2 = { { 1, -1 } };
NeighborhoodIteratorType::OffsetType offset3 = { { -1, 0 } };
NeighborhoodIteratorType::OffsetType offset4 = { { 1, 0 } };
NeighborhoodIteratorType::OffsetType offset5 = { { -1, 1 } };
NeighborhoodIteratorType::OffsetType offset6 = { { 1, 1 } };
for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out)
{
float sum;
sum = it.GetPixel(offset2) - it.GetPixel(offset1);
sum += 2.0 * it.GetPixel(offset4) - 2.0 * it.GetPixel(offset3);
sum += it.GetPixel(offset6) - it.GetPixel(offset5);
out.Set(sum);
}
using WritePixelType = unsigned char;
using RescaleFilterType =
rescaler->SetOutputMinimum(0);
rescaler->SetOutputMaximum(255);
rescaler->SetInput(output);
writer->SetFileName(argv[2]);
writer->SetInput(rescaler->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;
}