Search code examples
pythonimageimage-processinghdf5h5py

How can I visualise an image in h5 format data?


import h5py
f = h5py.File('the_file.h5', 'r')
one_data = f['key']
print(one_data.shape)
print(one_data.dtype)
print(one_data)

I use the code above to print the info. The print result is:

(320, 320, 3)
uint8
<HDF5 dataset "1458552843.750": shape (320, 320, 3), type "|u1">

Solution

  • 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)