rgb_to_grayscale¶
- torchvision.transforms.functional.rgb_to_grayscale(img: Tensor, num_output_channels: int = 1) Tensor[原始碼]¶
將 RGB 影像轉換為灰度影像。如果影像是 torch Tensor(張量),則預期形狀為 […, 3, H, W],其中 … 表示任意數量的引導維度
注意
請注意,此方法僅支援 RGB 影像作為輸入。對於其他顏色空間的輸入,請考慮將
to_grayscale()與 PIL Image 一起使用。- 引數:
img (PIL Image 或 Tensor) – 要轉換為灰度的 RGB 影像。
num_output_channels (int) – 輸出影像的通道數。值可為 1 或 3。預設值為 1。
- 返回:
影像的灰度版本。
如果 num_output_channels = 1:返回影像為單通道
如果 num_output_channels = 3:返回影像為 3 通道,其中 r = g = b
- 返回型別:
PIL Image 或 Tensor