![](/img/trans.png)
[英]I want to convert 32*32*3 rgb image to gray scale with 32*32*1 dimension using Python
[英]how do i convert image into gray scale using python?
我在文件夹中有 5 张图片。 我想将所有图像转换为灰度。
import glob
colorIm = []
for filename in glob.glob('/content/drive/My Drive/Colab Notebooks/Asplab/Cifar/*.png'):
print(filename)
img = Image.open(filename)
colorIm.append(img)
greyIm=colorIm.convert('L')
AttributeError: 'list' 对象没有属性 'convert'
您需要转换列表中的每个图像:
import glob
colorIm = []
for filename in glob.glob('/content/drive/My Drive/Colab Notebooks/Asplab/Cifar/*.png'):
print(filename)
img = Image.open(filename)
colorIm.append(img)
greyIm = [img.convert('L') for img in colorIm]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.