int main(int argc, char* argv[])
{
if( argc < 3 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImage outputImage [variance upperThreshold lowerThreshold]" << std::endl;
return EXIT_FAILURE;
}
const char * inputFilename = argv[1];
const char * outputFilename = argv[2];
float variance = 2.0;
float upperThreshold = 0.0;
float lowerThreshold = 0.0;
if( argc > 3 )
{
variance = atof( argv[3] );
}
if( argc > 4 )
{
upperThreshold = atof( argv[4] );
}
if( argc > 5 )
{
lowerThreshold = atof( argv[5] );
}
std::cout << "Variance = " << variance << std::endl;
std::cout << "UpperThreshold = " << upperThreshold << std::endl;
std::cout << "LowerThreshold = " << lowerThreshold << std::endl;
typedef unsigned char CharPixelType;
typedef double RealPixelType;
const unsigned int Dimension = 2;
CastToRealFilterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
CastToRealFilterType::Pointer toReal = CastToRealFilterType::New();
RescaleFilter::Pointer rescale = RescaleFilter::New();
CannyFilter::Pointer cannyFilter = CannyFilter::New();
reader->SetFileName( inputFilename );
writer->SetFileName( outputFilename );
rescale->SetOutputMinimum( 0 );
rescale->SetOutputMaximum( 255 );
toReal->SetInput( reader->GetOutput() );
cannyFilter->SetInput( toReal->GetOutput() );
cannyFilter->SetVariance( variance );
cannyFilter->SetUpperThreshold( upperThreshold );
cannyFilter->SetLowerThreshold( lowerThreshold );
rescale->SetInput( cannyFilter->GetOutput() );
writer->SetInput( rescale->GetOutput() );
try
{
writer->Update();
}
{
std::cout << "ExceptionObject caught !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}