Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何以h5格式数据可视化图像?_Python_Image_Image Processing_Hdf5_H5py - Fatal编程技术网

Python 如何以h5格式数据可视化图像?

Python 如何以h5格式数据可视化图像?,python,image,image-processing,hdf5,h5py,Python,Image,Image Processing,Hdf5,H5py,我使用上面的代码来打印信息。 打印结果为: import h5py f = h5py.File('the_file.h5', 'r') one_data = f['key'] print(one_data.shape) print(one_data.dtype) print(one_data) (3203203) uint8 jet提供的解决方案工作正常,但缺点是需要包含OpenCV(cv2)。如果您没有将OpenCV用于其他任何用途,那么仅仅为了保存文件而安装/包含它就有点过头了。或者,您可

我使用上面的代码来打印信息。 打印结果为:

import h5py
f = h5py.File('the_file.h5', 'r')
one_data = f['key']
print(one_data.shape)
print(one_data.dtype)
print(one_data)
(3203203)
uint8
jet提供的解决方案工作正常,但缺点是需要包含OpenCV(cv2)。如果您没有将OpenCV用于其他任何用途,那么仅仅为了保存文件而安装/包含它就有点过头了。或者,您可以使用占用空间较小的
imageio.imwrite
(),例如:

import cv2
import numpy as np
import h5py
f = h5py.File('the_file.h5', 'r')
dset = f['key']
data = np.array(dset[:,:,:])
file = 'test.jpg'
cv2.imwrite(file, data)
安装imageio与安装imageio一样简单

另外,
matplotlib.image.imsave
()提供了类似的图像保存功能

import cv2
import numpy as np
import h5py
f = h5py.File('the_file.h5', 'r')
dset = f['key']
data = np.array(dset[:,:,:])
file = 'test.jpg'
cv2.imwrite(file, data)
import imageio
import numpy as np
import h5py

f = h5py.File('the_file.h5', 'r')
dset = f['key']
data = np.array(dset[:,:,:])
file = 'test.png' # or .jpg
imageio.imwrite(file, data)