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;
}
const unsigned int Dimension = 2;
typedef unsigned char PixelType;
typedef unsigned char WritePixelType;
PixelType, Dimension > StructuringElementType;
ImageType, ImageType, StructuringElementType > OpeningFilterType;
ImageType, ImageType, StructuringElementType > ClosingFilterType;
ImageType, ImageType, ImageType > AdditionFilterType;
ImageType, ImageType, ImageType > SubtractionFilterType;
ImageType, WriteImageType> RescaleFilterType;
StructuringElementType structuringElement;
structuringElement.SetRadius( atoi(argv[3]) );
structuringElement.CreateStructuringElement();
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( argv[2] );
try
{
reader->Update();
}
{
std::cout << "Problems reading input image" << std::endl;
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
OpeningFilterType::Pointer opening = OpeningFilterType::New();
ClosingFilterType::Pointer closing = ClosingFilterType::New();
opening->SetKernel( structuringElement );
closing->SetKernel( structuringElement );
RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
rescaleFilter->SetOutputMinimum( 0 );
rescaleFilter->SetOutputMaximum( 255 );
opening->SetInput( reader->GetOutput() );
closing->SetInput( reader->GetOutput() );
SubtractionFilterType::Pointer topHat = SubtractionFilterType::New();
topHat->SetInput1( reader->GetOutput() );
topHat->SetInput2( opening->GetOutput() );
SubtractionFilterType::Pointer bottomHat = SubtractionFilterType::New();
bottomHat->SetInput1( closing->GetOutput() );
bottomHat->SetInput2( reader->GetOutput() );
AdditionFilterType::Pointer internalAddition = AdditionFilterType::New();
internalAddition->SetInput1( reader->GetOutput() );
internalAddition->SetInput2( topHat->GetOutput() );
SubtractionFilterType::Pointer imageEnhancement =
SubtractionFilterType::New();
imageEnhancement->SetInput1( internalAddition->GetOutput() );
imageEnhancement->SetInput2( bottomHat->GetOutput() );
rescaleFilter->SetInput( imageEnhancement->GetOutput() );
writer->SetInput( rescaleFilter->GetOutput() );
try
{
writer->Update();
}
{
std::cout << "ExceptionObject caught !" << std::endl;
std::cout << err <<std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}