Importing PNG files into Numpy?

后端 未结 7 1403
轮回少年
轮回少年 2020-12-08 18:32

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

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

I want to import all the PNG i

7条回答
  •  不知归路
    2020-12-08 18:51

    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

    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.

提交回复
热议问题