namespace itk
{
class ThresholdingPixelAccessor
{
public:
using InternalType = unsigned char;
using ExternalType = unsigned char;
ThresholdingPixelAccessor() {};
ExternalType Get( const InternalType & input ) const
{
return (input > m_Threshold) ? 1 : 0;
}
void SetThreshold( const InternalType threshold )
{
m_Threshold = threshold;
}
ThresholdingPixelAccessor &
operator=( const ThresholdingPixelAccessor & vpa ) = default;
private:
InternalType m_Threshold{0};
};
}
int main( int argc, char *argv[] )
{
if( argc < 4 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << "ImageAdaptor4 inputFileName outputBinaryFileName ";
std::cerr << " thresholdValue" << std::endl;
return EXIT_FAILURE;
}
using PixelType = itk::ThresholdingPixelAccessor::InternalType;
itk::ThresholdingPixelAccessor >;
ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
itk::ThresholdingPixelAccessor accessor;
accessor.SetThreshold( std::stoi( argv[3] ) );
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
reader->Update();
adaptor->SetImage( reader->GetOutput() );
ImageType >;
RescalerType::Pointer rescaler = RescalerType::New();
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( argv[2] );
rescaler->SetOutputMinimum( 0 );
rescaler->SetOutputMaximum( 255 );
rescaler->SetInput( adaptor );
writer->SetInput( rescaler->GetOutput() );
writer->Update();
return EXIT_SUCCESS;
}