예제 #1
0
def reg_epi(ref, flo_path):
    i = 0
    resampler2 = Reg.NiftyAladinSym()
    resampler2.set_reference_image(ref)
    for image in sorted_alphanumeric(os.listdir(flo_path)):
        flo_file = flo_path + image
        print(flo_file)
        flo = Eng_flo.ImageData(flo_file)
        resampler2.set_floating_image(flo)
        resampler2.process()
        tm_epi = resampler2.get_transformation_matrix_forward()
        tm_epi.write(path_EPI + 'tm_epi_' + str(i))
        i += 1
예제 #2
0
def reg_nac(ref, flo_path, list_NACs):
    i = 0
    nac_reg = Reg.NiftyAladinSym()
    nac_reg.set_reference_image(ref)
    for image in sorted_alphanumeric(list_NACs):
        nac_file = flo_path + image
        print(nac_file)
        flo = Eng_flo.ImageData(nac_file)
        nac_reg.set_floating_image(flo)
        nac_reg.process()
        tm_nac = nac_reg.get_transformation_matrix_forward()
        tm_nac.write(path_moco + 'tm_nac_' + str(i))
        i += 1
예제 #3
0
def register_data(static_path, dynamic_path, output_path):
    path_new_displacement_fields = "{0}/new_displacement_fields/".format(
        output_path)

    if not os.path.exists(path_new_displacement_fields):
        os.makedirs(path_new_displacement_fields, mode=0o770)

    path_new_deformation_fields = "{0}/new_deformation_fields/".format(
        output_path)

    if not os.path.exists(path_new_deformation_fields):
        os.makedirs(path_new_deformation_fields, mode=0o770)

    path_new_tm = "{0}/new_tm/".format(output_path)

    if not os.path.exists(path_new_tm):
        os.makedirs(path_new_tm, mode=0o770)

    algo = reg.NiftyAladinSym()

    dvf_path = []

    for i in range(len(dynamic_path)):
        ref = reg.ImageData(dynamic_path[i])
        flo = reg.ImageData(static_path)

        algo.set_reference_image(ref)
        algo.set_floating_image(flo)

        algo.process()

        displacement_field = algo.get_displacement_field_forward()
        displacement_field.write("{0}/new_displacement_field_{1}.nii".format(
            path_new_displacement_fields, str(i)))

        dvf_path.append("{0}/new_DVF_field_{1}.nii".format(
            path_new_deformation_fields, str(i)))

        deformation_field = algo.get_deformation_field_forward()
        deformation_field.write(dvf_path[i])

        tm = algo.get_transformation_matrix_forward()
        tm.write("{0}/new_tm_{1}.nii".format(path_new_tm, str(i)))

    return dvf_path
예제 #4
0
    os.makedirs(path_recon, mode=0o770)
    print('Create Folder: {}'.format(path_recon))
if not os.path.exists(path_NAC):
    os.makedirs(path_NAC, mode=0o770)
    print('Create Folder: {}'.format(path_NAC))
if not os.path.exists(path_moco_NAC):
    os.makedirs(path_moco_NAC, mode=0o770)
    print('Create Folder: {}'.format(path_moco_NAC))

#%% register EPI to PET with NiftyReg
ref_file = path_NAC + '/nii/' + 'NAC_0.nii'
flo_file = data_path_EPI_image
ref = Eng_ref.ImageData(ref_file)
flo = Eng_ref.ImageData(flo_file)

register = Reg.NiftyAladinSym()
register.set_reference_image(ref)
register.set_floating_image(flo)
register.process()
tm_fwd = register.get_transformation_matrix_forward()
tm_fwd.write(working_folder + '/tm_fwd.txt')
tm_inv = register.get_transformation_matrix_inverse()
tm_inv.write(working_folder + '/tm_inv.txt')

# idy = tm_inv * tm_fwd
# idy.write(working_folder + '/idy.txt')

matrix = numpy.loadtxt('tm_test_epi.txt')
inverse = numpy.linalg.inv(matrix)
tm_fwd2 = Reg.AffineTransformation(matrix)
tm_inv2 = Reg.AffineTransformation(inverse)