Mask images with random horizontal and vertical strips sized in pixels or axis-relative fractions, useful for occlusion and spectrogram augmentation.
Integer endpoints express strip sizes in pixels. Float endpoints in [0.0, 1.0] scale X lengths by image width and Y lengths by image height.
num_masks_x_rangeRange for the number of vertical strips. Defaults to (0, 0).
num_masks_y_rangeRange for the number of horizontal strips. Defaults to (0, 0).
mask_x_length_rangeRange of vertical-strip widths. Use two integers for pixels or two floats in [0.0, 1.0] for fractions of image width. Defaults to (0, 0).
mask_y_length_rangeRange of horizontal-strip heights. Use two integers for pixels or two floats in [0.0, 1.0] for fractions of image height. Defaults to (0, 0).
fillValue for the dropped pixels. Can be:
fill_maskFill value for dropout regions in the mask. If None, mask regions corresponding to image dropouts are unchanged. Defaults to None.
pProbability of applying the transform. Defaults to 0.5.
Use integer ranges for pixel-based strip sizes:
>>> import albumentations as A
>>> import numpy as np
>>> image = np.full((80, 120, 3), 255, dtype=np.uint8)
>>> pixel_transform = A.XYMasking(
... num_masks_x_range=(1, 2),
... num_masks_y_range=(1, 1),
... mask_x_length_range=(8, 16),
... mask_y_length_range=(4, 8),
... fill=0,
... p=1.0,
... )
>>> pixel_image = pixel_transform(image=image)["image"]mask_x_length_range and mask_y_length_range must have a positive maximum.fill="grayscale", fill_mask must be None.