Skip to content

some helpful codes for this project #2

Open
@menghd

Description

@menghd

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")      

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions