Ejemplo n.º 1
0
In this script, we build a synthetic sinogram to be used with PyHST as well as
with the demo_tv_reconstruction.py script. This will help to compare the
different methods.
"""

import numpy as np
from reconstruction.util import generate_synthetic_data
from reconstruction.projections import build_projection_operator
from EdfFile import EdfFile

# Synthetic data
l = 256
x = generate_synthetic_data(l)

# Projection operator and projections data, with noise
H = build_projection_operator(l, l / 5)
y = H * x.ravel()[:, np.newaxis]
y += 2 * np.random.randn(*y.shape)
y[y < 0] = 0

y = y.reshape((l / 5, l))
y = y.astype(np.float32)

# Write EdfFile with float32 data
phantom = EdfFile("phantom_float.edf")

for line in y:
    lines = np.tile(line, (3, 1))
    print "writing", lines.shape
    phantom._WriteImage({}, lines, DataType="FloatValue", Append=1)
    #phantom.WriteImage({}, lines)
Ejemplo n.º 2
0
import numpy as np
from reconstruction.util import generate_synthetic_data
from reconstruction.projections import build_projection_operator
from reconstruction.forward_backward_tv import fista_tv
from joblib import Parallel, delayed

# Synthetic data
l = 256
x = generate_synthetic_data(l, n_pts=100)

n_dir = 80


# Projection operator and projections data, with 2 realizations of the noise
H = build_projection_operator(l, n_dir)
y = H * x.ravel()[:, np.newaxis]
np.random.seed(0)
y1 = y + 2*np.random.randn(*y.shape)  # 1st realization
y2 = y + 2*np.random.randn(*y.shape)  # 2nd realization

# Range of beta parameter
betas = 2**np.arange(2, 6, 0.25)


def rec_error(beta):
    """
    cross-validation
    """
    res, energies = fista_tv(y1, beta, 400, H)
    yres = H * res[-1].ravel()[:, np.newaxis]
Ejemplo n.º 3
0
with the demo_tv_reconstruction.py script. This will help to compare the
different methods.
"""

import numpy as np
from reconstruction.util import generate_synthetic_data
from reconstruction.projections import build_projection_operator
from EdfFile import EdfFile

# Synthetic data
l = 256
x = generate_synthetic_data(l)


# Projection operator and projections data, with noise
H = build_projection_operator(l, l/5)
y = H * x.ravel()[:, np.newaxis]
y += 2*np.random.randn(*y.shape)
y[y<0] = 0

y = y.reshape((l/5, l))
y = y.astype(np.float32)

# Write EdfFile with float32 data
phantom = EdfFile("phantom_float.edf")

for line in y:
    lines = np.tile(line, (3, 1))
    print "writing", lines.shape
    phantom._WriteImage({}, lines, DataType="FloatValue", Append=1)
    #phantom.WriteImage({}, lines)