def test_FISTA_Denoising(self): print ("FISTA Denoising Poisson Noise Tikhonov") # adapted from demo FISTA_Tikhonov_Poisson_Denoising.py in CIL-Demos repository #loader = TestData(data_dir=os.path.join(sys.prefix, 'share','ccpi')) loader = TestData() data = loader.load(TestData.SHAPES) ig = data.geometry ag = ig N=300 # Create Noisy data with Poisson noise scale = 5 n1 = TestData.random_noise( data.as_array()/scale, mode = 'poisson', seed = 10)*scale noisy_data = ImageData(n1) # Regularisation Parameter alpha = 10 # Setup and run the FISTA algorithm operator = Gradient(ig) fid = KullbackLeibler(b=noisy_data) reg = FunctionOperatorComposition(alpha * L2NormSquared(), operator) x_init = ig.allocate() fista = FISTA(x_init=x_init , f=reg, g=fid) fista.max_iteration = 3000 fista.update_objective_interval = 500 fista.run(verbose=True) rmse = (fista.get_output() - data).norm() / data.as_array().size print ("RMSE", rmse) self.assertLess(rmse, 4.2e-4)
x_init = A3D.volume_geometry.allocate() # Allocate space for the channel-wise reconstruction fista_sol_TV_channel_wise = A3D_chan.volume_geometry.allocate() for i in range(ag.channels): # Setup L2NormSquarred fidelity term, for each channel f = FunctionOperatorComposition( 0.5 * L2NormSquared(b=data.subset(channel=i)), A3D) # Run FISTA fista = FISTA(x_init=x_init, f=f, g=g) fista.max_iteration = 100 fista.update_objective_interval = 50 fista.run(400, verbose=True, callback=show_data_3D) np.copyto(fista_sol_TV_channel_wise.array[i], fista.get_output().array) #%% show reconstruction show_4D_channel_slice(fista_sol_TV_channel_wise, 5, 'FISTA TV channel-wise reconstruction') show_4D_channel_slice(fista_sol_TV_channel_wise, 10, 'FISTA TV channel-wise reconstruction') show_4D_channel_slice(fista_sol_TV_channel_wise, 15, 'FISTA TV channel-wise reconstruction') #%% Coupling Total variation reconstruction in 4D volume. For this case there is no GPU implementation # But we can use another algorithm called PDHG ( primal - dual hybrid gradient)
plt.show() plt.figure() plt.semilogy(CGLS_alg.objective) plt.title('CGLS criterion') plt.show() # Create least squares object instance with projector and data. print ("Create least squares object instance with projector and data.") f = Norm2Sq(Cop,padded_data,c=0.5) # Run FISTA for least squares without constraints FISTA_alg = FISTA() FISTA_alg.set_up(x_init=x_init, f=f) FISTA_alg.max_iteration = 2000 FISTA_alg.update_objective_interval = 10 FISTA_alg.run(opt['iter']) x_FISTA = FISTA_alg.get_output() # Display ortho slices of reconstruction # Display all reconstructions and decay of objective function fig = plt.figure() current = 1 a=fig.add_subplot(rows,cols,current) a.set_title('horizontal_x') imgplot = plt.imshow(x_FISTA.subset(horizontal_x=hx).as_array(),vmin=v1,vmax=v2) current = current + 1 a=fig.add_subplot(rows,cols,current)
noisy_data = ImageData(n1) # Regularisation Parameter alpha = 5 ############################################################################### # Setup and run the FISTA algorithm operator = Gradient(ig) fidelity = L1Norm(b=noisy_data) regulariser = FunctionOperatorComposition(alpha * L2NormSquared(), operator) x_init = ig.allocate() opt = {'memopt': True} fista = FISTA(x_init=x_init, f=regulariser, g=fidelity, opt=opt) fista.max_iteration = 2000 fista.update_objective_interval = 50 fista.run(2000, verbose=False) ############################################################################### ############################################################################### # Setup and run the PDHG algorithm op1 = Gradient(ig) op2 = Identity(ig, ag) operator = BlockOperator(op1, op2, shape=(2, 1)) f = BlockFunction(alpha * L2NormSquared(), fidelity) g = ZeroFunction() normK = operator.norm() sigma = 1
Aop = AstraProjectorSimple(ig, ag, dev) sin = Aop.direct(data) eta = 0 noisy_data = AcquisitionData(sin.as_array() + np.random.normal(0, 1, ag.shape)) back_proj = Aop.adjoint(noisy_data) # Define Least Squares f = FunctionOperatorComposition(L2NormSquared(b=noisy_data), Aop) # Allocate solution x_init = ig.allocate() # Run FISTA for least squares fista = FISTA(x_init=x_init, f=f, g=ZeroFunction()) fista.max_iteration = 10 fista.update_objective_interval = 2 fista.run(100, verbose=True) # Run FISTA for least squares with lower/upper bound fista0 = FISTA(x_init=x_init, f=f, g=IndicatorBox(lower=0, upper=1)) fista0.max_iteration = 10 fista0.update_objective_interval = 2 fista0.run(100, verbose=True) # Run FISTA for Regularised least squares, with Squared norm of Gradient alpha = 20 Grad = Gradient(ig) block_op = BlockOperator(Aop, alpha * Grad, shape=(2, 1)) block_data = BlockDataContainer(noisy_data, Grad.range_geometry().allocate()) f1 = FunctionOperatorComposition(L2NormSquared(b=block_data), block_op)