Shortcuts

裁剪

torchvision.transforms.functional.crop(img: Tensor, top: int, left: int, height: int, width: int) Tensor[source]

在指定位置裁剪给定的图像并输出指定大小。 如果图像是torch Tensor,则期望其具有[…, H, W]形状,其中…表示任意数量的前导维度。 如果图像的任意一边尺寸小于输出尺寸,则图像会用0填充然后裁剪。

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

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

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

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

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

Returns:

裁剪后的图像。

Return type:

PIL 图像或张量

使用 crop 的示例:

变换的图示

Illustration of transforms