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 );
progress = 0 def progress_callback(algo, ratio): progress = ratio print("Progress:" + str(ratio))
def data_callback(algo, data, encoding): print("Data (" + encoding + "):" + data)
def cancellation_callback(algo): if(progress > 0.5): print("Algorithm cancelled.") return True return False
# change the number of core used by imagedev. 0 means the maximum number of core. if( imagedev.get_cpu_number() > 0 ): imagedev::setCpuNumber( 0 )
# Initialize the progress, cancellation, message and data callbacks imagedev.set_progress_ratio_callback(progress_callback) imagedev.set_progress_data_callback(data_callback) imagedev.set_cancellation_callback(cancellation_callback)
# Launch the elasticRegistration algorithm to see its progression fixedImage = ioformat.read_image(getBaseImagePath("autorad.tif")) movingImage = ioformat.read_image(getBaseImagePath("autorad.distorted.tif"))
try: imagedev.elastic_registration_2d(input_fixed_image=fixedImage, input_moving_image=movingImage, metric_type=imagedev.ElasticRegistration2d.MetricType.MEAN_SQUARE_DIFFERENCE, tolerance=0.025, pyramid_levels=[2, 0], elastic_standard_deviation=[10.0, 10.0], fluid_standard_deviation=[10.0, 10.0]) except Exception as e: print("The ElasticRegistration2d algorithm was cancelled.")
# Disable callbacks imagedev.set_progress_ratio_callback(None) imagedev.set_progress_data_callback(None) imagedev.set_cancellation_callback(None)
float progress = 0;
// change the number of core used by imagedev. 0 means the maximum number of core. if (ImageDev.Processing.GetCpuNumber() > 0) ImageDev.Processing.SetCpuNumber(0);
// Initialize the progress, cancellation, message and data callbacks Processing.SetProgressRatioCallback( (algo, ratio) => { Utilities.WriteInfoMsg("Progress: " + ratio); progress = ratio; } );
Processing.SetCancellationCallback( (algo) => { if (progress > 0.5f) { Console.WriteLine("Algorithm cancelled."); return true; } return false; } );
// Check that callback are set if (Processing.GetProgressRatioCallback() != null) { Utilities.WriteInfoMsg("Progression callback is set."); }
if (Processing.GetCancellationCallback() != null) { Utilities.WriteInfoMsg("Cancellation callback is set."); }
// Launch the elasticRegistration algorithm to see its progression var fixedImage = IOFormat.ViewIO.ReadImage(GetBaseImagePath("autorad.tif")) as ImageView; var movingImage = IOFormat.ViewIO.ReadImage(GetBaseImagePath("autorad.distorted.tif")) as ImageView;
ElasticRegistration2d elasticRegistration2dAlgo = new ElasticRegistration2d { inputFixedImage = fixedImage, inputMovingImage = movingImage, metricType = ElasticRegistration2d.MetricType.MEAN_SQUARE_DIFFERENCE, tolerance = 0.025, pyramidLevels = new uint[] { 2, 0 }, elasticStandardDeviation = new double[] { 10.0, 10.0 }, fluidStandardDeviation = new double[] { 10.0, 10.0 } };
try { elasticRegistration2dAlgo.Execute(); } catch { Console.WriteLine("The ElasticRegistration2d algorithm was cancelled."); }
// Disable callbacks Processing.SetProgressRatioCallback(null); Processing.SetCancellationCallback(null);