Importing PNG files into Numpy?
Importing PNG files into Numpy? 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 images into Numpy and then later want to apply k-means to generate a dictionary of patches using k-means (scikit) Does anybody know a python library that could load these images into numpy on a fly? 5 Answers 5 Using just scipy, glob and having PIL installed ( pip install pillow ) you can use scipy's imread method: pip install pillow 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. scipy.misc.imread imageio.imread instead ...