ICP with ITK Backend
ICP registration using ITK’s optimized implementation.
Class Reference
- class monai_physio.RegisterModelsICPITK(fixed_model, rotation_axis=None, number_of_points=5000, log_level=20)[source]
Bases:
RegisterModelsICPRegister surface models by ICP, optionally rotating about one axis only.
The pipelines, transform conventions and results are those of
RegisterModelsICP; only the ICP stages differ. Each stage optimizes an ITK transform whose parameters split rotation from the other degrees of freedom, so rotation can be restricted per axis:Rigid:
VersorRigid3DTransformSimilarity:
Similarity3DTransformAffine:
ComposeScaleSkewVersor3DTransform
With
rotation_axisset, the versor components about the other two axes are held at zero, and the affine stage’s skews that couplerotation_axisto another axis are held at zero too, since such a skew tilts that axis just as a rotation would. Scale and translation stay free along every axis.Each stage starts from the previous stage’s result, rotates and scales about the moving model’s current centroid, and pairs every sampled moving point with its closest fixed point, as ICP does.
- rotation_axis
World axis (0, 1 or 2) the stages may rotate about, or None for unrestricted rotation.
- Type:
Optional[int]
- __init__(fixed_model, rotation_axis=None, number_of_points=5000, log_level=20)[source]
Initialize ITK ICP model registration.
- Parameters:
fixed_model (
PolyData) – PyVista target surface model.rotation_axis (
Optional[int]) – World axis, 0, 1 or 2, that the alignment may rotate about; rotation about the other two is not allowed. For example 2 for axial CT or MR, where patients lie along the scanner’s z-axis and only in-plane rotation is expected. Default: None (rotation about any axis).number_of_points (
int) – Moving-model points, sampled evenly through the point list, that each stage pairs with the fixed model. All fixed-model points are candidates. Default: 5000log_level (
int|str) – Logging level. Default: logging.INFO
- Raises:
ValueError – If rotation_axis is not None, 0, 1 or 2.
- classmethod get_log_classes()
Get the list of classes currently showing logs.
- Return type:
- Returns:
List of class names that are allowed to show logs. Empty list if filter is disabled (all classes shown).
Example
>>> classes = MONAIPhysioBase.get_log_classes() >>> print(classes) ['RegisterModelsPCA', 'WorkflowFitStatisticalModelToPatient']
- log_critical(message, *args)
Log a critical message with optional %-style formatting.
- Parameters:
- Return type:
Example
>>> self.log_critical('System failure at %s', timestamp) >>> self.log_critical('Critical error: %(msg)s', {'msg': 'Out of memory'})
- log_debug(message, *args)
Log a debug message with optional %-style formatting.
- Parameters:
- Return type:
Example
>>> self.log_debug('Processing %s with %d items', filename, count) >>> self.log_debug('Value is %(value)d', {'value': 42})
- log_error(message, *args)
Log an error message with optional %-style formatting.
- Parameters:
- Return type:
Example
>>> self.log_error('Failed to load %s: %s', filename, error_msg) >>> self.log_error('Error code: %(code)d', {'code': 404})
- log_info(message, *args)
Log an info message with optional %-style formatting.
- Parameters:
- Return type:
Example
>>> self.log_info('Loading file: %s', filepath) >>> self.log_info('Iteration %(iter)d of %(total)d', {'iter': 5, 'total': 10})
- log_progress(current, total, prefix='Progress', *, log=True)
Log progress information and report it to the progress callback.
current / totalis also reported, within the current range, to the callback set byset_progress_callback().- Parameters:
- Return type:
Example
>>> for i in range(100): ... self.log_progress(i + 1, 100) >>> self.log_progress(5, 10, prefix='Processing')
Note
For custom formatted progress messages, use log_info() directly: >>> self.log_info(‘Loading %s: %d/%d’, filename, current, total)
- log_section(title, *args, width=70, char='=')
Log a formatted section header with optional %-style formatting.
Useful for visually separating major sections of output.
- Parameters:
- Return type:
Example
>>> self.log_section('Stage 1: Initialization') >>> self.log_section('Processing file: %s', filename) >>> self.log_section('Stage %(num)d: %(name)s', {'num': 2, 'name': 'Analysis'}) # Outputs: # ====================================================================== # Stage 2: Analysis # ======================================================================
- log_warning(message, *args)
Log a warning message with optional %-style formatting.
- Parameters:
- Return type:
Example
>>> self.log_warning('Memory usage at %d%%', usage_percent) >>> self.log_warning('Parameter %(name)s out of range', {'name': 'threshold'})
- register(moving_model)
Register
moving_modelto the fixed model.Calls
registration_method()and keeps its standard results on the instance.- Parameters:
moving_model (
DataSet) – Model to align to the fixed model.- Returns:
registered_model,moving_to_fixed_transform,fixed_to_moving_transformand any keys the subclass adds.- Return type:
The hook’s dictionary
- registration_method(moving_model)
Perform ICP alignment of moving model to fixed model.
The
register()hook; it uses the transform type and iteration limit set byset_transform_type()andset_max_iterations().- Rigid transform type (rotation + translation):
Centroid alignment: Translate moving model to align mass centers
Rigid ICP: Refine with rigid-body transformation
- Similarity transform type (rotation + translation + one uniform scale):
Centroid alignment: Translate moving model to align mass centers
- Bounding-box scaling: Scale isotropically about the fixed centroid
so the two bounding-box diagonals match, which keeps ICP’s closest-point search from locking onto a size mismatch
Similarity ICP: Refine rotation, translation and uniform scale
- Affine transform type (adds anisotropic scale and shear):
Centroid alignment: Translate moving model to align mass centers
Bounding-box scaling: As above
Similarity ICP: Refine rotation, translation and uniform scale
Affine ICP: Further refine with affine transformation
‘Rigid’ skips the bounding-box scaling so its result stays a pure rigid-body transform; use ‘Similarity’ when the models differ in size but the shape should not be distorted.
- Parameters:
moving_model (
DataSet) – PyVista surface model to be aligned to fixed model- Returns:
‘registered_model’: Aligned moving model (PyVista PolyData)
- ’moving_to_fixed_transform’: Moving-to-fixed transform
(ITK AffineTransform)
- ’fixed_to_moving_transform’: Fixed-to-moving transform
(ITK AffineTransform)
- Return type:
Dictionary containing
- set_fixed_model(fixed_model)
Replace the target model and forget the previous results.
- Parameters:
fixed_model (
DataSet) – New target model.- Return type:
- classmethod set_log_all_classes()
Enable logging output from all MONAI Physio classes.
Disables the class filter so all classes show their logs.
Example
>>> MONAIPhysioBase.set_log_all_classes() >>> # Now all classes will show their logs
- Return type:
- classmethod set_log_classes(class_names)
Set which classes should show their logging output.
Only log messages from the specified classes will be displayed. All other classes will have their logs hidden.
- Parameters:
class_names (
list[str]) – List of class names to show logs from. Example: [“RegisterModelsPCA”, “WorkflowFitStatisticalModelToPatient”]- Return type:
Example
>>> MONAIPhysioBase.set_log_classes(['RegisterModelsPCA']) >>> # Now only RegisterModelsPCA logs will be shown
- classmethod set_log_level(log_level)
Set a floor on the logging level of every MONAI Physio object.
Each object logs at its own
log_level; messages below this floor are dropped whatever that level is. Lowering the floor does not make an object log below its ownlog_level.- Parameters:
log_level (
int|str) – Logging level. Can be an integer (logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL) or a string (‘DEBUG’, ‘INFO’, ‘WARNING’, ‘ERROR’, ‘CRITICAL’).- Return type:
Example
>>> import logging >>> MONAIPhysioBase.set_log_level(logging.DEBUG) >>> # or >>> MONAIPhysioBase.set_log_level('DEBUG')
- set_max_iterations(max_iterations)
Set the maximum number of ICP iterations per stage.
- Parameters:
max_iterations (
int) – Maximum iterations per stage. Default: 2000- Raises:
ValueError – If max_iterations is less than 1.
- Return type:
- classmethod set_progress_callback(progress_callback)
Set the callback that receives progress from all MONAI Physio classes.
Like the log level, this is shared: set it once and every workflow and registrar reports to it, including those a workflow runs internally.
Each long-running method reports a fraction in
[0, 1]and a short message. A workflow divides that range among its steps once, as if every optional step ran; a step that is disabled is skipped, so the fraction jumps over its share. The fraction never decreases during a run and reaches 1.0 when the run completes. Progress from runs in concurrent threads is not kept apart.- Parameters:
progress_callback (
Optional[Callable[[float,str],None]]) – Receives each fraction and message, orNoneto stop reporting.- Return type:
Example
>>> def show(fraction: float, message: str) -> None: ... print(f"{fraction:6.1%} {message}") >>> MONAIPhysioBase.set_progress_callback(show) >>> result = workflow.process()
- set_transform_type(transform_type)
Choose the registration transform: ‘Rigid’, ‘Similarity’ or ‘Affine’.
- Parameters:
transform_type (
str) – Transform type. Default: ‘Affine’- Raises:
ValueError – If transform_type is not ‘Rigid’, ‘Similarity’ or ‘Affine’
- Return type:
Navigation
ICP (Iterative Closest Point) | Model Registration Modules | Distance Map Registration