summaryrefslogtreecommitdiffstats
path: root/Wrappers
diff options
context:
space:
mode:
Diffstat (limited to 'Wrappers')
-rw-r--r--Wrappers/Python/ccpi/filters/Regularizer.py31
-rw-r--r--Wrappers/Python/test/test_regularizers.py126
2 files changed, 54 insertions, 103 deletions
diff --git a/Wrappers/Python/ccpi/filters/Regularizer.py b/Wrappers/Python/ccpi/filters/Regularizer.py
index b9f12ca..4ca94f2 100644
--- a/Wrappers/Python/ccpi/filters/Regularizer.py
+++ b/Wrappers/Python/ccpi/filters/Regularizer.py
@@ -251,45 +251,33 @@ class Regularizer():
def SplitBregman_TV(input, regularization_parameter , **kwargs):
start_time = timeit.default_timer()
reg = Regularizer(Regularizer.Algorithm.SplitBregman_TV)
- out = []
a = reg(input, regularization_parameter, **kwargs)
- out.append(a)
- out.append(reg.pars)
txt = reg.printParametersToString()
txt += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
- out.append(txt)
- return out
+ return a, reg.pars, txt
@staticmethod
def FGP_TV(input, regularization_parameter , **kwargs):
start_time = timeit.default_timer()
reg = Regularizer(Regularizer.Algorithm.FGP_TV)
- out = []
a = reg(input, regularization_parameter, **kwargs)
- out.append(a)
- out.append(reg.pars)
txt = reg.printParametersToString()
txt += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
- out.append(txt)
- return out
+ return a, reg.pars, txt
@staticmethod
def LLT_model(input, regularization_parameter , time_step, number_of_iterations,
tolerance_constant, restrictive_Z_smoothing=0):
start_time = timeit.default_timer()
reg = Regularizer(Regularizer.Algorithm.LLT_model)
- out = []
a = reg(input, regularization_parameter, time_step=time_step,
number_of_iterations=number_of_iterations,
tolerance_constant=tolerance_constant,
restrictive_Z_smoothing=restrictive_Z_smoothing)
- out.append(a)
- out.append(reg.pars)
txt = reg.printParametersToString()
txt += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
- out.append(txt)
- return out
+ return a, reg.pars, txt
@staticmethod
def PatchBased_Regul(input, regularization_parameter,
@@ -298,18 +286,14 @@ class Regularizer():
PB_filtering_parameter):
start_time = timeit.default_timer()
reg = Regularizer(Regularizer.Algorithm.PatchBased_Regul)
- out = []
a = reg(input,
regularization_parameter,
searching_window_ratio=searching_window_ratio,
similarity_window_ratio=similarity_window_ratio,
PB_filtering_parameter=PB_filtering_parameter )
- out.append(a)
- out.append(reg.pars)
txt = reg.printParametersToString()
txt += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
- out.append(txt)
- return out
+ return a, reg.pars, txt
@staticmethod
def TGV_PD(input, regularization_parameter , first_order_term,
@@ -321,14 +305,11 @@ class Regularizer():
first_order_term=first_order_term,
second_order_term=second_order_term,
number_of_iterations=number_of_iterations)
- out = []
- out.append(a)
- out.append(reg.pars)
txt = reg.printParametersToString()
txt += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
- out.append(txt)
- return out
+
+ return a, reg.pars, txt
def printParametersToString(self):
txt = r''
diff --git a/Wrappers/Python/test/test_regularizers.py b/Wrappers/Python/test/test_regularizers.py
index 3c756f0..cf5da2b 100644
--- a/Wrappers/Python/test/test_regularizers.py
+++ b/Wrappers/Python/test/test_regularizers.py
@@ -86,34 +86,21 @@ reg_output = []
####################### SplitBregman_TV #####################################
# u = SplitBregman_TV(single(u0), 10, 30, 1e-04);
-use_object = True
-if use_object:
- reg = Regularizer(Regularizer.Algorithm.SplitBregman_TV)
- print (reg.pars)
- reg.setParameter(input=u0)
- reg.setParameter(regularization_parameter=10.)
- # or
- # reg.setParameter(input=u0, regularization_parameter=10., #number_of_iterations=30,
- #tolerance_constant=1e-4,
- #TV_Penalty=Regularizer.TotalVariationPenalty.l1)
- plotme = reg(output_all=True) [0]
- pars = reg.pars
- textstr = reg.printParametersToString()
+start_time = timeit.default_timer()
+reg = Regularizer(Regularizer.Algorithm.SplitBregman_TV)
+print (reg.pars)
+reg.setParameter(input=u0)
+reg.setParameter(regularization_parameter=10.)
+# or
+# reg.setParameter(input=u0, regularization_parameter=10., #number_of_iterations=30,
+ #tolerance_constant=1e-4,
+ #TV_Penalty=Regularizer.TotalVariationPenalty.l1)
+plotme = reg(output_all=True) [0]
+pars = reg.pars
+txtstr = reg.printParametersToString()
+txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
+print (txtstr)
- #out = reg(input=u0, regularization_parameter=10., #number_of_iterations=30,
- #tolerance_constant=1e-4,
- # TV_Penalty=Regularizer.TotalVariationPenalty.l1)
-
-#out2 = Regularizer.SplitBregman_TV(input=u0, regularization_parameter=10., number_of_iterations=30,
-# tolerance_constant=1e-4,
-# TV_Penalty=Regularizer.TotalVariationPenalty.l1)
-
-else:
- out2 = Regularizer.SplitBregman_TV(input=u0, regularization_parameter=10. )
- pars = out2[2]
- reg_output.append(out2)
- plotme = reg_output[-1][0]
- textstr = out2[-1]
a=fig.add_subplot(2,3,2)
@@ -121,32 +108,30 @@ a=fig.add_subplot(2,3,2)
# these are matplotlib.patch.Patch properties
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
# place a text box in upper left in axes coords
-a.text(0.05, 0.95, textstr, transform=a.transAxes, fontsize=14,
+a.text(0.05, 0.95, txtstr, transform=a.transAxes, fontsize=14,
verticalalignment='top', bbox=props)
imgplot = plt.imshow(plotme,cmap="gray")
###################### FGP_TV #########################################
# u = FGP_TV(single(u0), 0.05, 100, 1e-04);
-out2 = Regularizer.FGP_TV(input=u0, regularization_parameter=5e-4,
- number_of_iterations=10, output_all=True)
-pars = out2[-2]
+start_time = timeit.default_timer()
+reg = Regularizer(Regularizer.Algorithm.FGP_TV)
+out2 = reg(input=u0, regularization_parameter=5e-4,
+ number_of_iterations=10)
+txtstr = reg.printParametersToString()
+txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
+print (txtstr)
-reg_output.append(out2)
a=fig.add_subplot(2,3,3)
-textstr = out2[-1]
-
# these are matplotlib.patch.Patch properties
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
# place a text box in upper left in axes coords
-a.text(0.05, 0.95, textstr, transform=a.transAxes, fontsize=14,
- verticalalignment='top', bbox=props)
-imgplot = plt.imshow(reg_output[-1][0])
+imgplot = plt.imshow(out2,cmap="gray")
# place a text box in upper left in axes coords
-a.text(0.05, 0.95, textstr, transform=a.transAxes, fontsize=14,
+a.text(0.05, 0.95, txtstr, transform=a.transAxes, fontsize=14,
verticalalignment='top', bbox=props)
-imgplot = plt.imshow(reg_output[-1][0],cmap="gray")
###################### LLT_model #########################################
# * u0 = Im + .03*randn(size(Im)); % adding noise
@@ -156,35 +141,23 @@ imgplot = plt.imshow(reg_output[-1][0],cmap="gray")
# tolerance_constant, restrictive_Z_smoothing=0
del out2
-out2 = Regularizer.LLT_model(input=u0, regularization_parameter=25,
+start_time = timeit.default_timer()
+reg = Regularizer(Regularizer.Algorithm.LLT_model)
+out2 = reg(input=u0, regularization_parameter=25,
time_step=0.0003,
tolerance_constant=0.001,
number_of_iterations=300)
-print ("call ended??")
-
-i = 0
-while(i < len(out2)):
- shape = " not applicable"
- if type (out2[i]) == np.ndarray:
- shape = out2[i].shape
- print ("len out2[{0}] type {1} shape {2}".format(i, type(out2[i]) , shape))
- i += 1
-
-#print ("out2", out2)
-pars = out2[-2]
-
-reg_output.append(out2)
-
+txtstr = reg.printParametersToString()
+txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
+print (txtstr)
a=fig.add_subplot(2,3,4)
-textstr = out2[-1]
-
# these are matplotlib.patch.Patch properties
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
# place a text box in upper left in axes coords
-a.text(0.05, 0.95, textstr, transform=a.transAxes, fontsize=14,
+a.text(0.05, 0.95, txtstr, transform=a.transAxes, fontsize=14,
verticalalignment='top', bbox=props)
-imgplot = plt.imshow(reg_output[-1][0],cmap="gray")
+imgplot = plt.imshow(out2,cmap="gray")
# ###################### PatchBased_Regul #########################################
@@ -192,25 +165,25 @@ imgplot = plt.imshow(reg_output[-1][0],cmap="gray")
# # Im = double(imread('lena_gray_256.tif'))/255; % loading image
# # u0 = Im + .03*randn(size(Im)); u0(u0<0) = 0; % adding noise
# # ImDen = PB_Regul_CPU(single(u0), 3, 1, 0.08, 0.05);
-
-out2 = Regularizer.PatchBased_Regul(input=u0, regularization_parameter=0.05,
+start_time = timeit.default_timer()
+reg = Regularizer(Regularizer.Algorithm.PatchBased_Regul)
+out2 = reg(input=u0, regularization_parameter=0.05,
searching_window_ratio=3,
similarity_window_ratio=1,
PB_filtering_parameter=0.08)
-pars = out2[-2]
-reg_output.append(out2)
+txtstr = reg.printParametersToString()
+txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
+print (txtstr)
a=fig.add_subplot(2,3,5)
-textstr = out2[-1]
-
# these are matplotlib.patch.Patch properties
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
# place a text box in upper left in axes coords
-a.text(0.05, 0.95, textstr, transform=a.transAxes, fontsize=14,
+a.text(0.05, 0.95, txtstr, transform=a.transAxes, fontsize=14,
verticalalignment='top', bbox=props)
-imgplot = plt.imshow(reg_output[-1][0],cmap="gray")
+imgplot = plt.imshow(out2,cmap="gray")
# ###################### TGV_PD #########################################
@@ -219,26 +192,23 @@ imgplot = plt.imshow(reg_output[-1][0],cmap="gray")
# # u0 = Im + .03*randn(size(Im)); u0(u0<0) = 0; % adding noise
# # u = PrimalDual_TGV(single(u0), 0.02, 1.3, 1, 550);
-
-out2 = Regularizer.TGV_PD(input=u0, regularization_parameter=0.05,
+start_time = timeit.default_timer()
+reg = Regularizer(Regularizer.Algorithm.TGV_PD)
+out2 = reg(input=u0, regularization_parameter=0.05,
first_order_term=1.3,
second_order_term=1,
number_of_iterations=550)
-pars = out2[-2]
-reg_output.append(out2)
-
+txtstr = reg.printParametersToString()
+txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
+print (txtstr)
a=fig.add_subplot(2,3,6)
-
-textstr = out2[-1]
-
-
# these are matplotlib.patch.Patch properties
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
# place a text box in upper left in axes coords
-a.text(0.05, 0.95, textstr, transform=a.transAxes, fontsize=14,
+a.text(0.05, 0.95, txtstr, transform=a.transAxes, fontsize=14,
verticalalignment='top', bbox=props)
-imgplot = plt.imshow(reg_output[-1][0],cmap="gray")
+imgplot = plt.imshow(out2,cmap="gray")
plt.show()