diff options
| author | epapoutsellis <epapoutsellis@gmail.com> | 2019-04-29 16:37:10 +0100 | 
|---|---|---|
| committer | epapoutsellis <epapoutsellis@gmail.com> | 2019-04-29 16:37:10 +0100 | 
| commit | 58c3977744d09a4a8f72125902470098a10a75b4 (patch) | |
| tree | 25388ad1fefa62ff4d19dcd39d2b001049f7bc40 | |
| parent | 892002e03206a422a4ea89863939ee806be20c24 (diff) | |
| download | framework-58c3977744d09a4a8f72125902470098a10a75b4.tar.gz framework-58c3977744d09a4a8f72125902470098a10a75b4.tar.bz2 framework-58c3977744d09a4a8f72125902470098a10a75b4.tar.xz framework-58c3977744d09a4a8f72125902470098a10a75b4.zip | |
check demos
| -rw-r--r-- | Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Gaussian.py | 6 | ||||
| -rw-r--r-- | Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Poisson.py | 122 | 
2 files changed, 64 insertions, 64 deletions
| diff --git a/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Gaussian.py b/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Gaussian.py index 1a3e0df..39bbb2c 100644 --- a/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Gaussian.py +++ b/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Gaussian.py @@ -32,7 +32,7 @@ from ccpi.optimisation.functions import ZeroFunction, L2NormSquared, \  from skimage.util import random_noise  # Create phantom for TV Gaussian denoising -N = 300 +N = 100  data = np.zeros((N,N))  data[round(N/4):round(3*N/4),round(N/4):round(3*N/4)] = 0.5 @@ -46,9 +46,9 @@ n1 = random_noise(data.as_array(), mode = 'gaussian', mean=0, var = 0.05, seed=1  noisy_data = ImageData(n1)  # Regularisation Parameter -alpha = 0.5 +alpha = 2 -method = '0' +method = '1'  if method == '0': diff --git a/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Poisson.py b/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Poisson.py index a54e5ee..4903c44 100644 --- a/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Poisson.py +++ b/Wrappers/Python/wip/Demos/PDHG_TV_Denoising_Poisson.py @@ -48,7 +48,7 @@ noisy_data = ImageData(n1)  # Regularisation Parameter  alpha = 2 -method = '0' +method = '1'  if method == '0': @@ -124,63 +124,63 @@ plt.show()  #%% Check with CVX solution -#from ccpi.optimisation.operators import SparseFiniteDiff -# -#try: -#    from cvxpy import * -#    cvx_not_installable = True -#except ImportError: -#    cvx_not_installable = False -# -# -#if cvx_not_installable: -# -#    ##Construct problem     -#    u1 = Variable(ig.shape) -#    q = Variable() -#     -#    DY = SparseFiniteDiff(ig, direction=0, bnd_cond='Neumann') -#    DX = SparseFiniteDiff(ig, direction=1, bnd_cond='Neumann') -#     -#    # Define Total Variation as a regulariser -#    regulariser = alpha * sum(norm(vstack([DX.matrix() * vec(u1), DY.matrix() * vec(u1)]), 2, axis = 0)) -#     -#    fidelity = sum( u1 - multiply(noisy_data.as_array(), log(u1)) ) -#    constraints = [q>= fidelity, u1>=0] -#         -#    solver = ECOS -#    obj =  Minimize( regulariser +  q) -#    prob = Problem(obj, constraints) -#    result = prob.solve(verbose = True, solver = solver) -# -#     -#    diff_cvx = numpy.abs( pdhg.get_output().as_array() - u1.value ) -#         -#    plt.figure(figsize=(15,15)) -#    plt.subplot(3,1,1) -#    plt.imshow(pdhg.get_output().as_array()) -#    plt.title('PDHG solution') -#    plt.colorbar() -#    plt.subplot(3,1,2) -#    plt.imshow(u1.value) -#    plt.title('CVX solution') -#    plt.colorbar() -#    plt.subplot(3,1,3) -#    plt.imshow(diff_cvx) -#    plt.title('Difference') -#    plt.colorbar() -#    plt.show()     -#     -#    plt.plot(np.linspace(0,N,N), pdhg.get_output().as_array()[int(N/2),:], label = 'PDHG') -#    plt.plot(np.linspace(0,N,N), u1.value[int(N/2),:], label = 'CVX') -#    plt.legend() -#    plt.title('Middle Line Profiles') -#    plt.show() -#             -#    print('Primal Objective (CVX) {} '.format(obj.value)) -#    print('Primal Objective (PDHG) {} '.format(pdhg.objective[-1][0])) -# -# -# -# -# +from ccpi.optimisation.operators import SparseFiniteDiff + +try: +    from cvxpy import * +    cvx_not_installable = True +except ImportError: +    cvx_not_installable = False + + +if cvx_not_installable: + +    ##Construct problem     +    u1 = Variable(ig.shape) +    q = Variable() +     +    DY = SparseFiniteDiff(ig, direction=0, bnd_cond='Neumann') +    DX = SparseFiniteDiff(ig, direction=1, bnd_cond='Neumann') +     +    # Define Total Variation as a regulariser +    regulariser = alpha * sum(norm(vstack([DX.matrix() * vec(u1), DY.matrix() * vec(u1)]), 2, axis = 0)) +     +    fidelity = sum( u1 - multiply(noisy_data.as_array(), log(u1)) ) +    constraints = [q>= fidelity, u1>=0] +         +    solver = ECOS +    obj =  Minimize( regulariser +  q) +    prob = Problem(obj, constraints) +    result = prob.solve(verbose = True, solver = solver) + +     +    diff_cvx = numpy.abs( pdhg.get_output().as_array() - u1.value ) +         +    plt.figure(figsize=(15,15)) +    plt.subplot(3,1,1) +    plt.imshow(pdhg.get_output().as_array()) +    plt.title('PDHG solution') +    plt.colorbar() +    plt.subplot(3,1,2) +    plt.imshow(u1.value) +    plt.title('CVX solution') +    plt.colorbar() +    plt.subplot(3,1,3) +    plt.imshow(diff_cvx) +    plt.title('Difference') +    plt.colorbar() +    plt.show()     +     +    plt.plot(np.linspace(0,N,N), pdhg.get_output().as_array()[int(N/2),:], label = 'PDHG') +    plt.plot(np.linspace(0,N,N), u1.value[int(N/2),:], label = 'CVX') +    plt.legend() +    plt.title('Middle Line Profiles') +    plt.show() +             +    print('Primal Objective (CVX) {} '.format(obj.value)) +    print('Primal Objective (PDHG) {} '.format(pdhg.objective[-1][0])) + + + + + | 
