python读取目录下所有的jpg文件,并显示第一张图片的示例
如下所示:
# -*- coding: UTF-8 -*- import numpy as np import os from scipy.misc import imread, imresize import matplotlib.pyplot as plt from glob import glob # 读取目录下所有的jpg图片 def load_image(image_path, image_size): file_name=glob(image_path+"/*jpg") sample = [] for file in file_name: pic = imread(file).astype(np.float32) pic = imresize(pic, (image_size, image_size)).astype(np.float32) sample.append(pic) sample = np.array(sample) return sample if __name__=='__main__': samples=load_image("./images",150) # 显示第一张图片 pic=samples[:1,:,:,:] pic=np.reshape(pic,(150,150,3)).astype(np.uint8) plt.imshow(pic) plt.show()
相关推荐
云端轻躺 2007-09-04
cas的无名 2020-02-18
chouliqingke 2020-02-13
GonaShrimp 2019-09-02
lionelf 2012-04-07
XTUxiaoxin 2011-09-01
shouen 2011-01-26
流萤 2019-06-26
dalong 2013-07-22
阳光之吻 2019-06-21
zgxzowen 2008-08-21
gcong 2019-06-13
liubang000 2015-08-17
sunshunli 2011-03-11
yangxinhua 2018-12-31
学无涯愈进而愈惘 2018-08-30
yinghuihong 2018-02-25
81751330 2017-11-17