joint_registration
Joint registration
When calling register_vols with transformation_type set to joint, either SimpleITK or a custom combination (e.g. HyReg + SimpleITK elastic) can be used. Per default, the combination of HyReg + SimpleITK elastic is used. The config parameter allows for additional, framework specific settings. For all framework specific arguments, the reader should refer to vireg.inference.configs.configs.py.
Suggested use: For joint registration, the default registration method consisting of HyReg + SimpleITKe elastic is recommended.
SimpleITK registration
It is possible to register volumes entirely within the SimpleITK framework.
from vicom import Volume
from vireg.inference import register_vols, apply_transform
# Define vicom volumes to register
fixed_volume: Volume = ...
moving_volume: Volume = ...
fixed_mask: Volume | None
config: dict | None = ...
"""
Possible parameters for config
------------------------------
n_iterations_affine: int = 140
n_iterations_elastic: int = 140
n_resolutions: int = 1
metric: str = "AdvancedMattesMutualInformation"
n_histogram_bins: int = 128
reg_weight: int = 200
grid_spacing: int = 8
fast_run: bool = False
n_threads: int = 20
"""
# perform affine registration with torch
# the returned transform goes from moving to fixed
registered_vol, transform = register_vols(
fixed_volume,
moving_volume,
fixed_mask,
registration_method="sitk",
transformation_type="joint",
interpolation_mode = 'bspline', # or "bilinear", "nearest", "bspline"
config=config,
return_transform = True
)
# apply the transform to another image (i.e. a mask)
registered_mask = apply_transform(moving_mask, transform_params=transform, interpolation_mode = 'nearest')
Custom registration
By setting the registration_method to custom, it is possible to define the individual registration components for both affine and elastic registration. By default, HyReg and SimpleITK are used sequentially. If it is desired to change the parameters of these indivdual components, the config dictionary can be defined accordingly (see vireg.inference.configs.configs for reference).
from vicom import Volume
from vireg.inference import register_vols, apply_transform
# Define vicom volumes to register
fixed_volume: Volume = ...
moving_volume: Volume = ...
fixed_mask: Volume | None
config: dict | None = ...
"""
Possible parameters for config
------------------------------
affine_model_cfg: InferenceModelConfig | None = None
elastic_model_cfg: InferenceModelConfig | None = None
config: dict = , "sitk_config":
"""
# perform affine registration with torch
# the returned transform goes from moving to fixed
registered_vol, transform = register_vols(
fixed_volume,
moving_volume,
fixed_mask,
registration_method="custom",
transformation_type="joint",
interpolation_mode = 'bilinear', # or "bilinear", "nearest"
config=config,
return_transform = True
)
# apply the transform to another image (i.e. a mask)
registered_mask = apply_transform(moving_mask, transform_params=transform, interpolation_mode = 'nearest')
Elastic registration
It is possible to perform elastic registration only. For such cases, setting the transformation_type to elastic and the transformation_type to one of sitk or dl will use the corresponding frameworks.