テンソルするpytorch画像

from PIL import Image
import os.path as osp
import os
from torchvision.transforms import ToTensor
test_path = '../dataset/BSD500/images/test'
images_ls = os.listdir(test_path)
images_all_path = []
for image in images_ls:
    s_images_path = osp.join(test_path, image)
    images_all_path.append(s_images_path)
# print(images_all_path)

image = Image.open(images_all_path[0]).convert('YCbCr')
# image.show()
# print(image)
y, cb, cr = image.split()
print(y)
print(cb)
print(cr)
# y.show()
# cb.show()
image_to_tensor = ToTensor()
y = image_to_tensor(y)
print(y.shape)

 

おすすめ

転載: blog.csdn.net/weixin_40823740/article/details/115342634