#include "itksys/SystemTools.hxx"
#include <sstream>
int main( int argc, char *argv[])
{
if( argc < 2 )
{
std::cout << "Usage:" << std::endl;
std::cout << argv[0] << " InputFileName" << std::endl;
}
const unsigned int Dimension = 2;
typedef unsigned char PixelType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
ConnectedComponentImageFilterType;
ConnectedComponentImageFilterType::Pointer connected = ConnectedComponentImageFilterType::New ();
connected->SetInput(reader->GetOutput());
connected->Update();
std::cout << "Number of objects: " << connected->GetObjectCount() << std::endl;
LabelShapeKeepNObjectsImageFilterType::Pointer labelShapeKeepNObjectsImageFilter = LabelShapeKeepNObjectsImageFilterType::New();
labelShapeKeepNObjectsImageFilter->SetInput( connected->GetOutput() );
labelShapeKeepNObjectsImageFilter->SetBackgroundValue( 0 );
labelShapeKeepNObjectsImageFilter->SetNumberOfObjects( 1 );
labelShapeKeepNObjectsImageFilter->SetAttribute( LabelShapeKeepNObjectsImageFilterType::LabelObjectType::NUMBER_OF_PIXELS);
RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
rescaleFilter->SetOutputMinimum(0);
rescaleFilter->SetInput(labelShapeKeepNObjectsImageFilter->GetOutput());
reader->GetOutput(),true,
itksys::SystemTools::GetFilenameName(argv[1]));
std::stringstream desc;
desc << "Largest object of " << connected->GetObjectCount() << " objects";
rescaleFilter->GetOutput(),
true,
desc.str());
return EXIT_SUCCESS;
}