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
Method | Description |
---|---|
void setVerbose(bool enable) | Sets default callbacks that print the name of which algorithm is starting and its execution time. |
bool getVerbose() | Returns True if the verbose mode is enabled, False otherwise. |
void setCpuNumber(int cpuNumber) |
Activates a user-defined number of logical processors to be used by ImageDev algorithms.
Most of the ImageDev algorithms are CPU parallelized. However, if the computation time scales well with the CPU clock speed, it does not with the number of threads. Generally, using more than 8 threads is useless. For instance, a system with a 3.2 GHz, 8 threads processor configuration can run ImageDev algorithms faster than a system with 2.7 GHz and 32 threads. This phenomenon is easy to explain. When processing an image in parallel, each selected logical processor computes a result for an image block. Once two contiguous blocks are processed, a fusion step is necessary to merge the results of these blocks. This step may be more or less complex depending on several parameters, such as:
|
int getCpuNumber() | Returns the user-defined number of logical processors to be used by ImageDev algorithms. If the returned value is lower than or equal to zero, all processors are used. |
void setProgressRatioCallback( ProgressRatioCallback progressRatioCallback ) |
Sets the ratio callback used to track the progression of algorithms.
|
ProgressRatioCallback getProgressRatioCallback() | Returns a pointer or a reference to the ratio callback function if it has been defined, null or none otherwise. |
void setProgressMessageCallback( ProgressMessageCallback progressMessageCallback ) |
Sets the message callback used to be notified about generic messages sent by algorithms.
|
ProgressMessageCallback getProgressMessageCallback() | Returns a pointer or a reference to the message callback function if it has been defined, null or none otherwise. |
void setProgressDataCallback( ProgressDataCallback progressDataCallback ) |
Sets the data callback used to be notified about formatted messages sent by algorithms.
|
ProgressDataCallback getProgressDataCallback() | Returns a pointer or a reference to the data callback function if it has been defined, null or none otherwise. |
void setCancellationCallback( CancellationCallback cancellationCallback ) |
Sets the cancellation callback that can be used to interrupt an algorithm before being completed.
|
CancellationCallback getCancellationCallback() | Returns a pointer or a reference to the cancellation callback function if it has been defined, null or none otherwise. |
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 );