减少python中的图像通道



我有一个尺寸为(128,19,3(的图像,我想将其转换为(128、19,1(。我使用了这段代码(在python中(,但它将图像大小转换为(12819(,而不是我想要的(12819,1(。如果有人能帮助,谢谢

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]

最新更新