Exemplo n.º 1
0
normalize = lambda u: u / np.tile(
    (np.maximum(amp(u), 1e-10))[:, :, np.newaxis],
    (1, 1, 2))
prox_f = lambda u, tau: np.tile(
    soft_thresholding(amp(u), alpha * tau)[:, :, np.newaxis],
    (1, 1, 2)) * normalize(u)
prox_fs = dual_prox(prox_f)
prox_g = lambda x, tau: (x + tau * y) / (1 + tau)


# context
ctx = Context(full_output=True, maxiter=300)
ctx.callback = lambda x: G(x) + F(K(x))

t1 = time.time()
x_rec, cx = admm(prox_fs, prox_g, K, y, context=ctx)
t2 = time.time()
print("Performed 300 iterations in " + str(t2 - t1) + " seconds.")


plt.subplot(221)
plt.imshow(im, cmap='gray')
plt.title('Original')
plt.axis('off')
plt.subplot(222)
plt.imshow(y, cmap='gray')
plt.title('Noisy')
plt.axis('off')
plt.subplot(223)
plt.imshow(x_rec, cmap='gray')
plt.title('TV Regularization')
Exemplo n.º 2
0
G = lambda x : 1/2 * np.linalg.norm(y-x,'fro') ** 2

# Proximity operators
normalize = lambda u : u/np.tile(
    (np.maximum(amp(u), 1e-10))[:,:,np.newaxis],
    (1,1,2))
proxF = lambda u,tau : np.tile(
    soft_thresholding(amp(u), alpha*tau)[:,:,np.newaxis],
    (1,1,2) )* normalize(u)
proxFS = dual_prox(proxF)
proxG = lambda x,tau : (x + tau*y) / (1+tau)

callback = lambda x : G(x) + F(K(x))

t1 = time.time()
xRec, cx = pp.admm(proxFS, proxG, K, y,
         maxiter=300, full_output=1, callback=callback)
t2 = time.time()
print "Performed 300 iterations in " + str(t2-t1) + " seconds."


plt.subplot(221)
imgplot = plt.imshow(im)
imgplot.set_cmap('gray')
plt.title('Original')
plt.axis('off')
plt.subplot(222)
imgplot = plt.imshow(y)
imgplot.set_cmap('gray')
plt.title('Noisy')
plt.axis('off')
plt.subplot(223)
Exemplo n.º 3
0
# Proximity operators
normalize = lambda u: u / np.tile(
    (np.maximum(amp(u), 1e-10))[:, :, np.newaxis], (1, 1, 2))
prox_f = lambda u, tau: np.tile(
    soft_thresholding(amp(u), alpha * tau)[:, :, np.newaxis],
    (1, 1, 2)) * normalize(u)
prox_fs = dual_prox(prox_f)
prox_g = lambda x, tau: (x + tau * y) / (1 + tau)

callback = lambda x: G(x) + F(K(x))

t1 = time.time()
x_rec, cx = admm(prox_fs,
                 prox_g,
                 K,
                 y,
                 maxiter=300,
                 full_output=1,
                 callback=callback)
t2 = time.time()
print "Performed 300 iterations in " + str(t2 - t1) + " seconds."

pl.subplot(221)
pl.imshow(im, cmap='gray')
pl.title('Original')
pl.axis('off')
pl.subplot(222)
pl.imshow(y, cmap='gray')
pl.title('Noisy')
pl.axis('off')
pl.subplot(223)
Exemplo n.º 4
0
K = gradient
K.T = divergence
amp = lambda u: np.sqrt(np.sum(u ** 2, axis=2))
F = lambda u: alpha * np.sum(amp(u))
G = lambda x: 1 / 2 * lin.norm(y - x, "fro") ** 2

# Proximity operators
normalize = lambda u: u / np.tile((np.maximum(amp(u), 1e-10))[:, :, np.newaxis], (1, 1, 2))
prox_f = lambda u, tau: np.tile(soft_thresholding(amp(u), alpha * tau)[:, :, np.newaxis], (1, 1, 2)) * normalize(u)
prox_fs = dual_prox(prox_f)
prox_g = lambda x, tau: (x + tau * y) / (1 + tau)

callback = lambda x: G(x) + F(K(x))

t1 = time.time()
x_rec, cx = admm(prox_fs, prox_g, K, y, maxiter=300, full_output=1, callback=callback)
t2 = time.time()
print "Performed 300 iterations in " + str(t2 - t1) + " seconds."


pl.subplot(221)
pl.imshow(im, cmap="gray")
pl.title("Original")
pl.axis("off")
pl.subplot(222)
pl.imshow(y, cmap="gray")
pl.title("Noisy")
pl.axis("off")
pl.subplot(223)
pl.imshow(x_rec, cmap="gray")
pl.title("TV Regularization")
Exemplo n.º 5
0
# Proximity operators
normalize = lambda u: u / np.tile(
    (np.maximum(amp(u), 1e-10))[:, :, np.newaxis], (1, 1, 2))
prox_f = lambda u, tau: np.tile(
    soft_thresholding(amp(u), alpha * tau)[:, :, np.newaxis],
    (1, 1, 2)) * normalize(u)
prox_fs = dual_prox(prox_f)
prox_g = lambda x, tau: (x + tau * y) / (1 + tau)

# context
ctx = Context(full_output=True, maxiter=300)
ctx.callback = lambda x: G(x) + F(K(x))

t1 = time.time()
x_rec, cx = admm(prox_fs, prox_g, K, y, context=ctx)
t2 = time.time()
print("Performed 300 iterations in " + str(t2 - t1) + " seconds.")

plt.subplot(221)
plt.imshow(im, cmap='gray')
plt.title('Original')
plt.axis('off')
plt.subplot(222)
plt.imshow(y, cmap='gray')
plt.title('Noisy')
plt.axis('off')
plt.subplot(223)
plt.imshow(x_rec, cmap='gray')
plt.title('TV Regularization')
plt.axis('off')