Algorithm Search⌘K

Techniqueresearch

Regularization by denoising

Define the regularizer (1/2) x^T (x - D(x)) from an image denoiser D; its gradient is x - D(x) only if D is locally homogeneous with a symmetric Jacobian.

Regularization by denoising (RED) turns an image denoiser DD into an explicit regularizer for an inverse problem y=Ax+ey = Ax + e:

R(x)=12xT(x−D(x)),min⁡x 12∥Ax−y∥2+λR(x).R(x) = \tfrac12x^T\big(x - D(x)\big),\qquad \min_x\ \tfrac12\|Ax - y\|^2 + \lambda R(x).

The regularizer is small when xx is close to its denoised version or nearly orthogonal to the residual. Romano, Elad and Milanfar (2017) showed that, if DD is locally homogeneous and has a symmetric Jacobian, the gradient of RR is the denoising residual x−D(x)x - D(x). Then gradient and fixed point methods need only one call to DD per step and no derivative of DD. Reehorst and Schniter (2019) showed that common denoisers do not have a symmetric Jacobian. For them, x−D(x)x - D(x) is not the gradient of RR, nor of any function, and the RED algorithms do not minimize the RED objective. They still converge in many tests to a fixed point, whose meaning is the balance of the data gradient and the residual.

In plain words

A noise remover takes an image and returns a cleaner one. The difference between the two is what the noise remover thinks is noise. RED uses that difference as a penalty: a candidate image is good if the noise remover would barely change it.

The reconstruction then takes small steps. Each step pulls the image toward agreement with the measured data and pushes it in the direction in which the noise remover would move it. Under two technical conditions on the noise remover, this is plain gradient descent on a clear score, so the method is easy to analyze. Most real noise removers break one of the conditions, and then the steps still settle down but no longer lower a score.

When it applies

Setting. x∈Rnx \in \mathbb{R}^n, a forward matrix AA, data yy, a weight λ>0\lambda > 0, and a denoiser D:Rn→RnD : \mathbb{R}^n \to \mathbb{R}^n that is differentiable with Jacobian JD(x)J_D(x).

Fact 1 (the general gradient). By the product rule,

∇R(x)=x−12D(x)−12JD(x)Tx.\nabla R(x) = x - \tfrac12D(x) - \tfrac12J_D(x)^Tx.

This always holds. It needs the Jacobian of DD, which is costly for a network.

Fact 2 (Romano et al.). Suppose DD is locally homogeneous, D((1+ϵ)x)=(1+ϵ)D(x)D((1 + \epsilon)x) = (1 + \epsilon)D(x) for all small ϵ\epsilon, and JD(x)J_D(x) is symmetric. Differentiating the first condition in ϵ\epsilon gives JD(x)x=D(x)J_D(x)x = D(x), and with the second, JD(x)Tx=D(x)J_D(x)^Tx = D(x). So Fact 1 becomes

∇R(x)=x−D(x).\nabla R(x) = x - D(x).

If, in addition, the spectral radius of JD(x)J_D(x) is at most 1, Romano et al. show that RR is convex, so the RED objective is convex and every stationary point is a minimizer. A linear denoiser D(x)=WxD(x) = Wx is homogeneous, and the two facts give ∇R(x)=x−12(W+WT)x\nabla R(x) = x - \tfrac12(W + W^T)x; this is x−Wxx - Wx exactly when WW is symmetric.

Fact 3 (Reehorst and Schniter). If JDJ_D is not symmetric, the vector field x−D(x)x - D(x) is not the gradient of any function, since a gradient field has a symmetric Jacobian. So no objective, RR or other, has the RED steps as gradient steps. The common denoisers they tested, including BM3D, non-local means and trained CNNs, do not have symmetric Jacobians. They give another reading, through score matching. For the MMSE denoiser at noise level σ\sigma, Tweedie's formula gives D(x)−x=σ2∇log⁡pσ(x)D(x) - x = \sigma^2\nabla\log p_\sigma(x), where pσp_\sigma is the prior smoothed by the noise. Then x−D(x)x - D(x) is the gradient of −σ2log⁡pσ-\sigma^2\log p_\sigma, not of RR, and a RED fixed point is a stationary point of the MAP problem with the smoothed prior. A trained denoiser approximates this case.

Use RED when a good denoiser is at hand, when you want an explicit objective to monitor (with a linear symmetric or a carefully built denoiser), or when you want a method that uses the denoiser without its derivatives and accept a fixed point without a variational meaning.

The template

  1. RED-GRADIENT(A, y, D, λ, μ, x_0, K)
  2. 1x ← x_0
  3. 2for k = 1 to K
  4. 3d ← D(x) ▷ hole: the denoiser, a given function
  5. 4g ← A^T(Ax - y) + λ(x - d) ▷ the gradient, if Fact 2 holds
  6. 5x ← x - μ g
  7. 6return x

The holes are the denoiser, the weight λ\lambda, the step μ\mu and KK. Each step calls AA, ATA^T and DD once. Under Fact 2, a fixed step μ<2/L\mu < 2/L is safe when LL is a Lipschitz constant of the full gradient; for a linear symmetric WW, L=∥ATA+λ(I−W)∥L = \|A^TA + \lambda(I - W)\|. Romano et al. also give two other solvers. The fixed point iteration solves (ATA+λI)xk+1=ATy+λD(xk)(A^TA + \lambda I)x_{k+1} = A^Ty + \lambda D(x_k), which sets the gradient of line L4 to zero with DD frozen at the old point. The ADMM form splits x=vx = v and updates vv by a few fixed point steps of λ(v−D(v))+ρ(v−x−u)=0\lambda(v - D(v)) + \rho(v - x - u) = 0. All three have the same fixed points: AT(Ax−y)+λ(x−D(x))=0A^T(Ax - y) + \lambda(x - D(x)) = 0.

The denoiser is a given function: the code takes DD as an argument and runs lines L1 to L6 around it, and also gives the fixed point variant. The tests build DD by hand, as a fixed symmetric matrix, a fixed nonsymmetric matrix, or tanh⁡(Bx)\tanh(Bx) with a seeded matrix BB; no network is trained. They check the hand example below, that with a symmetric WW the residual equals the finite difference gradient of RR and RED reaches the solution of (ATA+λ(I−W))x=ATy(A^TA + \lambda(I - W))x = A^Ty, that with a nonsymmetric WW RED stops at a point that is not the minimizer, and Fact 1 for the nonlinear tanh⁡\tanh denoiser.

Classic examples

A symmetric smoother. Take A=IA = I, y=(1,0)y = (1, 0), λ=1\lambda = 1 and the averaging denoiser W=(1/21/21/21/2)W = \begin{pmatrix}1/2 & 1/2\\ 1/2 & 1/2\end{pmatrix}, which is symmetric with eigenvalues 1 and 0. Then R(x)=14(x1−x2)2R(x) = \tfrac14(x_1 - x_2)^2 and the minimizer solves (2I−W)x=y(2I - W)x = y, so x⋆=(0.75,0.25)x^\star = (0.75, 0.25). Gradient steps with μ=0.5\mu = 0.5 from x0=0x_0 = 0 give (0.5,0)(0.5, 0), (0.625,0.125)(0.625, 0.125), (0.6875,0.1875)(0.6875, 0.1875), (0.71875,0.21875)(0.71875, 0.21875), and the error halves at each step.

A nonsymmetric denoiser. Keep AA, yy and λ\lambda, and let W=(0101)W = \begin{pmatrix}0 & 1\\ 0 & 1\end{pmatrix}, which replaces the first entry by the second. It is linear, so homogeneous, and its eigenvalues are 0 and 1, but WW is not symmetric. RED (both the gradient and the fixed point forms) stops at the solution of (2I−W)x=y(2I - W)x = y, which is (0.5,0)(0.5, 0), with the objective value 0.250.25. The RED objective has the gradient (2I−12(W+WT))x−y(2I - \tfrac12(W + W^T))x - y, so its minimizer is (4/7,2/7)=(0.5714,0.2857)(4/7, 2/7) = (0.5714, 0.2857), with the lower value 3/14=0.21433/14 = 0.2143. The RED iteration converges, but not to the minimizer of the RED objective.

Practical denoisers. Romano et al. used trained and classical denoisers in RED for deblurring and super-resolution of standard test images and compared the results with other methods, PnP among them. These comparisons are measurements on those images. By Fact 3, their convergence argument does not apply to those denoisers.

Variations

  • Fixed point and ADMM solvers. As in the template. The fixed point form needs a linear solve per step, and the ADMM form reuses a fast solver for the data term.
  • Accelerated RED. Momentum and vector extrapolation of the fixed point iteration reduce the number of denoiser calls.
  • Score-based reading. Reehorst and Schniter interpret D(x)−xD(x) - x as a scaled score, which links RED to diffusion posterior sampling, where the denoiser is a score network at many noise levels.
  • Plug-and-play. PnP uses DD as a proximal step instead of a gradient. With a denoiser that is a proximal map, PnP has an objective; with a symmetric, homogeneous denoiser, RED has one. The two conditions are different.
  • Gradient step denoisers. Train the denoiser as D=I−∇gD = I - \nabla g for a network gg; then x−D(x)x - D(x) is a gradient by construction and RED-type methods minimize an explicit objective.

Pitfalls

  • Assuming the gradient. Using x−D(x)x - D(x) as ∇R\nabla R for a denoiser with a nonsymmetric Jacobian gives a method without an objective, as the second example shows. Do not report the RED objective value as a measure of progress then.
  • Step size. Without Fact 2 there is no Lipschitz bound to set μ\mu. Use the fixed point form or check that ∥xk+1−xk∥\|x_{k+1} - x_k\| goes down.
  • Weight and noise level. The weight λ\lambda and the noise level for which DD is set interact. Tune them together.
  • Cost of the true gradient. Fact 1 needs JDTxJ_D^Tx, one backpropagation through a network per step. It is exact but costs about as much again as the denoiser call.

Code

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

regularization_by_denoising.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/regularization-by-denoising/. The authors are listed in prov/K86DXS.jsonl.
"""Regularization by denoising (RED) of Romano, Elad and Milanfar.

The denoiser is given: a function denoiser(x). RED uses the residual
x - D(x) in place of the gradient of R(x) = (1/2) x^T (x - D(x)). This is
the true gradient only when D is locally homogeneous and has a symmetric
Jacobian. Matrices are lists of rows; vectors are lists of floats.
"""


def matvec(a, x):
    return [sum(p * q for p, q in zip(row, x)) for row in a]


def rmatvec(a, r):
    return [sum(a[i][j] * r[i] for i in range(len(a))) for j in range(len(a[0]))]


def red_gradient_descent(a, y, denoiser, lam, step, x0, iters):
    """Steps x <- x - step (A^T (A x - y) + lam (x - D(x)))."""
    x = list(x0)  # @line L1
    for _ in range(iters):  # @line L2
        d = denoiser(x)  # @line L3
        r = [p - q for p, q in zip(matvec(a, x), y)]
        g = [p + lam * (xi - di) for p, xi, di in zip(rmatvec(a, r), x, d)]  # @line L4
        x = [xi - step * gi for xi, gi in zip(x, g)]  # @line L5
    return x  # @line L6


def solve(m, b):
    """Solve m x = b by Gaussian elimination with partial pivoting."""
    n = len(b)
    t = [list(row) + [bi] for row, bi in zip(m, b)]
    for c in range(n):
        p = max(range(c, n), key=lambda r: abs(t[r][c]))
        t[c], t[p] = t[p], t[c]
        for r in range(c + 1, n):
            f = t[r][c] / t[c][c]
            for k in range(c, n + 1):
                t[r][k] -= f * t[c][k]
    x = [0.0] * n
    for r in range(n - 1, -1, -1):
        x[r] = (t[r][n] - sum(t[r][k] * x[k] for k in range(r + 1, n))) / t[r][r]
    return x


def red_fixed_point(a, y, denoiser, lam, x0, iters):
    """Steps x <- (A^T A + lam I)^{-1} (A^T y + lam D(x)), the fixed point variant."""
    n = len(x0)
    m = [[sum(a[i][j] * a[i][k] for i in range(len(a))) + (lam if j == k else 0.0)
          for k in range(n)] for j in range(n)]
    aty = rmatvec(a, y)
    x = list(x0)
    for _ in range(iters):
        x = solve(m, [p + lam * q for p, q in zip(aty, denoiser(x))])
    return x


def red_regularizer(x, denoiser):
    """R(x) = (1/2) x^T (x - D(x))."""
    return 0.5 * sum(xi * (xi - di) for xi, di in zip(x, denoiser(x)))


def red_regularizer_gradient(x, denoiser, denoiser_vjp):
    """The true gradient x - (1/2) D(x) - (1/2) J_D(x)^T x of R."""
    d, jt = denoiser(x), denoiser_vjp(x, x)
    return [xi - 0.5 * di - 0.5 * ji for xi, di, ji in zip(x, d, jt)]
test_regularization_by_denoising.py 104 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/regularization-by-denoising/. The authors are listed in prov/K86DXS.jsonl.

import math
import random

from regularization_by_denoising import (
    matvec,
    red_fixed_point,
    red_gradient_descent,
    red_regularizer,
    red_regularizer_gradient,
    rmatvec,
    solve,
)

EYE2 = [[1.0, 0.0], [0.0, 1.0]]


def close(u, v, tol):
    return max(abs(p - q) for p, q in zip(u, v)) < tol


def fd_gradient(fun, x, h=1e-6):
    out = []
    for j in range(len(x)):
        xp, xm = list(x), list(x)
        xp[j] += h
        xm[j] -= h
        out.append((fun(xp) - fun(xm)) / (2 * h))
    return out


def seeded_problem(seed, n=6, m=4):
    rng = random.Random(seed)
    a = [[rng.gauss(0.0, 1.0) for _ in range(n)] for _ in range(m)]
    y = [rng.gauss(0.0, 1.0) for _ in range(m)]
    b = [[rng.gauss(0.0, 1.0) for _ in range(n)] for _ in range(n)]
    return rng, a, y, b


def test_hand_example_symmetric():
    w = [[0.5, 0.5], [0.5, 0.5]]
    d = lambda x: matvec(w, x)
    assert red_gradient_descent(EYE2, [1.0, 0.0], d, 1.0, 0.5, [0.0, 0.0], 1) == [0.5, 0.0]
    assert close(red_gradient_descent(EYE2, [1.0, 0.0], d, 1.0, 0.5, [0.0, 0.0], 3), [0.6875, 0.1875], 1e-15)
    assert close(red_gradient_descent(EYE2, [1.0, 0.0], d, 1.0, 0.5, [0.0, 0.0], 60), [0.75, 0.25], 1e-12)


def test_symmetric_linear_denoiser_gives_the_exact_gradient():
    rng, a, y, b = seeded_problem(1)
    n = 6
    # W = I - c B^T B is symmetric; the gradient of R is (I - W) x.
    btb = [[sum(b[k][i] * b[k][j] for k in range(n)) for j in range(n)] for i in range(n)]
    w = [[(1.0 if i == j else 0.0) - 0.02 * btb[i][j] for j in range(n)] for i in range(n)]
    d = lambda x: matvec(w, x)
    x = [rng.gauss(0.0, 1.0) for _ in range(n)]
    g = fd_gradient(lambda z: red_regularizer(z, d), x)
    assert close(g, [xi - di for xi, di in zip(x, d(x))], 1e-7)
    # RED converges to the minimizer: (A^T A + lam (I - W)) x = A^T y.
    lam = 2.0
    m = [[sum(a[r][i] * a[r][j] for r in range(4)) + lam * 0.02 * btb[i][j]
          for j in range(n)] for i in range(n)]
    exact = solve(m, rmatvec(a, y))
    x_fp = red_fixed_point(a, y, d, lam, [0.0] * n, 3000)
    assert close(x_fp, exact, 1e-8)


def test_nonsymmetric_denoiser_does_not_minimize_the_red_objective():
    w = [[0.0, 1.0], [0.0, 1.0]]
    d = lambda x: matvec(w, x)
    y = [1.0, 0.0]
    x_gd = red_gradient_descent(EYE2, y, d, 1.0, 0.5, [0.0, 0.0], 50)
    x_fp = red_fixed_point(EYE2, y, d, 1.0, [0.0, 0.0], 50)
    assert close(x_gd, [0.5, 0.0], 1e-12) and close(x_fp, [0.5, 0.0], 1e-12)

    def objective(x):
        return 0.5 * ((x[0] - 1.0) ** 2 + x[1] ** 2) + red_regularizer(x, d)

    # The true minimizer solves (2I - (W + W^T)/2) x = y.
    best = [4.0 / 7.0, 2.0 / 7.0]
    assert close(fd_gradient(objective, best), [0.0, 0.0], 1e-8)
    assert abs(objective(x_gd) - 0.25) < 1e-12 and abs(objective(best) - 3.0 / 14.0) < 1e-12
    # The residual x - W x is not the gradient of R.
    x = [0.3, -0.8]
    g = fd_gradient(lambda z: red_regularizer(z, d), x)
    assert not close(g, [p - q for p, q in zip(x, d(x))], 0.1)


def test_general_gradient_formula_for_a_nonlinear_denoiser():
    rng, _, _, b = seeded_problem(2)
    n = 6

    def d(x):
        return [math.tanh(sum(bij * xj for bij, xj in zip(row, x))) for row in b]

    def d_vjp(x, v):
        t = d(x)
        return rmatvec(b, [vi * (1.0 - ti * ti) for vi, ti in zip(v, t)])

    x = [rng.gauss(0.0, 0.5) for _ in range(n)]
    g = fd_gradient(lambda z: red_regularizer(z, d), x)
    assert close(g, red_regularizer_gradient(x, d, d_vjp), 1e-7)
    assert not close(g, [xi - di for xi, di in zip(x, d(x))], 0.05)

Exercises

  1. Prove Fact 1, and derive Fact 2 from it.
  2. For WW symmetric with eigenvalues in [0,1][0, 1], show that R(x)=12xT(I−W)xR(x) = \tfrac12x^T(I - W)x is convex, and find the minimizer of the RED objective with A=IA = I.
  3. Verify both examples. In the second, check that the RED fixed point satisfies (2I−W)x=y(2I - W)x = y and that the objective has a smaller value at (4/7,2/7)(4/7, 2/7).
  4. Show that the soft threshold D(x)=soft⁡(x,θ)D(x) = \operatorname{soft}(x, \theta) is not locally homogeneous. Compute ∇R\nabla R by Fact 1 at a point where no entry equals ±θ\pm\theta, and compare it with x−D(x)x - D(x).
  5. Show that a smooth vector field FF on Rn\mathbb{R}^n is a gradient field only if its Jacobian is symmetric. Apply this to F(x)=x−WxF(x) = x - Wx.

References

  1. Yaniv Romano, Michael Elad and Peyman Milanfar, The little engine that could, regularization by denoising (RED), SIAM Journal on Imaging Sciences 10(4), 2017, pages 1804 to 1844 (the regularizer, the gradient under local homogeneity and a symmetric Jacobian, and the steepest descent, ADMM and fixed point solvers)
  2. Edward T. Reehorst and Philip Schniter, Regularization by denoising, clarifications and new interpretations, IEEE Transactions on Computational Imaging 5(1), 2019, pages 52 to 67 (the general gradient of the RED regularizer, the lack of Jacobian symmetry in practical denoisers, and the score matching reading of the RED algorithms)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • three classic examples