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 );
Method | Description |
---|---|
set_verbose(enable) | Sets default callbacks that print the name of which algorithm is starting, its progression, its execution time and manage cancellation. |
get_verbose() | Returns True if the verbose mode is enabled, False otherwise. |
set_cpu_number(cpu_number) |
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:
|
get_cpu_number() | 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. |
set_progress_ratio_callback(progress_ratio_callback) |
Sets the ratio callback used to track the progression of algorithms.
|
get_progress_ratio_callback() | Returns a pointer or a reference to the ratio callback function if it has been defined, null or none otherwise. |
set_progress_message_callback(progress_message_callback) |
Sets the message callback used to be notified about generic messages sent by algorithms.
|
get_progress_message_callback() | Returns a pointer or a reference to the message callback function if it has been defined, null or none otherwise. |
set_progress_data_callback(progress_data_callback) |
Sets the data callback used to be notified about formatted messages sent by algorithms.
|
get_progress_data_callback() | Returns a pointer or a reference to the data callback function if it has been defined, null or none otherwise. |
set_cancellation_callback(cancellation_callback) |
Sets the cancellation callback that can be used to interrupt an algorithm before being completed.
|
get_cancellation_callback() | Returns a pointer or a reference to the cancellation callback function if it has been defined, null or none otherwise. |
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)
Method | Description |
---|---|
public void SetVerbose(bool enable) | Sets default callbacks that print the name of which algorithm is starting and its execution time. |
public bool GetVerbose() | Returns True if the verbose mode is enabled, False otherwise. |
public 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:
|
public 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. |
public static void SetProgressRatioCallback(ProgressRatioCallback progressRatioCallback) |
Sets the ratio callback used to track the progression of algorithms.
|
public static ProgressRatioCallback GetProgressRatioCallback() | Returns a pointer or a reference to the ratio callback function if it has been defined, null or none otherwise. |
public static void SetProgressMessageCallback(ProgressMessageCallback progressMessageCallback) |
Sets the message callback used to be notified about generic messages sent by algorithms.
|
public static ProgressMessageCallback GetProgressMessageCallback() | Returns a pointer or a reference to the message callback function if it has been defined, null or none otherwise. |
public static void SetProgressDataCallback(ProgressDataCallback progressDataCallback) |
Sets the data callback used to be notified about formatted messages sent by algorithms.
|
public static ProgressDataCallback GetProgressDataCallback() | Returns a pointer or a reference to the data callback function if it has been defined, null or none otherwise. |
public static void SetCancellationCallback(CancellationCallback cancellationCallback) |
Sets the cancellation callback that can be used to interrupt an algorithm before being completed.
|
public static 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;
// 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);