python读取npz文件、h5文件信息

查看npz文件信息

import numpy as np
import os
from matplotlib import pyplot as plt
sampled_batch = np.load("train_npz/case0005_slice000.npz")
image = sampled_batch["image"].T
plt.imshow(image, cmap='gray')
plt.show()

《python读取npz文件、h5文件信息》

label = sampled_batch["label"].T
plt.imshow(label, cmap='gray')
plt.show()

《python读取npz文件、h5文件信息》

查看文件尺寸信息

sampled_batch["image"].shape,sampled_batch["label"].shape

((512, 512), (512, 512))

查看文件包含哪些信息

sampled_batch.files

[‘image’, ‘label’]

查看图像中的像素范围

sampled_batch['image'].min(), sampled_batch['image'].max()

(0.0, 1.0)

关闭文件

sampled_batch.close()

查看h5文件信息

import h5py
f = h5py.File('test_vol_h5/case0001.npy.h5', 'r')
for key in f.keys():
    print(f[key].name)
    print(f[key].shape)

/image
(147, 512, 512)
/label
(147, 512, 512)

查看图像shape

f['image'].shape,f['label'].shape

((147, 512, 512), (147, 512, 512))

    原文作者:我是一个小稻米
    原文地址: https://blog.csdn.net/weixin_44669966/article/details/124323712
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞