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];
const unsigned int Dimension = 2;
typedef float InputPixelType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( membershipImageFileName );
typedef unsigned char LabelType;
typedef float PriorType;
typedef float PosteriorType;
InputImageType,LabelType,
PosteriorType,PriorType > ClassifierFilterType;
ClassifierFilterType::Pointer filter = ClassifierFilterType::New();
filter->SetInput( reader->GetOutput() );
if( argv[3] )
{
filter->SetNumberOfSmoothingIterations( atoi( argv[3] ));
typedef ClassifierFilterType::ExtractedComponentImageType ExtractedComponentImageType;
ExtractedComponentImageType, ExtractedComponentImageType > SmoothingFilterType;
SmoothingFilterType::Pointer smoother = SmoothingFilterType::New();
smoother->SetNumberOfIterations( 1 );
smoother->SetTimeStep( 0.125 );
smoother->SetConductanceParameter( 3 );
filter->SetSmoothingFilter( smoother );
}
typedef ClassifierFilterType::OutputImageType ClassifierOutputImageType;
ClassifierOutputImageType, OutputImageType > RescalerType;
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;
}