예제 #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)
예제 #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)
예제 #3
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)
예제 #4
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)
예제 #5
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)