捷徑

crop

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

在指定位置和輸出大小裁剪給定的影像。如果影像為 torch Tensor,則預期其形狀為 […, H, W],其中 … 表示任意數量的領先維度。如果影像大小沿任何邊緣小於輸出大小,則影像會先以 0 填充,然後再裁剪。

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

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

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

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

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

傳回:

裁剪後的影像。

傳回類型:

PIL Image 或 Tensor

使用 crop 的範例

轉換的圖解

轉換的圖解

文件

取得 PyTorch 的完整開發者文件

查看文件

教學

取得適用於初學者和進階開發者的深入教學

查看教學

資源

尋找開發資源並獲得問題解答

查看資源