Importing PNG files into Numpy?

后端 未结 7 1405
轮回少年
轮回少年 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:52

    This can also be done with the Image class of the PIL library:

    from PIL import Image
    import numpy as np
    
    im_frame = Image.open(path_to_file + 'file.png')
    np_frame = np.array(im_frame.getdata())
    

    Note: The .getdata() might not be needed - np.array(im_frame) should also work

提交回复
热议问题