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}')
查看图片通道数,将单通道图片转化为RGB,转化为pytorch张量
最新推荐文章于 2024-05-13 01:56:09 发布