

def phantom_generation(tracts, std_noise_perc, range_tract_perc, true_value, folder_out, value_gm, value_csf):
    '\n    :param tracts: np array\n    :param std_noise: std of noise to generate pseudo-random gaussianly-distributed noise\n    :param range_tract: range of value to generate pseudo-random uniformly-distributed tract value\n    :param true_value: true value of the tract\n    :param folder_out: output folder\n    :param zero_last_tract: assign value 0 to last tract (corresponds to CSF)\n    :return: synthetic_vol, synthetic_voln, values_synthetic_data, tracts_sum\n    '
    fname_phantom = (folder_out + 'phantom_values.txt')
    range_tract = ((float(range_tract_perc) / 100) * true_value)
    std_noise = ((float(std_noise_perc) / 100) * true_value)
    numtracts = len(tracts)
    (nx, ny, nz) = tracts[0][0].shape
    fid_file = open(fname_phantom, 'w+')
    ((print >> fid_file), ((((('std_noise=' + str(std_noise_perc)) + '%, range_tract=') + str(range_tract_perc)) + '%, true_value=') + str(true_value)))
    tracts_weighted = np.zeros([numtracts, nx, ny, nz])
    synthetic_vol = np.zeros([nx, ny, nz])
    synthetic_voln = np.zeros([nx, ny, nz])
    values_synthetic_data = np.zeros([numtracts])
    for i in range(0, numtracts):
        if (i == (numtracts - 2)):
            values_synthetic_data[i] = value_gm
        elif (i == (numtracts - 1)):
            values_synthetic_data[i] = value_csf
        else:
            values_synthetic_data[i] = ((true_value - range_tract) + random.uniform(0, (2 * range_tract)))
        ((print >> fid_file), ((('label=' + str(i)) + ', value=') + str(values_synthetic_data[i])))
        tracts_weighted[i, :, :, :] = (values_synthetic_data[i] * tracts[(i, 0)])
        synthetic_vol = (synthetic_vol + tracts_weighted[i, :, :, :])
    tracts_sum = np.zeros([nx, ny, nz])
    for i in range(0, numtracts):
        tracts_sum = (tracts_sum + tracts[(i, 0)])
    fid_file.close()
    if (not (std_noise == 0)):
        synthetic_voln = (synthetic_vol + np.random.normal(loc=0, scale=std_noise, size=(nx, ny, nz)))
    else:
        synthetic_voln = synthetic_vol
    return [synthetic_vol, synthetic_voln, values_synthetic_data, tracts_sum]

dataset/ETHPy150Open neuropoly/spinalcordtoolbox/dev/atlas/validate_atlas/generate_phantom.py phantom_generation/original