def move_to_MNI_space(input_file, bvals, bvecs, brain_mask, output_dir): print("Moving input to MNI space...") os.system("calc_FA -i " + input_file + " -o " + output_dir + "/FA.nii.gz --bvals " + bvals + " --bvecs " + bvecs + " --brain_mask " + brain_mask) dwi_spacing = ImgUtils.get_image_spacing(input_file) template_path = resource_filename('examples.resources', 'MNI_FA_template.nii.gz') os.system( "flirt -ref " + template_path + " -in " + output_dir + "/FA.nii.gz -out " + output_dir + "/FA_MNI.nii.gz -omat " + output_dir + "/FA_2_MNI.mat -dof 6 -cost mutualinfo -searchcost mutualinfo") os.system("flirt -ref " + template_path + " -in " + input_file + " -out " + output_dir + "/Diffusion_MNI.nii.gz -applyisoxfm " + dwi_spacing + " -init " + output_dir + "/FA_2_MNI.mat -dof 6") os.system("cp " + bvals + " " + output_dir + "/Diffusion_MNI.bvals") os.system("cp " + bvecs + " " + output_dir + "/Diffusion_MNI.bvecs") new_input_file = join(output_dir, "Diffusion_MNI.nii.gz") bvecs = join(output_dir, "Diffusion_MNI.bvecs") bvals = join(output_dir, "Diffusion_MNI.bvals") brain_mask = Mrtrix.create_brain_mask(new_input_file, output_dir) return new_input_file, bvals, bvecs, brain_mask
def move_to_subject_space(output_dir): print("Moving input to subject space...") file_path_in = output_dir + "/bundle_segmentations.nii.gz" file_path_out = output_dir + "/bundle_segmentations_subjectSpace.nii.gz" dwi_spacing = ImgUtils.get_image_spacing(file_path_in) os.system("convert_xfm -omat " + output_dir + "/MNI_2_FA.mat -inverse " + output_dir + "/FA_2_MNI.mat") os.system("flirt -ref " + output_dir + "/FA.nii.gz -in " + file_path_in + " -out " + file_path_out + " -applyisoxfm " + dwi_spacing + " -init " + output_dir + "/MNI_2_FA.mat -dof 6") os.system("fslmaths " + file_path_out + " -thr 0.5 -bin " + file_path_out)