【问题标题】:flip with any degree of angle?以任何角度翻转?
【发布时间】:2020-10-24 22:36:07
【问题描述】:

这是用相应框翻转图像的python示例之一
是否可以将其写为翻转 20 度角或 20,25 或 45 度角?
如何更改此代码以制作任意角度的角度???

import torchvision.transforms.functional as FT

def flip(image, boxes):
    """
    Flip image horizontally.

    :param image: image, a PIL Image
    :param boxes: bounding boxes in boundary coordinates, a tensor of dimensions (n_objects, 4)
    :return: flipped image, updated bounding box coordinates
    """
    # Flip image
    new_image = FT.hflip(image)
    #print('new_image->',new_image)
    # Flip boxes
    new_boxes = boxes
    new_boxes[:, 0] = image.width - boxes[:, 0] - 1
    new_boxes[:, 2] = image.width - boxes[:, 2] - 1
    new_boxes = new_boxes[:, [2, 1, 0, 3]]

    return new_image, new_boxes

【问题讨论】:

    标签: pytorch transform torch flip torchvision


    【解决方案1】:

    您可以使用torchvision.transforms.functional.rotate 将图像旋转一个角度 例如

    import torchvision.transforms.functional as FT
    image = FT.rotate(image, angle)
    

    您也可以使用随机选择角度

    import random
    # randonly select angle b/w 20 and 45
    angle = random.randint(20, 45)
    

    或使用torchvision.transforms.RandomRotation

    select random rotation b/w min and max degree
    loader_transform = torchvision.transforms.RandomRotation(degrees=(min, max))
    img = loader_transform(img)
    

    【讨论】:

    • 我也要旋转盒子
    猜你喜欢
    • 1970-01-01
    • 2011-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多