From 6d55ee76936a20af5b71c067e8f3ff6f9441d15e Mon Sep 17 00:00:00 2001 From: epapoutsellis Date: Thu, 9 May 2019 10:55:47 +0100 Subject: fix proximal conj --- .../ccpi/optimisation/functions/KullbackLeibler.py | 26 +++++++++++----- .../Python/demos/PDHG_TV_Denoising_Gaussian.py | 35 +++++++++------------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/Wrappers/Python/ccpi/optimisation/functions/KullbackLeibler.py b/Wrappers/Python/ccpi/optimisation/functions/KullbackLeibler.py index cf1a244..3096191 100644 --- a/Wrappers/Python/ccpi/optimisation/functions/KullbackLeibler.py +++ b/Wrappers/Python/ccpi/optimisation/functions/KullbackLeibler.py @@ -106,17 +106,27 @@ class KullbackLeibler(Function): z = x + tau * self.bnoise return 0.5*((z + 1) - ((z-1)**2 + 4 * tau * self.b).sqrt()) else: - - z_m = x + tau * self.bnoise -1 - self.b.multiply(4*tau, out=out) - z_m.multiply(z_m, out=z_m) - out += z_m - + + tmp = x + tau * self.bnoise + self.b.multiply(4*tau, out=out) + out.add((tmp-1)**2, out=out) out.sqrt(out=out) - out *= -1 - out += tmp2 + out.add(tmp+1, out=out) out *= 0.5 + + + +# z_m = x + tau * self.bnoise -1 +# self.b.multiply(4*tau, out=out) +# z_m.multiply(z_m, out=z_m) +# out += z_m +# +# out.sqrt(out=out) +# +# out *= -1 +# out += tmp2 +# out *= 0.5 diff --git a/Wrappers/Python/demos/PDHG_TV_Denoising_Gaussian.py b/Wrappers/Python/demos/PDHG_TV_Denoising_Gaussian.py index c830025..afdb6a2 100644 --- a/Wrappers/Python/demos/PDHG_TV_Denoising_Gaussian.py +++ b/Wrappers/Python/demos/PDHG_TV_Denoising_Gaussian.py @@ -18,14 +18,10 @@ # limitations under the License. # #========================================================================= - - """ Total Variation Denoising using PDHG algorithm: - min_{x} max_{y} < K x, y > + g(x) - f^{*}(y) - Problem: min_{x} \alpha * ||\nabla x||_{2,1} + \frac{1}{2} * || x - g ||_{2}^{2} @@ -35,12 +31,12 @@ Problem: min_{x} \alpha * ||\nabla x||_{2,1} + \frac{1}{2} * || x - g ||_{2} g: Noisy Data with Gaussian Noise - Method = 0: K = [ \nabla, - Identity] + Method = 0 ( PDHG - split ) : K = [ \nabla, + Identity] + - Method = 1: K = \nabla - - + Method = 1 (PDHG - explicit ): K = \nabla + """ from ccpi.framework import ImageData, ImageGeometry @@ -54,20 +50,17 @@ from ccpi.optimisation.algorithms import PDHG from ccpi.optimisation.operators import BlockOperator, Identity, Gradient from ccpi.optimisation.functions import ZeroFunction, L2NormSquared, \ MixedL21Norm, BlockFunction - - -from ccpi.data import camera - - -# Load Data -data = camera(size=(256,256)) - -N, M = data.shape - -# Image and Acquitition Geometries + +# Load Data +N = 100 + +data = np.zeros((N,N)) +data[round(N/4):round(3*N/4),round(N/4):round(3*N/4)] = 0.5 +data[round(N/8):round(7*N/8),round(3*N/8):round(5*N/8)] = 1 +data = ImageData(data) ig = ImageGeometry(voxel_num_x = N, voxel_num_y = N) ag = ig - + # Create Noisy data. Add Gaussian noise np.random.seed(10) noisy_data = ImageData( data.as_array() + np.random.normal(0, 0.1, size=ig.shape) ) -- cgit v1.2.3