在python中将16位rgb图像作为numpy数组读取失败

2024-05-18 04:26:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从一个有两个子目录的文件夹加载自己的图像数据集,其中所有图像都是RGB比例的16位png,图像的尺寸是(64*64)。我将它们转换为灰度,并强制numpy数组的数据类型为uint16。它返回一个图像列表作为(64*64)numpy数组

path="D:/PROJECT ___ CU/Images for 3D/imagedatanew/Training2/"

imageset=[]
image_labels=[]

for directory in os.listdir(path):
    for file in os.listdir(path+directory):
        print(path+directory+"/"+file)
        img=Image.open(path+directory+"/"+file)
        featurevector=numpy.array(img.convert("L"),dtype='uint16')
        imageset.append(featurevector)
        image_labels.append(directory)

但当我试图将这个二维数组列表转换为三维数组时,我做不到

im=numpy.array(imageset)
im.shape
>>> im.shape
>>> (207,) ##there are 207 images in total

我要数组为(207,64,64) 而且,当我运行im数组时,它将dtype返回为“object”,我无法理解


Tags: pathin图像imagenumpy列表forlabels