albumentations.augmentations.medical.functional


Deterministic medical acquisition and intensity operations.

gibbs_ringingfunction

gibbs_ringing(
    img: NDArray[np.uint8] | NDArray[np.float16] | NDArray[np.float32],
    retained_fraction: float
)

Truncate a channel-last image or volume spectrum to a conjugate-symmetric central box. Spatial axes use signed frequency bins with abs(k) <= floor(retained_fraction * length / 2). Zeroing slabs of the real half-spectrum avoids shifted spectra and a dense spatial mask. Strong truncation transforms only retained last-axis frequencies over the remaining axes. The full owned spectrum is reused before the final real inverse, limiting temporary storage.

Parameters

NameTypeDefaultDescription
img
One of:
  • NDArray[np.uint8]
  • NDArray[np.float16]
  • NDArray[np.float32]
--
retained_fractionfloat--

bias_fieldfunction

bias_field(
    img: NDArray[np.uint8] | NDArray[np.float16] | NDArray[np.float32],
    coarse_field: np.ndarray,
    is_batch: bool = False
)

Upsample a Gaussian log-gain grid, exponentiate it, and multiply image or volume intensities. The coarse grid has spatial axes followed by channels. A leading image/volume batch axis in `img` shares one generated field; no interpolation occurs across batch or channel axes.

Parameters

NameTypeDefaultDescription
img
One of:
  • NDArray[np.uint8]
  • NDArray[np.float16]
  • NDArray[np.float32]
--
coarse_fieldnp.ndarray--
is_batchboolFalse-

generate_bias_fieldfunction

generate_bias_field(
    coarse_field: np.ndarray,
    spatial_shape: tuple[int, ...]
)

Interpolate a float32 channel-last 2D or 3D log-gain grid and exponentiate it. Bilinear/trilinear interpolation preserves the channel count. The input coefficients remain unchanged.

Parameters

NameTypeDefaultDescription
coarse_fieldnp.ndarray--
spatial_shapetuple[int, ...]--

rician_noisefunction

rician_noise(
    img: NDArray[np.uint8] | NDArray[np.float16] | NDArray[np.float32],
    real_noise: np.ndarray,
    imaginary_noise: np.ndarray
)

Apply sampled real and imaginary MRI noise fields through magnitude reconstruction.

Parameters

NameTypeDefaultDescription
img
One of:
  • NDArray[np.uint8]
  • NDArray[np.float16]
  • NDArray[np.float32]
--
real_noisenp.ndarray--
imaginary_noisenp.ndarray--

k_space_spikefunction

k_space_spike(
    img: NDArray[np.uint8] | NDArray[np.float16] | NDArray[np.float32],
    spikes: np.ndarray,
    intensity: float
)

Apply Hermitian MRI Fourier spikes to channel-last images and volumes. Each spike adds a real amplitude `intensity * max|F|` at its frequency bin and at the conjugate mirror. Large normalized float32 volumes with up to five shared spikes and intensity <= 1 use cosine waves. Other inputs retain real FFT reconstruction, including the uint8 rounding behavior.

Parameters

NameTypeDefaultDescription
img
One of:
  • NDArray[np.uint8]
  • NDArray[np.float16]
  • NDArray[np.float32]
--
spikesnp.ndarray--
intensityfloat--

ghosting_artifactfunction

ghosting_artifact(
    volume: NDArray[np.uint8] | NDArray[np.float16] | NDArray[np.float32],
    num_ghosts: int,
    intensity: float,
    axis: int,
    restore: float
)

Attenuate conjugate-symmetric periodic frequency planes outside a protected central band. The plane mask depends only on the selected spatial frequency. Transforms of the other axes cancel, so one axis-wise real FFT implements the full 3D spectral-plane filter without full-volume complex FFTs.

Parameters

NameTypeDefaultDescription
volume
One of:
  • NDArray[np.uint8]
  • NDArray[np.float16]
  • NDArray[np.float32]
--
num_ghostsint--
intensityfloat--
axisint--
restorefloat--

motion_artifactfunction

motion_artifact(
    volume: VolumeType,
    matrices: np.ndarray,
    boundaries: tuple[int, ...],
    axis: int,
    interpolation: int
)

Combine sequential centred k-space segments from absolute rigid motion states. The first segment is stationary. Each subsequent segment uses one forward `(x, y, z)` matrix. Segment masks depend only on the acquisition axis, so the other spatial FFTs cancel with their inverses. A full complex FFT along that axis preserves asymmetric, non-Hermitian segments. Large writable single-channel volumes use CPU Tensor FFTs. Only one moved volume and its spectrum are retained at a time, and the combined spectrum is reused for the inverse.

Parameters

NameTypeDefaultDescription
volumeVolumeType--
matricesnp.ndarray--
boundariestuple[int, ...]--
axisint--
interpolationint--

get_anisotropy_downsample_shapefunction

get_anisotropy_downsample_shape(
    spatial_shape: tuple[int, int, int],
    axes: tuple[int, ...],
    downscale_factor: float
)

Derive an anisotropic intermediate shape by scaling selected axes while retaining non-selected axes, ensuring every requested spatial dimension remains valid.

Parameters

NameTypeDefaultDescription
spatial_shapetuple[int, int, int]--
axestuple[int, ...]--
downscale_factorfloat--

anisotropy_3dfunction

anisotropy_3d(
    volume: VolumeType | torch.Tensor,
    downsample_shape: tuple[int, int, int],
    antialias: bool
)

Simulate thicker or lower-resolution volume acquisition by shrinking selected spatial axes and restoring the original shape for 3D robustness training. Both routes delegate to Albucore `resize3d`, which resizes only spatial axes and preserves the input representation. NumPy applies antialiasing while shrinking; PyTorch does not yet provide 5D trilinear antialiasing, so Tensor input uses the non-antialiased native route until upstream support is available.

Parameters

NameTypeDefaultDescription
volume
One of:
  • VolumeType
  • torch.Tensor
--
downsample_shapetuple[int, int, int]--
antialiasbool--