New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does h5py support image datasets? #771
Comments
BTW, I'm looking to do a truecolor image, instead of a indexed image. |
The |
Thanks for the info! I think I'm most of the way there. I'm making a plot with MatplotLib and saving it as a PNG so I can use the Image library to open the PNG file as a NumPy ndarray 'int8'. I can pass this 3d array (800,1200,4) to my HDF5 file using h5py's create_dataset call. This plus a few attributes (CLASS=IMAGE, IMAGE_VERSION='1.2', IMAGE_SUBCLASS=IMAGE_TRUECOLOR, INTERLACE_MODE=INTERLACE_PIXEL) puts the data in my hdf5 file without errors. However, this data comes out as a table in my hdf5 file. I can make this show up as an image after some selections with HDFView, but everything defaults to a table. Would you happen to know if there are any other requirements to have the image data show up as an image, instead of a table? |
I am not using images myself. I don't know how HDFView is suppose to behave in such circumstances. The attributes you have given correspond to the specification in https://support.hdfgroup.org/HDF5/doc/ADGuide/ImageSpec.html so I see no reason for it not to work. If you post sample code, I am willing to test it on my system. Also, as you have a PNG image, you might consider to store it "as is", as a binary stream instead of a full raster image. |
Here is the idea: I have a set of latitude and longitude points that I need to save in an image in an hdf5 file. This is a simplified example of what I want to do that shows the problem I'm having: import matplotlib.pyplot as plt figure = plt.figure(dpi=200) #Draw the image hf = h5py.File('/home/usr/imageSample.HDF5', 'w') dset=hf.create_dataset("/myData/myImage", data=idata, dtype='uint8', chunks=True) hf.close() |
Just figured out. Its something to do with the attribute additions in the end. The correct calls are: Thank you for your help! |
Hi, Thanks for the update with the fix! For info, I checked the earlier syntax but defining only the 4 attributes set in the update, i.e. dset.attrs['CLASS'] = 'IMAGE'
dset.attrs['IMAGE_VERSION'] = '1.2'
dset.attrs['IMAGE_SUBCLASS'] = 'IMAGE_TRUECOLOR'
dset.attrs['INTERLACE_MODE'] = 'INTERLACE_PIXEL' and it works as well (hdfview shows the image properly). If your problem is solved, could you close the issue? Regards, Pierre |
Pierre, |
I need to add a png/jpg image to my hdf5 file. I tried using create_dataset("image", data='path/to/filefig.png', dtype='uint8') and get this error:
IOError: Can't prepare for writing data (No appropriate function for conversion path)
Is appending an image file to my hdf5 file possible?
Thanks,
-Mariana
The text was updated successfully, but these errors were encountered: