首页 > 解决方案 > 将 ImageField 中的图像转换为 numpy 数组

问题描述

class Image(models.Model):
    image = models.ImageField(upload_to="uploads/%Y/%m/%d", null=False, blank=True)

如何从 ImageField 转换为 numpy 数组?

标签: pythondjangonumpy

解决方案


from PIL import Image

for image in unlabeled_images: 
    image.image.open()
    img = np.array(Image.open(image.image).convert("RGB"))

我可以这样解决我自己的问题。如果有人有更好的解决方案告诉我


推荐阅读