python创建图像数组_python中的图像数组

我使用numpy和matplotlib在python中导入图像。我想装箱一个三维数组,这样在第1和第2轴我有像素值,在第0轴我有图像编号。到目前为止我得到了这样的消息:from PIL import Image

import numpy

import matplotlib.pyplot as plt

import glob

imageFolderPath = '/home/B/Pictures/'

imagePath = glob.glob(imageFolderPath+'/*.JPG')

im_array = numpy.array(Image.open(imagePath[0]).convert('L'), 'f')

im_array = numpy.expand_dims(im_array, axis=0)

for c in range(1, len(imagePath)):

im_array_new = numpy.array(Image.open(imagePath[c]).convert('L'), 'f')

im_array_new = numpy.expand_dims(im_array_new, axis=0)

im_array = numpy.append(im_array, im_array_new, axis=0)

这工作,但有点难看。我不喜欢这样的事实,我必须扩展二维数组的维度,然后将它们附加在一起。

在python中有没有更优雅的方法来实现这一点?可能不需要预先分配一个巨大的3d数组(n个照片,x维,y维)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值