2

I have Converted 3 Channel RGB image into 2 channel grayscale image using :

from PIL import Image
import glob
images = glob.glob('C:/Users/.../*.jpg')
for i in range(len(images)):
    img = Image.open(images[i]).convert('LA')
    img = img.resize((224,224),Image.ANTIALIAS)
    img.save('C:/Users/.../0_{}.png'.format(i))

My Goal was to create 1 channel grayscale but after doing code above, i found out that results are 2 channels images ! is there any way that i can decrease this channels to 1 as if i converted them from 3 to 1 at first place ? Thanks.

1 Answers1

4

Calling convert with LA gives it two channels, L, which is luminosity, and A, which is alpha (transparency). So if you do Image.open(images[i]).convert('L') there will only be one channel in the resulting image.

Calvin Godfrey
  • 2,171
  • 1
  • 11
  • 27