← Back to all transforms

GridDropout

Description

GridDropout, drops out rectangular regions of an image and the corresponding mask in a grid fashion.

    Args:
        ratio (float): The ratio of the mask holes to the unit_size (same for horizontal and vertical directions).
            Must be between 0 and 1. Default: 0.5.
        random_offset (bool): Whether to offset the grid randomly between 0 and grid unit size - hole size.
            If True, entered shift_x and shift_y are ignored and set randomly. Default: False.
        fill_value (Optional[ColorType]): Value for the dropped pixels. Default: 0.
        mask_fill_value (Optional[ColorType]): Value for the dropped pixels in mask.
            If None, transformation is not applied to the mask. Default: None.
        unit_size_range (Optional[tuple[int, int]]): Range from which to sample grid size. Default: None.
             Must be between 2 and the image shorter edge.
        holes_number_xy (Optional[tuple[int, int]]): The number of grid units in x and y directions.
            First value should be between 1 and image width//2,
            Second value should be between 1 and image height//2.
            Default: None.
        shift_xy (tuple[int, int]): Offsets of the grid start in x and y directions.
            Offsets of the grid start in x and y directions from (0,0) coordinate.
            Default: (0, 0).

        p (float): Probability of applying the transform. Default: 0.5.

    Targets:
        image, mask

    Image types:
        uint8, float32

    Reference:
        https://arxiv.org/abs/2001.04086

    

Parameters

  • p: float (default: 0.5)
  • ratio: float (default: 0.5)
  • unit_size_min: int | None (default: null)
  • unit_size_max: int | None (default: null)
  • holes_number_x: int | None (default: null)
  • holes_number_y: int | None (default: null)
  • shift_x: int | None (default: null)
  • shift_y: int | None (default: null)
  • random_offset: bool (default: false)
  • fill_value: float | Sequence[float] | None (default: 0)
  • mask_fill_value: float | Sequence[float] | None (default: null)
  • unit_size_range: Annotated[tuple[int, int], AfterValidator(func=<function check_1plus at 0x7e8f03f4aac0>), AfterValidator(func=<function nondecreasing at 0x7e8f03f4ac00>)] | None (default: null)
  • shift_xy: tuple[int, int] (default: (0, 0))
  • holes_number_xy: Annotated[tuple[int, int], AfterValidator(func=<function check_1plus at 0x7e8f03f4aac0>)] | None (default: null)

Targets

  • Image
  • Mask

Try it out

Original Image (width = 484, height = 733):

Original

Transformed Image:

Transform not yet applied