我正在尝试从 Kaggle 数据集中打开图像,我已将其导入到我的 python 程序中并已加载 我无法打开照片,当我运行代码时它只会产生一个空格
我尝试了下面的代码(这是我更广泛的代码的一部分),但它只产生一个 with
def loadImages(path):
# return array of images
imagesList = listdir(path)
loadedImages = []
for image in imagesList:
img = PImage.open(path + image)
loadedImages.append(img)
return loadedImages
path = "embryo-classification-based-on-microscopic-images/test/0/"
imgs = loadImages(path)
for img in imgs:
img.show()
有人在网站上给出了解决方案,我在代码中填写了信息,是这样的:
from matplotlib import pyplot as plt
from PIL import Image
import os
def load(path):
# Return array of images
imagesList = os.listdir(path)
loadedImages = []
for image in imagesList:
img_path = os.path.join(path, image)
img = Image.open(img_path)
loadedImages.append(img)
return loadedImages
path = "embryo-classification-based-on-microscopic-images/test/0/"
imgs = load(path)
# Display images using matplotlib
for img in imgs:
plt.imshow(img)
plt.axis('off') # Hide axis
plt.show()
数据集路径被插入到加载函数中,因此它包含图像。 使用matplotlib来显示,如果出现任何问题,请告诉我编辑我的答案,谢谢!