@@ -195,7 +195,7 @@ def Func_Phi(X, epsilon=1e-3):
195
195
def Func_Phi_deriv (X , epsilon = 1e-3 ):
196
196
return 0.5 / Func_Phi (X , epsilon )
197
197
198
- def solve_images (J , W_m , alpha , W_init , gamma = 1 , beta = 0.01 , lambda_w = 0.01 , lambda_i = 0.01 , lambda_a = 0.01 , iters = 2 ):
198
+ def solve_images (J , W_m , alpha , W_init , gamma = 1 , beta = 1 , lambda_w = 0.005 , lambda_i = 1 , lambda_a = 0.01 , iters = 4 ):
199
199
'''
200
200
Master solver, follows the algorithm given in the supplementary.
201
201
W_init: Initial value of W
@@ -269,13 +269,20 @@ def solve_images(J, W_m, alpha, W_init, gamma=1, beta=0.01, lambda_w=0.01, lambd
269
269
270
270
Wk [i ] = x [:size ].reshape (m , n , p )
271
271
Ik [i ] = x [size :].reshape (m , n , p )
272
- plt .subplot (2 ,1 ,1 ); plt .imshow (PlotImage (Wk [i ]))
273
- plt .subplot (2 ,1 ,2 ); plt .imshow (PlotImage (Ik [i ])); plt .show ()
272
+ plt .subplot (3 ,1 ,1 ); plt .imshow (PlotImage (J [i ]))
273
+ plt .subplot (3 ,1 ,2 ); plt .imshow (PlotImage (Wk [i ]))
274
+ plt .subplot (3 ,1 ,3 ); plt .imshow (PlotImage (Ik [i ]))
275
+ plt .draw ()
276
+ plt .pause (0.001 )
274
277
print (i )
275
278
276
279
# Step 2
277
280
print ("Step 2" )
278
281
W = np .median (Wk , axis = 0 )
282
+
283
+ plt .imshow (PlotImage (W ))
284
+ plt .draw ()
285
+ plt .pause (0.001 )
279
286
280
287
# Step 3
281
288
print ("Step 3" )
@@ -287,21 +294,26 @@ def solve_images(J, W_m, alpha, W_init, gamma=1, beta=0.01, lambda_w=0.01, lambd
287
294
alphaWk_gy = cv2 .Sobel (alphaWk , cv2 .CV_64F , 0 , 1 , 3 )
288
295
phi_f = diags ( Func_Phi_deriv ( ((Wm_gx - alphaWk_gx )** 2 + (Wm_gy - alphaWk_gy )** 2 ).reshape (- 1 )) )
289
296
290
- phi_k = diags (Func_Phi_deriv (((alpha * Wk [i ] + (1 - alpha )* Ik [i ] - J [i ])** 2 )* (W - Ik [i ])).reshape (- 1 ))
297
+ phi_kA = diags (( (Func_Phi_deriv ((((alpha * Wk [i ] + (1 - alpha )* Ik [i ] - J [i ])** 2 )))) * ((W - Ik [i ])** 2 ) ).reshape (- 1 ))
298
+ phi_kB = (( (Func_Phi_deriv ((((alpha * Wk [i ] + (1 - alpha )* Ik [i ] - J [i ])** 2 ))))* (W - Ik [i ])* (J [i ]- Ik [i ]) ).reshape (- 1 ))
299
+
291
300
phi_alpha = diags (Func_Phi_deriv (alpha_gx ** 2 + alpha_gy ** 2 ).reshape (- 1 ))
292
301
L_alpha = sobelx .T .dot (phi_alpha .dot (sobelx )) + sobely .T .dot (phi_alpha .dot (sobely ))
293
302
294
- L_f = sobelx .T .dot (phi_f ).dot (sobelx ) + sobely .dot (phi_f ).dot (sobely )
295
- A_tilde_f = W_diag .dot (L_f ).dot (W_diag )
296
-
303
+ L_f = sobelx .T .dot (phi_f ).dot (sobelx ) + sobely .T .dot (phi_f ).dot (sobely )
304
+ A_tilde_f = W_diag .T .dot (L_f ).dot (W_diag )
297
305
# Ax = b, setting up A
298
306
if i == 0 :
299
- A1 = phi_k + lambda_a * L_alpha + beta * A_tilde_f
300
- b1 = phi_k . dot (( J [ i ] - Ik [ i ]). reshape ( - 1 )) + beta * W_diag .dot (L_f ).dot (W_m .reshape (- 1 ))
307
+ A1 = phi_kA + lambda_a * L_alpha + beta * A_tilde_f
308
+ b1 = phi_kB + beta * W_diag .dot (L_f ).dot (W_m .reshape (- 1 ))
301
309
else :
302
- A1 += (phi_k + lambda_a * L_alpha + beta * A_tilde_f )
303
- b1 += (phi_k . dot (( J [ i ] - Ik [ i ]). reshape ( - 1 )) + beta * W_diag .dot (L_f ).dot (W_m .reshape (- 1 )))
310
+ A1 += (phi_kA + lambda_a * L_alpha + beta * A_tilde_f )
311
+ b1 += (phi_kB + beta * W_diag . T .dot (L_f ).dot (W_m .reshape (- 1 )))
304
312
305
313
alpha = linalg .spsolve (A1 , b1 ).reshape (m ,n ,p )
314
+
315
+ plt .imshow (PlotImage (alpha ))
316
+ plt .draw ()
317
+ plt .pause (0.001 )
306
318
307
319
return (Wk , Ik , W , alpha )
0 commit comments