int main( int argc, char * argv[] )
{
if( argc < 6 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile ";
std::cerr << " outputImageFileErosion outputImageFileDilation";
std::cerr << " lowerThreshold upperThreshold " << std::endl;
return EXIT_FAILURE;
}
typedef unsigned char InputPixelType;
typedef unsigned char OutputPixelType;
InputPixelType,
Dimension > StructuringElementType;
InputImageType,
OutputImageType,
StructuringElementType > ErodeFilterType;
InputImageType,
OutputImageType,
StructuringElementType > DilateFilterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writerDilation = WriterType::New();
WriterType::Pointer writerErosion = WriterType::New();
ThresholdFilterType::Pointer thresholder = ThresholdFilterType::New();
ErodeFilterType::Pointer binaryErode = ErodeFilterType::New();
DilateFilterType::Pointer binaryDilate = DilateFilterType::New();
StructuringElementType structuringElement;
structuringElement.SetRadius( 1 );
structuringElement.CreateStructuringElement();
binaryErode->SetKernel( structuringElement );
binaryDilate->SetKernel( structuringElement );
reader->SetFileName( argv[1] );
writerErosion->SetFileName( argv[2] );
writerDilation->SetFileName( argv[3] );
const InputPixelType lowerThreshold = atoi( argv[4] );
const InputPixelType upperThreshold = atoi( argv[5] );
thresholder->SetInput( reader->GetOutput() );
InputPixelType background = 0;
InputPixelType foreground = 255;
thresholder->SetOutsideValue( background );
thresholder->SetInsideValue( foreground );
thresholder->SetLowerThreshold( lowerThreshold );
thresholder->SetUpperThreshold( upperThreshold );
binaryErode->SetInput( thresholder->GetOutput() );
binaryDilate->SetInput( thresholder->GetOutput() );
binaryErode->SetErodeValue( foreground );
binaryDilate->SetDilateValue( foreground );
writerDilation->SetInput( binaryDilate->GetOutput() );
writerDilation->Update();
writerErosion->SetInput( binaryErode->GetOutput() );
writerErosion->Update();
return EXIT_SUCCESS;
}