registration
registration.registrator
- class brainles_preprocessing.registration.registrator.Registrator
Bases:
ABC- _abc_impl = <_abc._abc_data object>
- abstract inverse_transform(fixed_image_path: Any, moving_image_path: Any, transformed_image_path: Any, matrix_path: Any, log_file_path: str, interpolator: str = 'default')
Abstract method for inverse transforming images.
- Parameters:
fixed_image_path (Any) – The fixed image to be transformed.
moving_image_path (Any) – The moving image to be transformed.
transformed_image_path (Any) – The resulting transformed image.
matrix_path (Any) – The transformation matrix applied during transformation.
log_file_path (str) – The path to the log file for recording transformation details.
interpolator (str) – The interpolator to be used during transformation.
- abstract register(fixed_image_path: Any, moving_image_path: Any, transformed_image_path: Any, matrix_path: Any, log_file_path: str)
Abstract method for registering images.
- Parameters:
fixed_image_path (Any) – The fixed image for registration.
moving_image_path (Any) – The moving image to be registered.
transformed_image_path (Any) – The resulting transformed image after registration.
matrix_path (Any) – The transformation matrix applied during registration.
log_file_path (str) – The path to the log file for recording registration details.
- abstract transform(fixed_image_path: Any, moving_image_path: Any, transformed_image_path: Any, matrix_path: Any, log_file_path: str, interpolator: str = 'default', **kwargs)
Abstract method for transforming images.
- Parameters:
fixed_image_path (Any) – The fixed image to be transformed.
moving_image_path (Any) – The moving image to be transformed.
transformed_image_path (Any) – The resulting transformed image.
matrix_path (Any) – The transformation matrix applied during transformation.
log_file_path (str) – The path to the log file for recording transformation details.
interpolator (str) – The interpolator to be used during transformation.
registration.ANTs
- class brainles_preprocessing.registration.ANTs.ANTs.ANTsRegistrator(registration_params: Dict[str, Any] | None = None, transformation_params: Dict[str, Any] | None = None)
Bases:
Registrator- _abc_impl = <_abc._abc_data object>
- static _log_to_file(log_file_path: str | Path, fixed_image_path: str | Path, moving_image_path: str | Path, transformed_image_path: str | Path, matrix_path: str | Path, operation_name: str, start_time: datetime, end_time: datetime, interpolator: str | None = None) None
Log the operation details to a file.
- Parameters:
log_file_path (str or Path) – Path to the log file.
fixed_image_path (str or Path) – Path to the fixed image.
moving_image_path (str or Path) – Path to the moving image.
transformed_image_path (str or Path) – Path to the transformed image.
matrix_path (str or Path) – Path to the transformation matrix.
operation_name (str) – Name of the operation (‘registration’ or ‘transformation’).
start_time (datetime.datetime) – Start time of the operation.
end_time (datetime.datetime) – End time of the operation.
interpolator (Optional[str]) – Interpolator used for the transformation, if applicable.
- inverse_transform(fixed_image_path: str | Path, moving_image_path: str | Path, transformed_image_path: str | Path, matrix_path: str | Path | List[str | Path], log_file_path: str | Path, interpolator: str = 'nearestNeighbor', **kwargs) None
Apply an inverse transformation using ANTs.
- Parameters:
fixed_image_path (str or Path) – Path to the fixed image.
moving_image_path (str or Path) – Path to the moving image.
transformed_image_path (str or Path) – Path to the transformed image (output).
matrix_path (str or Path or List[str | Path]) – Path to the transformation matrix or a list of matrices.
log_file_path (str or Path) – Path to the log file.
interpolator (str) – Interpolator to use for the transformation. Default is ‘nearestNeighbor’.
**kwargs – Additional transformation parameters to update the instantiated defaults.
- register(fixed_image_path: str | Path, moving_image_path: str | Path, transformed_image_path: str | Path, matrix_path: str | Path, log_file_path: str | Path, **kwargs) None
Register images using ANTs.
- Parameters:
fixed_image_path (str or Path) – Path to the fixed image.
moving_image_path (str or Path) – Path to the moving image.
transformed_image_path (str or Path) – Path to the transformed image (output).
matrix_path (str or Path) – Path to the transformation matrix (output).
log_file_path (str or Path) – Path to the log file.
**kwargs – Additional registration parameters to update the instantiated defaults.
- Raises:
FileNotFoundError – If the fixed or moving image paths do not exist.
- transform(fixed_image_path: str | Path, moving_image_path: str | Path, transformed_image_path: str | Path, matrix_path: str | Path | List[str | Path], log_file_path: str | Path, interpolator: str = 'nearestNeighbor', **kwargs) None
Apply a transformation using ANTs. By default the padding value corresponds to the minimum of the moving image. Can be adjusted using the defaultvalue parameter.
- Parameters:
fixed_image_path (str or Path) – Path to the fixed image.
moving_image_path (str or Path) – Path to the moving image.
transformed_image_path (str or Path) – Path to the transformed image (output).
matrix_path (str or Path or List[str | Path]) – Path to the transformation matrix or a list of matrices.
log_file_path (str or Path) – Path to the log file.
interpolator (str) – Interpolator to use for the transformation. Default is ‘nearestNeighbor’.
**kwargs – Additional transformation parameters to update the instantiated defaults.
- Raises:
AssertionError – If the interpolator is not valid.
FileNotFoundError – If the fixed or moving image paths do not exist.
registration.niftyreg
- class brainles_preprocessing.registration.niftyreg.niftyreg.NiftyRegRegistrator(registration_abspath: str = '/home/docs/checkouts/readthedocs.org/user_builds/brainles-preprocessing/checkouts/stable/brainles_preprocessing/registration/niftyreg', registration_script: str | None = None, transformation_script: str | None = None)
Bases:
Registrator- _abc_impl = <_abc._abc_data object>
- _compose_affine_transforms(transform_paths: List[str | Path], output_path: str | Path) None
Compose a list of affine transform matrices (4x4), applied in order. i.e., output = Tn @ Tn-1 @ … @ T1
- Parameters:
transform_paths (list of str or Path) – Paths to .txt files with 4x4 affine matrices.
output_path (str or Path) – Where to save the composed transform.
- Returns:
None
- _invert_affine_transform(transform_path: str | Path, output_path: str | Path) None
Invert a single affine transform matrix (4x4) and save it.
- Parameters:
transform_path (str or Path) – Path to the .txt file with the 4x4 affine matrix.
output_path (str or Path) – Where to save the inverted transform.
- Returns:
None
- inverse_transform(fixed_image_path: str, moving_image_path: str, transformed_image_path: str, matrix_path: str | Path | List[str | Path], log_file_path: str, interpolator: str = '0') None
Apply inverse transformation using NiftyReg.
- Parameters:
fixed_image_path (str) – Path to the fixed image.
moving_image_path (str) – Path to the moving image.
transformed_image_path (str) – Path to the transformed image (output).
matrix_path (str | Path | List[str | Path]) – Path(s) to the transformation matrix(es) in inverse order.
log_file_path (str) – Path to the log file.
interpolator (str) – Interpolation order (0, 1, 3, 4) (0=NN, 1=LIN; 3=CUB, 4=SINC), Default is ‘1’ (linear).
- register(fixed_image_path: str, moving_image_path: str, transformed_image_path: str, matrix_path: str | Path, log_file_path: str) None
Register images using NiftyReg.
- Parameters:
fixed_image_path (str) – Path to the fixed image.
moving_image_path (str) – Path to the moving image.
transformed_image_path (str) – Path to the transformed image (output).
matrix_path (str) – Path to the transformation matrix (output).
log_file_path (str) – Path to the log file.
- transform(fixed_image_path: str, moving_image_path: str, transformed_image_path: str, matrix_path: str | Path | List[str | Path], log_file_path: str, interpolator: str = '0', **kwargs: dict) None
Apply a transformation using NiftyReg. By default the padding value corresponds to the minimum of the moving image.
- Parameters:
fixed_image_path (str) – Path to the fixed image.
moving_image_path (str) – Path to the moving image.
transformed_image_path (str) – Path to the transformed image (output).
matrix_path (str | Path | List[str | Path]) – Path(s) to the transformation matrix(es).
log_file_path (str) – Path to the log file.
interpolator (str) – Interpolation order (0, 1, 3, 4) (0=NN, 1=LIN; 3=CUB, 4=SINC). Default is ‘1’ (linear).
- Raises:
AssertionError – If the interpolator is not valid.
registration.greedy
- class brainles_preprocessing.registration.greedy.greedy.GreedyRegistrator
Bases:
Registrator- _abc_impl = <_abc._abc_data object>
- inverse_transform(fixed_image_path: str, moving_image_path: str, transformed_image_path: str, matrix_path: str, log_file_path: str | None = None, interpolator: str = 'linear') None
Abstract method for inverse transforming images.
- Parameters:
fixed_image_path (Any) – The fixed image to be transformed.
moving_image_path (Any) – The moving image to be transformed.
transformed_image_path (Any) – The resulting transformed image.
matrix_path (Any) – The transformation matrix applied during transformation.
log_file_path (str) – The path to the log file for recording transformation details.
interpolator (str) – The interpolator to be used during transformation.
- register(fixed_image_path: str, moving_image_path: str, transformed_image_path: str, matrix_path: str, log_file_path: str | None = None) None
Register images using greedy. Ref: https://pypi.org/project/picsl-greedy/ and https://greedy.readthedocs.io/en/latest/reference.html#greedy-usage.
This is an optional dependency - to use this registrator, you need to install the brainles_preprocessing package with the picsl_greedy extra: pip install brainles_preprocessing[picsl_greedy].
- Parameters:
fixed_image_path (str) – Path to the fixed image.
moving_image_path (str) – Path to the moving image.
transformed_image_path (str) – Path to the transformed image (output).
matrix_path (str) – Path to the transformation matrix (output). This gets overwritten if it already exists.
log_file_path (Optional[str]) – Path to the log file, which is not used.
- transform(fixed_image_path: str, moving_image_path: str, transformed_image_path: str, matrix_path: str, log_file_path: str | None = None, interpolator: str = 'LINEAR', **kwargs: dict | None) None
Apply a transformation using greedy.
- Parameters:
fixed_image_path (str) – Path to the fixed image.
moving_image_path (str) – Path to the moving image.
transformed_image_path (str) – Path to the transformed image (output).
matrix_path (str) – Path to the transformation matrix (output). This gets overwritten if it already exists.
log_file_path (Optional[str]) – Path to the log file, which is not used.
interpolator (Optional[str]) – The interpolator to use; one of NN, LINEAR or LABEL. Defaults to LINEAR.
registration.elastix
- class brainles_preprocessing.registration.elastix.elastix.ElastixRegistrator
Bases:
Registrator- __initialize_parameter_object() elastixParameterObject
Initialize the parameter object for elastix registration.
- Returns:
The parameter object for registration.
- Return type:
itk.ParameterObject
- _abc_impl = <_abc._abc_data object>
- inverse_transform(fixed_image_path: str, moving_image_path: str, transformed_image_path: str, matrix_path: str, log_file_path: str | None = None, interpolator: str = 'linear') None
Abstract method for inverse transforming images.
- Parameters:
fixed_image_path (Any) – The fixed image to be transformed.
moving_image_path (Any) – The moving image to be transformed.
transformed_image_path (Any) – The resulting transformed image.
matrix_path (Any) – The transformation matrix applied during transformation.
log_file_path (str) – The path to the log file for recording transformation details.
interpolator (str) – The interpolator to be used during transformation.
- register(fixed_image_path: str, moving_image_path: str, transformed_image_path: str, matrix_path: str, log_file_path: str | None = None, parameter_object: elastixParameterObject | None = None) None
Register images using elastix.
This is an optional dependency - to use this registrator, you need to install the brainles_preprocessing package with the itk-elastix extra: pip install brainles_preprocessing[itk-elastix].
- Parameters:
fixed_image_path (str) – Path to the fixed image.
moving_image_path (str) – Path to the moving image.
transformed_image_path (str) – Path to the transformed image (output).
matrix_path (str) – Path to the transformation matrix (output). This gets overwritten if it already exists.
log_file_path (Optional[str]) – Path to the log file.
parameter_object (Optional[itk.ParameterObject]) – The parameter object for elastix registration.
- transform(fixed_image_path: str, moving_image_path: str, transformed_image_path: str, matrix_path: str, log_file_path: str | None = None, interpolator: str = 'linear', **kwargs) None
Apply a transformation using elastix.
- Parameters:
fixed_image_path (str) – Path to the fixed image.
moving_image_path (str) – Path to the moving image.
transformed_image_path (str) – Path to the transformed image (output).
matrix_path (str) – Path to the transformation matrix (output). This gets overwritten if it already exists.
log_file_path (Optional[str]) – Path to the log file.