albumentations.augmentations.transforms3d.functional
Module containing functional implementations of 3D transformations. This module provides a collection of utility functions for manipulating and transforming 3D volumetric data (such as medical imaging volumes). The functions here implement the core algorithms for operations like padding, cropping, rotation, and other spatial manipulations specifically designed for 3D data.
Members
- functionadjust_padding_by_position3d
- functioncrop3d
- functioncutout3d
- functionfilter_keypoints_in_holes3d
- functionkeypoints_rot90
- functionpad_3d_with_params
- functiontransform_cube
- functiontransform_cube_keypoints
adjust_padding_by_position3dfunction
adjust_padding_by_position3d(
paddings: list[tuple[int, int]],
position: Literal['center', 'random'],
py_random: random.Random
)
Adjust padding values based on desired position for 3D data.
Parameters
Name | Type | Default | Description |
---|---|---|---|
paddings | list[tuple[int, int]] | - | List of tuples containing padding pairs for each dimension [(d_pad), (h_pad), (w_pad)] |
position | One of:
| - | Position of the image after padding. |
py_random | random.Random | - | Random number generator |
Returns
- tuple[int, int, int, int, int, int]: Final padding values (d_front, d_back, h_top, h_bottom, w_left, w_right)
crop3dfunction
crop3d(
volume: np.ndarray,
crop_coords: tuple[int, int, int, int, int, int]
)
Crop 3D volume using coordinates.
Parameters
Name | Type | Default | Description |
---|---|---|---|
volume | np.ndarray | - | Input volume with shape (z, y, x) or (z, y, x, channels) |
crop_coords | tuple[int, int, int, int, int, int] | - | (z_min, z_max, y_min, y_max, x_min, x_max) coordinates for cropping |
Returns
- np.ndarray: Cropped volume with same number of dimensions as input
cutout3dfunction
cutout3d(
volume: np.ndarray,
holes: np.ndarray,
fill_value: tuple[float, ...] | float
)
Cut out holes in 3D volume and fill them with a given value.
Parameters
Name | Type | Default | Description |
---|---|---|---|
volume | np.ndarray | - | Input volume with shape (depth, height, width) or (depth, height, width, channels) |
holes | np.ndarray | - | Array of holes with shape (num_holes, 6). Each hole is represented as [z1, y1, x1, z2, y2, x2] |
fill_value | One of:
| - | Value to fill the holes |
Returns
- np.ndarray: Volume with holes filled with the given value
filter_keypoints_in_holes3dfunction
filter_keypoints_in_holes3d(
keypoints: np.ndarray,
holes: np.ndarray
)
Filter out keypoints that are inside any of the 3D holes.
Parameters
Name | Type | Default | Description |
---|---|---|---|
keypoints | np.ndarray | - | Array of keypoints with shape (num_keypoints, 3+). The first three columns are x, y, z coordinates. |
holes | np.ndarray | - | Array of holes with shape (num_holes, 6). Each hole is represented as [z1, y1, x1, z2, y2, x2]. |
Returns
- np.ndarray: Array of keypoints that are not inside any hole.
keypoints_rot90function
keypoints_rot90(
keypoints: np.ndarray,
k: int,
axes: tuple[int, int],
volume_shape: tuple[int, int, int]
)
Rotate keypoints 90 degrees k times around the specified axes.
Parameters
Name | Type | Default | Description |
---|---|---|---|
keypoints | np.ndarray | - | Array of keypoints with shape (num_keypoints, 3+). The first three columns are x, y, z coordinates. |
k | int | - | Number of times to rotate by 90 degrees. |
axes | tuple[int, int] | - | Axes to rotate around. |
volume_shape | tuple[int, int, int] | - | Shape of the volume (depth, height, width). |
Returns
- np.ndarray: Rotated keypoints with same shape as input.
pad_3d_with_paramsfunction
pad_3d_with_params(
volume: np.ndarray,
padding: tuple[int, int, int, int, int, int],
value: tuple[float, ...] | float
)
Pad 3D volume with given parameters.
Parameters
Name | Type | Default | Description |
---|---|---|---|
volume | np.ndarray | - | Input volume with shape (depth, height, width) or (depth, height, width, channels) |
padding | tuple[int, int, int, int, int, int] | - | Padding values in format: (depth_front, depth_back, height_top, height_bottom, width_left, width_right) where: - depth_front/back: padding at start/end of depth axis (z) - height_top/bottom: padding at start/end of height axis (y) - width_left/right: padding at start/end of width axis (x) |
value | One of:
| - | Value to fill the padding |
Returns
- np.ndarray: Padded volume with same number of dimensions as input
Notes
The padding order matches the volume dimensions (depth, height, width). For each dimension, the first value is padding at the start (smaller indices), and the second value is padding at the end (larger indices).
transform_cubefunction
transform_cube(
cube: np.ndarray,
index: int
)
Transform cube by index (0-47)
Parameters
Name | Type | Default | Description |
---|---|---|---|
cube | np.ndarray | - | Input array with shape (D, H, W) or (D, H, W, C) |
index | int | - | Integer from 0 to 47 specifying which transformation to apply |
Returns
- np.ndarray: Transformed cube with same shape as input
transform_cube_keypointsfunction
transform_cube_keypoints(
keypoints: np.ndarray,
index: int,
volume_shape: tuple[int, int, int]
)
Transform keypoints according to the cube transformation specified by index.
Parameters
Name | Type | Default | Description |
---|---|---|---|
keypoints | np.ndarray | - | Array of keypoints with shape (num_keypoints, 3+). The first three columns are x, y, z coordinates. |
index | int | - | Integer from 0 to 47 specifying which transformation to apply. |
volume_shape | tuple[int, int, int] | - | Shape of the volume (depth, height, width). |
Returns
- np.ndarray: Transformed keypoints with same shape as input.