简体   繁体   中英

I have converted 3 channel RGB image into 2 channels grayscale image, How to decrease greyscale channels to 1?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM