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
Пример #4
0
    plt.figure()
    plt.imshow(res1.as_array())
    plt.colorbar()
    plt.show()
    
    # CCPi Regularisation toolkit high tolerance
    r_alpha = alpha
    r_iterations = iters
    r_tolerance = 1e-9
    r_iso = 0
    r_nonneg = 1
    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)
    
    plt.figure()
    plt.imshow(res2.as_array())
    plt.colorbar()
    plt.show()
    
    plt.figure()
    plt.imshow(np.abs(res1.as_array()-res2.as_array()))
    plt.colorbar()
    plt.title("Difference CIL_FGP_TV vs CCPi_FGP_TV")
    plt.show()

    np.testing.assert_array_almost_equal(res1.as_array(), res2.as_array(), decimal = 4)
Пример #5
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)
Пример #6
0
    def test_compare_regularisation_toolkit(self):

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

        data = dataexample.SHAPES.get()
        ig = data.geometry
        ag = ig

        # Create noisy data.
        n1 = np.random.normal(0, 0.1, size=ig.shape)
        noisy_data = ig.allocate()
        noisy_data.fill(n1 + data.as_array())

        alpha = 0.1
        iters = 1000

        # CIL_FGP_TV no tolerance
        g_CIL = alpha * TotalVariation(
            iters, tolerance=None, lower=0, info=True)
        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-9
        r_iso = 0
        r_nonneg = 1
        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 - t1)

        np.testing.assert_array_almost_equal(res1.as_array(),
                                             res2.as_array(),
                                             decimal=4)

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

        print("Compare CIL_FGP_TV vs CCPiReg_FGP_TV with iterations.")
        iters = 408
        # CIL_FGP_TV no tolerance
        g_CIL = alpha * TotalVariation(iters, tolerance=1e-9, lower=0.)
        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-9
        r_iso = 0
        r_nonneg = 1
        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)

        print(mae(res1, res2))
        np.testing.assert_array_almost_equal(res1.as_array(),
                                             res2.as_array(),
                                             decimal=3)