コード例 #1
0
tau = 1 / normK

# Setup and run the PDHG algorithm
pdhg = PDHG(f=f, g=g, operator=operator, tau=tau, sigma=sigma)
pdhg.max_iteration = 5000
pdhg.update_objective_interval = 500
pdhg.run(5000)

# Show results
plt.figure(figsize=(20, 5))
plt.subplot(1, 4, 1)
plt.imshow(data.subset(channel=0).as_array())
plt.title('Ground Truth')
plt.colorbar()
plt.subplot(1, 4, 2)
plt.imshow(noisy_data.subset(channel=0).as_array())
plt.title('Noisy Data')
plt.colorbar()
plt.subplot(1, 4, 3)
plt.imshow(pdhg.get_output()[0].as_array())
plt.title('TGV Reconstruction')
plt.colorbar()
plt.subplot(1, 4, 4)
plt.plot(np.linspace(0, ig.shape[1], ig.shape[1]),
         data.as_array()[int(ig.shape[0] / 2), :],
         label='GTruth')
plt.plot(np.linspace(0, ig.shape[1], ig.shape[1]),
         pdhg.get_output()[0].as_array()[int(ig.shape[0] / 2), :],
         label='TGV reconstruction')
plt.legend()
plt.title('Middle Line Profiles')
コード例 #2
0
# Image parameters
N = 128
vert = 4

# Set up image geometry
ig = ImageGeometry(voxel_num_x=N, voxel_num_y=N, voxel_num_z=vert)

# Set up empty image data
Phantom = ImageData(
    geometry=ig, dimension_labels=['horizontal_x', 'horizontal_y', 'vertical'])

# Populate image data by looping over and filling slices
i = 0
while i < vert:
    if vert > 1:
        x = Phantom.subset(vertical=i).array
    else:
        x = Phantom.array
    x[round(N / 4):round(3 * N / 4), round(N / 4):round(3 * N / 4)] = 0.5
    x[round(N / 8):round(7 * N / 8), round(3 * N / 8):round(5 * N / 8)] = 0.98
    if vert > 1:
        Phantom.fill(x, vertical=i)
    i += 1

# Display slice of phantom
if vert > 1:
    plt.imshow(Phantom.subset(vertical=0).as_array())
else:
    plt.imshow(Phantom.as_array())
plt.show()