Created
August 5, 2016 04:53
-
-
Save kcho/d5fb56ef1d07bcfca75785282a7e344a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nibabel as nb | |
import numpy as np | |
from nilearn.image import resample_img | |
import pp | |
from glob import glob | |
import os | |
import re | |
def main(): | |
workshopDataLoc = '/media/workshop/openData_for_workshop/NITRC/workshop' | |
subjects = [x for x in os.listdir(workshopDataLoc) if x.startswith('subj')] | |
for subject in subjects: | |
print subject | |
subj_DTI_in = glob(os.path.join(workshopDataLoc, subject, 'DTI/*DTI.nii'))[0] | |
subj_DTI_out = re.sub('DTI.nii', 'DTI-resampled.nii.gz', subj_DTI_in) | |
resample(subj_DTI_in, subj_DTI_out) | |
#print subj_DTI_in, subj_DTI_out | |
def resample(inputImg, outputImg, vsize=[2.3,2.3,2.3]): | |
image_to_resample = nb.load(inputImg) | |
desired_affine = np.diag(vsize) | |
resampled_image = resample_img(image_to_resample, | |
target_affine=desired_affine) | |
resampled_image.to_filename(outputImg) | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment