![](/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.