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)