cv2,skimage,PIL读取图像后的类型,高、宽、通道数的顺序,以及RGB顺序

import cv2
from skimage import io
from PIL import Image
from torchvision import transforms

to_tensor = transforms.ToTensor()

# 灰度图像
cv_img = cv2.imread(r'test_model\data\test\img\MCUCXR_0301_1.png')
print('----------------------cv2-------------------------')
print(type(cv_img)) # numpy.ndarray
print(cv_img.shape)  # H W C # 默认为rgb图像(3通道,其实是BGR)
cv_tensor = to_tensor(cv_img) 
print(cv_tensor.shape) # C H W
print(cv_img)

skimage_img = io.imread(r'test_model\data\test\img\MCUCXR_0301_1.png')
print('----------------------skimage---------------------')
print(type(skimage_img)) # numpy.ndarray
print(skimage_img.shape) # H W
skimage_tensor = to_tensor(skimage_img)
print(skimage_tensor.shape) # C H W (对于rgb图像,顺序为RGB)
print(skimage_img)

PIL_img = Image.open(r'test_model\data\test\img\MCUCXR_0301_1.png')
print('----------------------PIL-------------------------')
print(type(PIL_img)) # PIL专有
print(PIL_img.mode)  # mode:'RGBA'、'RGB'、'L'
PIL_tensor = to_tensor(PIL_img)
print(PIL_tensor.shape) # C H W
print(PIL_img)


# RGBA彩色图像
cv_img = cv2.imread(r'test_model\data\test\img\1.png')
print('----------------------cv2-------------------------')
print(type(cv_img))
print(cv_img.shape)  # H W C # 默认为rgb图像(4通道,其实是BGRA)
cv_tensor = to_tensor(cv_img) 
print(cv_tensor.shape) # C H W
print(cv_img)

skimage_img = io.imread(r'test_model\data\test\img\1.png')
print('----------------------skimage---------------------')
print(type(skimage_img))
print(skimage_img.shape) # H W C (对于rgba图像,默认读取RGB,顺序为RGB) 加上限定条件为BGRA
skimage_tensor = to_tensor(skimage_img)
print(skimage_tensor.shape) # C H W 
print(skimage_img)

PIL_img = Image.open(r'test_model\data\test\img\1.png')
print('----------------------PIL-------------------------')
print(type(PIL_img))
print(PIL_img.mode)  # mode:'RGBA'、'RGB'、'L'
PIL_tensor = to_tensor(PIL_img)
print(PIL_tensor.shape) # C H W
print(PIL_img)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值