albumentations.augmentations.medical.functional
Deterministic medical acquisition and intensity operations.
Members
- functiongibbs_ringing
- functionbias_field
- functiongenerate_bias_field
- functionrician_noise
- functionk_space_spike
- functionghosting_artifact
- functionmotion_artifact
- functionget_anisotropy_downsample_shape
- functionanisotropy_3d
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
| Name | Type | Default | Description |
|---|---|---|---|
| img | One of:
| - | - |
| retained_fraction | float | - | - |
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
| Name | Type | Default | Description |
|---|---|---|---|
| img | One of:
| - | - |
| coarse_field | np.ndarray | - | - |
| is_batch | bool | False | - |
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
| Name | Type | Default | Description |
|---|---|---|---|
| coarse_field | np.ndarray | - | - |
| spatial_shape | tuple[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
| Name | Type | Default | Description |
|---|---|---|---|
| img | One of:
| - | - |
| real_noise | np.ndarray | - | - |
| imaginary_noise | np.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
| Name | Type | Default | Description |
|---|---|---|---|
| img | One of:
| - | - |
| spikes | np.ndarray | - | - |
| intensity | float | - | - |
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
| Name | Type | Default | Description |
|---|---|---|---|
| volume | One of:
| - | - |
| num_ghosts | int | - | - |
| intensity | float | - | - |
| axis | int | - | - |
| restore | float | - | - |
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
| Name | Type | Default | Description |
|---|---|---|---|
| volume | VolumeType | - | - |
| matrices | np.ndarray | - | - |
| boundaries | tuple[int, ...] | - | - |
| axis | int | - | - |
| interpolation | int | - | - |
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
| Name | Type | Default | Description |
|---|---|---|---|
| spatial_shape | tuple[int, int, int] | - | - |
| axes | tuple[int, ...] | - | - |
| downscale_factor | float | - | - |
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
| Name | Type | Default | Description |
|---|---|---|---|
| volume | One of:
| - | - |
| downsample_shape | tuple[int, int, int] | - | - |
| antialias | bool | - | - |