簡體   English   中英

減少python中的圖像通道

[英]Reduce image channels in python

我有一個尺寸為 (128, 19, 3) 的圖像,我想將其轉換為 (128, 19, 1)。 我使用了此代碼(在 python 中),但它將圖像大小轉換為 (128, 19) 而不是我想要的 (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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM