[英]how do i convert image into gray scale using python?
I have 5 images in folder.我在文件夹中有 5 张图片。 I want to convert all that images into grey scale.我想将所有图像转换为灰度。
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' object has no attribute 'convert' AttributeError: 'list' 对象没有属性 'convert'
You need to convert each image in the list:您需要转换列表中的每个图像:
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.