You are on page 1of 2

from PIL import Image

import os

import numpy as np

path_to_files = "./images/"

array_of_images = []

for _, file in enumerate(os.listdir(path_to_files)):

if "direction.jpg" in file: # to check if file has a certain name

single_im = Image.open(file)

single_array = np.array(im)

array_of_images.append(single_array)

np.savez("all_images.npz",array_of_images) # save all in one file

Npy

import numpy as np

from PIL import Image

from matplotlib import pyplot as plt

filename = './images/1'

img = Image.open( filename + '.png' )

data = np.array( img, dtype='uint8' )


np.save( filename + '.npy', data)

# visually testing our output

img_array = np.load(filename + '.npy')

plt.imshow(img_array)

You might also like