将 jpg 图像转换为 .hdf5 文件格式

3

为了以后的参考,我自己回答这个问题。

最近我在使用一组.jpg类型的数据集,并需要将它们转换成.hdf5格式的图像。我看到了一些将另一种格式转换成.jpg的答案,但是没有从.jpg转换成.hdf5的。那么,怎样才能最好地做到这一点呢?

2个回答

4
解决方案如下:
def convert_file(input_dir, filename, output_dir):
    filepath = input_dir + '/' + filename
    fin = open(filepath, 'rb')
    binary_data = fin.read()
    new_filepath = output_dir + '/' + filename[:-4] + '.hdf5'
    f = h5py.File(new_filepath)
    dt = h5py.special_dtype(vlen=np.dtype('uint8'))
    dset = f.create_dataset('binary_data', (100, ), dtype=dt)
    dset[0] = np.fromstring(binary_data, dtype='uint8')

我有一个工具可以实现此功能,位于https://github.com/raguiar2/jpg_to_h5


1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接