summaryrefslogtreecommitdiffstats
path: root/Wrappers/Python
diff options
context:
space:
mode:
authorDaniil Kazantsev <dkazanc@hotmail.com>2018-05-12 19:03:26 +0100
committerDaniil Kazantsev <dkazanc@hotmail.com>2018-05-12 19:03:26 +0100
commitd1875172687fc854df35fa9bfc6ac07a148d7f18 (patch)
treea93ede4c3e74262be654ffbecbd160f31409a04a /Wrappers/Python
parent3d939a6139e664c3f8143031d0aaf765298efda5 (diff)
downloadframework-plugins-d1875172687fc854df35fa9bfc6ac07a148d7f18.tar.gz
framework-plugins-d1875172687fc854df35fa9bfc6ac07a148d7f18.tar.bz2
framework-plugins-d1875172687fc854df35fa9bfc6ac07a148d7f18.tar.xz
framework-plugins-d1875172687fc854df35fa9bfc6ac07a148d7f18.zip
fixed objective2
Diffstat (limited to 'Wrappers/Python')
-rw-r--r--Wrappers/Python/ccpi/plugins/regularisers.py9
-rw-r--r--Wrappers/Python/wip/demo_compare_RGLTK_TV_denoising.py18
2 files changed, 10 insertions, 17 deletions
diff --git a/Wrappers/Python/ccpi/plugins/regularisers.py b/Wrappers/Python/ccpi/plugins/regularisers.py
index 9f4d3fc..46464a9 100644
--- a/Wrappers/Python/ccpi/plugins/regularisers.py
+++ b/Wrappers/Python/ccpi/plugins/regularisers.py
@@ -34,9 +34,8 @@ class _ROF_TV_(Operator):
self.device = device # string for 'cpu' or 'gpu'
def __call__(self,x):
# evaluate objective function of TV gradient
- # typeEnergy is either 1 (LS + TV for denoising) or 2 (just TV fidelity)
EnergyValTV = TV_ENERGY(np.asarray(x.as_array(), dtype=np.float32), np.asarray(x.as_array(), dtype=np.float32), self.lambdaReg, 2)
- return EnergyValTV
+ return 0.5*EnergyValTV[0]
def prox(self,x,Lipshitz):
pars = {'algorithm' : ROF_TV, \
'input' : np.asarray(x.as_array(), dtype=np.float32),\
@@ -62,9 +61,8 @@ class _FGP_TV_(Operator):
self.device = device # string for 'cpu' or 'gpu'
def __call__(self,x):
# evaluate objective function of TV gradient
- # typeEnergy is either 1 (LS + TV for denoising) or 2 (just TV fidelity)
EnergyValTV = TV_ENERGY(np.asarray(x.as_array(), dtype=np.float32), np.asarray(x.as_array(), dtype=np.float32), self.lambdaReg, 2)
- return EnergyValTV
+ return 0.5*EnergyValTV[0]
def prox(self,x,Lipshitz):
pars = {'algorithm' : FGP_TV, \
'input' : np.asarray(x.as_array(), dtype=np.float32),\
@@ -96,9 +94,8 @@ class _SB_TV_(Operator):
self.device = device # string for 'cpu' or 'gpu'
def __call__(self,x):
# evaluate objective function of TV gradient
- # typeEnergy is either 1 (LS + TV for denoising) or 2 (just TV fidelity)
EnergyValTV = TV_ENERGY(np.asarray(x.as_array(), dtype=np.float32), np.asarray(x.as_array(), dtype=np.float32), self.lambdaReg, 2)
- return EnergyValTV
+ return 0.5*EnergyValTV[0]
def prox(self,x,Lipshitz):
pars = {'algorithm' : SB_TV, \
'input' : np.asarray(x.as_array(), dtype=np.float32),\
diff --git a/Wrappers/Python/wip/demo_compare_RGLTK_TV_denoising.py b/Wrappers/Python/wip/demo_compare_RGLTK_TV_denoising.py
index 0d57e5e..2bf1286 100644
--- a/Wrappers/Python/wip/demo_compare_RGLTK_TV_denoising.py
+++ b/Wrappers/Python/wip/demo_compare_RGLTK_TV_denoising.py
@@ -75,11 +75,13 @@ plt.title('CVX TV with objective equal to {:.2f}'.format(objectivetv_denoise.va
plt.show()
print(objectivetv_denoise.value)
-#%% THen FBPD
-
+#%%
# Data fidelity term
f_denoise = Norm2sq(I,y,c=0.5)
+#%%
+
+#%% THen FBPD
# Initial guess
x_init_denoise = ImageData(np.zeros((N,N)))
@@ -112,9 +114,7 @@ xtv_rof = g_rof.prox(y,1.0)
print("CCPi-RGL TV ROF:")
plt.figure()
plt.imshow(xtv_rof.as_array())
-valObjRof = g_rof(xtv_rof)
-data_energy = 0.5*np.sum(np.power((xtv_rof.as_array() - y.array),2))
-EnergytotalROF = data_energy + 0.5*valObjRof[0]
+EnergytotalROF = f_denoise(xtv_rof) + g_rof(xtv_rof)
plt.title('ROF TV prox with objective equal to {:.2f}'.format(EnergytotalROF))
plt.show()
print(EnergytotalROF)
@@ -127,9 +127,7 @@ xtv_fgp = g_fgp.prox(y,1.0)
print("CCPi-RGL TV FGP:")
plt.figure()
plt.imshow(xtv_fgp.as_array())
-valObjFGP = g_fgp(xtv_fgp)
-data_energy = 0.5*np.sum(np.power((xtv_fgp.as_array() - y.array),2))
-EnergytotalFGP = data_energy + 0.5*valObjFGP[0]
+EnergytotalFGP = f_denoise(xtv_fgp) + g_fgp(xtv_fgp)
plt.title('FGP TV prox with objective equal to {:.2f}'.format(EnergytotalFGP))
plt.show()
print(EnergytotalFGP)
@@ -141,9 +139,7 @@ xtv_sb = g_sb.prox(y,1.0)
print("CCPi-RGL TV SB:")
plt.figure()
plt.imshow(xtv_sb.as_array())
-valObjSB = g_sb(xtv_sb)
-data_energy = 0.5*np.sum(np.power((xtv_sb.as_array() - y.array),2))
-EnergytotalSB = data_energy + 0.5*valObjSB[0]
+EnergytotalSB = f_denoise(xtv_sb) + g_fgp(xtv_sb)
plt.title('SB TV prox with objective equal to {:.2f}'.format(EnergytotalSB))
plt.show()
print(EnergytotalSB)