Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some helpful codes for this project #2

Open
menghd opened this issue Apr 23, 2021 · 0 comments
Open

some helpful codes for this project #2

menghd opened this issue Apr 23, 2021 · 0 comments

Comments

@menghd
Copy link

menghd commented Apr 23, 2021

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")      
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant