def test_TotalVariation_vs_FGP_TV_gpu(self):   

        # Isotropic TV cil
        TV_cil_iso = self.alpha * TotalVariation(max_iteration=self.iterations)
        res_TV_cil_iso = TV_cil_iso.proximal(self.data, tau=1.0)        

        # Anisotropic TV cil
        TV_cil_aniso = self.alpha * TotalVariation(max_iteration=self.iterations, isotropic=False) 
        res_TV_cil_aniso = TV_cil_aniso.proximal(self.data, tau=1.0)               
        
        # Isotropic FGP_TV CCPiReg toolkit (gpu)
        TV_regtoolkit_gpu_iso = self.alpha * FGP_TV(max_iteration=self.iterations, device = 'gpu') 
        res_TV_regtoolkit_gpu_iso = TV_regtoolkit_gpu_iso.proximal(self.data, tau=1.0)

        # Anisotropic FGP_TV CCPiReg toolkit (gpu)
        TV_regtoolkit_gpu_aniso = self.alpha * FGP_TV(max_iteration=self.iterations, device = 'gpu', isotropic=False)  
        res_TV_regtoolkit_gpu_aniso = TV_regtoolkit_gpu_aniso.proximal(self.data, tau=1.0)  

        # Anisotropic FGP_TV CCPiReg toolkit (cpu)
        TV_regtoolkit_cpu_aniso = self.alpha * FGP_TV(max_iteration=self.iterations, device = 'cpu', isotropic=False)         
        res_TV_regtoolkit_cpu_aniso = TV_regtoolkit_cpu_aniso.proximal(self.data, tau=1.0)          

        # Isotropic FGP_TV CCPiReg toolkit (cpu)
        TV_regtoolkit_cpu_iso = self.alpha * FGP_TV(max_iteration=self.iterations, device = 'cpu')
        res_TV_regtoolkit_cpu_iso = TV_regtoolkit_cpu_iso.proximal(self.data, tau=1.0)        

        np.testing.assert_array_almost_equal(res_TV_cil_iso.array, res_TV_regtoolkit_gpu_iso.array, decimal=3)
        np.testing.assert_array_almost_equal(res_TV_regtoolkit_cpu_iso.array, res_TV_regtoolkit_gpu_iso.array, decimal=3)

        np.testing.assert_array_almost_equal(res_TV_cil_aniso.array, res_TV_regtoolkit_gpu_aniso.array, decimal=3)
        np.testing.assert_array_almost_equal(res_TV_regtoolkit_cpu_aniso.array, res_TV_regtoolkit_gpu_aniso.array, decimal=3)              
 def test_FGP_TV_complex(self):
     data = dataexample.CAMERA.get(size=(256, 256))
     datarr = data.as_array()
     cmpx = np.zeros(data.shape, dtype=np.complex)
     cmpx.real = datarr[:]
     cmpx.imag = datarr[:]
     data.array = cmpx
     reg = FGP_TV()
     out = reg.proximal(data, 1)
     outarr = out.as_array()
     np.testing.assert_almost_equal(outarr.imag, outarr.real)
    def test_functionality_FGP_TV(self):

        data = dataexample.CAMERA.get(size=(256,256))
        datarr = data.as_array()
        from cil.plugins.ccpi_regularisation.functions import FGP_TV
        from ccpi.filters import regularisers

        tau = 1.
        fcil = FGP_TV()
        outcil = fcil.proximal(data, tau=tau)
        # use CIL defaults
        outrgl, info = regularisers.FGP_TV(datarr, fcil.alpha*tau, fcil.max_iteration, fcil.tolerance, 0, 1, 'cpu' )
        np.testing.assert_almost_equal(outrgl, outcil.as_array())
    def test_FGP_TV_raise_on_4D_data(self):

        from cil.plugins.ccpi_regularisation.functions import FGP_TV
        
        tau = 1.
        fcil = FGP_TV()
        data = ImageGeometry(3,4,5,channels=10).allocate(0)


        try:
            outcil = fcil.proximal(data, tau=tau)
            assert False
        except ValueError:
            assert True
Beispiel #5
0
fista.run(300)
LS_reco = fista.get_output()
show2D(LS_reco,
       slice_list=[('vertical', 204 // bins), ('horizontal_y', 570 // bins)],
       title="LS reconstruction",
       fix_range=(-0.02, 0.07))

#%%
plt.figure()
plt.semilogy(fista.objective)
plt.title('FISTA LS criterion')
plt.show()

#%% Setup total-variation (TV) with a non-negativity (NN) contraint
alpha = 1
TV = alpha * FGP_TV(isotropic=True, device='gpu')

#%% Setup FISTA to solve for LS with TV+NN
fista = FISTA(x_init=ig.allocate(0), f=LS, g=TV, max_iteration=1000)
fista.update_objective_interval = 10

#%% Run FISTA
fista.run(300)
TV_NN_reco_isotropic = fista.get_output()
show2D(TV_NN_reco_isotropic,
       slice_list=[('vertical', 204 // bins), ('horizontal_y', 570 // bins)],
       title="TV_NN 100it reconstruction",
       fix_range=(-0.02, 0.07))

#%%
plt.figure()
Beispiel #6
0
    from cil.plugins.astra.operators import ProjectionOperator as A  #
    from cil.plugins.ccpi_regularisation.functions import FGP_TV

    K = A(ig_cs, ag_shift)
    # the c parameter is used to remove scaling of L2NormSquared in PDHG
    #
    c = 2
    f = LeastSquares(K, ldata, c=0.5 * c)
    if sparse_beads:
        f.L = 1071.1967 * c
    else:
        f.L = 24.4184 * c
    alpha_rgl = 0.003
    alpha = alpha_rgl * ig_cs.voxel_size_x
    g = c * alpha * TotalVariation(lower=0.)
    g = FGP_TV(alpha, 100, 1e-5, 1, 1, 0, 'gpu')

    algo = FISTA(initial=K.domain.allocate(0),
                 f=f,
                 g=g,
                 max_iteration=10000,
                 update_objective_interval=2)
    #%%
    import cProfile
    algo.update_objective_interval = 10
    cProfile.run('algo.run(100, verbose=1)')
    #%%
    plotter2D(algo.solution, cmap='gist_earth')

    #%%
    def test_FGP_TV_rmul(self):
        from cil.plugins.ccpi_regularisation.functions import FGP_TV
        f = FGP_TV()

        self.rmul_test(f)