Skip to content

Laplacian sharpening

Fact Value
Also called Laplacian sharpen
Status Implemented and tested
Family Linear spatial filters (also Enhancement, illumination and color)
Engine Browser
Type Linear, spatial, convolution
Output Image
Operator shown as dynamic-kernel (exact)
Support radius 1
Code web/src/core/filters/linear/laplacian-sharpen.ts, laplacianSharpenFilter
Operator code web/src/core/filters/linear/laplacian-sharpen.ts, laplacianSharpenKernel
Channels RGB, Brightness only

Overview

Laplacian sharpening subtracts a multiple of the Laplacian from the image. The Laplacian measures how much a pixel differs from its neighbors, so subtracting it makes each difference larger. Edges get steeper and fine detail stands out. It is the smallest sharpening filter: one 3x3 kernel.

A line plot across a soft edge, before and after Laplacian sharpening with c 0.5 and c 1. The sharpened curves are steeper, with a small dip on the dark side and a small peak on the bright side. A line plot across a soft edge, before and after Laplacian sharpening with c 0.5 and c 1. The sharpened curves are steeper, with a small dip on the dark side and a small peak on the bright side.
Laplacian sharpening makes a soft edge steeper, with a small dip and peak beside it.

How it works

  1. Compare each pixel with its neighbors. That is the Laplacian.
  2. Multiply the Laplacian by the amount.
  3. Subtract it from the pixel.

Mathematical foundation

\[ \begin{gathered} I_{\text{out}}(x,y) = I(x,y) - c\, \big(L \star I\big)(x,y) = \sum_{j=-1}^{1} \sum_{i=-1}^{1} \big(\delta(i,j) - c\, L(i,j)\big)\, I(x+i,\, y+j), \\[4pt] c = 1, \quad \text{neighbors} = \text{4} \end{gathered} \]

The formula shows the default parameter values.

where

  • \(I\): Input channel value
  • \(I_{\text{out}}\): Output channel value
  • \(L\): The 3x3 Laplacian kernel with a negative center, 4 or 8 neighbors
  • \(\delta\): Unit impulse, 1 at the center and 0 elsewhere
  • \(c\): Amount
  • \(\star\): Correlation

L is the discrete Laplacian with a negative center. It is positive where a pixel is darker than its neighbors and negative where it is brighter. Subtracting c times L makes bright pixels brighter and dark pixels darker next to an edge, so the edge gets steeper. The whole filter is one kernel whose weights add up to 1.

The Laplacian with a negative center approximates \(\nabla^2 I\). Along a soft edge, \(\nabla^2 I\) is positive on the dark side and negative on the bright side. Subtracting it lowers the dark side and raises the bright side, so the edge gets steeper. Because the Laplacian kernel's weights add up to 0, the sharpening kernel's weights add up to 1, and flat areas keep their exact value.

Kernel or operator

The kernels for 4 and 8 neighbors with \(c = 1\), from the filter code.

\[ S_4 = \begin{bmatrix} 0 & -1 & 0 \\ -1 & 5 & -1 \\ 0 & -1 & 0 \end{bmatrix}, \qquad S_8 = \begin{bmatrix} -1 & -1 & -1 \\ -1 & 9 & -1 \\ -1 & -1 & -1 \end{bmatrix} \qquad (c = 1) \]

Algorithm

  1. Build the kernel, 1 at the center minus c times the Laplacian kernel.
  2. Pad the image with the border mode and correlate it with the kernel.
  3. Clip to 0 to 255 and round to 8 bits. Keep alpha unchanged.

Parameters

Parameter Default Values Meaning
Amount amount 1 0.1 to 5 The factor c that multiplies the Laplacian before it is subtracted.
Neighbors neighbors 4 neighbors 4 neighbors, 8 neighbors Which Laplacian kernel is used.
Border mode border Reflect 101 (default) Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap How pixels outside the image are filled when the window reaches past the edge.
Channels channelScope RGB RGB, Brightness only Which part of the color image the filter changes.

Implementation

laplacianSharpenKernel in web/src/core/filters/linear/laplacian-sharpen.ts builds the kernel from the Laplacian kernel in laplacian.ts, so both filters share one definition. The image is correlated with the kernel and the result is clipped.

Worked example

\[ W = \begin{bmatrix} 100 & 100 & 100 \\ 100 & 140 & 100 \\ 100 & 100 & 100 \end{bmatrix}, \qquad S_4 \star W = 5 \cdot 140 - 4 \cdot 100 = 300 \]

The center is 40 brighter than its neighbors. The Laplacian is 4 x 100 - 4 x 140 = -160, and subtracting it once raises the center to 300. The difference to the neighbors grows from 40 to 200, so the spot looks sharper.

Complexity

  • Time: \(O(N)\)
  • Memory: \(O(N)\)

N is the number of pixels per channel. The kernel is always 3x3.

Artifacts and limitations

Limitations

  • It works on the finest scale only. For wider detail, use the unsharp mask.
  • It sharpens noise as strongly as edges.

Artifacts

  • Thin halos along edges.
  • Amplified noise and grain.

Tests

The test compares the filter with scipy.ndimage.correlate for both neighbor sets, two amounts and three border modes. The fixture script first checks the kernel against \(I - c\) times scipy.ndimage.laplace.

References