如何使用keras将列表中的每个灰度图像转换为二维数组?
我有一个由多个排序的灰度图像组成的列表,称为 imageList。我想将每个图像转换为二维数组,并将它们按照转换的顺序存储在名为 arrayList 的列表中。像这样:
imageList = ['1.png', '2.png', '3.png', '4.png',....,'1000.png']
arrayList = [[1th_2dArray] , [2th_2dArray], ......, [1000th_2dArray]]
请注意,我调整了图像大小并将它们从 RGB 转换为灰度,然后将它们存储在我的图像列表。
PS:我是 python 新手,我知道为了将图像转换为数组,我可以使用其他方法,例如 Pillow 或 OpenCV 库,任何建议将不胜感激。
I have a list consisting of several sorted grayscale images called imageList. I want to convert each of the images into 2d array and store each of them in a list called arrayList in the same order as it converted. like this:
imageList = ['1.png', '2.png', '3.png', '4.png',....,'1000.png']
arrayList = [[1th_2dArray] , [2th_2dArray], ......, [1000th_2dArray]]
note that I resized my images and converted them from RGB to grayscale and then store them in my imageList.
P.S: I'm new at python and I know for converting an image to an array I can use other methods such as Pillow or OpenCV Library, any suggestion would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IIUC,您有一个要转换为数组的图像的路径列表,因此您可以尝试如下操作:
因此每个图像都会被加载,然后转换为数组。然后,省略通道维度,得到二维数组。
IIUC, you have a list of paths to images that you want to convert to arrays, so you can try something like this:
So each image is loaded and then converted to an array. Afterwards, the channel dimension is omitted, resulting in 2D arrays.