Example #1
0
for i in range(len(path_t1)):
    clean_ana(os.path.join(path_t1[i], "T1.nii"),
              1000.0,
              4095.0,
              overwrite=True)
"""
mask t1 and epi
"""
for i in range(len(path_t1)):
    mask_ana(os.path.join(path_t1[i], "T1.nii"),
             os.path.join(path_t1[i], "mask.nii"),
             background_bright=False)

for i in range(len(path_epi)):
    mask_epi(os.path.join(path_epi[i], "bepi.nii"),
             os.path.join(path_t1[i], "pT1.nii"),
             os.path.join(path_t1[i], "mask.nii"), niter_mask, sigma_mask,
             file_cmap)
"""
flirt
"""
os.chdir(path_flirt)
flirt = FLIRT()
flirt.inputs.cost_func = "corratio"
flirt.inputs.dof = 6
flirt.inputs.interp = "trilinear"  # trilinear, nearestneighbour, sinc or spline
flirt.inputs.in_file = os.path.join(path_epi_target, "pbepi.nii")
flirt.inputs.reference = os.path.join(path_epi_source, "pbepi.nii")
flirt.inputs.output_type = "NIFTI"
flirt.inputs.out_file = os.path.join(path_flirt, "flirt.nii")
flirt.inputs.out_matrix_file = os.path.join(path_flirt, "flirt_matrix.mat")
flirt.run()
Example #2
0
n4.inputs.dimension = 3
n4.inputs.input_image = os.path.join(path_epi, "epi.nii")
n4.inputs.bias_image = os.path.join(path_epi, 'n4bias.nii')
n4.inputs.output_image = os.path.join(path_epi, "bepi.nii")
n4.run()
"""
clean ana
"""
clean_ana(os.path.join(path_t1, "T1.nii"), 1000.0, 4095.0, overwrite=True)
"""
mask t1 and epi
"""
mask_ana(os.path.join(path_t1, "T1.nii"),
         os.path.join(path_t1, "mask.nii"),
         background_bright=False)
mask_epi(os.path.join(path_epi, "bepi.nii"), os.path.join(path_t1, "pT1.nii"),
         os.path.join(path_t1, "mask.nii"), niter_mask, sigma_mask)
"""
syn
"""
embedded_antsreg(
    os.path.join(path_t1, "pT1.nii"),  # source image
    os.path.join(path_epi, "pbepi.nii"),  # target image 
    run_rigid,  # whether or not to run a rigid registration first 
    rigid_iterations,  # number of iterations in the rigid step
    run_affine,  # whether or not to run an affine registration first
    affine_iterations,  # number of iterations in the affine step
    run_syn,  # whether or not to run a SyN registration
    coarse_iterations,  # number of iterations at the coarse level
    medium_iterations,  # number of iterations at the medium level
    fine_iterations,  # number of iterations at the fine level
    cost_function,  # CrossCorrelation or MutualInformation
Example #3
0
# get brainmask
clean_ana(os.path.join(path_t1, "T1.nii"), 1000.0, 4095.0, overwrite=True)
mask_ana(os.path.join(path_t1, "T1.nii"),
         os.path.join(path_t1, "mask.nii"),
         background_bright=False)

# bias field correction
n4 = N4BiasFieldCorrection()
n4.inputs.dimension = 3
n4.inputs.input_image = os.path.join(path_mri, "orig.nii")
n4.inputs.bias_image = os.path.join(path_mri, "n4bias.nii")
n4.inputs.output_image = os.path.join(path_mri, "borig.nii")
n4.run()

mask_epi(os.path.join(path_mri, "borig.nii"), os.path.join(path_t1, "pT1.nii"),
         os.path.join(path_t1, "mask.nii"), niter_mask, sigma_mask, input_cmap)

multiply_images(os.path.join(path_mri, "orig.nii"),
                os.path.join(path_t1, "mask_def-img3.nii.gz"),
                os.path.join(path_mri, "brainmask.nii"))

# convert orig and brainmask to mgz
mgh2nii(os.path.join(path_mri, "orig.nii"), path_mri, out_type="mgz")
mgh2nii(os.path.join(path_mri, "brainmask.nii"), path_mri, out_type="mgz")

# choose initialization method
if init_reg == "header":
    bbr_var = " --init-header"
elif init_reg == "freesurfer":
    bbr_var = " --init-coreg"
elif init_reg == "fsl":
Example #4
0
    # copy input files into temporary folder
    sh.copyfile(input_t1[i], os.path.join(path_temp,"T1"+ext_t1))
    sh.copyfile(input_mask[i], os.path.join(path_temp,"mask"+ext_mask))

    # get mean time series
    get_mean(input_epi[i], path_temp, "epi", type="mean")

    # new filenames
    file_epi_mean = os.path.join(path_temp, "mean_epi"+ext_epi)
    file_t1 = os.path.join(path_temp,"T1"+ext_t1)
    file_mask = os.path.join(path_temp,"mask"+ext_mask)

    # get mask
    clean_ana(file_t1, 1000.0, 4095.0, overwrite=True) # clean ana
    mask_ana(file_t1, file_mask, background_bright=False) # mask t1
    mask_epi(file_epi_mean, os.path.join(path_temp,"pT1"+ext_t1), file_mask, niter_mask, sigma_mask)
    
    # get outlier count within mask
    os.system("3dToutcount " + \
          "-mask " + os.path.join(path_temp,"mask_def-img3.nii.gz") + " " + \
          "-fraction " + \
          "-qthr " +str(qthr) + " " + input_epi[i] + " " + \
          " > " + os.path.join(path_output,"outlier_afni.txt"))
    
    # make plot
    log_data = np.loadtxt(os.path.join(path_output,"outlier_afni.txt"))

    # plots
    fig, ax = plt.subplots()
    ax.plot(log_data, "r")
    ax.set_xlabel("Time in TR")