python - 减少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]
推荐阅读
- rubygems - Ruby 和 Rails 中的 gem 和包有什么区别?
- c# - 无法从 IMongoQueryable mongodb c# driver linq 语句的 GroupBy 中的组中获取组项
- nginx - Nginx 403 禁止
- java - 如何获取发送到 JMETER 中用于 ISO8583 采样器的服务器的字节数组?
- python - 如何在熊猫图中调整宽度和高度?
- javascript - 如何切换菜单可见性
- spring - Spring Kafka 没有 spring boot 消费者不消费消息
- java - 以 json 格式为客户端返回一条消息以及数据 - Java/Spring/REST
- jmeter - 如何在 Jmeter 中忽略重定向 URL 的代理
- python - 如何显示与输入匹配的同一行中的值?