admin管理员组

文章数量:1356753

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}")

本文标签: numpyIssues to convert h5 file to png with PythonStack Overflow