int main( int argc, char* argv[] )
{
if( argc != 5 )
{
std::cerr << "Usage: "<< std::endl;
std::cerr << argv[0];
std::cerr << " <InputFileName> <OutputFileName> <Lower Threshold> <Upper Threshold>";
std::cerr << std::endl;
return EXIT_FAILURE;
}
const char * inputFileName = argv[1];
const char * outputFileName = argv[2];
using PixelType = unsigned char;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( inputFileName );
auto lowerThreshold = static_cast< PixelType >( atoi( argv[3] ) );
auto upperThreshold = static_cast< PixelType >( atoi( argv[4] ) );
BinaryThresholdFilterType::Pointer threshold = BinaryThresholdFilterType::New();
threshold->SetInput( reader->GetOutput() );
threshold->SetLowerThreshold( lowerThreshold );
threshold->SetUpperThreshold( upperThreshold );
threshold->SetOutsideValue( 0 );
FilterType::Pointer filter = FilterType::New();
filter->SetInput( threshold->GetOutput() );
filter->SetObjectValue( 255 );
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( outputFileName );
writer->SetInput( filter->GetOutput() );
try
{
writer->Update();
}
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}