Skip to content

optical_distortion

OpticalDistortion

Bases: MultiVariateAlbumentation

Apply optical distortion to an image / mask.

Parameters:

Name Type Description Default
mode Union[None, str, Iterable[str]]

What mode(s) to execute this Op in. For example, "train", "eval", "test", or "infer". To execute regardless of mode, pass None. To execute in all modes except for a particular one, you can pass an argument like "!infer" or "!train".

None
ds_id Union[None, str, Iterable[str]]

What dataset id(s) to execute this Op in. To execute regardless of ds_id, pass None. To execute in all ds_ids except for a particular one, you can pass an argument like "!ds1".

None
image_in Optional[str]

The key of an image to be modified.

None
mask_in Optional[str]

The key of a mask to be modified (with the same random factors as the image).

None
masks_in Optional[str]

The key of masks to be modified (with the same random factors as the image).

None
image_out Optional[str]

The key to write the modified image (defaults to image_in if None).

None
mask_out Optional[str]

The key to write the modified mask (defaults to mask_in if None).

None
masks_out Optional[str]

The key to write the modified masks (defaults to masks_in if None).

None
distort_limit Union[float, Tuple[float, float]]

If distort_limit is a single float, the range will be (-distort_limit, distort_limit).

0.05
shift_limit Union[float, Tuple[float, float]]

If shift_limit is a single float, the range will be (-shift_limit, shift_limit).

0.05
interpolation int

Flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4.

INTER_LINEAR
border_mode int

Flag that is used to specify the pixel extrapolation method. Should be one of: cv2.BORDER_CONSTANT, cv2.BORDER_REPLICATE, cv2.BORDER_REFLECT, cv2.BORDER_WRAP, cv2.BORDER_REFLECT_101.

BORDER_REFLECT_101
value Union[None, int, float, List[int], List[float]]

Padding value if border_mode is cv2.BORDER_CONSTANT.

None
mask_value Union[None, int, float, List[int], List[float]]

Padding value if border_mode is cv2.BORDER_CONSTANT applied for masks.

None
Image types

uint8, float32

Source code in fastestimator/fastestimator/op/numpyop/multivariate/optical_distortion.py
@traceable()
class OpticalDistortion(MultiVariateAlbumentation):
    """Apply optical distortion to an image / mask.

    Args:
        mode: What mode(s) to execute this Op in. For example, "train", "eval", "test", or "infer". To execute
            regardless of mode, pass None. To execute in all modes except for a particular one, you can pass an argument
            like "!infer" or "!train".
        ds_id: What dataset id(s) to execute this Op in. To execute regardless of ds_id, pass None. To execute in all
            ds_ids except for a particular one, you can pass an argument like "!ds1".
        image_in: The key of an image to be modified.
        mask_in: The key of a mask to be modified (with the same random factors as the image).
        masks_in: The key of masks to be modified (with the same random factors as the image).
        image_out: The key to write the modified image (defaults to `image_in` if None).
        mask_out: The key to write the modified mask (defaults to `mask_in` if None).
        masks_out: The key to write the modified masks (defaults to `masks_in` if None).
        distort_limit: If distort_limit is a single float, the range will be (-distort_limit, distort_limit).
        shift_limit: If shift_limit is a single float, the range will be (-shift_limit, shift_limit).
        interpolation: Flag that is used to specify the interpolation algorithm. Should be one of:
            cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4.
        border_mode: Flag that is used to specify the pixel extrapolation method. Should be one of:
            cv2.BORDER_CONSTANT, cv2.BORDER_REPLICATE, cv2.BORDER_REFLECT, cv2.BORDER_WRAP, cv2.BORDER_REFLECT_101.
        value: Padding value if border_mode is cv2.BORDER_CONSTANT.
        mask_value: Padding value if border_mode is cv2.BORDER_CONSTANT applied for masks.

    Image types:
        uint8, float32
    """
    def __init__(self,
                 distort_limit: Union[float, Tuple[float, float]] = 0.05,
                 shift_limit: Union[float, Tuple[float, float]] = 0.05,
                 interpolation: int = cv2.INTER_LINEAR,
                 border_mode: int = cv2.BORDER_REFLECT_101,
                 value: Union[None, int, float, List[int], List[float]] = None,
                 mask_value: Union[None, int, float, List[int], List[float]] = None,
                 mode: Union[None, str, Iterable[str]] = None,
                 ds_id: Union[None, str, Iterable[str]] = None,
                 image_in: Optional[str] = None,
                 mask_in: Optional[str] = None,
                 masks_in: Optional[str] = None,
                 image_out: Optional[str] = None,
                 mask_out: Optional[str] = None,
                 masks_out: Optional[str] = None):
        super().__init__(
            OpticalDistortionAlb(distort_limit=distort_limit,
                                 shift_limit=shift_limit,
                                 interpolation=interpolation,
                                 border_mode=border_mode,
                                 value=value,
                                 mask_value=mask_value,
                                 always_apply=True),
            image_in=image_in,
            mask_in=mask_in,
            masks_in=masks_in,
            bbox_in=None,
            keypoints_in=None,
            image_out=image_out,
            mask_out=mask_out,
            masks_out=masks_out,
            bbox_out=None,
            keypoints_out=None,
            bbox_params=None,
            keypoint_params=None,
            mode=mode,
            ds_id=ds_id)