import h5py as h5
import numpy as np
from PIL import Image
import os
import matplotlib.pyplot as plt
train = h5.File('test/testa.h5','r')#读取数据
for i in range(116):
one_sample = train['data'][i,0]
os.makedirs('./testa/'+str(i),mode=0o777)
counter = 0
for layer_img in one_sample:
save_path = './testa/'+str(i)+'/p' + str(counter) + ".jpg"
img = np.array(layer_img)#存入数组
img = Image.fromarray(layer_img).convert('L') # 先转换为image,再转为灰度图
img=img.resize((79*5, 95*5),Image.ANTIALIAS).save(save_path)#放大5倍并保存为temp.jpg
print(counter+1)
counter+=1
提取MRI
于 2022-02-27 09:42:18 首次发布