int main(int argc, char* argv[] )
{
if( argc < 3 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile outputImageFile [smoothingIterations]" << std::endl;
return EXIT_FAILURE;
}
const char * membershipImageFileName = argv[1];
const char * labelMapImageFileName = argv[2];
using InputPixelType = float;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( membershipImageFileName );
using LabelType = unsigned char;
using PriorType = float;
using PosteriorType = float;
InputImageType,LabelType,
PosteriorType,PriorType >;
ClassifierFilterType::Pointer filter = ClassifierFilterType::New();
filter->SetInput( reader->GetOutput() );
if( argv[3] )
{
filter->SetNumberOfSmoothingIterations( std::stoi( argv[3] ));
using ExtractedComponentImageType = ClassifierFilterType::ExtractedComponentImageType;
ExtractedComponentImageType, ExtractedComponentImageType >;
SmoothingFilterType::Pointer smoother = SmoothingFilterType::New();
smoother->SetNumberOfIterations( 1 );
smoother->SetTimeStep( 0.125 );
smoother->SetConductanceParameter( 3 );
filter->SetSmoothingFilter( smoother );
}
using ClassifierOutputImageType = ClassifierFilterType::OutputImageType;
ClassifierOutputImageType, OutputImageType >;
RescalerType::Pointer rescaler = RescalerType::New();
rescaler->SetInput( filter->GetOutput() );
rescaler->SetOutputMinimum( 0 );
rescaler->SetOutputMaximum( 255 );
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( labelMapImageFileName );
writer->SetInput( rescaler->GetOutput() );
try
{
writer->Update();
}
{
std::cerr << "Exception caught: " << std::endl;
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
filter->
Print( std::cout );
std::cout << "Test passed." << std::endl;
return EXIT_SUCCESS;
}