Processing
This section introduces processing interaction functions.
Most of ImageDev algorithms frequently send messages to:
See related example Note: This example mainly shows how to use the verbose mode and how to intercept algorithm progression and messages. Other functions are illustrated at the end of this page.
Most of ImageDev algorithms frequently send messages to:
- Check if an algorithm needs to be interrupted before being completed.
- Indicate its current progression status.
- Notify a message indicating a relevant information (more rarely implemented).
- Notify data indicating a relevant information (more rarely implemented).
See related example Note: This example mainly shows how to use the verbose mode and how to intercept algorithm progression and messages. Other functions are illustrated at the end of this page.
Syntax
float progress = 0.f;
// change the number of core used by imagedev. 0 means the maximum number of core. if ( imagedev::getCpuNumber() > 0 ) imagedev::setCpuNumber( 0 );
// Initialize the progress, cancellation, message and data callbacks auto ratioCallback = [&]( const GenericAlgorithm&, float ratio ) { std::cout << "progress " << ratio << std::endl; progress = ratio; }; auto dataCallback = []( const GenericAlgorithm&, const std::string& data, const std::string& encoding ) { std::cout << "new data (" << encoding << "): " << data << std::endl; }; auto cancellationCallback = [&]( const GenericAlgorithm& ) { if ( progress > 0.5f ) { std::cout << "Algorithm cancelled" << std::endl; return true; } return false; }; imagedev::setProgressRatioCallback( ratioCallback ); imagedev::setProgressDataCallback( dataCallback ); imagedev::setCancellationCallback( cancellationCallback );
// Launch the elasticRegistration algorithm to see its progression boost::filesystem::path autorad = getBaseImagePath( "autorad.tif" ); boost::filesystem::path autoradDist = getBaseImagePath( "autorad.distorted.tif" );
std::shared_ptr < iolink::ImageView > fixedImage = ioformat::readImage( autorad.string() ); std::shared_ptr < iolink::ImageView > movingImage = ioformat::readImage( autoradDist.string() );
imagedev::ElasticRegistration2d elasticRegistration2dAlgo; elasticRegistration2dAlgo.setInputFixedImage( fixedImage ); elasticRegistration2dAlgo.setInputMovingImage( movingImage ); elasticRegistration2dAlgo.setMetricType( imagedev::ElasticRegistration2d::MetricType::MEAN_SQUARE_DIFFERENCE ); elasticRegistration2dAlgo.setTolerance( 0.025 ); elasticRegistration2dAlgo.setPyramidLevels( { 2, 0 } ); elasticRegistration2dAlgo.setElasticStandardDeviation( { 10.0, 10.0 } ); elasticRegistration2dAlgo.setFluidStandardDeviation( { 10.0, 10.0 } );
try { elasticRegistration2dAlgo.execute(); } catch ( imagedev::Exception& ) { std::cout << "The ElasticRegistration2d algorithm was cancelled." << std::endl; }
// disable callbacks imagedev::setProgressRatioCallback( nullptr ); imagedev::setProgressDataCallback( nullptr ); imagedev::setCancellationCallback( nullptr );