简体   繁体   English

我如何使用python将图像转换为灰度?

[英]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.

相关问题 我想使用Python将32 * 32 * 3 rgb图像转换为32 * 32 * 1维度的灰度 - I want to convert 32*32*3 rgb image to gray scale with 32*32*1 dimension using Python 如何在opencv中正确地将图像转换为灰度 - How can I properly convert image to gray scale in opencv 转换图像灰度python错误 - convert image gray scale python error 无法使用 scikit 图像将 RGB 图像转换为灰度 - Not able to convert RGB image to gray scale using scikit image 如何使用 rgb 对 python 中的图片进行灰度化? - how to gray scale a picture in python using rgb? 如果我在python中具有强度矩阵,则可以打印灰度图像 - to print a gray scale image if i have the matrix of intensities in python 如何在python中调整图像的大小以降低MNIST时尚数据等灰度低分辨率? - How can I resize an image in python to gray scale low resolution like MNIST fashion data? 如何使用PIL \\ Numpy在Python中获取灰度图像的平均像素值? - How to Get an Average Pixel Value of a Gray Scale Image in Python Using PIL\Numpy? 如何仅使用 Python stdlib 检查 jpeg 图像是彩色还是灰度 - How to check whether a jpeg image is color or gray scale using only Python stdlib 如何使用opencv python将红色通道与灰度图像合并? - How to merge red channel with gray scale image with opencv python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM