to_grayscale¶
- torchvision.transforms.functional.to_grayscale(img, num_output_channels=1)[source]¶
将任何模式(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
的使用示例