from torchvision import transforms
from PIL import Image
# 加载图像
img_path = 'images/VIS/VIS1.png' # 用你的图像路径替换这里
img = Image.open(img_path)
# 查看图像通道数
print(len(img.split()))
# 将图像转化为三通道
img =img.convert('RGB')
# 将图像转换为PyTorch张量
transform = transforms.ToTensor()
img_tensor = transform(img)
# 检查通道数
channels = img_tensor.shape[0]
print(f'图像通道数: {channels}')
08-03
2842
07-22
2602
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交