コード例 #1
0
def random_rotate(lr: None, hr: None, p: float = 0.5) -> [Any, Any]:
    r"""Randomly select the rotation angle.

    Args:
        lr (PIL.BmpImagePlugin.BmpImageFile): Low-resolution images loaded with PIL.
        hr (PIL.BmpImagePlugin.BmpImageFile): High-resolution images loaded with PIL.
        p (float): When the random probability is less than the value, it rotates clockwise.
            When the random probability is greater than the value, it rotates clockwise. (Default: 0.5)

    Returns:
        Rotated low-resolution image and rotated high-resolution image.
    """
    angle = random.choice([90, 180, 270])
    if random.random() >= p:
        lr = F.rotate(lr, angle)
        hr = F.rotate(hr, angle)

    return lr, hr
コード例 #2
0
def rotate_image_pil(
    img: PIL.Image.Image,
    angle: float,
    interpolation: InterpolationMode = InterpolationMode.NEAREST,
    expand: bool = False,
    fill: Optional[List[float]] = None,
    center: Optional[List[float]] = None,
) -> PIL.Image.Image:
    return _FP.rotate(
        img, angle, interpolation=pil_modes_mapping[interpolation], expand=expand, fill=fill, center=center
    )
コード例 #3
0
def rotate_image_pil(
    img: PIL.Image.Image,
    angle: float,
    interpolation: InterpolationMode = InterpolationMode.NEAREST,
    expand: bool = False,
    fill: Optional[List[float]] = None,
    center: Optional[List[float]] = None,
) -> PIL.Image.Image:
    if center is not None and expand:
        warnings.warn(
            "The provided center argument is ignored if expand is True")
        center = None

    return _FP.rotate(img,
                      angle,
                      interpolation=pil_modes_mapping[interpolation],
                      expand=expand,
                      fill=fill,
                      center=center)