问题描述
我有一个尺寸为(128,19,3)的图像,我想将其转换为(128,19,1)。我使用了这段代码(在python中),但是它将图像大小转换为我想要的(128,19,1)而不是(128,19,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]