nifreeze.registration.itk_backend module¶
Registration with ITK’s registration framework (the …v4 classes of ITK 5).
ITK’s framework optimizes several transforms together, which elastix’s does not. So
this backend can estimate each volume’s mapping as head motion followed by a field along
the phase-encoding direction, \(W = E M\), with 9 parameters (6 rigid, and the
phase-encoding row of \(E\); see
split_phase_encoding()), when the settings say
restrict: phase-encoding. Otherwise it estimates a full affine (12 parameters).
With motion: fixed as well, the head motion stays as the start gives it (in the
eddy-current pass, the head-motion step’s estimate), and only the field’s 3 parameters
are estimated, about the grid’s centre. The estimates are then not split: the
eddy-current pass stores them as it stores elastix’s, with the head motion it holds
factored out and kept unchanged.
The images reach ITK in their voxel frame (identity direction, origin zero, the voxel
spacing), so ITK’s physical axes are the voxel axes, and the restriction to the
phase-encoding axis, an axis of the data array, is exact on oblique data. The estimate
goes back to RAS+. The images are prepared as the elastix backend prepares them:
clipped to the sample’s window and coded to 12 bits (as clip selects), then
winsorized and histogram-matched when the settings ask. Only the fixed image is masked.
Settings are the itk sections of AFFINE (or of
any such file), with one registration per stage. A stage samples its metric on a share of
the grid (sampling_percentage), or at a number of points within the mask
(samples), as elastix’s random samplers do: its cost then does not grow with the grid.
- nifreeze.registration.itk_backend.BOTH_SAMPLINGS_ERROR_MSG = 'An ITK stage takes sampling_percentage or samples, not both'¶
A stage with both a share and a count of samples error message.
- nifreeze.registration.itk_backend.FIXED_MOTION_ERROR_MSG = 'ITK settings keep the head motion fixed only with restrict: phase-encoding'¶
Fixed head motion without the restriction error message.
- class nifreeze.registration.itk_backend.ITK(self, align_config: 'Mapping[str, Any] | str | PathLike | None' = None, *, seed: 'int | None' = 12345, **kwargs: 'Any') 'None'[source]¶
Bases:
RegistrationRegister with ITK’s registration framework, given the images in memory.
- Parameters:
align_config (
Mappingoros.pathlike, optional) – ITK’s settings, or a file with anitksection (seeget_settings()).seed (
int, optional) – Seed of the metrics’ random sampling;Noneleaves ITK’s.**kwargs – See
Registration. With settings restricted to phase encoding,phase_encodingis required.
- split(matrix: ndarray, affine: ndarray) tuple[ndarray, ndarray] | None[source]¶
See
split().With
motion: fixed, the head motion was not estimated, so there is nothing to split: the field, about the grid’s centre, carries its own shift along phase encoding, which the split would move into the head motion.
- nifreeze.registration.itk_backend.METRICS = ('mattes', 'correlation')¶
Mattes’ mutual information, or normalized correlation.
- Type:
The metrics of a stage
- nifreeze.registration.itk_backend.MOTIONS = ('refine', 'fixed')¶
refine it, or keep the start’s.
- Type:
What a restricted registration does with the head motion
- nifreeze.registration.itk_backend.NO_PHASE_ENCODING_ERROR_MSG = "The settings restrict the field to phase encoding, but its direction is unknown: give the backend phase_encoding (the dataset's, as BIDS writes it)."¶
Restricted settings without a phase-encoding direction error message.
- nifreeze.registration.itk_backend.NO_STAGES_ERROR_MSG = 'ITK settings need at least one stage'¶
Settings without stages error message.
- nifreeze.registration.itk_backend.OUTSIDE_FAMILY_WARN_MSG = "Volume {index}'s initial mapping is not head motion followed by a field along phase encoding; the registration starts from its projection."¶
An initial mapping outside the 9-parameter family warning message.
- nifreeze.registration.itk_backend.RESTRICTIONS = ('phase-encoding',)¶
The fields a setting
restrictcan name.
- nifreeze.registration.itk_backend.SAMPLINGS = ('none', 'regular', 'random')¶
The samplings of a stage’s metric.
- nifreeze.registration.itk_backend.SETTINGS_KEYS = {'motion', 'restrict', 'stages', 'use_histogram_matching', 'winsorize_lower_quantile', 'winsorize_upper_quantile'}¶
The keys of a settings file.
- nifreeze.registration.itk_backend.STAGE_KEYS = {'bins', 'gradient_tolerance', 'iterations', 'learning_rate', 'metric', 'minimum_step', 'relaxation', 'samples', 'sampling', 'sampling_percentage', 'shrink_factor', 'smoothing_sigma'}¶
The keys of a stage.
- nifreeze.registration.itk_backend.UNKNOWN_SETTINGS_ERROR_MSG = 'Unknown ITK settings: {keys}'¶
Unknown settings error message.
- nifreeze.registration.itk_backend.UNKNOWN_VALUE_ERROR_MSG = 'Unknown ITK {key} {value!r}: expected one of {values}'¶
Unknown value of a setting error message.
- nifreeze.registration.itk_backend.get_settings(align_config: Mapping[str, Any] | str | PathLike | None = None) dict[source]¶
Read and validate ITK settings.
- Parameters:
align_config (
Mappingoros.pathlike, optional) – The settings, or a file with anitksection (default:AFFINE).- Returns:
A copy of the settings, validated.
- Return type:
Examples
>>> settings = get_settings() >>> settings["restrict"], [stage["metric"] for stage in settings["stages"]] ('phase-encoding', ['mattes', 'correlation'])
>>> get_settings({"stages": [{"metric": "mattes", "smoothing": 1}]}) Traceback (most recent call last): ValueError: Unknown ITK settings: ['smoothing']
>>> get_settings(settings | {"motion": "fixed"})["motion"] 'fixed'