将图片转换成列表

import cv2
a = cv2.imread  ("E:\jre\wujiaoxing.png")
cv2.imshow("djfks",a)
img_list = a.tolist()#将图片转换成数组列表格式
print(img_list)
cv2.waitKey(0)

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
图片换为HDF5文件需要使用Python的h5py库和Pillow库,步骤如下: 1. 导入必要的库: ```python import h5py from PIL import Image import numpy as np ``` 2. 定义变量,包括图片路径、HDF5文件名、数据集名等: ```python img_path = '/path/to/image.jpg' h5_file = 'images.h5' dataset_name = 'images' ``` 3. 读取图像数据,并将其换为numpy数组: ```python img = Image.open(img_path) img_array = np.array(img) ``` 4. 创建HDF5文件并将图像数组写入其: ```python with h5py.File(h5_file, 'w') as f: f.create_dataset(dataset_name, data=img_array) ``` 在这个示例,我们使用`with`语句创建HDF5文件并将其分配给变量"f",文件以写入模式("w")打开。然后,我们使用`f.create_dataset`函数创建一个名为"images"的数据集,并将图像数组写入其。最后,文件会在`with`代码块结束时自动关闭。 如果你需要将多张图像写入同一个数据集,请参考以下示例代码: ```python img_folder = '/path/to/images' h5_file = 'images.h5' dataset_name = 'images' image_list = [] for filename in os.listdir(img_folder): if filename.endswith('.jpg') or filename.endswith('.png'): img_path = os.path.join(img_folder, filename) img = Image.open(img_path) img_array = np.array(img) image_list.append(img_array) with h5py.File(h5_file, 'w') as f: f.create_dataset(dataset_name, data=image_list) ``` 在这个示例,我们使用一个循环读取文件夹的所有图像,并将它们换为numpy数组。然后,我们将所有图像数组存储在一个列表,并使用`f.create_dataset`函数将列表写入名为"images"的数据集

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值