如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# -*- 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() |
以上这篇python读取目录下所有的jpg文件,并显示第一张图片的示例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/xky1306102chenhong/article/details/81605699