python读取目录下所有的jpg文件,并显示第一张图片的示例
作者:xky1306102chenhong 时间:2023-06-21 16:31:58
如下所示:
# -*- 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()
来源:https://blog.csdn.net/xky1306102chenhong/article/details/81605699
标签:python,目录,jpg,图片
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python实现脚本转换为命令行程序
2022-02-28 10:48:30
Vue2实现组件props双向绑定
2024-05-08 09:33:25
![](https://img.aspxhome.com/file/2023/3/130273_0s.jpg)
DWCS3-CSS布局之一CSS规则大纲
2008-06-11 18:48:00
超简单的scrapy实现ip动态代理与更换ip的方法实现
2022-12-21 19:58:05
![](https://img.aspxhome.com/file/2023/4/100924_0s.png)
Python中如何导入类示例详解
2023-05-09 08:35:58
SpringBoot+MySQL+Jpa实现对数据库的增删改查和分页详解
2024-01-17 16:20:59
![](https://img.aspxhome.com/file/2023/5/71155_0s.png)
golang 实现tcp转发代理的方法
2023-08-06 02:46:55
Python基础之输入,输出与高阶赋值详解
2023-05-21 10:00:32
AJAX概述
2007-11-03 13:41:00
Tensorflow获取张量Tensor的具体维数实例
2021-12-24 20:25:10
Vue.js开发环境搭建
2024-05-28 15:55:38
![](https://img.aspxhome.com/file/2023/7/123117_0s.png)
asp中Access与Sql Server数据库区别总结
2007-11-18 15:08:00
pycharm无法导入lxml的解决办法
2023-08-24 04:34:39
![](https://img.aspxhome.com/file/2023/2/87922_0s.png)
Jupyter notebook快速入门教程(推荐)
2021-02-13 13:53:57
![](https://img.aspxhome.com/file/2023/9/117579_0s.jpg)
vue使用@scroll监听滚动事件时,@scroll无效问题的解决方法详解
2024-05-09 15:24:55
Python安装OpenCV的示例代码
2022-05-25 23:35:44
![](https://img.aspxhome.com/file/2023/2/134492_0s.jpg)
mysql中全连接full join...on...的用法说明
2024-01-13 19:44:22
oracle关键字作为字段名使用方法
2024-01-18 07:57:59
人工智能学习pyTorch自建数据集及可视化结果实现过程
2022-08-04 14:54:33
![](https://img.aspxhome.com/file/2023/5/75105_0s.png)
查看当前mysql使用频繁的sql语句(详解)
2024-01-18 19:58:47