Shortcuts

resized_crop

torchvision.transforms.functional.resized_crop(img: Tensor, top: int, left: int, height: int, width: int, size: List[int], interpolation: InterpolationMode = InterpolationMode.BILINEAR, antialias: Optional[bool] = True) Tensor[source]

裁剪给定的图像并将其调整到所需的大小。 如果图像是torch张量,则期望其具有[…, H, W]形状,其中…表示任意数量的前导维度

特别是在RandomResizedCrop中使用。

Parameters:
  • img (PIL ImageTensor) – 要裁剪的图像。(0,0) 表示图像的左上角。

  • top (int) – 裁剪框左上角的垂直分量。

  • left (int) – 裁剪框左上角的水平分量。

  • height (int) – 裁剪框的高度。

  • width (int) – 裁剪框的宽度。

  • size (序列整数) – 期望的输出大小。与 resize 的语义相同。

  • 插值 (InterpolationMode) – 由 torchvision.transforms.InterpolationMode 定义的期望插值枚举。 默认值为 InterpolationMode.BILINEAR。如果输入是张量,则仅支持 InterpolationMode.NEARESTInterpolationMode.NEAREST_EXACTInterpolationMode.BILINEARInterpolationMode.BICUBIC。 相应的 Pillow 整数常量,例如 PIL.Image.BILINEAR 也被接受。

  • antialias (bool, optional) –

    是否应用抗锯齿。 它只影响具有双线性或双三次模式的张量,否则会被忽略:在PIL图像上,双线性或双三次模式总是应用抗锯齿;在其他模式(对于PIL图像和张量)上,抗锯齿没有意义,此参数会被忽略。 可能的值为:

    • True (默认): 将对双线性或双三次模式应用抗锯齿。 其他模式不受影响。这可能是你想要使用的。

    • False: 不会对任何模式的张量应用抗锯齿。PIL 图像在双线性或双三次模式下仍然应用抗锯齿,因为 PIL不支持无抗锯齿。

    • None: 对于张量等同于False,对于 PIL图像等同于True。此值存在是为了兼容旧版本,除非你确实知道自己在做什么,否则你可能不想使用它。

    默认值在v0.17版本中从None更改为True,以使PIL和Tensor后端保持一致。

Returns:

裁剪后的图像。

Return type:

PIL 图像或张量

使用 resized_crop 的示例:

变换的图示

Illustration of transforms