def coreg(sbref_image):
  #take brain extracted anat as an input, but do not use it
  #only to force the pipeline to run brain extraction first
    import ants, os, re
    #the trick is to get the anat image without the solicit from the pipeline
    cwd = os.getcwd()
    subj_no = re.findall('\d+',cwd)[-1]

    img = '/media/amr/Amr_4TB/NARPS/workingdir_narps_preproc_preproc/preproc/_subject_id_sub-{0}/brain_extraction_anat/highres001_BrainExtractionBrain.nii.gz'.format(subj_no)


    fixed = ants.image_read(img)
    moving = ants.image_read(sbref_image)
    #you have to setup the outprefix, otherwise it will send the output to tmp folder 

    mytx = ants.registration(fixed=fixed , moving=moving, type_of_transform='Rigid', outprefix = 'sbref_2_anat_sub-{0}'.format(subj_no))

    mywarpedimage = ants.apply_transforms(fixed=fixed, moving=moving,
                                          transformlist=mytx['fwdtransforms'])

    ants.image_write(image=mywarpedimage, filename='sbref_2_anat_sub-{0}.nii.gz'.format(subj_no))

    composite_transform = os.path.abspath('sbref_2_anat_sub-{0}0GenericAffine.mat'.format(subj_no))

    warped_image = os.path.abspath('sbref_2_anat_sub-{0}.nii.gz'.format(subj_no))

    return composite_transform, warped_image #always you need return
def coreg(bold_image):
  #take brain extracted anat as an input, but do not use it
  #only to force the pipeline to run brain extraction first
    import ants, os, re
    import nipype.interfaces.fsl as fsl
    #the trick is to get the anat image without the solicit from the pipeline
    cwd = os.getcwd()
    subj_no = re.findall('\d+',cwd)[-1]

    img = '/home/in/aeed/poldrack_gabmling/workingdir_MGT_poldrack_preproc_preproc/preproc/_subject_id_sub-{0}/brain_extraction_anat/sub-{0}_T1w_brain.nii.gz'.format(subj_no)

    fixed = ants.image_read(img)
    moving = ants.image_read(bold_image)
    #you have to setup the outprefix, otherwise it will send the output to tmp folder 

    mytx = ants.registration(fixed=fixed , moving=moving, type_of_transform='Rigid', outprefix = 'bold_2_anat_sub-{0}'.format(subj_no))

    mywarpedimage = ants.apply_transforms(fixed=fixed, moving=moving,
                                          transformlist=mytx['fwdtransforms'])

    ants.image_write(image=mywarpedimage, filename='bold_2_anat_sub-{0}.nii.gz'.format(subj_no))

    composite_transform = os.path.abspath('bold_2_anat_sub-{0}0GenericAffine.mat'.format(subj_no))

    warped_image = os.path.abspath('bold_2_anat_sub-{0}.nii.gz'.format(subj_no))

    return composite_transform, warped_image #always you need return
Beispiel #3
0
def coreg(bold_image):
    # take brain extracted anat as an input, but do not use it
    # only to force the pipeline to run brain extraction first
    import ants
    import os
    import re
    import nipype.interfaces.fsl as fsl
    # the trick is to get the anat image without the solicit from the pipeline
    cwd = os.getcwd()
    subj_no = re.findall('\d+', cwd)[-1]

    img = '/media/amr/Amr_4TB/Work/stimulation/Data_CA3/{0}/Anat_{0}_bet.nii.gz'.format(
        subj_no)

    fixed = ants.image_read(img)
    moving = ants.image_read(bold_image)
    # you have to setup the outprefix, otherwise it will send the output to tmp folder

    mytx = ants.registration(fixed=fixed,
                             moving=moving,
                             type_of_transform='Rigid',
                             aff_metric='GC',
                             outprefix='bold_2_anat_sub-{0}'.format(subj_no))

    mywarpedimage = ants.apply_transforms(fixed=fixed,
                                          moving=moving,
                                          transformlist=mytx['fwdtransforms'])

    ants.image_write(image=mywarpedimage,
                     filename='bold_2_anat_sub-{0}.nii.gz'.format(subj_no))

    # composite_transform = os.path.abspath('bold_2_anat_sub-{0}_0GenericAffine.mat'.format(subj_no))

    # warped_image = os.path.abspath('bold_2_anat_sub-{0}.nii.gz'.format(subj_no))
    composite_transform = 'bold_2_anat_sub-{0}_0GenericAffine.mat'.format(
        subj_no)

    warped_image = 'bold_2_anat_sub-{0}.nii.gz'.format(subj_no)

    return composite_transform, warped_image  # always you need return