Skip to content

Instantly share code, notes, and snippets.

@takecx
Last active July 4, 2019 15:04
Show Gist options
  • Save takecx/da8bbad9ef1ed2f2b3a044419199cbb2 to your computer and use it in GitHub Desktop.
Save takecx/da8bbad9ef1ed2f2b3a044419199cbb2 to your computer and use it in GitHub Desktop.
Read multiple image data to ndarray - (n_samples,height,width,channels)
import os
import numpy as np
import glob
import cv2
image_dir = './images/'
search_pattern = '*.png'
datas = []
for image_path in glob.glob(os.path.join(image_dir,search_pattern)):
# (height,width,channels)
data = cv2.imread(image_path)
# (1,height,width,channels)
data_expanded = np.expand_dims(data,axis=0)
datas.append(data_expanded)
# (n_samples,height,width,channels)
image_datas = np.concatenate(datas,axis=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment