nifreeze.registration package

Registration of each volume to its prediction, through interchangeable backends.

class nifreeze.registration.Registration(self, align_config: 'Mapping | str | PathLike | None' = None, *, seed: 'int | None' = None, num_threads: 'int | None' = None, clip: 'str | bool | None' = 'both', debug_dir: 'str | Path | None' = None, phase_encoding: 'str | None' = None) → 'None'[source]

Bases: ABC

Estimate the transform that maps each point of a fixed image into a moving one.

The fixed image is the model’s prediction; the moving image is the sample, on the same grid. Calls run one at a time (elastix sets ITK’s process-wide thread count).

Parameters:
  • align_config (Mapping or os.pathlike, optional) – The backend’s settings, or a YAML file with a section per backend, such as RIGID (the default) and AFFINE (see load_config()).

  • seed (int, optional) – Seed of the backend’s random sampling.

  • num_threads (int, optional) – Threads of each registration.

  • clip (str, optional) – Clip "sample", "predicted", "both" (default) or "none" of the images to the sample’s intensity window, estimated within the mask.

  • debug_dir (os.pathlike, optional) – Keep predicted_<index>.nii and sample_<index>.nii, the values registered, and aligned_<index>.nii, the sample with its affine corrected by the estimate (a viewer shows it on top of the prediction).

  • phase_encoding (str, optional) – The images’ phase-encoding direction, as BIDS writes PhaseEncodingDirection (i, j or k, with an optional -). Only backends whose settings restrict a field to it use it (see split()).

__call__(fixed: ndarray, moving: ndarray, affine: ndarray, mask: ndarray | None = None, index: int = 0, init: ndarray | None = None) → Affine[source]

Register one volume.

Parameters:
  • fixed, moving (ndarray) – The fixed image (the prediction) and the moving one (the sample).

  • affine (ndarray) – The voxel-to-RAS+ affine of their grid.

  • mask (ndarray, optional) – The mask of the fixed image (the moving one is never masked).

  • index (int, optional) – The volume’s index, which names its files.

  • init (ndarray, optional) – The initial estimate, a RAS+ fixed-to-moving matrix.

Returns:

The fixed-to-moving transform (RAS+), the initialization included.

Return type:

Affine

split(matrix: ndarray, affine: ndarray) → tuple[ndarray, ndarray] | None[source]

Split an estimate into head motion and a field, when the backend models both.

A backend whose settings restrict the field to the phase-encoding direction estimates each mapping as head motion, then that field, and returns the two (see split_phase_encoding()). The others return None, and the estimate is stored whole.

Parameters:
  • matrix (ndarray) – An estimate of this backend, a 4 x 4 RAS+ matrix.

  • affine (ndarray) – The voxel-to-RAS+ affine of the images it was estimated on.

Returns:

The head motion and the field, each a 4 x 4 RAS+ matrix; or None.

Return type:

tuple or None

class nifreeze.registration.RegistrationFactory(self, /, *args, **kwargs)[source]

Bases: object

Build a registration backend by name, as models are built by name.

static init(name: str | None = None, **kwargs: Any) → Registration[source]

Build the backend name (of BACKENDS, or any "module:class").

Without a name, the backend is that of default_backend().

>>> type(RegistrationFactory.init("nifreeze.registration.ants:Ants")).__name__
'Ants'

Submodules