engine#

class AlignmentTool(data_dir: str | Path, fixed_image: ITKImage = None, moving_image: ITKImage = None, fixed_landmarks_name: str = 'fixed_points.pts', moving_landmarks_name: str = 'moving_points.pts')[source]#

Bases: object

A class to perform registration using elastix and landmarks (points) files.

get_points(as_index=False)[source]#

Get fixed and moving points arrays

Arguments

as_index (bool, optional):
Whether the output should be in index coords. Defaults to False.

If False, the output arrays will be in physical coords.

Returns

tuple[np.array, np.array]: fixed_pts, moving_pts

perform_registration(parameters=None, delete_tmp=True, debug=False, write_transformed_points=False)[source]#

Perform the registration using the current fixed and moving images and the current registration parameters unless new parameters are passed.

Parameters:
  • parameters (elastixParameterObject, optional) – The parameters to be used in the next registration. Defaults to None.

  • delete_tmp (bool, optional) – Whether to delete the temporary files created during the registration. Defaults to True.

  • debug (bool, optional) – Whether to log the registration to the console. Defaults to False.

  • write_transformed_points (bool, optional) – Whether to write the transformed points to a file. Defaults to False.

set_next_registration_parameters(parameters)[source]#

Set the parameters for the next registration and shift the current result image to the moving image

Parameters:

parameters (elastixParameterObject) – The parameters to be used in the next registration

set_points(fixed_points, moving_points, as_index=False)[source]#

Set corresponding points (index) position from n x dim point array

Arguments

fixed_points: np.array

the array of moving points

moving_points: np.array

the array of moving points

as_index: bool

Whether the passed points are already in index coords. Defaults to False.

try_load_points()[source]#
class ElastixPointFileManager(data_dir)[source]#

Bases: object

A class to handle the reading and writing of points in elastix/transformix format. This is a text file with the following format: point # this can be point or index n_points # the number of points to be found below x1 y1 z1 x2 y2 z2 …

delete(filenames)[source]#
path(filename)[source]#
read(filename)[source]#

Parses the output points from the output file of transformix

Arguments

filenamestr | Path

File name of the transformix output file.

Returns

pointsarray

The points coordinates in index coords.

write(points, filename=None, prefix='')[source]#

Write points as elastix/transformix point file, in physical coords

Arguments

pointsnp.array

array of coords in physical coords

filenamestr

File name of the elastix point file.

prefixstr

Prefix to be added to the filename.

Returns

filename: str

File name of the elastix point file.