将PNG文件导入Numpy? [英] Importing PNG files into Numpy?

查看:528
本文介绍了将PNG文件导入Numpy?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大约200个灰度PNG图像存储在这样的目录中。

I have about 200 grayscale PNG images stored within a directory like this.

1.png
2.png
3.png
...
...
200.png

我想将所有PNG图像导入Numpy然后想要使用k-means来生成补丁字典,使用k-means(scikit)

I want to import all the PNG images into Numpy and then later want to apply k-means to generate a dictionary of patches using k-means (scikit)

有没有人知道一个python库可以将这些图像加载到numpy中吗?

Does anybody know a python library that could load these images into numpy on a fly?

推荐答案

使用scipy ,glob和安装了PIL( pip install pillow )你可以使用scipy的 imread 方法:

Using just scipy, glob and having PIL installed (pip install pillow) you can use scipy's imread method:

from scipy import misc
import glob

for image_path in glob.glob("/home/adam/*.png"):
    image = misc.imread(image_path)
    print image.shape
    print image.dtype



UPDATE



根据文档, scipy.misc.imread 在SciPy 1.0.0开始时已弃用,将在1.2.0中删除。考虑使用 imageio.imread而不是。请参阅 Charles的回答

UPDATE

According to the doc, scipy.misc.imread is deprecated starting SciPy 1.0.0, and will be removed in 1.2.0. Consider using imageio.imread instead. See the answer by Charles.

这篇关于将PNG文件导入Numpy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆