int
main(int argc, char * argv[])
{
if (argc < 4)
{
std::cerr << "Usage: " << std::endl;
std::cerr
<< argv[0]
<< " inputImageFile outputImageFile sigma [RescaledOutputImageFile] "
<< std::endl;
return EXIT_FAILURE;
}
using InputPixelType = float;
using OutputPixelType = float;
using FilterType =
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
FilterType::Pointer filterX1 = FilterType::New();
FilterType::Pointer filterY1 = FilterType::New();
FilterType::Pointer filterX2 = FilterType::New();
FilterType::Pointer filterY2 = FilterType::New();
filterX1->SetDirection(0);
filterY1->SetDirection(1);
filterX2->SetDirection(0);
filterY2->SetDirection(1);
const bool normalizeAcrossScale = false;
filterX1->SetNormalizeAcrossScale(normalizeAcrossScale);
filterY1->SetNormalizeAcrossScale(normalizeAcrossScale);
filterX2->SetNormalizeAcrossScale(normalizeAcrossScale);
filterY2->SetNormalizeAcrossScale(normalizeAcrossScale);
filterX1->SetInput(reader->GetOutput());
filterY1->SetInput(filterX1->GetOutput());
filterY2->SetInput(reader->GetOutput());
filterX2->SetInput(filterY2->GetOutput());
const double sigma = std::stod(argv[3]);
filterX1->SetSigma(sigma);
filterY1->SetSigma(sigma);
filterX2->SetSigma(sigma);
filterY2->SetSigma(sigma);
using AddFilterType =
AddFilterType::Pointer addFilter = AddFilterType::New();
addFilter->SetInput1(filterY1->GetOutput());
addFilter->SetInput2(filterX2->GetOutput());
try
{
addFilter->Update();
}
catch (const itk::ExceptionObject & err)
{
std::cout << "ExceptionObject caught !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
using WritePixelType = float;
WriterType::Pointer writer = WriterType::New();
writer->SetInput(addFilter->GetOutput());
writer->SetFileName(argv[2]);
writer->Update();
if (argc > 4)
{
using CharPixelType = unsigned char;
using RescaleFilterType =
RescaleFilterType::Pointer rescale = RescaleFilterType::New();
rescale->SetInput(addFilter->GetOutput());
rescale->SetOutputMinimum(0);
rescale->SetOutputMaximum(255);
CharWriterType::Pointer charWriter = CharWriterType::New();
charWriter->SetFileName(argv[4]);
charWriter->SetInput(rescale->GetOutput());
charWriter->Update();
}
return EXIT_SUCCESS;
}