简体   繁体   中英

Reduce image channels in python

I have an image with dimension of (128, 19, 3), i want to convert it to (128, 19, 1). I used this code (in python) but it converts the image size to (128, 19) not (128, 19, 1) which i want. thanks if anyone can help

from PIL import Image
import glob
images = glob.glob('D:\\thesis\\Paper 3\\Feature 
Extraction\\two_dimension_Feature_extraction\\stft_feature\\Training_set\\P300\\*.png')
img = Image.open(images[0]).convert('L')

只需在数组末尾添加一个维度:

img = img[...,None]

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