Esempio n. 1
0
def generate_data(validation=False):
    """Generate a set of random data."""
    n_iter = 1 if validation else n_data

    x_arr = np.empty((n_iter, space.shape[0], space.shape[1], 1),
                     dtype='float32')
    y_arr = np.empty(
        (n_iter, operator.range.shape[0], operator.range.shape[1], 1),
        dtype='float32')
    x_true_arr = np.empty((n_iter, space.shape[0], space.shape[1], 1),
                          dtype='float32')

    for i in range(n_iter):
        if validation:
            phantom = odl.phantom.shepp_logan(space, True)
        else:
            phantom = random_phantom(space)

        data = operator(phantom)
        noisy_data = data + odl.phantom.white_noise(operator.range) * np.mean(
            np.abs(data)) * 0.05
        fbp = pseudoinverse(noisy_data)

        x_arr[i, ..., 0] = fbp
        x_true_arr[i, ..., 0] = phantom
        y_arr[i, ..., 0] = noisy_data

    return x_arr, y_arr, x_true_arr
Esempio n. 2
0
def generate_data(validation=False, noiseLev = noiseLev):
    """Generate a set of random data."""
    n_generate = val_size if validation else n_data

    x_arr = np.empty((n_generate, 1, ray_trafo.range.shape[0], ray_trafo.range.shape[1]), dtype='float32')
    x_true_arr = np.empty((n_generate, 1, space.shape[0], space.shape[1]), dtype='float32')

    for i in range(n_generate):
        if validation:
            phantom = odl.phantom.shepp_logan(space, True)
        else:
            phantom = (random_phantom(space,n_ellipse=30))
        data = ray_trafo(phantom)
        noisy_data = data + odl.phantom.white_noise(ray_trafo.range) * np.mean(np.abs(data)) * noiseLev
        

        x_arr[i, 0] = noisy_data
        x_true_arr[i, 0] = phantom

    return x_arr, x_true_arr