python使用h5py读取mat文件数据,并保存图像
来源:互联网 发布:psv重新构筑数据库 编辑:程序博客网 时间:2024/04/30 03:14
1 安装h5py
sudo apt-get install libhdf5-devsudo pip install h5py
假设你已经安装好python和numpy模块
2 读取mat文件数据
import numpy as npimport h5pyf = h5py.File('data.mat') data = f['cell_name'][:]cell_name是元胞数组的名称,假如有多级元胞目录,可以指定任意的元胞数组进行读取,比如
data = f['cell_name/.../指定的元胞数组'][:]
3 保存图像
img = images[i,...].transpose((2, 1, 0))file = 'make3d_dataset_f460/images/'+str(i+1)+'.jpg'img = img*255img = img.astype('uint8')cv2.imwrite(file, img)#pyplot.imsave(file, img)
整个代码流程:
import cv2import numpy as npimport h5pyfrom matplotlib import pyplotheight = 460width = 345def extract_data():with h5py.File('make3d_dataset_f460.mat','r') as f:images = f['make3d_dataset_fchange/images'][:]image_num = len(images)for i in range(image_num):img = images[i,...].transpose((2, 1, 0))file = 'make3d_dataset_f460/images/'+str(i+1)+'.jpg'img = img*255img = img.astype('uint8')cv2.imwrite(file, img)#pyplot.imsave(file, img)def extract_labels():with h5py.File('make3d_dataset_f460.mat','r') as f:depths = f['make3d_dataset_fchange/depths'][:]depth_num = len(depths)for i in range(depth_num):img = depths[i,...].transpose((1, 0))file = 'make3d_dataset_f460/depths/'+str(i+1)+'.jpg'depth = imgdepth = depth.astype('uint8')cv2.imwrite(file, depth)#pyplot.imsave(file, img)def main(argv=None):# Input and groundtruth producerextract_data()extract_labels()print("Training data is converted into images!")if __name__ == '__main__':main()
1 0
- python使用h5py读取mat文件数据,并保存图像
- python利用h5py模块读取matlab中的mat文件并打印矩阵的数据类型,尺寸,数据
- Python第三方库h5py——读取mat文件并显示值
- python读取.mat数据之scipy.io&h5py
- 在Python读取mat文件,并保存为pickle格式
- Python 之 h5py 读取 matlab 中 .mat 文件 cell 方法浅析
- Python读取、保存、查看.mat文件
- Python 从 mat 文件读写 到 h5py 文件包
- python读取并写入mat文件
- python读取并写入mat文件
- 读取csv数据并保存成图像
- .net读取图像并保存为文件
- 使用python读取.txt文件并保存到Excel中
- 读取mat文件中特定数据保存到txt中
- Python读取mat文件
- python 读取 mat 文件
- python 读取摄像头数据并保存
- Python读取mat文件,并转为csv文件
- 一个属性解决安卓控件倾斜放置
- MFC退出窗口
- Android中程序与Service交互的方式——综述
- web.xml报错<async-supported>true</async-supported>
- 关于mybatis的if判断里传入0时的问题
- python使用h5py读取mat文件数据,并保存图像
- Knight Moves
- PuTTY的简介及使用
- Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类
- Scala进阶源码实战之一——数组、函数基础、流程控制、文件、异常
- Android_Handler实现异步回调加载数据
- Android从启动到程序运行发生的事情
- HDU 2167 Pebbles
- ASP.Net MVC开发基础学习笔记(10):分部视图PartialView