这篇博客代码在胰腺数据中可以用,但是用于ADNI数据保存的图像都是噪声,不能用。
下面的链接是用于ADNI数据集的代码,个人觉得还是下面链接中的代码稍微好用些,因为不会报错:
https://blog.csdn.net/weixin_43330946/article/details/89576759
from PIL import Image
import numpy as np
import os
import nibabel as nib
import imageio
def read_and_save_niifile(niifile):
filenames = os.listdir(filepath)
img_k_list = []
for f in filenames:
img_path = os.path.join(filepath, f)
img = nib.load(img_path)
img_fdata = img.get_fdata() #(512, 512, 110)
fname = f.replace('.nii', '')
img_k_path = os.path.join(imgfile,fname)
if not os.path.exists(img_k_path):
os.mkdir(img_k_path)
for i in range(img.shape[2]):
fn = fname+'_'+str(i).zfill(3)+'.