1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| import matplotlib.pyplot as plt import numpy as np import os from skimage.transform import resize from glob import glob import SimpleITK as sitk file_dir = r"D:\MyData\3Dircadb1_fusion_date\npy\train_image\*" dest_dir = r"D:\MyData\3Dircadb1_fusion_date\png"
def npy_png(file_dir, dest_dir): if not os.path.exists(dest_dir): os.makedirs(dest_dir) path = glob(file_dir) k=0 for file in path: arr = np.load(file) z = arr.shape[0] k += 1 for i in range(z-1): arr1 = arr[i:i+1,...] arr2 = arr1[0, ...] disp_to_img = resize(arr2, [128, 128]) plt.imsave(os.path.join(dest_dir, "{}_{}_disp.png".format(k,i)), disp_to_img, cmap='plasma')
if __name__ == "__main__": npy_png(file_dir, dest_dir)
|