HyperDenseNet_pytorch icon indicating copy to clipboard operation
HyperDenseNet_pytorch copied to clipboard

some helpful codes for this project

Open menghd opened this issue 4 years ago • 0 comments

u can try to run following codes if u meet the same problems:

#coding = utf-8
import os
import shutil
import nibabel as nb

srcdir = r'C:\Users\xxx\Desktop\iSeg-2017-Training'
destdir = r'C:\Users\xxx\Desktop\DataNii'
os.chdir(srcdir)
for filename in os.listdir():
        if (os.path.splitext(filename)[1] == '.img'):
            img = nb.load(filename)
            nb.save(img, filename.replace('.img', '.nii'))
        if (os.path.splitext(filename)[1] == '.nii'):    
            shutil.move(filename, destdir)
print("done")
import nibabel as nib
import numpy as np
import os
path = r"C:\Users\xxx\Desktop\DataNii\Validation\GT"
os.chdir(path)
dict = {0: 0, 10: 1, 150: 2, 250: 3}
for file in os.listdir(path):
    gt = nib.load(file).get_fdata()
    shape = gt.shape
    gt = gt.reshape(-1) 
    for i in range(len(gt)):
        gt[i] = dict[gt[i]]
    gt = gt.reshape(shape)
    img_gt = nib.Nifti1Image(gt, np.eye(4))
    nib.save(img_gt, file)
print("done")      

menghd avatar Apr 23 '21 05:04 menghd