int
main(int argc, char * argv[])
{
if (argc < 4)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile ";
std::cerr << " outputImageFile radius " << std::endl;
return EXIT_FAILURE;
}
using PixelType = unsigned char;
using WritePixelType = unsigned char;
using StructuringElementType =
using OpeningFilterType =
ImageType,
StructuringElementType>;
using ClosingFilterType =
ImageType,
StructuringElementType>;
using AdditionFilterType =
using SubtractionFilterType = itk::
ConstrainedValueDifferenceImageFilter<ImageType, ImageType, ImageType>;
using RescaleFilterType =
StructuringElementType structuringElement;
structuringElement.
SetRadius(std::stoi(argv[3]));
structuringElement.CreateStructuringElement();
reader->SetFileName(argv[1]);
writer->SetFileName(argv[2]);
try
{
reader->Update();
}
catch (const itk::ExceptionObject & err)
{
std::cout << "Problems reading input image" << std::endl;
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
opening->SetKernel(structuringElement);
closing->SetKernel(structuringElement);
rescaleFilter->SetOutputMinimum(0);
rescaleFilter->SetOutputMaximum(255);
opening->SetInput(reader->GetOutput());
closing->SetInput(reader->GetOutput());
topHat->SetInput1(reader->GetOutput());
topHat->SetInput2(opening->GetOutput());
bottomHat->SetInput1(closing->GetOutput());
bottomHat->SetInput2(reader->GetOutput());
internalAddition->SetInput1(reader->GetOutput());
internalAddition->SetInput2(topHat->GetOutput());
imageEnhancement->SetInput1(internalAddition->GetOutput());
imageEnhancement->SetInput2(bottomHat->GetOutput());
rescaleFilter->SetInput(imageEnhancement->GetOutput());
writer->SetInput(rescaleFilter->GetOutput());
try
{
writer->Update();
}
catch (const itk::ExceptionObject & err)
{
std::cout << "ExceptionObject caught !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}