namespace itk
{
class ThresholdingPixelAccessor
{
public:
typedef unsigned char InternalType;
typedef unsigned char ExternalType;
ThresholdingPixelAccessor() : m_Threshold(0) {};
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 )
{
m_Threshold = vpa.m_Threshold;
return *this;
}
private:
InternalType m_Threshold;
};
}
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;
}
typedef itk::ThresholdingPixelAccessor::InternalType PixelType;
const unsigned int Dimension = 2;
itk::ThresholdingPixelAccessor > ImageAdaptorType;
ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
itk::ThresholdingPixelAccessor accessor;
accessor.SetThreshold( atoi( argv[3] ) );
adaptor->SetPixelAccessor( accessor );
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( argv[1] );
reader->Update();
adaptor->SetImage( reader->GetOutput() );
ImageType > RescalerType;
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;
}