nispace.utils.utils.mirror_nifti

nispace.utils.utils.mirror_nifti(img, affine=None, direction='left_to_right', match_r=False, mask=None)[source]

Mirror/flip a volumetric image across the (affine-derived) x=0 hemisphere boundary.

Plain numpy/nibabel (no numba). Not currently called anywhere in NiSpace (dead code) — kept as a public utility. match_r/mask parameters are accepted but currently unused by the implementation.

Parameters:
  • img (np.ndarray or image-like) – Input volume. If an array, affine must be provided.

  • affine (np.ndarray, optional) – 4x4 affine; required when img is an array, otherwise taken from img itself.

  • direction (str, default="left_to_right") – One of "left_to_right"/"right_to_left" (overwrite one hemisphere with the mirrored other), "average"/"bilateral" (average both mirrored hemispheres), "switch" (swap hemispheres), or "drop_left"/"drop_right" (zero out one hemisphere).

  • match_r (bool, optional) – Currently unused.

  • mask (optional) – Currently unused.

Returns:

Mirrored volume, same type as the input (array in, array out).

Return type:

np.ndarray or nibabel.Nifti1Image

Raises:

ValueError – If img is an array without affine, if img is not 3D, or if direction is not one of the supported modes.