Algorithm Search⌘K

Algorithmadvanced

Chambolle's projection algorithm

Also called Chambolle dual algorithm for total variation, Chambolle's semi-implicit dual iteration.

Solve total variation denoising by a fixed point iteration on a dual field, which computes the projection of the noisy image onto the set of bounded divergence fields.

Time
O(K N) worst
Space
O(N) extra
Where
K = the number of iterations; N = the number of pixels
Properties
deterministicnot exactfeasible iteratesiterativemean preservingmonotone dual objective
Origin
Antonin Chambolle, 2004

Chambolle's projection algorithm computes the minimizer of the total variation denoising energy 12∥u−f∥2+λ TV(u)\tfrac12\|u - f\|^2 + \lambda\,\mathrm{TV}(u) without touching the nonsmooth total variation directly. It uses one fact from convex duality: the discrete total variation is the largest value of ⟨u,div⁡p⟩\langle u, \operatorname{div} p\rangle over the vector fields pp with length at most 1 at every pixel. So the denoised image is u=f−πλK(f)u = f - \pi_{\lambda K}(f), where πλK\pi_{\lambda K} is the projection onto the closed convex set λK\lambda K of divergences of such fields. The algorithm finds this projection by a simple fixed point step on the dual field pp, with a denominator that keeps every iterate feasible. Chambolle proved in 2004 that the iterates converge for every step τ≤1/8\tau \le 1/8. The output is the proximal operator of λ TV\lambda\,\mathrm{TV}, so the same routine is the inner step of many deblurring and reconstruction methods.

In plain words

A noisy image is a clean image plus a noise part. The method does not look for the clean image directly. It looks for the noise part, because the noise part has a simple description: it is built from a small arrow at each pixel, and no arrow may be longer than a fixed limit. The method keeps one arrow per pixel and improves all arrows at the same time. At each step every arrow turns toward the direction that removes more of the remaining noise, and a division shrinks it back so that it never passes the limit. When the arrows stop changing, the noise part is known, and the clean image is the noisy image minus the noise part. Each step only compares a pixel with its neighbors, so a step is cheap, but many steps can be needed.

The problem

The input is an image ff with N=n1n2N = n_1 n_2 pixels and a weight λ>0\lambda > 0. The output is the unique minimizer of

E(u)=12∥u−f∥2+λ TV(u),TV(u)=∑i,j∣(∇u)ij∣,E(u) = \tfrac12\|u - f\|^2 + \lambda\,\mathrm{TV}(u), \qquad \mathrm{TV}(u) = \sum_{i,j} |(\nabla u)_{ij}|,

where (∇u)ij=(ui+1,j−uij,  ui,j+1−uij)(\nabla u)_{ij} = (u_{i+1,j} - u_{ij},\; u_{i,j+1} - u_{ij}) are forward differences with the Neumann rule (a difference that leaves the image is 0) and ∣⋅∣|\cdot| is the Euclidean length, which gives the isotropic total variation. The divergence is defined by div⁡=−∇⊤\operatorname{div} = -\nabla^\top, so ⟨∇u,p⟩=−⟨u,div⁡p⟩\langle \nabla u, p\rangle = -\langle u, \operatorname{div} p\rangle for every image uu and field pp. With this choice

TV(u)=max⁡{⟨u,div⁡p⟩:∣pij∣≤1 for all i,j},\mathrm{TV}(u) = \max\{\langle u, \operatorname{div} p\rangle : |p_{ij}| \le 1 \text{ for all } i, j\},

and the minimizer is u=f−λdiv⁡p∗u = f - \lambda \operatorname{div} p^*, where p∗p^* is any solution of the dual problem

min⁡p∥div⁡p−f/λ∥2subject to∣pij∣≤1 for all i,j.\min_p \|\operatorname{div} p - f/\lambda\|^2 \quad\text{subject to}\quad |p_{ij}| \le 1 \text{ for all } i, j.

The dual solution p∗p^* need not be unique, but λdiv⁡p∗=πλK(f)\lambda\operatorname{div} p^* = \pi_{\lambda K}(f) is. The weight λ\lambda is a design choice: it sets the size of the smallest feature that survives, and it is tuned for each class of images.

The algorithm

  1. ChambolleProjection(f, λ, τ, K)
  2. 1p ← 0 ▷ one 2-vector per pixel
  3. 2for k = 1 to K
  4. 3v ← div p - f / λ ▷ the dual residual
  5. 4z ← ∇v
  6. 5at each pixel: p ← (p + τ z) / (1 + τ |z|)
  7. 6w ← λ div p ▷ the projection of f onto λK
  8. 7return u = f - w

The dual problem has the constraint ∣pij∣≤1|p_{ij}| \le 1, and its optimality condition at each pixel is −zij+αijpij=0-z_{ij} + \alpha_{ij} p_{ij} = 0 with a multiplier αij≥0\alpha_{ij} \ge 0. In both cases (∣pij∣<1|p_{ij}| < 1, which forces zij=0z_{ij} = 0, and ∣pij∣=1|p_{ij}| = 1) the multiplier is αij=∣zij∣\alpha_{ij} = |z_{ij}|. Chambolle's step is a gradient step on this condition, with the multiplier term taken at the new point:

pn+1=pn+τ(zn−∣zn∣ pn+1).p^{n+1} = p^n + \tau\big(z^n - |z^n|\,p^{n+1}\big).

Solving for pn+1p^{n+1} gives line L5. The denominator keeps the iterates feasible: if ∣p∣≤1|p| \le 1, then ∣p+τz∣≤1+τ∣z∣|p + \tau z| \le 1 + \tau|z|. Line L4 is minus one half of the gradient of the dual objective, and lines L6 and L7 map the dual field back to the image. A practical stop is the duality gap E(un)−D(pn)E(u^n) - D(p^n) with D(p)=12∥f∥2−12∥f−λdiv⁡p∥2D(p) = \tfrac12\|f\|^2 - \tfrac12\|f - \lambda\operatorname{div}p\|^2, which bounds 12∥un−u∗∥2\tfrac12\|u^n - u^*\|^2.

Example

Take the one-row image f=(0,0,3,3)f = (0, 0, 3, 3) with λ=1\lambda = 1. In one dimension the field has three entries (p1,p2,p3)(p_1, p_2, p_3), one per difference, div⁡p=(p1, p2−p1, p3−p2, −p3)\operatorname{div} p = (p_1,\, p_2 - p_1,\, p_3 - p_2,\, -p_3), and ∥div⁡∥2≤4\|\operatorname{div}\|^2 \le 4, so the proof below covers τ≤1/4\tau \le 1/4. Take τ=1/4\tau = 1/4.

Step 1: p=0p = 0, so v=−f=(0,0,−3,−3)v = -f = (0, 0, -3, -3) and z=∇v=(0,−3,0)z = \nabla v = (0, -3, 0). Line L5 gives p2=(0−3/4)/(1+3/4)=−3/7p_2 = (0 - 3/4)/(1 + 3/4) = -3/7, and the other entries stay 0. Then div⁡p=(0,−3/7,3/7,0)\operatorname{div} p = (0, -3/7, 3/7, 0) and u=(0, 0.4286, 2.5714, 3)u = (0,\ 0.4286,\ 2.5714,\ 3). The edge has started to shrink, but the flat parts have not moved yet, because the field is still 0 next to them.

kk pp uu gap E(u)−D(p)E(u) - D(p)
1 (0,−0.4286,0)(0, -0.4286, 0) (0,0.4286,2.5714,3)(0, 0.4286, 2.5714, 3) 2.0816
2 (−0.0968,−0.6279,−0.0968)(-0.0968, -0.6279, -0.0968) (0.0968,0.5311,2.4689,2.9032)(0.0968, 0.5311, 2.4689, 2.9032) 1.5057
3 (−0.1852,−0.7493,−0.1852)(-0.1852, -0.7493, -0.1852) (0.1852,0.5641,2.4359,2.8148)(0.1852, 0.5641, 2.4359, 2.8148) 1.0865
10 (−0.4469,−0.9830,−0.4469)(-0.4469, -0.9830, -0.4469) (0.4469,0.5362,2.4638,2.5531)(0.4469, 0.5362, 2.4638, 2.5531) 0.1315
20 (−0.4963,−0.9997,−0.4963)(-0.4963, -0.9997, -0.4963) (0.4963,0.5034,2.4966,2.5037)(0.4963, 0.5034, 2.4966, 2.5037) 0.0078
50 (−0.5,−1,−0.5)(-0.5, -1, -0.5) (0.5,0.5,2.5,2.5)(0.5, 0.5, 2.5, 2.5) 1.5⋅10−61.5 \cdot 10^{-6}

The limit is p∗=(−1/2,−1,−1/2)p^* = (-1/2, -1, -1/2) and u∗=(1/2,1/2,5/2,5/2)u^* = (1/2, 1/2, 5/2, 5/2): each side moves toward the other by λ\lambda divided by its length 2, as the total variation denoising page derives. At the edge ∇u∗=2\nabla u^* = 2 and p2∗=−1p^*_2 = -1, so −∇u∗=∣∇u∗∣ p∗-\nabla u^* = |\nabla u^*|\,p^* there, which is the optimality condition. With τ=1/8\tau = 1/8 the same gap needs about 100 steps instead of 50.

Correctness

The full proof is in proofs/correctness.md. Let F(p)=∥div⁡p−f/λ∥2F(p) = \|\operatorname{div} p - f/\lambda\|^2 and let κ\kappa bound ∥div⁡∥2\|\operatorname{div}\|^2, with κ=8\kappa = 8 in two dimensions. Write one step as p′=p+τηp' = p + \tau\eta with η=z−∣z∣p′\eta = z - |z|p'. Then

F(p′)≤F(p)−τ(∑i,j∣zij∣2(1−∣pij′∣2)+(1−τκ)∥η∥2),F(p') \le F(p) - \tau\Big(\sum_{i,j} |z_{ij}|^2\big(1 - |p'_{ij}|^2\big) + (1 - \tau\kappa)\|\eta\|^2\Big),

so for τ≤1/κ\tau \le 1/\kappa the dual objective does not increase (a theorem). If it does not decrease, the step does not move: at each pixel either z=0z = 0, or ∣p′∣=1|p'| = 1, and then the triangle inequality forces p=z/∣z∣=p′p = z/|z| = p'. This is the case τ=1/8\tau = 1/8 that needs care. A fixed point satisfies −∇u=∣∇u∣ p-\nabla u = |\nabla u|\,p at each pixel for u=f−λdiv⁡pu = f - \lambda\operatorname{div} p, so ⟨u,λdiv⁡p⟩=λ TV(u)\langle u, \lambda\operatorname{div}p\rangle = \lambda\,\mathrm{TV}(u), and this makes uu the minimizer with E(v)≥E(u)+12∥v−u∥2E(v) \ge E(u) + \tfrac12\|v - u\|^2 for all vv. The step map is continuous and the iterates are bounded, so every limit point of (pn)(p^n) is a fixed point and un→u∗u^n \to u^*. The field pnp^n itself need not converge, because the dual solution is not unique.

Proof: Chambolle's dual iteration decreases the dual objective for a step of at most 1/8 and its primal iterates converge to the total variation denoised imagefull

Setting. Images are vectors in X=Rn1×n2X = \mathbb{R}^{n_1 \times n_2} and fields are pairs p=(p1,p2)∈Y=X×Xp = (p_1, p_2) \in Y = X \times X, with pij∈R2p_{ij} \in \mathbb{R}^2 and Euclidean length ∣pij∣|p_{ij}|. The gradient ∇:X→Y\nabla : X \to Y uses forward differences with a zero difference at the last row and column, and div⁡=−∇⊤\operatorname{div} = -\nabla^\top, so ⟨∇u,p⟩Y=−⟨u,div⁡p⟩X\langle \nabla u, p\rangle_Y = -\langle u, \operatorname{div}p\rangle_X. Let κ\kappa be a bound with ∥div⁡p∥2≤κ∥p∥2\|\operatorname{div} p\|^2 \le \kappa\|p\|^2 for all pp. Let f∈Xf \in X, λ>0\lambda > 0, g=f/λg = f/\lambda,

E(u)=12∥u−f∥2+λ TV(u),TV(u)=∑ij∣(∇u)ij∣,E(u) = \tfrac12\|u - f\|^2 + \lambda\,\mathrm{TV}(u),\qquad \mathrm{TV}(u) = \sum_{ij}|(\nabla u)_{ij}|,
P={p∈Y:∣pij∣≤1 for all i,j},K={div⁡p:p∈P},F(p)=∥div⁡p−g∥2.P = \{p \in Y : |p_{ij}| \le 1 \text{ for all } i, j\},\qquad K = \{\operatorname{div}p : p \in P\},\qquad F(p) = \|\operatorname{div}p - g\|^2.

The step map TT of lines L3 to L5 is: z=∇(div⁡p−g)z = \nabla(\operatorname{div}p - g) and (Tp)ij=(pij+τzij)/(1+τ∣zij∣)(Tp)_{ij} = (p_{ij} + \tau z_{ij})/(1 + \tau|z_{ij}|). The algorithm sets p0=0p^0 = 0, pn+1=Tpnp^{n+1} = Tp^n and un=f−λdiv⁡pnu^n = f - \lambda\operatorname{div}p^n.

Lemma 0 (the bound κ=8\kappa = 8 in two dimensions, κ=4\kappa = 4 in one). (div⁡p)ij=a−b+c−d(\operatorname{div}p)_{ij} = a - b + c - d, where a=p1,ija = p_{1,ij}, b=p1,i−1,jb = p_{1,i-1,j}, c=p2,ijc = p_{2,ij}, d=p2,i,j−1d = p_{2,i,j-1} and an entry outside the image or on the last row (for p1p_1) or column (for p2p_2) is replaced by 0. By the Cauchy-Schwarz inequality (a−b+c−d)2≤4(a2+b2+c2+d2)(a - b + c - d)^2 \le 4(a^2 + b^2 + c^2 + d^2). Each entry of pp appears in the sums of at most two pixels, so ∥div⁡p∥2≤8∥p∥2\|\operatorname{div}p\|^2 \le 8\|p\|^2. In one dimension there are two terms per pixel, the factor 4 becomes 2, and κ=4\kappa = 4. □\square

Lemma 1 (dual formula). For all uu, TV(u)=max⁡p∈P⟨u,div⁡p⟩\mathrm{TV}(u) = \max_{p \in P}\langle u, \operatorname{div}p\rangle, so λ TV(u)=max⁡w∈λK⟨u,w⟩\lambda\,\mathrm{TV}(u) = \max_{w \in \lambda K}\langle u, w\rangle.

Proof. For p∈Pp \in P, ⟨u,div⁡p⟩=−⟨∇u,p⟩≤∑ij∣(∇u)ij∣ ∣pij∣≤TV(u)\langle u, \operatorname{div}p\rangle = -\langle\nabla u, p\rangle \le \sum_{ij}|(\nabla u)_{ij}|\,|p_{ij}| \le \mathrm{TV}(u). Equality holds for pij=−(∇u)ij/∣(∇u)ij∣p_{ij} = -(\nabla u)_{ij}/|(\nabla u)_{ij}| where (∇u)ij≠0(\nabla u)_{ij} \ne 0 and pij=0p_{ij} = 0 elsewhere, and this pp is in PP. □\square

Lemma 2 (a certificate of optimality). Let w∈λKw \in \lambda K and u=f−wu = f - w with ⟨u,w⟩=λ TV(u)\langle u, w\rangle = \lambda\,\mathrm{TV}(u). Then for every v∈Xv \in X,

E(v)≥E(u)+12∥v−u∥2.E(v) \ge E(u) + \tfrac12\|v - u\|^2.

So uu is the unique minimizer u∗u^* of EE.

Proof. By Lemma 1, λ TV(v)≥⟨v,w⟩\lambda\,\mathrm{TV}(v) \ge \langle v, w\rangle for every vv, with equality at v=uv = u by assumption. Since v−f=(v−u)−wv - f = (v - u) - w,

E(v)≥12∥v−u∥2−⟨v−u,w⟩+12∥w∥2+⟨v,w⟩=12∥v−u∥2+12∥w∥2+⟨u,w⟩=12∥v−u∥2+E(u).□E(v) \ge \tfrac12\|v - u\|^2 - \langle v - u, w\rangle + \tfrac12\|w\|^2 + \langle v, w\rangle = \tfrac12\|v - u\|^2 + \tfrac12\|w\|^2 + \langle u, w\rangle = \tfrac12\|v - u\|^2 + E(u). \qquad\square

The minimizer u∗u^* exists because EE is continuous and E(u)→∞E(u) \to \infty as ∥u∥→∞\|u\| \to \infty, and it is unique because EE is strongly convex. Let w∗=πλK(f)w^* = \pi_{\lambda K}(f), which exists because KK is the linear image of the compact convex set PP and so is compact and convex. The projection inequality gives ⟨f−w∗,w−w∗⟩≤0\langle f - w^*, w - w^*\rangle \le 0 for all w∈λKw \in \lambda K, so ⟨f−w∗,w∗⟩=max⁡w∈λK⟨f−w∗,w⟩=λ TV(f−w∗)\langle f - w^*, w^*\rangle = \max_{w \in \lambda K}\langle f - w^*, w\rangle = \lambda\,\mathrm{TV}(f - w^*) by Lemma 1. Lemma 2 then gives u∗=f−πλK(f)u^* = f - \pi_{\lambda K}(f). This is the dual problem: λdiv⁡p∗=πλK(f)\lambda\operatorname{div}p^* = \pi_{\lambda K}(f) exactly when p∗p^* minimizes FF over PP.

Lemma 3 (feasibility). If p∈Pp \in P then Tp∈PTp \in P, and p′=Tpp' = Tp satisfies p′=p+τηp' = p + \tau\eta with η=z−∣z∣ p′\eta = z - |z|\,p' at each pixel.

Proof. ∣pij+τzij∣≤1+τ∣zij∣|p_{ij} + \tau z_{ij}| \le 1 + \tau|z_{ij}|, so ∣pij′∣≤1|p'_{ij}| \le 1. Multiply the definition of p′p' by 1+τ∣z∣1 + \tau|z|: p′+τ∣z∣p′=p+τzp' + \tau|z|p' = p + \tau z. □\square

By induction from p0=0p^0 = 0, every iterate is in PP. This is the loop invariant of lines L2 to L5.

Lemma 4 (descent). Let p∈Pp \in P, p′=Tpp' = Tp and 0<τ≤1/κ0 < \tau \le 1/\kappa. Then

F(p′)≤F(p)−τ(∑ij∣zij∣2(1−∣pij′∣2)+(1−τκ)∥η∥2)≤F(p).F(p') \le F(p) - \tau\Big(\sum_{ij}|z_{ij}|^2\big(1 - |p'_{ij}|^2\big) + (1 - \tau\kappa)\|\eta\|^2\Big) \le F(p).

Proof. Put r=div⁡p−gr = \operatorname{div}p - g, so z=∇rz = \nabla r. Then div⁡p′−g=r+τdiv⁡η\operatorname{div}p' - g = r + \tau\operatorname{div}\eta and

F(p′)=∥r∥2+2τ⟨div⁡η,r⟩+τ2∥div⁡η∥2≤F(p)−2τ⟨η,z⟩+τ2κ∥η∥2,F(p') = \|r\|^2 + 2\tau\langle \operatorname{div}\eta, r\rangle + \tau^2\|\operatorname{div}\eta\|^2 \le F(p) - 2\tau\langle \eta, z\rangle + \tau^2\kappa\|\eta\|^2,

using ⟨div⁡η,r⟩=−⟨η,∇r⟩\langle\operatorname{div}\eta, r\rangle = -\langle\eta, \nabla r\rangle. At each pixel 2η⋅z−∣η∣2=∣z∣2−∣z−η∣2=∣z∣2−∣z∣2∣p′∣22\eta\cdot z - |\eta|^2 = |z|^2 - |z - \eta|^2 = |z|^2 - |z|^2|p'|^2, because z−η=∣z∣p′z - \eta = |z|p'. So

2⟨η,z⟩−τκ∥η∥2=∑ij∣zij∣2(1−∣pij′∣2)+(1−τκ)∥η∥2,2\langle\eta, z\rangle - \tau\kappa\|\eta\|^2 = \sum_{ij}|z_{ij}|^2\big(1 - |p'_{ij}|^2\big) + (1 - \tau\kappa)\|\eta\|^2,

and both terms are at least 0 by Lemma 3 and τκ≤1\tau\kappa \le 1. □\square

Lemma 5 (no decrease means a fixed point). Let p∈Pp \in P and 0<τ≤1/κ0 < \tau \le 1/\kappa. If F(Tp)=F(p)F(Tp) = F(p) then Tp=pTp = p.

Proof. By Lemma 4 the bracket is 0, so ∣zij∣2(1−∣pij′∣2)=0|z_{ij}|^2(1 - |p'_{ij}|^2) = 0 at each pixel. If zij=0z_{ij} = 0 then pij′=pijp'_{ij} = p_{ij} by the formula. Otherwise ∣pij′∣=1|p'_{ij}| = 1, so ∣pij+τzij∣=1+τ∣zij∣≥∣pij∣+τ∣zij∣|p_{ij} + \tau z_{ij}| = 1 + \tau|z_{ij}| \ge |p_{ij}| + \tau|z_{ij}|. The triangle inequality then holds with equality and ∣pij∣=1|p_{ij}| = 1. Equality in the triangle inequality with zij≠0z_{ij} \ne 0 and pij≠0p_{ij} \ne 0 means pij=c zijp_{ij} = c\,z_{ij} with c>0c > 0, so pij=zij/∣zij∣p_{ij} = z_{ij}/|z_{ij}|. Then pij+τzij=(1+τ∣zij∣) zij/∣zij∣p_{ij} + \tau z_{ij} = (1 + \tau|z_{ij}|)\,z_{ij}/|z_{ij}| and pij′=zij/∣zij∣=pijp'_{ij} = z_{ij}/|z_{ij}| = p_{ij}. □\square

For τ<1/κ\tau < 1/\kappa the term (1−τκ)∥η∥2(1 - \tau\kappa)\|\eta\|^2 alone gives η=0\eta = 0. The argument above is what covers the end point τ=1/κ\tau = 1/\kappa, which is τ=1/8\tau = 1/8 in two dimensions.

Lemma 6 (a fixed point gives the minimizer). If p∈Pp \in P and Tp=pTp = p, then u=f−λdiv⁡pu = f - \lambda\operatorname{div}p is u∗u^*.

Proof. Tp=pTp = p means p+τz=(1+τ∣z∣)pp + \tau z = (1 + \tau|z|)p at each pixel, so z=∣z∣ pz = |z|\,p. Since u=−λ(div⁡p−g)u = -\lambda(\operatorname{div}p - g), we have ∇u=−λz\nabla u = -\lambda z, so −(∇u)ij=∣(∇u)ij∣ pij-(\nabla u)_{ij} = |(\nabla u)_{ij}|\,p_{ij}. Where (∇u)ij≠0(\nabla u)_{ij} \ne 0 this forces ∣pij∣=1|p_{ij}| = 1. Hence

⟨u,div⁡p⟩=−⟨∇u,p⟩=∑ij∣(∇u)ij∣ ∣pij∣2=TV(u).\langle u, \operatorname{div}p\rangle = -\langle\nabla u, p\rangle = \sum_{ij}|(\nabla u)_{ij}|\,|p_{ij}|^2 = \mathrm{TV}(u).

With w=λdiv⁡p∈λKw = \lambda\operatorname{div}p \in \lambda K and u=f−wu = f - w, Lemma 2 applies. □\square

Theorem. Let 0<τ≤1/κ0 < \tau \le 1/\kappa, so τ≤1/8\tau \le 1/8 for images and τ≤1/4\tau \le 1/4 for signals. Then F(pn)F(p^n) is nonincreasing and un=f−λdiv⁡pn→u∗u^n = f - \lambda\operatorname{div}p^n \to u^*, the minimizer of EE.

Proof. By Lemma 4 the sequence F(pn)F(p^n) is nonincreasing and at least 0, so it has a limit mm. The iterates lie in the compact set PP (Lemma 3). Let pnk→pˉp^{n_k} \to \bar p be any convergent subsequence. The map TT is continuous, because its denominator is at least 1. So pnk+1=Tpnk→Tpˉp^{n_k + 1} = Tp^{n_k} \to T\bar p, and by continuity of FF, F(Tpˉ)=lim⁡F(pnk+1)=m=F(pˉ)F(T\bar p) = \lim F(p^{n_k+1}) = m = F(\bar p). Lemma 5 gives Tpˉ=pˉT\bar p = \bar p, and Lemma 6 gives f−λdiv⁡pˉ=u∗f - \lambda\operatorname{div}\bar p = u^*. So along every convergent subsequence of (pn)(p^n), un→u∗u^n \to u^*. If unu^n did not converge to u∗u^*, there would be ε>0\varepsilon > 0 and a subsequence with ∥un−u∗∥≥ε\|u^n - u^*\| \ge \varepsilon; by compactness of PP it has a further subsequence on which pnp^n converges, and on it un→u∗u^n \to u^*, a contradiction. □\square

Termination with a certificate. For p∈Pp \in P let D(p)=12∥f∥2−12∥f−λdiv⁡p∥2D(p) = \tfrac12\|f\|^2 - \tfrac12\|f - \lambda\operatorname{div}p\|^2. With w=λdiv⁡pw = \lambda\operatorname{div}p, Lemma 1 gives for every vv

E(v)≥12∥v−f∥2+⟨v,w⟩≥min⁡x(12∥x−f∥2+⟨x,w⟩)=⟨f,w⟩−12∥w∥2=D(p).E(v) \ge \tfrac12\|v - f\|^2 + \langle v, w\rangle \ge \min_x\Big(\tfrac12\|x - f\|^2 + \langle x, w\rangle\Big) = \langle f, w\rangle - \tfrac12\|w\|^2 = D(p).

So E(u∗)≥D(p)E(u^*) \ge D(p), and by Lemma 2 applied at u∗u^*,

12∥u−u∗∥2≤E(u)−E(u∗)≤E(u)−D(p)\tfrac12\|u - u^*\|^2 \le E(u) - E(u^*) \le E(u) - D(p)

for every image uu and every p∈Pp \in P. The gap E(un)−D(pn)E(u^n) - D(p^n) is computable, and it tends to 0: un→u∗u^n \to u^*, EE is continuous, and D(pn)=12∥f∥2−12∥un∥2→12∥f∥2−12∥u∗∥2=E(u∗)D(p^n) = \tfrac12\|f\|^2 - \tfrac12\|u^n\|^2 \to \tfrac12\|f\|^2 - \tfrac12\|u^*\|^2 = E(u^*), the last equality by strong duality (⟨u∗,w∗⟩=λ TV(u∗)\langle u^*, w^*\rangle = \lambda\,\mathrm{TV}(u^*) with u∗=f−w∗u^* = f - w^*). So the loop with the stop rule "gap at most ε\varepsilon" ends after finitely many steps for every ε>0\varepsilon > 0, and then ∥u−u∗∥2≤2ε\|u - u^*\|^2 \le 2\varepsilon.

Complexity

One iteration computes a divergence, a gradient and a pixelwise update: Θ(N)\Theta(N) arithmetic operations and Θ(N)\Theta(N) extra memory for pp and two work images. KK iterations cost Θ(KN)\Theta(K N). Theorem 3.1 of Chambolle's paper gives convergence but no rate. Treated as projected gradient descent on the dual, the same dual problem has objective error O(1/K)O(1/K), and with the acceleration of Beck and Teboulle O(1/K2)O(1/K^2); the gap bound above turns a dual error ee into ∥u−u∗∥2≤2e\|u - u^*\|^2 \le 2e. After kk steps the field at a pixel depends only on the data within about 2k2k pixels, because each step looks at the neighbors twice. So a flat region of width ww needs at least about w/2w/2 steps before the value at one end can depend on the data at the other end, which it must do to become the regional mean.

Properties

  • The iterates stay feasible: ∣pijn∣≤1|p^n_{ij}| \le 1 for all nn, so λdiv⁡pn∈λK\lambda\operatorname{div}p^n \in \lambda K and the dual value D(pn)D(p^n) is a valid lower bound of min⁡E\min E at every step.
  • For τ≤1/8\tau \le 1/8 the dual objective ∥div⁡pn−f/λ∥2\|\operatorname{div}p^n - f/\lambda\|^2 is nonincreasing.
  • The mean is kept: ∑ij(div⁡p)ij=−⟨∇1,p⟩=0\sum_{ij} (\operatorname{div}p)_{ij} = -\langle \nabla 1, p\rangle = 0, so unu^n has the mean of ff at every step.
  • The output is prox⁡λTV(f)\operatorname{prox}_{\lambda\mathrm{TV}}(f). Moreau's identity reads here f=prox⁡λTV(f)+πλK(f)f = \operatorname{prox}_{\lambda\mathrm{TV}}(f) + \pi_{\lambda K}(f), because the convex conjugate of TV\mathrm{TV} is the indicator of KK.
  • The method needs no matrix, no linear solve and no smoothing of the total variation.
  • A warm start from a previous pp is allowed, because the proof only needs ∣pij0∣≤1|p^0_{ij}| \le 1.

Variants and improvements

  • Projected gradient on the dual: p←π∣p∣≤1(p+τz)p \leftarrow \pi_{|p| \le 1}(p + \tau z) at each pixel. Chambolle later used this form with τ<1/4\tau < 1/4 in two dimensions. It is projected gradient descent on FF with the step τ/2\tau/2, and the gradient of FF is Lipschitz with constant 2κ=162\kappa = 16, so the classic condition step <2/16< 2/16 gives τ<1/4\tau < 1/4.
  • Accelerated dual: Beck and Teboulle (2009) apply the FISTA momentum to the projected dual gradient, which gives O(1/K2)O(1/K^2) for the dual objective.
  • Anisotropic total variation: with ∣∂1u∣+∣∂2u∣|\partial_1 u| + |\partial_2 u| the constraint is ∣p1,ij∣≤1|p_{1,ij}| \le 1 and ∣p2,ij∣≤1|p_{2,ij}| \le 1, and the step becomes a clip of each component.
  • Weighted and color total variation: a pixel weight wijw_{ij} changes the bound to ∣pij∣≤wij|p_{ij}| \le w_{ij}, and a vectorial total variation couples the channels in the length of pp.
  • Inner solver: inside the proximal gradient method for deblurring, min⁡12∥Au−g∥2+λ TV(u)\min \tfrac12\|Au - g\|^2 + \lambda\,\mathrm{TV}(u), each outer step needs prox⁡sλTV\operatorname{prox}_{s\lambda\mathrm{TV}}, which this algorithm computes with a warm start.
  • Primal-dual methods: the Chambolle-Pock algorithm and split Bregman solve the same model and also handle a forward operator directly.

When to use it

Use it when you need the proximal operator of total variation, as a short and safe subroutine, or as a reference solver for small images in tests. It has one parameter, every iterate is feasible, and the duality gap gives a stop rule with a guarantee. For large images or a high accuracy it is slow, and in reported experiments accelerated dual or primal-dual methods reach the same gap in fewer iterations; this is a measurement, not a theorem. If the problem has a forward operator, use a primal-dual method rather than nesting this one inside an outer loop.

Pitfalls

  • The divergence must be exactly −∇⊤-\nabla^\top, including the border rows and columns. A divergence with a different border rule breaks the duality and the proof, and the result is wrong near the border. Test ⟨∇u,p⟩=−⟨u,div⁡p⟩\langle \nabla u, p\rangle = -\langle u, \operatorname{div}p\rangle on random data.
  • The proof covers τ≤1/8\tau \le 1/8 in two dimensions. Chambolle remarks that τ=1/4\tau = 1/4 works better in practice, but there is no proof for that step size with this update.
  • Some papers put the weight on the data term, μ2∥u−f∥2+TV(u)\tfrac\mu2\|u - f\|^2 + \mathrm{TV}(u). Then λ=1/μ\lambda = 1/\mu.
  • A stop rule on ∥pn+1−pn∥\|p^{n+1} - p^n\| can stop too early when the steps are small. The duality gap is the safe stop rule.
  • The field pnp^n can move along a set of dual solutions without converging. Only div⁡pn\operatorname{div}p^n and unu^n have a limit.
  • For a large λ\lambda the solution is nearly flat over large regions, and the number of iterations grows with the size of these regions.

Implementations

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.

chambolle_projection_algorithm.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/chambolle-projection-algorithm/. The authors are listed in prov/R2YTGF.jsonl.
"""Chambolle's projection algorithm for total variation denoising.

The model is min_u (1/2) ||u - f||^2 + lam * TV(u) on an n1 x n2 image f
(a list of rows), with the isotropic discrete total variation of forward
differences and a Neumann border (the last difference in each direction is 0).
The minimizer is u = f - P(f), where P is the projection onto the set
lam * K, K = {div p : |p_ij| <= 1 at every pixel}. The algorithm computes the
dual field p by Chambolle's semi-implicit fixed point step.
"""

import math

Image = list[list[float]]
Field = tuple[Image, Image]


def zeros(n1: int, n2: int) -> Image:
    return [[0.0] * n2 for _ in range(n1)]


def grad(u: Image) -> Field:
    """Forward differences with a Neumann border. Cost O(n1 n2)."""
    n1, n2 = len(u), len(u[0])
    g1, g2 = zeros(n1, n2), zeros(n1, n2)
    for i in range(n1):
        for j in range(n2):
            if i < n1 - 1:
                g1[i][j] = u[i + 1][j] - u[i][j]
            if j < n2 - 1:
                g2[i][j] = u[i][j + 1] - u[i][j]
    return g1, g2


def div(p: Field) -> Image:
    """The divergence, defined as minus the adjoint of grad. Cost O(n1 n2)."""
    p1, p2 = p
    n1, n2 = len(p1), len(p1[0])
    d = zeros(n1, n2)
    for i in range(n1):
        for j in range(n2):
            a = (p1[i][j] if i < n1 - 1 else 0.0) - (p1[i - 1][j] if i > 0 else 0.0)
            b = (p2[i][j] if j < n2 - 1 else 0.0) - (p2[i][j - 1] if j > 0 else 0.0)
            d[i][j] = a + b
    return d


def total_variation(u: Image) -> float:
    g1, g2 = grad(u)
    return sum(math.hypot(a, b) for r1, r2 in zip(g1, g2) for a, b in zip(r1, r2))


def energy(u: Image, f: Image, lam: float) -> float:
    """The primal energy (1/2)||u - f||^2 + lam TV(u)."""
    fit = sum((a - b) ** 2 for ru, rf in zip(u, f) for a, b in zip(ru, rf))
    return 0.5 * fit + lam * total_variation(u)


def dual_energy(p: Field, f: Image, lam: float) -> float:
    """D(p) = (1/2)(||f||^2 - ||f - lam div p||^2), a lower bound of the energy for |p| <= 1."""
    d = div(p)
    ff = sum(a * a for r in f for a in r)
    rr = sum((a - lam * b) ** 2 for rf, rd in zip(f, d) for a, b in zip(rf, rd))
    return 0.5 * (ff - rr)


def chambolle_projection(f: Image, lam: float, tau: float = 0.125, iters: int = 200,
                         tol: float | None = None, p0: Field | None = None) -> tuple[Image, Field]:
    """Return (u, p): the TV denoised image and the dual field.

    Precondition: lam > 0 and 0 < tau <= 1/8 for the proved convergence
    (tau = 1/4 often works in practice but has no proof for this step).
    With tol set, stop when the duality gap E(u) - D(p) is at most tol;
    then ||u - u*||^2 <= 2 tol. Cost O(n1 n2) per iteration, O(n1 n2) space.
    """
    n1, n2 = len(f), len(f[0])
    p1, p2 = (zeros(n1, n2), zeros(n1, n2)) if p0 is None else ([r[:] for r in p0[0]], [r[:] for r in p0[1]])  # @line L1
    for k in range(iters):  # @line L2
        d = div((p1, p2))
        v = [[d[i][j] - f[i][j] / lam for j in range(n2)] for i in range(n1)]  # @line L3
        z1, z2 = grad(v)  # @line L4
        for i in range(n1):
            for j in range(n2):
                s = 1.0 + tau * math.hypot(z1[i][j], z2[i][j])  # @line L5
                p1[i][j] = (p1[i][j] + tau * z1[i][j]) / s
                p2[i][j] = (p2[i][j] + tau * z2[i][j]) / s
        if tol is not None and (k + 1) % 10 == 0:
            u = _primal(f, lam, (p1, p2))
            if energy(u, f, lam) - dual_energy((p1, p2), f, lam) <= tol:
                break
    return _primal(f, lam, (p1, p2)), (p1, p2)


def _primal(f: Image, lam: float, p: Field) -> Image:
    d = div(p)
    w = [[lam * a for a in r] for r in d]  # @line L6
    return [[f[i][j] - w[i][j] for j in range(len(f[0]))] for i in range(len(f))]  # @line L7


def dual_residual(f: Image, lam: float, p: Field) -> float:
    """||div p - f/lam||^2, the dual objective that the iteration decreases."""
    d = div(p)
    return sum((a - b / lam) ** 2 for rd, rf in zip(d, f) for a, b in zip(rd, rf))


def chambolle_step(f: Image, lam: float, tau: float, p: Field) -> Field:
    """One step of lines L3 to L5, returned as a new field (for tests of monotonicity)."""
    _, q = chambolle_projection(f, lam, tau, iters=1, p0=p)
    return q
test_chambolle_projection_algorithm.py 114 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/chambolle-projection-algorithm/. The authors are listed in prov/R2YTGF.jsonl.

import itertools
import math
import random

from chambolle_projection_algorithm import (
    chambolle_projection,
    chambolle_step,
    div,
    dual_energy,
    dual_residual,
    energy,
    grad,
)


def brute_force_1d(f: list[float], lam: float) -> list[float]:
    """Exact 1D TV denoising: try every sign pattern of the differences.

    For a pattern s, runs with s = 0 merge into segments; on a segment S the
    value is mean(S) - lam (s_left - s_right) / |S|. The pattern of the true
    minimizer gives the true minimizer, so the best candidate is exact.
    """
    n = len(f)
    best, best_val = None, math.inf
    for s in itertools.product((-1, 0, 1), repeat=n - 1):
        segs, start = [], 0
        for b in range(n - 1):
            if s[b] != 0:
                segs.append((start, b + 1))
                start = b + 1
        segs.append((start, n))
        u = []
        for k, (a, b) in enumerate(segs):
            sl = s[a - 1] if a > 0 else 0
            sr = s[b - 1] if b < n else 0
            v = sum(f[a:b]) / (b - a) - lam * (sl - sr) / (b - a)
            u.extend([v] * (b - a))
        val = energy([u], [f], lam)
        if val < best_val:
            best, best_val = u, val
    return best


def test_adjoint() -> None:
    rng = random.Random(1)
    for n1, n2 in ((1, 5), (3, 4), (5, 2)):
        u = [[rng.uniform(-1, 1) for _ in range(n2)] for _ in range(n1)]
        p = ([[rng.uniform(-1, 1) for _ in range(n2)] for _ in range(n1)],
             [[rng.uniform(-1, 1) for _ in range(n2)] for _ in range(n1)])
        g1, g2 = grad(u)
        lhs = sum(g1[i][j] * p[0][i][j] + g2[i][j] * p[1][i][j] for i in range(n1) for j in range(n2))
        d = div(p)
        rhs = -sum(u[i][j] * d[i][j] for i in range(n1) for j in range(n2))
        assert abs(lhs - rhs) < 1e-12


def test_step_image() -> None:
    f = [[0.0, 0.0, 4.0, 4.0] for _ in range(4)]
    u, _ = chambolle_projection(f, 1.0, iters=3000, tol=1e-10)
    for row in u:
        for a, b in zip(row, (0.5, 0.5, 3.5, 3.5)):
            assert abs(a - b) < 1e-4


def test_brute_force_1d() -> None:
    rng = random.Random(7)
    for _ in range(8):
        n = rng.randint(2, 6)
        f = [float(rng.randint(-3, 3)) for _ in range(n)]
        lam = rng.choice((0.3, 0.7, 1.5))
        u, _ = chambolle_projection([f], lam, iters=20000, tol=1e-11)
        ref = brute_force_1d(f, lam)
        assert max(abs(a - b) for a, b in zip(u[0], ref)) < 1e-4


def test_monotone_and_feasible() -> None:
    rng = random.Random(3)
    f = [[rng.uniform(0, 5) for _ in range(5)] for _ in range(4)]
    lam = 0.8
    p = ([[0.0] * 5 for _ in range(4)], [[0.0] * 5 for _ in range(4)])
    r = dual_residual(f, lam, p)
    for _ in range(200):
        p = chambolle_step(f, lam, 0.125, p)
        r2 = dual_residual(f, lam, p)
        assert r2 <= r + 1e-12
        r = r2
        assert all(math.hypot(a, b) <= 1 + 1e-12 for r1, r2_ in zip(*p) for a, b in zip(r1, r2_))


def test_gap_certificate_and_mean() -> None:
    rng = random.Random(5)
    f = [[rng.uniform(0, 5) for _ in range(4)] for _ in range(4)]
    lam = 0.5
    u, p = chambolle_projection(f, lam, iters=5000, tol=1e-7)
    gap = energy(u, f, lam) - dual_energy(p, f, lam)
    assert -1e-9 <= gap <= 1e-7
    mean_f = sum(map(sum, f)) / 16
    mean_u = sum(map(sum, u)) / 16
    assert abs(mean_f - mean_u) < 1e-12
    # Small random moves do not lower the energy below the dual bound.
    for _ in range(20):
        v = [[a + rng.uniform(-0.01, 0.01) for a in row] for row in u]
        assert energy(v, f, lam) >= dual_energy(p, f, lam) - 1e-12


def test_large_lambda_gives_mean() -> None:
    f = [[1.0, 2.0], [3.0, 6.0]]
    u, _ = chambolle_projection(f, 100.0, iters=2000, tol=1e-12)
    for row in u:
        for a in row:
            assert abs(a - 3.0) < 1e-5

History

Rudin, Osher and Fatemi proposed total variation denoising in 1992, and Chambolle and Lions (1997) studied the model and its use for image recovery. Dual and primal-dual formulations followed, among them the Newton type primal-dual method of Chan, Golub and Mulet (1999). In 2004 Antonin Chambolle observed that total variation is the support function of the convex set KK, so its proximal operator is the identity minus a projection, and gave the semi-implicit dual step on this page with a short convergence proof. The method became a standard building block because it is simple and has no smoothing parameter. Beck and Teboulle (2009) accelerated the dual approach, and Chambolle and Pock (2011) gave a primal-dual method that handles a general forward operator.

References

  1. Antonin Chambolle, An algorithm for total variation minimization and applications, Journal of Mathematical Imaging and Vision 20(1-2), 2004, pages 89 to 97 (Section 3, the semi-implicit step and Theorem 3.1 for a step of at most 1/8)
  2. Leonid I. Rudin, Stanley Osher and Emad Fatemi, Nonlinear total variation based noise removal algorithms, Physica D 60(1-4), 1992, pages 259 to 268
  3. Antonin Chambolle and Pierre-Louis Lions, Image recovery via total variation minimization and related problems, Numerische Mathematik 76(2), 1997, pages 167 to 188
  4. Amir Beck and Marc Teboulle, Fast gradient-based algorithms for constrained total variation image denoising and deblurring problems, IEEE Transactions on Image Processing 18(11), 2009, pages 2419 to 2434 (the accelerated projected gradient on the same dual problem)
  5. Antonin Chambolle and Thomas Pock, An introduction to continuous optimization for imaging, Acta Numerica 25, 2016, pages 161 to 319
  6. Joan Duran, Bartomeu Coll and Catalina Sbert, Chambolle's projection algorithm for total variation denoising, Image Processing On Line, 2013

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 proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
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
  • a scene preset for the example