Stay updated

News & Insights
utils

albumentations.augmentations.dropout.transforms


Drops random pixels from the image.

Members

PixelDropoutclass

PixelDropout(
    dropout_prob: float = 0.01,
    per_channel: bool = False,
    drop_value: tuple[float, ...] | float | None = 0,
    mask_drop_value: tuple[float, ...] | float | None,
    p: float = 0.5
)

Drops random pixels from the image. This transform randomly sets pixels in the image to a specified value, effectively "dropping out" those pixels. It can be applied to both the image and its corresponding mask.

Parameters

NameTypeDefaultDescription
dropout_probfloat0.01Probability of dropping out each pixel. Should be in the range [0, 1]. Default: 0.01
per_channelboolFalseIf True, the dropout mask will be generated independently for each channel. If False, the same dropout mask will be applied to all channels. Default: False
drop_value
One of:
  • tuple[float, ...]
  • float
  • None
0Value to assign to the dropped pixels. If None, the value will be randomly sampled for each application: - For uint8 images: Random integer in [0, 255] - For float32 images: Random float in [0, 1] If a single number, that value will be used for all dropped pixels. If a sequence, it should contain one value per channel. Default: 0
mask_drop_value
One of:
  • tuple[float, ...]
  • float
  • None
-Value to assign to dropped pixels in the mask. If None, the mask will remain unchanged. If a single number, that value will be used for all dropped pixels in the mask. If a sequence, it should contain one value per channel. Default: None
pfloat0.5Probability of applying the transform. Should be in the range [0, 1]. Default: 0.5

Examples

>>> import numpy as np
>>> import albumentations as A
>>> image = np.random.randint(0, 256, (100, 100, 3), dtype=np.uint8)
>>> mask = np.random.randint(0, 2, (100, 100), dtype=np.uint8)
>>> transform = A.PixelDropout(dropout_prob=0.1, per_channel=True, p=1.0)
>>> result = transform(image=image, mask=mask)
>>> dropped_image, dropped_mask = result['image'], result['mask']

Notes

- When applied to bounding boxes, this transform may cause some boxes to have zero area if all pixels within the box are dropped. Such boxes will be removed. - When applied to keypoints, keypoints that fall on dropped pixels will be removed if the keypoint processor is configured to remove invisible keypoints.