Пример #1
0
def image_to_parametric(pet_image,
                        dt,
                        model_name,
                        model_inputs,
                        km_outputs,
                        thr=0.005):
    parametric_images = []
    for p in range(len(km_outputs)):
        parametric_images.append(np.zeros(pet_image.shape[0:3]))
    pet_image_fit = np.zeros(pet_image.shape)
    thr = thr * np.amax(pet_image)
    mask = np.argwhere(np.mean(pet_image, axis=-1) > thr)
    for i in range(mask.shape[0]):
        print(str(i) + '/' + str(mask.shape[0]))
        tac = TAC(pet_image[mask[i][0], mask[i][1], mask[i][2], ], dt)
        tac.run_model(model_name, model_inputs)
        # #
        plt.plot(tac.mft, tac.km_results['tacf'], 'r', tac.mft, tac.tac, 'go')
        plt.show()
        # #
        pet_image_fit[mask[i][0], mask[i][1],
                      mask[i][2], ] = tac.km_results['tacf']
        print(tac.km_results)
        for p in range(len(km_outputs)):
            parametric_images[p][mask[i][0], mask[i][1],
                                 mask[i][2], ] = tac.km_results[
                                     km_outputs[p].lower()]
    parametric_images_dict = dict(zip(km_outputs, parametric_images))
    return parametric_images_dict, pet_image_fit
Пример #2
0
def parametric_to_image(parametric_images_dict, dt, model, km_inputs):
    parametric_images = list(parametric_images_dict.values())
    pet_image = np.zeros(parametric_images[0].shape[0:3] + (dt.shape[-1], ))
    mask = np.argwhere(parametric_images[0] != 0)
    for i in range(mask.shape[0]):
        km_inputs_local = km_inputs.copy()
        for p in parametric_images_dict.keys():
            km_inputs_local.update({
                p.lower():
                parametric_images_dict[p][mask[i][0], mask[i][1], mask[i][2]]
            })
        tac = TAC([], dt)
        getattr(tac, 'run_' + model + '_para2tac')(**km_inputs_local)
        pet_image[mask[i][0], mask[i][1],
                  mask[i][2], ] = tac.km_results['tacf']
    return pet_image
Пример #3
0
    7.29047317769810, 6.22241739146864, 5.38418292132310, 4.82308160452273,
    4.51763401957080, 4.23271724360837, 3.99675706316514
])

tac = np.array([
    0.0612937319754616, 2.56733416202755, 13.2302628562565, 17.5212376697891,
    19.8554469827973, 21.2888518029975, 22.3164453083215, 21.9106339934451,
    21.6976991361882, 21.2760967663021, 21.0320027737135, 20.3356078483447,
    19.7789261620624, 18.7016942272702, 17.5381378584246, 16.6955628809652,
    15.8305514461795, 15.1466577726934, 14.2137260024906, 13.7598553636470,
    12.9989332998008, 11.8293518915139, 10.3648913297944, 8.93110113265639,
    7.50503727314817, 6.49229487908344, 5.83027369667342, 5.35683342894270,
    4.94744092837665, 4.79454967790696, 4.49907835991146
])

tac = TAC(tac, dt)
ref = Ref(ref, dt)
ref.interp_1()
w = dt2tdur(tac.dt)
w = w / np.amax(w)
beta_lim = [0.0100000 / 60, 0.300000 / 60]
n_beta = 40
b = basis.make_basis(ref.inputf1, dt, beta_lim=beta_lim, n_beta=n_beta, w=w)

# provide all user inputs in one dict here and later 'get_model_inputs' will select the needed ones
user_inputs = {
    'dt': dt,
    'inputf1': ref.inputf1,
    'w': w,
    'r1': 0.905,
    'k2p': 0.00025,
Пример #4
0
user_inputs = {'dt': dt,
               'inputf1': ref.inputf1cubic,
               'w': None,
               'r1': 0.905,
               'k2p': 0.00025,
               'beta_lim': beta_lim,
               'n_beta': n_beta,
               'b': b
               }
user_inputs_fill_gaps = {'b': b_fill_gaps,
                         'inputf1_dt': inputf1_dt_fill_gaps
                         }
km_outputs = ['R1', 'k2', 'BP']


tac = TAC(ref.tac, dt)
for model_name in models:
    model_inputs = get_model_inputs(user_inputs, model_name)
    tac.run_model(model_name, model_inputs)
    # make
    tac.km_results.update(user_inputs_fill_gaps)
    km_inputs = tac.km_results
    model_km_inputs = get_model_inputs(km_inputs, model_name+ '_para2tac')
    tac.run_model_para2tac(model_name + '_para2tac', model_km_inputs)

    plt.plot(tac.mft, tac.tac, 'b*', label='tac')
    plt.plot(dt2mft(dt_fill_gaps), tac.km_results['tacf'], 'r', label='fit')
    plt.legend()
    plt.show()