kwneuro.reg module

class kwneuro.reg.TransformResource(_ants_fwd_paths, _ants_inv_paths, _matrices=None, _warps=None)

Bases: object

A wrapper for ANTs registration results that simplifies viewing and applying transforms. While the underlying transform files are always stored on-disk, they remain in a temporary directory until explicitly persisted via the save() method.

Parameters:
apply(fixed, moving, invert=False, interpolation='linear')

Wrapper around ants.apply_transforms using this result.

Parameters:
Return type:

InMemoryVolumeResource

static initialize_from_ants(ants_result)

Initializes a TransformResource from an ANTs registration result by wrapping references to the temporary transform files generated by ANTs.

Parameters:

ants_result (dict[str, list[str]])

Return type:

TransformResource

property matrices: list[ANTsTransform]

Returns the affine transform if it exists.

save(output_dir)

Copies the underlying ANTs transformation files to a permanent directory and returns a new TransformResource pointing to the saved locations

Parameters:

output_dir (Path | str)

Return type:

TransformResource

property warp_fields: list[InMemoryVolumeResource]

Returns the non-linear displacement field if it exists.

kwneuro.reg.register_volumes(fixed, moving, type_of_transform='SyN', mask=None, moving_mask=None)

Registers a moving volume to a fixed reference volume using ANTs.

Parameters:
  • fixed (VolumeResource) – The reference volume.

  • moving (VolumeResource) – The volume to be warped.

  • type_of_transform (str) – The transformation model (e.g., “SyN”, “Rigid”). The full list of supported transforms can be found in the ANTs documentation.

  • mask (VolumeResource | None) – Optional mask for the fixed image space.

  • moving_mask (VolumeResource | None) – Optional mask for the moving image space.

Return type:

tuple[InMemoryVolumeResource, TransformResource]

Returns:

A tuple containing the registered volume and the transform object.