Exemplo n.º 1
0
                             det_num,det_w)
elif test_case==2:
    angles = np.linspace(0,2*np.pi,angles_num,endpoint=False)
    ag = AcquisitionGeometry('cone',
                             '2D',
                             angles,
                             det_num,
                             det_w,
                             dist_source_center=SourceOrig, 
                             dist_center_detector=OrigDetec)
else:
    NotImplemented

# Set up Operator object combining the ImageGeometry and AcquisitionGeometry
# wrapping calls to ASTRA as well as specifying whether to use CPU or GPU.
Aop = AstraProjectorSimple(ig, ag, 'gpu')

# Forward and backprojection are available as methods direct and adjoint. Here 
# generate test data b and do simple backprojection to obtain z.
b = Aop.direct(Phantom)
z = Aop.adjoint(b)

plt.imshow(b.array)
plt.title('Simulated data')
plt.colorbar()
plt.show()

plt.imshow(z.array)
plt.title('Backprojected data')
plt.colorbar()
plt.show()
Exemplo n.º 2
0
    ag = AcquisitionGeometry('parallel', '2D', angles, det_num, det_w)
elif test_case == 2:
    angles = np.linspace(0, 2 * np.pi, angles_num, endpoint=False)
    ag = AcquisitionGeometry('cone',
                             '2D',
                             angles,
                             det_num,
                             det_w,
                             dist_source_center=SourceOrig,
                             dist_center_detector=OrigDetec)
else:
    NotImplemented

# Set up Operator object combining the ImageGeometry and AcquisitionGeometry
# wrapping calls to ASTRA as well as specifying whether to use CPU or GPU.
Aop = AstraProjectorSimple(ig, ag, 'gpu')

# Forward and backprojection are available as methods direct and adjoint. Here
# generate test data b and do simple backprojection to obtain z.
b = Aop.direct(Phantom)
z = Aop.adjoint(b)

plt.imshow(b.array)
plt.title('Simulated data')
plt.show()

plt.imshow(z.array)
plt.title('Backprojected data')
plt.show()

# Using the test data b, different reconstruction methods can now be set up as
# Reduce to single (noncentral) slice by extracting relevant parameters from data and its
# geometry. Perhaps create function to extract central slice automatically?
b2d = b.subset(vertical=128)
ag2d = AcquisitionGeometry('parallel',
                         '2D',
                         ag.angles,
                         pixel_num_h=ag.pixel_num_h)
b2d.geometry = ag2d

# Create 2D image geometry
ig2d = ImageGeometry(voxel_num_x=ag2d.pixel_num_h, 
                     voxel_num_y=ag2d.pixel_num_h)

# Create GPU projector/backprojector operator with ASTRA.
Aop = AstraProjectorSimple(ig2d,ag2d,'gpu')

# Demonstrate operator is working by applying simple backprojection.
z = Aop.adjoint(b2d)
plt.imshow(z.array)
plt.title('Simple backprojection')
plt.colorbar()
plt.show()

# Set initial guess ImageData with zeros for algorithms, and algorithm options.
x_init = ImageData(numpy.zeros((imsize,imsize)),
                   geometry=ig2d)
opt_CGLS = {'tol': 1e-4, 'iter': 20}

# Run CGLS algorithm and display reconstruction.
x_CGLS, it_CGLS, timing_CGLS, criter_CGLS = CGLS(x_init, Aop, b2d, opt_CGLS)
Exemplo n.º 4
0
eqzero = ProjAngleChannels == 0
ProjAngleChannels[eqzero] = 1
ProjAngleChannels_NormLog = -np.log(
    ProjAngleChannels)  # normalised and neg-log data

# extact sinogram over energy channels
selectedVertical_slice = 256
sino_all_channels = ProjAngleChannels_NormLog[:, :, :, selectedVertical_slice]
# Set angles to use
angles = np.linspace(-np.pi, np.pi, totalAngles, endpoint=False)

# set the geometry
ig = ImageGeometry(n, n)
ag = AcquisitionGeometry('parallel', '2D', angles, n, 1)
Aop = AstraProjectorSimple(ig, ag, 'gpu')

# loop to reconstruct energy channels
REC_chan = np.zeros((totChannels, n, n), 'float32')
for i in range(0, totChannels, 1):
    sino_channel = sino_all_channels[:,
                                     i, :]  # extract a sinogram for i-th channel

    print("Initial guess")
    x_init = ImageData(geometry=ig)

    # Create least squares object instance with projector and data.
    print("Create least squares object instance with projector and data.")
    f = Norm2sq(Aop, DataContainer(sino_channel), c=0.5)

    print("Run FISTA-TV for least squares")
Exemplo n.º 5
0
# Choose the number of voxels to reconstruct onto as number of detector pixels
N = data.geometry.pixel_num_h

# Geometric magnification
mag = (np.abs(data.geometry.dist_center_detector) + \
      np.abs(data.geometry.dist_source_center)) / \
      np.abs(data.geometry.dist_source_center)

# Voxel size is detector pixel size divided by mag
voxel_size_h = data.geometry.pixel_size_h / mag

# Construct the appropriate ImageGeometry
ig2d = ImageGeometry(voxel_num_x=N,
                     voxel_num_y=N,
                     voxel_size_x=voxel_size_h,
                     voxel_size_y=voxel_size_h)

# Set up the Projector (AcquisitionModel) using ASTRA on GPU
Aop = AstraProjectorSimple(ig2d, ag2d, "gpu")

# Set initial guess for CGLS reconstruction
x_init = ImageData(np.zeros((N, N)), geometry=ig2d)

# Run 50-iteration CGLS reconstruction
opt = {'tol': 1e-4, 'iter': 50}
x, it, timing, criter = CGLS(x_init, Aop, data2d, opt=opt)

# Display reconstruction
plt.figure()
plt.imshow(x.as_array())
plt.colorbar()