Ejemplo n.º 1
0
def BSpline_SyN_ANTs_transform_image(setting, IN=None, out=None):
    fixedIm_address = su.address_generator(setting, 'Im', cn=IN, type_im=0)
    movingIm_address = su.address_generator(setting, 'Im', cn=IN, type_im=1)
    transform0 = su.address_generator(setting,
                                      'DVF_nonRigid_composed',
                                      cn=IN,
                                      out=out)
    nonRigid_MovedImage_address = su.address_generator(setting,
                                                       'nonRigid_MovedImage',
                                                       cn=IN,
                                                       out=out)
    number_of_threads = setting['numberOfThreads']
    script = su.address_generator(setting,
                                  'nonRigidTransformMovedImageScript',
                                  cn=IN,
                                  out=out)
    log = script + '_log'
    setLogFile(log)

    with open(script, "w") as textScr:
        # please note that the last registration that you did, should be the first transform parameters
        textScr.write(ANTsP.header_transform())
        textScr.write(ANTsP.write_number_of_threads(number_of_threads))
        textScr.write(ANTsP.write_input_image(movingIm_address))
        textScr.write(ANTsP.write_reference_image(fixedIm_address))
        textScr.write(ANTsP.write_transform_parameters(transform0))
        textScr.write(ANTsP.write_dimension(setting['dimension']))
        textScr.write(ANTsP.write_output(nonRigid_MovedImage_address))
        textScr.write(
            ANTsP.write_default_pixel_value(setting['defaultPixelValue']))
        textScr.write(ANTsP.transform_image(number_of_transforms=1))
        textScr.write(ANTsP.footer())
        textScr.close()
    os.chmod(script, 0o774)
    os.system(script)
Ejemplo n.º 2
0
def affine_ANTs_transform_image(setting, cn=None):
    fixedIm_address = su.address_generator(setting, 'Im', cn=cn, type_im=0)
    movingIm_address = su.address_generator(setting, 'Im', cn=cn, type_im=1)
    affineOutMat = su.address_generator(setting, 'affineOutMat', cn=cn)
    affine_MovedImage_address = su.address_generator(setting,
                                                     'affine_MovedImage',
                                                     cn=cn)
    number_of_threads = setting['numberOfThreads']
    script = su.address_generator(setting,
                                  'affineTransformMovedImageScript',
                                  cn=cn)

    with open(script, "w") as textScr:
        # please note that the last registration that you did, should be the first transform parameters
        textScr.write(ANTsP.header_transform())
        textScr.write(ANTsP.write_number_of_threads(number_of_threads))
        textScr.write(ANTsP.write_input_image(movingIm_address))
        textScr.write(ANTsP.write_reference_image(fixedIm_address))
        textScr.write(ANTsP.write_transform_parameters(affineOutMat))
        textScr.write(ANTsP.write_dimension(setting['dimension']))
        textScr.write(ANTsP.write_output(affine_MovedImage_address))
        textScr.write(
            ANTsP.write_default_pixel_value(setting['defaultPixelValue']))
        textScr.write(ANTsP.transform_image(number_of_transforms=1))
        textScr.write(ANTsP.footer())
        textScr.close()
    os.chmod(script, 0o774)
    os.system(script)
Ejemplo n.º 3
0
def affine_ANTs(setting, cn=None):
    fixedIm_address = su.address_generator(setting, 'Im', cn=cn, type_im=0)
    movingIm_address = su.address_generator(setting, 'Im', cn=cn, type_im=1)
    affineFolder = su.address_generator(setting, 'affineFolder', cn=cn)
    if not os.path.exists(affineFolder):
        os.makedirs(affineFolder)

    output_name = su.address_generator(setting, 'affineOut', cn=cn)
    number_of_threads = setting['numberOfThreads']
    affine_script = su.address_generator(setting, 'affineScript', cn=cn)
    with open(affine_script, "w") as textScr:
        textScr.write(ANTsP.header_registration())
        textScr.write(ANTsP.write_number_of_threads(number_of_threads))
        textScr.write(ANTsP.write_fixed_image(fixedIm_address))
        textScr.write(ANTsP.write_moving_image(movingIm_address))
        textScr.write(ANTsP.write_dimension(setting['dimension']))
        textScr.write(ANTsP.write_output(output_name))
        if setting['useMask']:
            textScr.write(
                ANTsP.write_fixed_mask(
                    su.address_generator(setting,
                                         setting['MaskName_Affine'][0],
                                         cn=cn,
                                         type_im=0)))
            textScr.write(
                ANTsP.write_moving_mask(
                    su.address_generator(setting,
                                         setting['MaskName_Affine'][0],
                                         cn=cn,
                                         type_im=1)))
        textScr.write(ANTsP.affine_EMPIRE10(use_mask=setting['useMask']))
        textScr.write(ANTsP.footer())
        textScr.close()
    os.chmod(affine_script, 0o774)
    os.system(affine_script)
Ejemplo n.º 4
0
def BSpline_SyN_ANTs_transform(setting,
                               cn=None,
                               out=None,
                               number_of_transforms=2):
    if 'nonrigid_number_of_transform' in setting.keys():
        number_of_transforms = setting[
            'nonrigid_number_of_transform']  # remove later
    fixedIm_address = su.address_generator(setting, 'Im', cn=cn, type_im=0)
    movingIm_address = su.address_generator(setting, 'Im', cn=cn, type_im=1)
    if number_of_transforms == 1:
        transform0 = su.address_generator(setting,
                                          'DVF_nonRigid0',
                                          cn=cn,
                                          out=out)
    if number_of_transforms == 2:
        transform0 = su.address_generator(setting,
                                          'DVF_nonRigid1',
                                          cn=cn,
                                          out=out)
        transform1 = su.address_generator(setting,
                                          'DVF_nonRigid0',
                                          cn=cn,
                                          out=out)
    DVF_nonRigid_composed = su.address_generator(setting,
                                                 'DVF_nonRigid_composed',
                                                 cn=cn,
                                                 out=out)
    number_of_threads = setting['numberOfThreads']
    nonrigid_transform_script = su.address_generator(setting,
                                                     'nonRigidTransformScript',
                                                     cn=cn,
                                                     out=out)

    with open(nonrigid_transform_script, "w") as textScr:
        # please note that the last registration that you did, should be the first transform parameters
        textScr.write(ANTsP.header_transform())
        textScr.write(ANTsP.write_number_of_threads(number_of_threads))
        textScr.write(ANTsP.write_input_image(movingIm_address))
        textScr.write(ANTsP.write_reference_image(fixedIm_address))
        textScr.write(
            ANTsP.write_transform_parameters(transform0, transform_number=0))
        if number_of_transforms > 1:
            textScr.write(
                ANTsP.write_transform_parameters(transform1,
                                                 transform_number=1))
        textScr.write(ANTsP.write_dimension(setting['dimension']))
        textScr.write(ANTsP.write_output(DVF_nonRigid_composed))
        textScr.write(
            ANTsP.write_default_pixel_value(setting['defaultPixelValue']))
        textScr.write(
            ANTsP.transform(number_of_transforms=number_of_transforms))
        textScr.write(ANTsP.footer())
        textScr.close()
    os.chmod(nonrigid_transform_script, 0o774)
    os.system(nonrigid_transform_script)
Ejemplo n.º 5
0
def BSpline_SyN_ANTs_final_transform(setting, cn=None, outfinal=None):
    fixedIm_address = su.address_generator(setting, 'Im', cn=cn, type_im=0)
    movingIm_address = su.address_generator(setting, 'Im', cn=cn, type_im=1)
    transform1 = su.address_generator(setting,
                                      'DVF_nonRigid0_final',
                                      cn=cn,
                                      outfinal=outfinal)
    transform0 = su.address_generator(setting,
                                      'DVF_nonRigid1_final',
                                      cn=cn,
                                      outfinal=outfinal)
    DVF_nonRigid_composed = su.address_generator(setting,
                                                 'DVF_nonRigid_composed_final',
                                                 cn=cn,
                                                 outfinal=outfinal)
    number_of_threads = setting['numberOfThreads']
    script = su.address_generator(setting,
                                  'nonRigidTransformScript_final',
                                  cn=cn,
                                  outfinal=outfinal)

    with open(script, "w") as textScr:
        # please note that the last registration that you did, should be the first transform parameters
        textScr.write(ANTsP.header_transform())
        textScr.write(ANTsP.write_number_of_threads(number_of_threads))
        textScr.write(ANTsP.write_input_image(movingIm_address))
        textScr.write(ANTsP.write_reference_image(fixedIm_address))
        textScr.write(
            ANTsP.write_transform_parameters(transform0, transform_number=0))
        textScr.write(
            ANTsP.write_transform_parameters(transform1, transform_number=1))
        textScr.write(ANTsP.write_dimension(setting['dimension']))
        textScr.write(ANTsP.write_output(DVF_nonRigid_composed))
        textScr.write(
            ANTsP.write_default_pixel_value(setting['defaultPixelValue']))
        textScr.write(ANTsP.transform(number_of_transforms=2))
        textScr.write(ANTsP.footer())
        textScr.close()
    os.chmod(script, 0o774)
    os.system(script)
Ejemplo n.º 6
0
def affine_ANTs_transform(setting, cn=None):
    fixedIm_address = su.address_generator(setting, 'Im', cn=cn, type_im=0)
    movingIm_address = su.address_generator(setting, 'Im', cn=cn, type_im=1)
    affineOutMat = su.address_generator(setting, 'affineOutMat', cn=cn)
    affineDVF_address = su.address_generator(setting, 'affineDVF', cn=cn)
    number_of_threads = setting['numberOfThreads']
    affine_transform_script = su.address_generator(setting,
                                                   'affineTransformScript',
                                                   cn=cn)
    with open(affine_transform_script, "w") as textScr:
        textScr.write(ANTsP.header_transform())
        textScr.write(ANTsP.write_number_of_threads(number_of_threads))
        textScr.write(ANTsP.write_input_image(movingIm_address))
        textScr.write(ANTsP.write_reference_image(fixedIm_address))
        textScr.write(ANTsP.write_transform_parameters(affineOutMat))
        textScr.write(ANTsP.write_dimension(setting['dimension']))
        textScr.write(ANTsP.write_output(affineDVF_address))
        textScr.write(
            ANTsP.write_default_pixel_value(setting['defaultPixelValue']))
        textScr.write(ANTsP.transform(number_of_transforms=1))
        textScr.write(ANTsP.footer())
        textScr.close()
    os.chmod(affine_transform_script, 0o774)
    os.system(affine_transform_script)
Ejemplo n.º 7
0
def BSpline_SyN_ANTs(setting, cn=None, out=None):
    if 'ImageType_Registration' in setting.keys():
        image_type_registration = setting['ImageType_Registration']
    else:
        image_type_registration = 'Im'
    fixed_im_address = su.address_generator(setting,
                                            image_type_registration,
                                            cn=cn,
                                            type_im=0)
    moving_im_address = su.address_generator(setting,
                                             image_type_registration,
                                             cn=cn,
                                             type_im=1)
    output_name = su.address_generator(setting, 'DVF_nonRigid', cn=cn, out=out)
    initial_transform = su.address_generator(setting,
                                             'DVF_perturb',
                                             cn=cn,
                                             out=out)
    number_of_threads = setting['numberOfThreads']
    nonrigid_script = su.address_generator(setting,
                                           'nonRigidScript',
                                           cn=cn,
                                           out=out)
    folder_address = su.address_generator(setting,
                                          'nonRigidFolder',
                                          cn=cn,
                                          out=out)
    if not os.path.exists(folder_address):
        os.makedirs(folder_address)
    with open(nonrigid_script, "w") as textScr:
        textScr.write(ANTsP.header_registration())
        textScr.write(ANTsP.write_number_of_threads(number_of_threads))
        textScr.write(ANTsP.write_fixed_image(fixed_im_address))
        textScr.write(ANTsP.write_moving_image(moving_im_address))
        textScr.write(ANTsP.write_initial_transform(initial_transform))
        textScr.write(ANTsP.write_dimension(setting['dimension']))
        textScr.write(ANTsP.write_output(output_name))
        if setting['useMask']:
            textScr.write(
                ANTsP.write_fixed_mask(
                    su.address_generator(setting,
                                         setting['MaskName_BSpline'],
                                         cn=cn,
                                         type_im=0)))
            textScr.write(
                ANTsP.write_moving_mask(
                    su.address_generator(setting,
                                         setting['MaskName_BSpline'],
                                         cn=cn,
                                         type_im=1)))
        if os.path.isfile(
                su.address_generator(setting, 'ParameterFolder') +
                setting['NonRigidParameter']):
            with open(
                    su.address_generator(setting, 'ParameterFolder') +
                    setting['NonRigidParameter'], 'r') as f_parameter:
                parameter_str = f_parameter.read()
            textScr.write('command="antsRegistration ' + parameter_str + '"')
        else:
            textScr.write(ANTsP.BSpline_SyN_EMPIRE10(setting))
        textScr.write(ANTsP.footer())
        textScr.close()
    os.chmod(nonrigid_script, 0o774)
    os.system(nonrigid_script)
Ejemplo n.º 8
0
def bspline_syn_ants_final(setting, cn=None, outfinal=None):
    if 'ImageType_Registration' in setting.keys():
        image_type_registration = setting['ImageType_Registration']
    else:
        image_type_registration = 'Im'
    fixed_im_address = su.address_generator(setting,
                                            image_type_registration,
                                            cn=cn,
                                            type_im=0)
    moving_im_address = su.address_generator(setting,
                                             image_type_registration,
                                             cn=cn,
                                             type_im=1)
    output_name = su.address_generator(setting,
                                       'DVF_nonRigid_final',
                                       cn=cn,
                                       outfinal=outfinal)
    initial_transform = su.address_generator(setting,
                                             'DVF_perturb_final',
                                             cn=cn,
                                             outfinal=outfinal)
    number_of_threads = setting['numberOfThreads']
    nonrigid_script_final = su.address_generator(setting,
                                                 'nonRigidScript_final',
                                                 cn=cn,
                                                 outfinal=outfinal)
    with open(nonrigid_script_final, "w") as textScr:
        textScr.write(ANTsP.header_registration())
        textScr.write(ANTsP.write_number_of_threads(number_of_threads))
        textScr.write(ANTsP.write_fixed_image(fixed_im_address))
        textScr.write(ANTsP.write_moving_image(moving_im_address))
        textScr.write(ANTsP.write_initial_transform(initial_transform))
        textScr.write(ANTsP.write_dimension(setting['dimension']))
        textScr.write(ANTsP.write_output(output_name))
        if setting['useMask']:
            textScr.write(
                ANTsP.write_fixed_mask(
                    su.address_generator(setting,
                                         setting['MaskName_BSpline_Final'],
                                         cn=cn,
                                         type_im=0)))
            textScr.write(
                ANTsP.write_moving_mask(
                    su.address_generator(setting,
                                         setting['MaskName_BSpline_Final'],
                                         cn=cn,
                                         type_im=1)))
        if os.path.isfile(
                su.address_generator(setting, 'ParameterFolder') +
                setting['NonRigidParameter_final']):
            with open(
                    su.address_generator(setting, 'ParameterFolder') +
                    setting['NonRigidParameter_final'], 'r') as f_parameter:
                parameter_str = f_parameter.read()
            textScr.write('command="antsRegistration ' + parameter_str + '"')
        else:
            textScr.write(ANTsP.bspline_syn_empire10_final(setting))
        textScr.write(ANTsP.footer())
        textScr.close()
    os.chmod(nonrigid_script_final, 0o774)
    os.system(nonrigid_script_final)