最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

numpy - Issues to convert .h5 file to .png with Python - Stack Overflow

programmeradmin4浏览0评论

this what i write but when i open an png image it s just the image i put here, help idk why

for filename in os.listdir(input_dir):
    if filename.endswith(".h5"):
        file_path = os.path.join(input_dir, filename)

       
        with h5py.File(file_path, "r") as f:
            if "image" in f:
                image_data = np.array(f["image"])
                print(f"Image size: {image_data.shape}")

              
                image_data = np.clip(image_data, 0, 255)
                image_data = image_data.astype(np.uint8)

                
                img = Image.fromarray(image_data)
                output_path = os.path.join(output_dir, filename.replace(".h5", ".png"))
                img.save(output_path)
                print(f"Save: {output_path}")
发布评论

评论列表(0)

  1. 暂无评论