Exemple #1
0
        def setup(data, dnoise):
            if dnoise == 's&p':
                n1 = applynoise.saltnpepper(data,
                                            salt_vs_pepper=0.9,
                                            amount=0.2,
                                            seed=10)
            elif dnoise == 'poisson':
                scale = 5
                n1 = applynoise.poisson(data.as_array() / scale,
                                        seed=10) * scale
            elif dnoise == 'gaussian':
                n1 = applynoise.gaussian(data.as_array(), seed=10)
            else:
                raise ValueError('Unsupported Noise ', noise)
            noisy_data = ig.allocate()
            noisy_data.fill(n1)

            # Regularisation Parameter depending on the noise distribution
            if dnoise == 's&p':
                alpha = 0.8
            elif dnoise == 'poisson':
                alpha = 1
            elif dnoise == 'gaussian':
                alpha = .3
                # fidelity
            if dnoise == 's&p':
                g = L1Norm(b=noisy_data)
            elif dnoise == 'poisson':
                g = KullbackLeibler(b=noisy_data)
            elif dnoise == 'gaussian':
                g = 0.5 * L2NormSquared(b=noisy_data)
            return noisy_data, alpha, g
Exemple #2
0
    def test_compare_with_PDHG(self):
        # Load an image from the CIL gallery.
        data = dataexample.SHAPES.get()
        ig = data.geometry
        # Add gaussian noise
        noisy_data = applynoise.gaussian(data, seed=10, var=0.005)

        # TV regularisation parameter
        alpha = 1

        # fidelity = 0.5 * L2NormSquared(b=noisy_data)
        # fidelity = L1Norm(b=noisy_data)
        fidelity = KullbackLeibler(b=noisy_data, use_numba=False)

        # Setup and run the PDHG algorithm
        F = BlockFunction(alpha * MixedL21Norm(), fidelity)
        G = ZeroFunction()
        K = BlockOperator(GradientOperator(ig), IdentityOperator(ig))

        # Compute operator Norm
        normK = K.norm()

        # Primal & dual stepsizes
        sigma = 1. / normK
        tau = 1. / normK

        pdhg = PDHG(f=F,
                    g=G,
                    operator=K,
                    tau=tau,
                    sigma=sigma,
                    max_iteration=100,
                    update_objective_interval=10)
        pdhg.run(verbose=0)

        sigma = 1
        tau = sigma / normK**2

        admm = LADMM(f=G,
                     g=F,
                     operator=K,
                     tau=tau,
                     sigma=sigma,
                     max_iteration=100,
                     update_objective_interval=10)
        admm.run(verbose=0)

        from cil.utilities.quality_measures import psnr
        if debug_print:
            print("PSNR", psnr(admm.solution, pdhg.solution))
        np.testing.assert_almost_equal(psnr(admm.solution, pdhg.solution),
                                       84.46678222768597,
                                       decimal=4)
    def setUp(self):
        print ("SETUP", np.version.version)
        if has_skimage:

            id_coins = dataexample.CAMERA.get()

            id_coins_noisy = noise.gaussian(id_coins, var=0.05, seed=10)
            
            ig = id_coins.geometry.copy()
            dc1 = ig.allocate('random')
            dc2 = ig.allocate('random')

            self.dc1 = dc1
            self.dc2 = dc2
            self.id_coins = id_coins
            self.id_coins_noisy = id_coins_noisy
Exemple #4
0
    def test_compare_regularisation_toolkit_tomophantom(self):

        print("Compare CIL_FGP_TV vs CCPiReg_FGP_TV no tolerance (3D)")

        print("Building 3D phantom using TomoPhantom software")
        model = 13  # select a model number from the library
        N_size = 64  # Define phantom dimensions using a scalar value (cubic phantom)
        path = os.path.dirname(tomophantom.__file__)
        path_library3D = os.path.join(path, "Phantom3DLibrary.dat")
        #This will generate a N_size x N_size x N_size phantom (3D)
        phantom_tm = TomoP3D.Model(model, N_size, path_library3D)

        ig = ImageGeometry(N_size, N_size, N_size)
        data = ig.allocate()
        data.fill(phantom_tm)

        noisy_data = noise.gaussian(data, seed=10)

        alpha = 0.1
        iters = 1000

        print("Use tau as an array of ones")
        # CIL_TotalVariation no tolerance
        g_CIL = alpha * TotalVariation(iters, tolerance=None, info=True)
        res1 = g_CIL.proximal(noisy_data, ig.allocate(1.))
        t0 = timer()
        res1 = g_CIL.proximal(noisy_data, ig.allocate(1.))
        t1 = timer()
        print(t1 - t0)

        # CCPi Regularisation toolkit high tolerance
        r_alpha = alpha
        r_iterations = iters
        r_tolerance = 1e-9
        r_iso = 0
        r_nonneg = 0
        r_printing = 0
        g_CCPI_reg_toolkit = CCPiReg_FGP_TV(r_alpha, r_iterations, r_tolerance,
                                            r_iso, r_nonneg, r_printing, 'cpu')

        t2 = timer()
        res2 = g_CCPI_reg_toolkit.proximal(noisy_data, 1.)
        t3 = timer()
        print(t3 - t2)
        np.testing.assert_array_almost_equal(res1.as_array(),
                                             res2.as_array(),
                                             decimal=3)

        # CIL_FGP_TV no tolerance
        #g_CIL = FGP_TV(ig, alpha, iters, tolerance=None, info=True)
        g_CIL.tolerance = None
        t0 = timer()
        res1 = g_CIL.proximal(noisy_data, 1.)
        t1 = timer()
        print(t1 - t0)

        ###################################################################
        ###################################################################
        ###################################################################
        ###################################################################

        data = dataexample.PEPPERS.get(size=(256, 256))
        ig = data.geometry
        ag = ig

        noisy_data = noise.gaussian(data, seed=10)

        alpha = 0.1
        iters = 1000

        # CIL_FGP_TV no tolerance
        g_CIL = alpha * TotalVariation(iters, tolerance=None)
        t0 = timer()
        res1 = g_CIL.proximal(noisy_data, 1.)
        t1 = timer()
        print(t1 - t0)

        # CCPi Regularisation toolkit high tolerance
        r_alpha = alpha
        r_iterations = iters
        r_tolerance = 1e-8
        r_iso = 0
        r_nonneg = 0
        r_printing = 0
        g_CCPI_reg_toolkit = CCPiReg_FGP_TV(r_alpha, r_iterations, r_tolerance,
                                            r_iso, r_nonneg, r_printing, 'cpu')

        t2 = timer()
        res2 = g_CCPI_reg_toolkit.proximal(noisy_data, 1.)
        t3 = timer()
        print(t3 - t2)
Exemple #5
0
 def test_noise_gaussian(self):
     camera = dataexample.CAMERA.get()
     noisy_camera = noise.gaussian(camera, seed=1)
     norm = (camera - noisy_camera).norm()
     self.assertAlmostEqual(norm, 48.881268, places=4)