Skip to content

Laplacian Filter Tool: Edge Detection, Laplacian of Gaussian and Image Sharpening

Apply the 4-neighbour, 8-neighbour or isotropic Laplacian kernel, the Laplacian of Gaussian or a Difference of Gaussians to a test image or your own photo. View the signed response, find edges as zero crossings, sharpen the image, and see why smoothing must come before the second derivative. Click any pixel to see the arithmetic.

3 × 3, LoG & DoGZero-crossing edgesSharpeningFrequency response
By Bimal Ghimire · Updated November 4, 2026

Key facts

  • Laplacian: ∇²f = ∂²f/∂x² + ∂²f/∂y². It is a second derivative, rotation invariant, and zero on flat areas and linear ramps.
  • Discrete kernels: 4-neighbour [0 1 0; 1 −4 1; 0 1 0] ≈ ∇²; 8-neighbour [1 1 1; 1 −8 1; 1 1 1] ≈ 3∇². Every Laplacian kernel sums to 0.
  • Edges are zero crossings: at a blurred step the Laplacian swings from positive to negative; the edge lies where it crosses zero.
  • Noise: the response grows like frequency squared, so noise is amplified (×√20 ≈ 4.5 in standard deviation for the 4-neighbour kernel). Smooth first: LoG = ∇²(Gσ * f) = (∇²Gσ) * f.
  • LoG kernel: ∇²G = (x² + y² − 2σ²)/(2πσ⁶)·e−(x²+y²)/2σ², zero at r = √2σ; DoG with k = 1.6 approximates it.
  • Sharpening: g = f − c∇²f (negative-centre kernel). With c = 1 this is [0 −1 0; −1 5 −1; 0 −1 0].

Laplacian Filter Tool

Images never leave your device
 
0 = no smoothing. A Gaussian blur before the Laplacian suppresses noise.
Constant zero makes a false edge at the border.
Input
Response

Effective kernel (blue −, red +)
Kernel

Each edge in the top chart produces a positive and a negative lobe in the bottom chart. The edge itself is where the response crosses zero between them (marked). Add noise and compare the 4-neighbour kernel with the LoG.

Plotted as −H so that the curves are positive. The ideal Laplacian has −H = |ω|² = (2πf)² in every direction. A filter is isotropic when its axis (solid) and diagonal (dashed) curves coincide. Smoothing turns the ever-rising parabola into a band-pass curve that ignores the finest, noisiest frequencies.

How to Use the Laplacian Filter Tool

  1. Choose an operator. Start with the 4-neighbour kernel on the shapes image. Grey means zero, white is positive and black is negative.
  2. Add noise. Move the noise slider to 10 and watch the plain Laplacian drown in noise. Then switch to LoG with σ = 2 (or give the 3 × 3 kernel a pre-smoothing σ).
  3. Find edges. Choose Edges to mark zero crossings in red. Raise the threshold to drop weak crossings caused by noise and texture.
  4. Sharpen. Choose Sharpen and set the amount. Look at the row profile to see the overshoot that makes edges look crisp.
  5. Inspect. The kernel tab shows the effective kernel, the frequency tab shows which detail sizes the operator responds to, and clicking a pixel on the input shows its calculation in the step-by-step tab.

Laplacian Filter Formulas

Continuous Laplacian
$$\nabla^2 f=\frac{\partial^2 f}{\partial x^2}+\frac{\partial^2 f}{\partial y^2}$$
Rotation invariant: rotating the image rotates the result, so one operator detects edges in all directions.
Central second difference (from Taylor series)
$$\frac{\partial^2 f}{\partial x^2}\approx f(x+1,y)-2f(x,y)+f(x-1,y),\qquad\text{error}=\tfrac{1}{12}\,\frac{\partial^4 f}{\partial x^4}+\dots$$
Adding the x and y differences gives the 4-neighbour kernel. The truncation error depends on direction, which is why discrete Laplacians are not perfectly isotropic.
Kernels and their frequency responses (ω in radians per pixel)
$$\begin{aligned}L_4&=\begin{bmatrix}0&1&0\\1&-4&1\\0&1&0\end{bmatrix}: & H&=2\cos\omega_x+2\cos\omega_y-4\approx-(\omega_x^2+\omega_y^2)\\ L_8&=\begin{bmatrix}1&1&1\\1&-8&1\\1&1&1\end{bmatrix}: & H&=(1+2\cos\omega_x)(1+2\cos\omega_y)-9\approx-3(\omega_x^2+\omega_y^2)\end{aligned}$$
The isotropic 9-point kernel (1/6)[1 4 1; 4 −20 4; 1 4 1] has H ≈ −|ω|² + |ω|⁴/12, the same in every direction up to fourth order.
Laplacian of Gaussian (LoG)
$$\nabla^2(G_\sigma*f)=(\nabla^2G_\sigma)*f,\qquad \nabla^2G_\sigma(x,y)=\frac{x^2+y^2-2\sigma^2}{2\pi\sigma^6}\,e^{-\frac{x^2+y^2}{2\sigma^2}}$$
Zero crossing of the kernel at r = √2σ; its Fourier transform is −|ω|² e−σ²|ω|²/2, a band-pass filter that peaks at |ω| = √2/σ (period 2π σ/√2 ≈ 4.44σ pixels).
Difference of Gaussians (DoG)
$$\frac{\partial G_\sigma}{\partial\sigma}=\sigma\,\nabla^2G_\sigma\;\;\Rightarrow\;\;G_{k\sigma}-G_\sigma\approx(k-1)\,\sigma^2\,\nabla^2G_\sigma$$
This tool divides the DoG by (k − 1)σ² so that its values are on the same scale as the LoG.
Sharpening
$$g=f-c\,\nabla^2 f\qquad(c=1,\;L_4:\;\;g=f*\begin{bmatrix}0&-1&0\\-1&5&-1\\0&-1&0\end{bmatrix})$$
For LoG and DoG this tool uses σ²∇²(Gσ*f) so that the amount c means the same thing at every scale.

Laplacian Kernels Compared

OperatorApproximatesNoise variance gain Σk²IsotropyBest for
4-neighbour [0 1 0; 1 −4 1; 0 1 0]∇²20Fair: weaker on diagonals at high frequencyTeaching, clean images, solving PDEs on grids
8-neighbour [1 1 1; 1 −8 1; 1 1 1]3∇²72 (= 8 per unit of ∇²)Better than 4-neighbourSharpening and edge enhancement
Isotropic (1/6)[1 4 1; 4 −20 4; 1 4 1]∇²13Best of the 3 × 3 kernels (4th-order isotropic)Accurate measurement on a pixel grid
LoG, σ∇²(Gσ * f)0.161 (σ = 1), 0.0025 (σ = 2)ExcellentEdges and blobs in noisy images
DoG, σ and kσ(k − 1)σ²∇²Gσ≈ LoGExcellentFast multi-scale detection (SIFT)

Σk² is the sum of squared kernel weights: the factor by which the variance of white noise is multiplied. The LoG values are for SciPy's sampled kernel. Compare operators at the same signal response, not just by Σk²: the LoG also attenuates the edge, but much less than it attenuates noise.

Zero-Crossing Edge Detection (Marr–Hildreth)

  1. Smooth with a Gaussian of σ chosen for the scale of the edges you want (larger σ: fewer, smoother, more displaced edges).
  2. Take the Laplacian; in practice steps 1 and 2 are a single LoG (or DoG) convolution.
  3. Find zero crossings: pixels whose response changes sign relative to a neighbour.
  4. Threshold the slope: keep only crossings where the jump between the positive and negative sides is large, which removes the many weak crossings caused by noise and texture.

Zero crossings form closed contours, which is both a strength (no gaps) and a weakness (spurious closed loops in flat noisy areas). They also shift at corners and at curved edges as σ grows. The Canny detector, which uses first derivatives and hysteresis, generally performs better for straight edges, but the LoG remains the standard tool for blob detection: a bright disc of radius R gives the strongest scale-normalized response σ²∇²G at σ = R/√2.

Worked Examples

Example 1: A step edge in 1-D

For the signal f = [10, 10, 10, 10, 50, 50, 50, 50], the second difference f(x − 1) − 2f(x) + f(x + 1) is [0, 0, 0, 40, −40, 0, 0, 0]. It is zero on both flat parts, +40 on the dark side and −40 on the bright side of the step. The sign changes between positions 3 and 4, exactly where the edge is.

Example 2: A bright spot in 2-D

A pixel of value 120 has neighbours 53 (above), 50 (right), 51 (below) and 52 (left). The 4-neighbour response is 53 + 50 + 51 + 52 − 4 × 120 = −274. A bright spot gives a strongly negative Laplacian and a dark spot a positive one; a flat area or a linear ramp gives 0.

Example 3: Sharpening creates overshoot

Sharpening the step of Example 1 with c = 1: g = f − ∇²f = [10, 10, 10, −30, 90, 50, 50, 50]. The edge contrast rises from 40 to 120, which the eye reads as sharper. On 8-bit images −30 is clipped to 0, and the overshoot appears as a dark and a bright halo along each edge.

Example 4: Why smooth first?

Add white noise with σₙ = 10 to the step of height 40. The 4-neighbour Laplacian responds to the edge with ±40 but to the noise with a standard deviation of 10√20 ≈ 45: the edge is invisible. A LoG with σ = 2 gives an edge peak of about ±2.3 (grey levels per pixel²) and a noise standard deviation of only 10 × √0.00249 ≈ 0.50, a signal-to-noise ratio of about 4.6 instead of 0.9.

Example 5: Choosing σ for blobs

For a disc of radius R, the scale-normalized LoG at its centre is σ²∇²G * disc = −(R²/σ²) e−R²/(2σ²). Setting the derivative with respect to σ to zero gives σ = R/√2 and a peak value of −2/e ≈ −0.736 per unit of contrast. Trees about 8 pixels in radius in a 0.5 m aerial image are therefore found best with σ ≈ 5.7 pixels.

Laplacian Filter in Python, OpenCV and MATLAB

import numpy as np, cv2
from scipy import ndimage
f = img.astype(float)

lap4 = ndimage.laplace(f)                       # 4-neighbour kernel, mode='reflect'
k8 = np.array([[1, 1, 1], [1, -8, 1], [1, 1, 1]], float)
lap8 = ndimage.correlate(f, k8)
log = ndimage.gaussian_laplace(f, sigma=2.0)    # LoG, separable, truncate=4
dog = ndimage.gaussian_filter(f, 1.6 * 2) - ndimage.gaussian_filter(f, 2)

lap_cv = cv2.Laplacian(f, cv2.CV_64F, ksize=1)   # ksize=1: [0 1 0; 1 -4 1; 0 1 0]
# careful: ksize=3 is NOT the 8-neighbour kernel; it is [2 0 2; 0 -8 0; 2 0 2]

sharp = np.clip(f - 1.0 * lap4, 0, 255)         # sharpening, c = 1
focus = cv2.Laplacian(gray, cv2.CV_64F).var()   # variance of the Laplacian (blur measure)
% MATLAB
L  = imfilter(double(I), [0 1 0; 1 -4 1; 0 1 0], 'replicate');
h  = fspecial('log', 13, 2);          % LoG kernel, size 13, sigma 2 (adjusted to sum to 0)
L2 = imfilter(double(I), h, 'replicate');
E  = edge(I, 'log', [], 2);           % Marr-Hildreth zero-crossing edges
% note: del2(I) returns the discrete Laplacian divided by 4
Sign conventions differ. scikit-image's filters.laplace uses [0 −1 0; −1 4 −1; 0 −1 0] (positive centre), so its output is the negative of SciPy's and OpenCV's. With that kernel, sharpening is f + c·response. MATLAB's fspecial('laplacian', alpha) uses a negative centre with a default α = 0.2.
Check: this tool's LoG and 3 × 3 filters were tested against scipy.ndimage.gaussian_laplace, laplace and correlate in all boundary modes, agreeing within 10⁻⁴.

Assumptions and Limitations

  • No direction or strength by itself. The Laplacian does not give the edge orientation, and its value at the zero crossing is zero by definition; edge strength must come from the slope across the crossing or from the gradient magnitude.
  • Double edges and spurious loops. Lines (thin features) produce two zero crossings, one on each side; noise produces closed loops unless thresholded.
  • Scale matters. σ that is too small leaves noise; too large merges nearby edges and shifts corners. Real scenes, such as a satellite image with field boundaries and rivers of different widths, usually need several scales.
  • Sharpening is not restoration. It boosts existing high frequencies, including noise and compression artefacts; it cannot recover detail that the optics or the sensor removed (that needs deconvolution with a known PSF).
  • In this tool the Laplacian is computed on luma (0.299R + 0.587G + 0.114B); sharpening is applied to each RGB channel. Uploaded images are resized to at most 512 pixels and never leave your browser.

Related Tools and Guides

Frequently Asked Questions

What is a Laplacian filter?

A Laplacian filter approximates the Laplacian ∇²f = ∂²f/∂x² + ∂²f/∂y², the sum of the second derivatives of the image. It is zero in flat regions and on linear ramps and responds strongly where intensity changes curvature: at edges, lines and small spots. Because it is isotropic, a single kernel detects edges in every direction.

What are the standard 3 × 3 Laplacian kernels?

The 4-neighbour kernel [0 1 0; 1 −4 1; 0 1 0] approximates ∇² using the horizontal and vertical neighbours. The 8-neighbour kernel [1 1 1; 1 −8 1; 1 1 1] also uses the diagonals and approximates 3∇² for smooth images. Many textbooks and libraries use the negated kernels with a positive centre (for example scikit-image), which flips the sign of the response but not the edge locations.

Why is the Laplacian so sensitive to noise?

Its frequency response grows with the square of frequency, H ≈ −(ωx² + ωy²), so it amplifies fine-grained noise most. For white noise the 4-neighbour kernel multiplies the noise variance by the sum of its squared weights, 1 + 1 + 1 + 1 + 16 = 20, so noise with σ = 10 grey levels becomes a response with σ ≈ 45. Smoothing first with a Gaussian (the LoG) solves this.

What is the Laplacian of Gaussian (LoG)?

The LoG is the Laplacian applied after Gaussian smoothing, which by linearity equals one convolution with ∇²G = (x² + y² − 2σ²)/(2πσ⁶) · exp(−(x² + y²)/(2σ²)). Its inverted profile is the "Mexican hat". It crosses zero at a radius of √2σ. Marr and Hildreth (1980) proposed marking edges at the zero crossings of the LoG.

How do you sharpen an image with a Laplacian filter?

Subtract a multiple of the Laplacian from the image: g = f − c∇²f with a negative-centre kernel, or add it with a positive-centre kernel. With c = 1 and the 4-neighbour kernel this is the single kernel [0 −1 0; −1 5 −1; 0 −1 0]. Sharpening creates overshoot on both sides of edges, which looks crisper but also amplifies noise and can cause halos.

What is the difference between LoG and DoG?

A Difference of Gaussians, G(kσ) − G(σ), approximates (k − 1)σ²∇²G because ∂G/∂σ = σ∇²G. Marr and Hildreth found k ≈ 1.6 gives a close match. DoG is cheaper because each Gaussian is separable, and SIFT uses it to find keypoints across scales.

How is the variance of the Laplacian used to measure blur?

Sharp images contain strong high-frequency content, so their Laplacian has large values and a large variance. Blurring removes those frequencies and the variance drops. The variance of the Laplacian is a simple focus or blur measure (Pech-Pacheco et al., 2000), but its value depends on image content and noise, so a threshold must be calibrated for each type of scene.

References

Marr, D., & Hildreth, E. (1980). Theory of edge detection. Proceedings of the Royal Society of London B, 207(1167), 187–217.

Gonzalez, R. C., & Woods, R. E. (2018). Digital Image Processing (4th ed.), Section 3.6 (sharpening spatial filters) and Chapter 10 (edge detection). Pearson.

Lindeberg, T. (1998). Feature detection with automatic scale selection. International Journal of Computer Vision, 30(2), 79–116.

Lowe, D. G. (2004). Distinctive image features from scale-invariant keypoints. International Journal of Computer Vision, 60(2), 91–110.

Pech-Pacheco, J. L., Cristóbal, G., Chamorro-Martínez, J., & Fernández-Valdivia, J. (2000). Diatom autofocusing in brightfield microscopy: a comparative study. Proceedings of the 15th International Conference on Pattern Recognition, 3, 314–317.

SciPy documentation: scipy.ndimage.gaussian_laplace. OpenCV documentation: Image Filtering (Laplacian).

Cite this tool: Ghimire, B. (2026). Laplacian Filter Tool: Edge Detection, LoG & Image Sharpening. Engineers Views. https://engineersviews.com/tools/laplacian-filter-edge-detection/