0

I have 5 images in folder. 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'

2
  • You want img.convert('L') and not colorIm.convert('L'). Commented Mar 10, 2020 at 10:15
  • Probably in the last line you should replace colorIm by img, but neither your identifiers nor the lack of comments help, You may want to re-read the minimum example explanation here. Commented Mar 10, 2020 at 10:16

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your ans. how do i convert that all images into numpy array?
If you want a list of numpy arrays, you can do greyIm = [np.array(img) for img in greyIm]. If you want all of them in a one array of shape (5, height, width), you can then do greyIm = np.stack(greyIm).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.