Finn Sherry

Diffusion-Shock Filtering

We extended Diffusion-Shock (DS) filtering to Position-Orientation space for SSVM 2025 (🔓arXiv, 🧑‍💻code, 💬slides). DS filtering can be used to denoise images and to inpaint missing structures. I made a WebGPU implementation of DS filtering on Euclidean space.

DS filtering, first developed by Schaefer and Weickert for SSVM 2023, combines homogeneous diffusion and coherence enhancing shock filtering. Since these two elements are well-understood, deriving stability conditions is straightforward, unlike many alternative inpainting PDEs.

The (Regularised) DS PDE is given by \[ \partial_t u = g_\lambda(\Vert \nabla u_\nu\Vert^2) \Delta u - (1 - g_\lambda(\Vert \nabla u_\nu\Vert^2)) S_\epsilon(\partial_{\bf w w} u_\sigma) \vert \nabla u \vert. \] In this, we can identify 4 main terms:

  1. The diffusion generator \(\Delta u\): the Laplace operator \(\Delta\) simply generates diffusion. For inpainting tasks, this can be useful to fill in large areas. For denoising tasks, this can remove noise in otherwise flat areas.
  2. The shock generator \(\vert \nabla u\vert\): depending on the sign, in front of the generator, we get either dilation or erosion. Dilation expands light areas, while erosion expands dark areas. Note that we perform erosion in our iterative scheme to solve the eikonal PDE.
  3. The diffusion-shock switch \(g_\lambda(\Vert \nabla u_\nu\Vert^2)\): wherever \(g_\lambda(\Vert \nabla u_\nu\Vert^2) \approx 1\), only diffusion is performed, while wherever \(g_\lambda(\Vert \nabla u_\nu\Vert^2) \approx 0\) only shock occurs. First, the input \(u\) is regularised by Gaussian convolution: \(u_\nu := K_\nu * u\), with \(\nu\) the standard deviation of the Gaussian kernel \(K_\nu\). The guidance term uses the Charbonnier weight, \[ g_\lambda(\Vert \nabla u_\nu\Vert^2) := \frac{1}{\sqrt{1 + \Vert \nabla u_\nu\Vert^2 / \lambda^2}}; \] when \(\Vert \nabla u_\nu\Vert\) is large, e.g. on an edge in the image, the guidance term will be small, so shock will be performed. This ensures edges will be preserved. The contrast parameter \(\lambda\) can be used to tune the balance between diffusion and shock: increasing \(\lambda\) will increase the amount of diffusion.
  4. The morphological switch \(S_\epsilon(\partial_{\bf w w} u_\sigma)\): wherever \(S_\epsilon(\partial_{\bf w w} u_\sigma) > 0\), erosion is performed, while dilation is performed wherever \(S_\epsilon(\partial_{\bf w w} u_\sigma) < 0\). In essence, this guidance term measures the local convexity of the image: points that are dark with respect to their surrounding are convex. To preserve edges, we want to extend local extrema. Hence, we want to perform dilation in relatively light/concave areas and erosion in relatively dark/convex areas. We again first regularise the input by Gaussian convolution, now with standard deviation \(\sigma\). Then, we compute the dominant eigenvector \({\bf w}\) of the structure tensor, regularised at scale \(\rho\): this should point orthogonal to the local orientation. We then compute the second derivative along this direction, and pass it through a sigmoid. The slope of the sigmoid is controlled by the parameter \(\epsilon\).

Here is a WebGPU implementation of DS inpainting: