nifreeze.registration.elastix module

Registration with elastix, through itk-elastix (the elastix extra).

The images pass to elastix in memory: no files, unlike ANTs’ command line. Elastix is a Registration: register(fixed, moving, affine, mask, index, init) returns the transform that maps each point of the fixed image (the model’s prediction) onto the moving image (the sample), in RAS+.

The images reach elastix with the values ANTs reads: clipped to the sample’s window (as clip selects) and coded to 12 bits (as _to_nifti() writes them), then winsorized and histogram-matched with ANTs’ parameters, when the settings ask for it. Only the fixed image is masked.

Settings are the elastix sections of RIGID and AFFINE (or of any such file): one elastix parameter map per stage, with the values that depend on the data filled at each call.

class nifreeze.registration.elastix.Elastix(self, align_config: 'Mapping[str, Any] | str | PathLike | None' = None, *, seed: 'int | None' = 12345, **kwargs: 'Any') → 'None'[source]

Bases: Registration

Register with elastix, given the images in memory.

Parameters:
  • align_config (Mapping or os.pathlike, optional) – Elastix’s settings, or a file with an elastix section (see get_settings()).

  • seed (int, optional) – Seed of elastix’s random sampling (RandomSeed); None leaves elastix’s default.

  • **kwargs – See Registration. With num_threads set, estimates repeat bit for bit at a fixed seed.

nifreeze.registration.elastix.LPS = array([[-1.,  0.,  0.,  0.],        [ 0., -1.,  0.,  0.],        [ 0.,  0.,  1.,  0.],        [ 0.,  0.,  0.,  1.]])

The change between RAS+ and ITK’s LPS world (its own inverse).

nifreeze.registration.elastix.MATCH_LEVELS = 256

Histogram levels of ANTs’ histogram matching.

nifreeze.registration.elastix.MATCH_POINTS = 12

Match points of ANTs’ histogram matching.

nifreeze.registration.elastix.NO_STAGES_ERROR_MSG = 'Elastix settings need at least one stage'

Settings without stages error message.

nifreeze.registration.elastix.SETTINGS_KEYS = {'stages', 'use_histogram_matching', 'winsorize_lower_quantile', 'winsorize_upper_quantile'}

The keys of a settings file.

nifreeze.registration.elastix.STAGE_KEYS = {'parameters', 'sampling_percentage', 'shrink_factor', 'smoothing_sigma'}

The keys of a stage.

nifreeze.registration.elastix.UNKNOWN_SETTINGS_ERROR_MSG = 'Unknown elastix settings: {keys}'

Unknown settings error message.

nifreeze.registration.elastix.WINSORIZE_BINS = 256

Bins of the histogram from which ANTs takes the winsorizing quantiles.

nifreeze.registration.elastix.get_settings(align_config: Mapping[str, Any] | str | PathLike | None = None) → dict[source]

Read elastix settings.

Parameters:

align_config (Mapping or os.pathlike, optional) – Elastix’s settings, or a file with an elastix section (default: RIGID).

Returns:

A copy of the settings, validated.

Return type:

dict

Examples

>>> settings = get_settings()
>>> [stage["parameters"]["Transform"] for stage in settings["stages"]]
[['EulerTransform'], ['EulerTransform']]
>>> from nifreeze.registration import AFFINE
>>> get_settings(AFFINE)["stages"][0]["parameters"]["Transform"]
['AffineTransform']
>>> get_settings({"stages": [{"parameters": {}, "smoothing": 1}]})
Traceback (most recent call last):
ValueError: Unknown elastix settings: ['smoothing']