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

无法在python中将16位rgb图像作为numpy数组读取,python,arrays,image,numpy,Python,Arrays,Image,Numpy,我正在尝试从一个文件夹加载自己的图像数据集,其中有两个子目录,其中所有图像都是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

我正在尝试从一个文件夹加载自己的图像数据集,其中有两个子目录,其中所有图像都是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)
但是当我试图将这个2D数组列表转换为3D数组时,我不能这样做

im=numpy.array(imageset)
im.shape
>>> im.shape
>>> (207,) ##there are 207 images in total
我希望数组的值为(207,64,64)
此外,当我运行im数组时,它会将数据类型返回为“object”,我无法理解这可能是因为您正在使用对象而不是numpy数组创建numpy数组。在尝试使用每个元素生成数组之前,是否已尝试查看它们的数据类型?如果它们不都匹配,numpy也会使它们成为对象。请验证所有图像实际上都是相同的形状。在将
featurevector.shape添加到
imageset
之前,请先打印
featurevector.shape
,或者选中
[a.shape以查看im中的a]