summaryrefslogtreecommitdiffstats
path: root/Wrappers/Python/test
diff options
context:
space:
mode:
Diffstat (limited to 'Wrappers/Python/test')
-rw-r--r--Wrappers/Python/test/test_regularizers.py126
1 files changed, 48 insertions, 78 deletions
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()