to_grayscale¶
- torchvision.transforms.functional.to_grayscale(img, num_output_channels=1)[原始碼]¶
將任何模式(RGB、HSV、LAB 等)的 PIL 影像轉換為灰度版本。此變換不支援 torch Tensor。
- 引數:
img (PIL Image) – 要轉換為灰度的 PIL 影像。
num_output_channels (int) – 輸出影像的通道數。值可以是 1 或 3。預設為 1。
- 返回:
影像的灰度版本。
如果 num_output_channels = 1:返回的影像是單通道
如果 num_output_channels = 3:返回的影像是 3 通道,其中 r = g = b
- 返回型別:
PIL Image
使用
to_grayscale的示例