Skip to content

Commit 12a91b5

Browse files
committed
added final bits
1 parent a01abc8 commit 12a91b5

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
for i in xrange(3):
3939
W[:,:,i]/=C[i]
4040

41+
Jt = J[idx]
4142
# now we have the values of alpha, Wm, J
4243
# Solve for all images
43-
44+
Wk, Ik, W, alpha = solve_images(Jt, W_m, alpha, W)
4445

4546

4647
# W_m_threshold = (255*PlotImage(np.average(W_m, axis=2))).astype(np.uint8)

src/watermark_reconstruct.py

+23-11
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def Func_Phi(X, epsilon=1e-3):
195195
def Func_Phi_deriv(X, epsilon=1e-3):
196196
return 0.5/Func_Phi(X, epsilon)
197197

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):
199199
'''
200200
Master solver, follows the algorithm given in the supplementary.
201201
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
269269

270270
Wk[i] = x[:size].reshape(m, n, p)
271271
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)
274277
print(i)
275278

276279
# Step 2
277280
print("Step 2")
278281
W = np.median(Wk, axis=0)
282+
283+
plt.imshow(PlotImage(W))
284+
plt.draw()
285+
plt.pause(0.001)
279286

280287
# Step 3
281288
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
287294
alphaWk_gy = cv2.Sobel(alphaWk, cv2.CV_64F, 0, 1, 3)
288295
phi_f = diags( Func_Phi_deriv( ((Wm_gx - alphaWk_gx)**2 + (Wm_gy - alphaWk_gy)**2 ).reshape(-1)) )
289296

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+
291300
phi_alpha = diags(Func_Phi_deriv(alpha_gx**2 + alpha_gy**2).reshape(-1))
292301
L_alpha = sobelx.T.dot(phi_alpha.dot(sobelx)) + sobely.T.dot(phi_alpha.dot(sobely))
293302

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)
297305
# Ax = b, setting up A
298306
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))
301309
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)))
304312

305313
alpha = linalg.spsolve(A1, b1).reshape(m,n,p)
314+
315+
plt.imshow(PlotImage(alpha))
316+
plt.draw()
317+
plt.pause(0.001)
306318

307319
return (Wk, Ik, W, alpha)

0 commit comments

Comments
 (0)