gpt4 book ai didi

python - 将 jpg 图像转换为 .hdf5

转载 作者:行者123 更新时间:2023-12-01 07:56:34 33 4
gpt4 key购买 nike

在这里回答我自己的问题以供将来引用。

我最近正在处理 .jpg 图像类型的数据集,需要将它们转换为 .hdf5 图像。我看到了一些以相反方式转换的答案,但没有从 .jpg.hdf5 。最好的方法是什么?

最佳答案

解决方案如下所示

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

关于python - 将 jpg 图像转换为 .hdf5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55943311/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com