""" 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)
In the example below, we observe for a binary image that using this cross-validation method, we select the value of beta that minimizes as well the segmentation error. """ print __doc__ 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)
""" 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