Where Edge-Detection Kernels Came From
On this page
Edges are derivatives, and derivatives need smoothing
Every classic edge kernel in this post is built from the same two parts: a finite-difference derivative and a binomial (discrete Gaussian) smoother. Once you see that, every integer in the familiar kernels can be derived rather than memorized.
An edge is where image intensity changes quickly. First-derivative detectors look for peaks in the gradient magnitude. Second-derivative detectors look for the zero-crossings between a positive and a negative response.
The difficulty is noise. In the frequency domain, differentiation multiplies each component of the signal by its frequency:
Natural images concentrate their energy at low frequencies, while sensor noise is roughly white, with equal power at every frequency. A first derivative therefore amplifies noise far more than image content, and a second derivative does so quadratically.
The same problem shows up in the spatial domain. Adding a tiny ripple changes a signal by at most , but changes its derivative by up to , which grows without bound as increases. Differentiation is ill-posed in Hadamard’s sense: small input errors do not guarantee small output errors [2].
The standard fix is to smooth before differentiating. Smoothing restores stability but blurs, and can displace, the edges. Every kernel below is a particular compromise between noise suppression and localization, the trade-off Canny later formalized [3].
Conventions used throughout
- Correlation, not convolution. Kernels are written as most image libraries and CNNs apply them: slide, multiply, sum, with no flip. Under true convolution, antisymmetric kernels such as change sign.
- Axes. increases to the right and increases downward, following an image’s row index.
- Operators. is convolution and is the outer product. Convolving a column vector with a row vector gives exactly their outer product, which is how every 2D kernel here is built from 1D pieces.
- Scaling. Integer kernels are shown unnormalized, with the normalizing factor stated alongside.
- Noise gain. If the input carries white noise of variance , a kernel with coefficients outputs noise of variance . This one number is used to compare kernels fairly.
Binomial kernels: smoothing by repeated averaging
Averaging neighbouring pixels over and over produces the rows of Pascal’s triangle, and those rows converge to a Gaussian whose variance is .
The simplest smoother is the two-tap average . On its own it is a weak filter: it is not centred (it shifts the signal by half a pixel) and it rolls off high frequencies only gently. Convolving it with itself fixes both problems. With copies of the two-tap kernel (that is, convolutions):
So , , and , each normalized by . Even gives an odd-length kernel with a well-defined centre pixel, which is why and are the ones used in practice.
Why the limit is a Gaussian
The normalized kernel is exactly the probability mass function of a variable: the number of heads in fair coin flips. That distribution has mean and variance . By the de Moivre–Laplace theorem (the special case of the central limit theorem for coin flips), it approaches a normal distribution as grows.
Centred on its middle tap, therefore approximates a sampled Gaussian with . Two useful anchors: behaves like px, and like px.
The frequency domain shows the same result more directly. The magnitude response of the centred, normalized kernel is
where the approximation uses . The right-hand side is exactly the Fourier transform of a Gaussian. Note also that is exactly zero at the Nyquist frequency : every binomial kernel completely removes the one-pixel checkerboard pattern, which is the most noise-like signal an image can contain.
Useful properties
- Scales add like Gaussians. , so variances add, just as blurring with Gaussians of and equals one blur with . Blurring twice with is the same as blurring once with .
- Integer arithmetic. All weights are integers and the normalizer is a power of two, so the whole filter reduces to adds and a bit shift.
- An approximation, not the exact discrete Gaussian. Lindeberg showed that the discrete kernel with a true scale-space structure is , where is the modified Bessel function and [4]. Binomial kernels track it closely for all but the smallest scales, which is why they remain the practical choice.
The Gaussian kernel: separable, isotropic, and usually truncated
The familiar “Gaussian” kernel is the outer product of with itself, and it corresponds to px, not .
Separability
The 2D Gaussian factors into a product of 1D Gaussians:
As a matrix, a separable kernel has rank . A blur can therefore run as a vertical pass followed by a horizontal pass, cutting the per-pixel cost from to multiply-adds ( for a kernel).
The Gaussian is also the only rotationally symmetric kernel that is separable, a result that goes back to Maxwell’s derivation of molecular velocities. That combination, the same response in every direction and a cheap implementation, is a large part of why the Gaussian is the default smoother.
In deep learning, the analogue of this trick is the spatially separable convolution, such as Inception-v3’s replacement of an layer by a layer followed by an layer [5]. It is not the depthwise separable convolution of Xception and MobileNet [6, 7], which factors a layer differently: a per-channel spatial filter followed by a convolution that mixes channels. Learned kernels are rarely rank , so either factorization is a modelling choice rather than an exact identity.
The kernel from binomials
The outer product of with itself gives the standard integer kernel:
From the previous section, each axis has variance , so this kernel approximates a Gaussian with px.
The kernel from sampling
The alternative is to evaluate the continuous Gaussian at integer offsets and renormalize. The prefactor cancels in the normalization, so only the exponential matters. For on a grid:
Rounded to two decimals, the corners are , not . The version sums to rather than and darkens the image by .
Truncation changes
A window cuts a Gaussian off at , which discards more than half of its 2D mass (only lies inside the square). After renormalization, the 1D profile is , whose variance is , so the effective is about px rather than .
That is almost exactly the binomial with . The two constructions converge on essentially the same kernel, and neither is really . The binomial version has one advantage: its response at the Nyquist frequency is exactly , while the truncated sample leaks a small, sign-flipped .
The practical rule is to choose the support from , not the other way round. A radius of pixels keeps over of the 1D mass, so calls for a kernel.
First derivatives: Sobel is a tiny derivative of a Gaussian
Sobel’s horizontal kernel is a central difference along times smoothing along . Because the central difference itself hides a average, the whole operator is a discrete derivative of a binomial-smoothed image.
The central difference
Expand around with pixel spacing , keeping one more term than is usually shown:
Subtracting cancels every even-order term. Dividing by then gives
The estimate is second-order accurate: its error shrinks as . With this is the kernel . The forward difference , by contrast, is only first-order accurate and estimates the derivative half a pixel away from where it is stored.
The hidden smoothing
The central difference factors into a forward difference and a two-tap average:
So “central difference” already means “average, then differentiate.” Its frequency response shows the consequence. The ideal derivative has magnitude , which keeps growing, but the central difference has magnitude . It matches at low frequencies and falls back to zero at Nyquist, so it is a band-pass filter, not an unbounded high-pass. Its noise gain is , versus for the forward difference.
Building Sobel
Sobel and Feldman add smoothing across the derivative direction [8]:
The correct normalizer is : a factor for and for the central difference. With it, applied to a ramp returns exactly . Libraries often skip this factor, which only matters when gradient values are compared across operators or thresholds are fixed in physical units.
Using the factorization above, can be rewritten as a smoothing followed by a plain forward difference:
That is the discrete counterpart of the identity : Sobel is a derivative-of-Gaussian filter with px across the edge. The smoothing pays for itself. The normalized Sobel kernel has a noise gain of , compared with for the bare central difference, while returning the same value on any ramp.
Magnitude and orientation
With and the normalized Sobel responses:
Use rather than . Plain folds the angle into and cannot tell a dark-to-light transition from a light-to-dark one. The edge itself runs perpendicular to . The cheap approximation overestimates the magnitude by up to at .
Isotropy, and the Scharr fix
Sobel’s orientation estimate is biased for fine structure, because the product of and is not rotationally symmetric at high frequencies. Scharr optimized the smoothing weights for isotropy and obtained (overall normalizer ) [9].
The difference is measurable. For a sinusoidal pattern with a -pixel wavelength, the worst-case angle error is for the bare central difference, for Sobel and for Scharr. At an -pixel wavelength the errors are , and . The price is slightly less smoothing: Scharr’s noise gain is against Sobel’s .
Real limitations
- One small, fixed scale. At px, Sobel responds to fine texture and noise as strongly as to object boundaries. Larger structures need larger derivative-of-Gaussian kernels.
- Thick, unthresholded output. Gradient magnitude forms a ridge several pixels wide. Canny’s pipeline adds non-maximum suppression along and hysteresis thresholding to turn it into thin, connected edges [3].
- Residual anisotropy. As above, fixable with Scharr-type weights.
Second derivatives: the Laplacian
The -point Laplacian is the sum of two 1D second differences. Unlike the central difference, it contains no hidden smoothing, and its noise gain is .
The stencil
Adding the two Taylor expansions from the previous section, instead of subtracting them, cancels the odd-order terms:
So estimates with an error. Applying it along and along and summing gives the Laplacian:
The -point stencil is rotation-invariant only to leading order. Two common alternatives mix in the diagonals, the -neighbour kernel and the -point kernel:
The leading error term of , , is itself isotropic.
Why it is so noisy
The second difference factors as : two forward differences and no average. Its response keeps rising all the way to the Nyquist frequency, where it reaches . In 2D, the kernel’s largest gain, , is for the one-pixel checkerboard, which is exactly what pixel noise looks like.

Figure: Smoothing turns the Laplacian from a high-pass into a band-pass filter. Gain versus frequency for the ideal operator , the raw second difference , and the binomial-smoothed .
The ideal second derivative grows without bound, and follows it right up to Nyquist. Smoothing with first gives , whose response matches the ideal at low frequencies and returns to zero at Nyquist. That curve is the entire idea behind the Laplacian of Gaussian, shown here in 1D.
In numbers, the -point kernel’s noise gain is , so output noise has about times the standard deviation of the input noise. Normalized Sobel, at , reduces it to times. Both kernels are scaled to return exact derivatives on low-order polynomials, so the gap is not an artefact of scaling.
What zero-crossings do and do not mean
In 1D, crosses zero wherever has an extremum. That includes the maxima (true edges) but also the minima between two edges, which produce phantom edges. Practical detectors keep only zero-crossings where the gradient, or the slope across the crossing, is large enough.
In 2D, the Laplacian mixes two directions. Writing for the gradient direction:
Here is the second derivative across the edge and is the curvature of the iso-intensity contour. On a straight edge , and the Laplacian’s zero-crossing sits exactly at the edge centre. On curved edges and at corners, the second term shifts it, which is why LoG edges round off corners. Haralick and Canny used the directional derivative instead [10, 3], and Torre and Poggio analysed the resulting localization differences [2].
The Laplacian of Gaussian
LoG smooths with a Gaussian and takes the Laplacian in a single kernel. The widely copied kernel with at its centre is not a sample of the LoG formula; the kernel obtained by combining with the -point Laplacian is the better-founded choice.
Why a Gaussian
Marr and Hildreth proposed zero-crossings of the LoG-filtered image as a model of early edge detection [1]. They chose the Gaussian because it is jointly localized in space and frequency: it minimizes the product of spatial and spectral spread, so it removes high frequencies without smearing the image more than necessary.
Two later results made the choice rigorous. Torre and Poggio framed numerical differentiation as an ill-posed problem and showed that filtering before differentiating is a regularization that makes it well-posed [2]. Separately, Yuille and Poggio [11] and, for 1D signals, Babaud et al. [12] proved that the Gaussian is the only filter that never creates new zero-crossings as its scale increases. That property is what makes it safe to follow edges from coarse to fine scales, the core idea of Witkin’s scale space [13].
Continuous derivation
Differentiation and convolution are both linear and shift-invariant, so they commute:
The Laplacian can therefore be applied to the Gaussian once, analytically, and the result used as a single precomputed kernel. Differentiating twice in :
The derivative has the same form. Summing the two:
Four properties matter in practice:
- Sign. The formula is negative at the centre. The “Mexican hat” is its negative, , with a positive centre, and most published kernels (including both kernels below) use that sign. Either sign finds the same zero-crossings, as long as it is used consistently.
- Width. The kernel crosses zero at radius . That is the size of the positive lobe of the hat.
- Zero integral. integrates to zero, so a correct kernel ignores constant brightness. Truncated samples lose this property.
- Two separable terms. . A LoG can therefore run as two separable filters, about multiply-adds per pixel instead of .
What sampling actually gives
Sampling at on a grid and scaling the centre to gives:
The diagonal neighbours are exactly because they sit at , the zero crossing. The entries sum to rather than , because the window cuts off the negative tail. On a flat grey region this kernel would still respond.
The residual is of the kernel’s positive weight at , at and under at . So either use a window of at least for , or subtract the kernel’s mean from every entry to force a zero sum.
The popular -centre kernel
Many tutorials present this integer kernel as a sampled LoG:
No value of reproduces it by sampling. Its inner block matches a sampled at , which, scaled to a centre of , gives at the -neighbours and at the diagonals. At that , though, the taps two pixels out should be about . The kernel’s values there are what make it sum to zero.
It is best read as a hand-tuned integer approximation at a very small scale. Its positive lobe is a single pixel (zero crossing at px), so it smooths only a little more than the plain Laplacian.

The discrete derivation
Building the kernel from discrete parts avoids both problems. With and :
In words: this is the -point Laplacian applied to the binomial blur. The 1D factor is:
The last equality is a neat check on the whole framework: a binomial-smoothed second difference is exactly the central difference applied twice. That is why its response in the figure above is , the square of the central difference’s .
Taking the outer products:
Centre both on a grid (Term A gets a zero row above and below, Term B a zero column left and right) and add:
This estimates and, like the continuous formula, is negative at the centre. Negating it gives the Mexican-hat form. The operation is a sign flip, not an absolute value; taking absolute values would make every entry non-negative and destroy the zero sum.
Comparing the two kernels
The binomial kernel is close to the sample above: the same zero diagonals, against at the -neighbours, and against at the knight’s-move positions. It moves the truncated corner weight onto the axis taps ( against ), and as a result sums to exactly zero.
Its low-frequency behaviour matches a LoG with , while a least-squares fit to sampled shapes lands near ; at scales this small, the of a kernel is only approximate. The -centre kernel, by the same measures, sits at –.
The gap between them is therefore not a minor quantization effect. The kernels represent different scales, and only one follows from a derivation. Scaled so that each returns exactly on quadratic images ( for the binomial kernel, for the -centre one), their noise gains are and . The plain -point Laplacian is at .
Difference of Gaussians: LoG for the price of two blurs
Because the Gaussian solves the heat equation, subtracting two slightly different blurs approximates a scaled LoG.
Differentiating the Gaussian with respect to its own scale gives the diffusion identity:
The right-hand side is a finite difference in . Three consequences follow:
- Cheap LoG. A pyramid of Gaussian blurs is often computed anyway, and subtracting neighbouring levels yields LoG responses almost for free. Marr and Hildreth found a width ratio of about to be a good balance between approximation quality and sensitivity [1].
- Built-in scale normalization. The DoG approximates , not . Lindeberg showed that this factor is exactly what makes responses comparable across scales, so the strongest response picks out a structure’s characteristic size [14].
- Blob detection. Lowe’s SIFT detector locates keypoints as extrema of the DoG over both space and scale, using with levels per octave [15].
The whole family at a glance
Nearly every kernel in this post is a difference operator convolved with a binomial smoother; the kernels differ only in how much smoothing they carry and in which direction.
| Kernel | Built from | Normalizer | Implied (px) | Noise gain |
|---|---|---|---|---|
| Gaussian | ||||
| Central difference | along | |||
| Sobel | across, along | |||
| Scharr | across, along | |||
| -point Laplacian | per axis | |||
| -centre LoG | hand-tuned integers | – | ||
| Binomial LoG |
and . “Implied ” matches each kernel’s low-frequency response to that of a Gaussian or Gaussian derivative, which shows that even the “unsmoothed” differences carry a small implicit scale. Noise gains are for the normalized kernels: smoothers sum to , and derivative kernels return exact derivatives on low-order polynomials.
The same recipe resurfaces in learned models: the first-layer filters of trained CNNs tend to look like oriented derivative-of-Gaussian and Gabor filters [16], which is these kernels rediscovered from data.
References
- Marr, D., & Hildreth, E. (1980). Theory of edge detection. Proceedings of the Royal Society of London, Series B, 207(1167), 187–217.
- Torre, V., & Poggio, T. A. (1986). On edge detection. IEEE Transactions on Pattern Analysis and Machine Intelligence, 8(2), 147–163.
- Canny, J. (1986). A computational approach to edge detection. IEEE TPAMI, 8(6), 679–698.
- Lindeberg, T. (1990). Scale-space for discrete signals. IEEE TPAMI, 12(3), 234–254.
- Szegedy, C., Vanhoucke, V., Ioffe, S., Shlens, J., & Wojna, Z. (2016). Rethinking the Inception architecture for computer vision. CVPR, 2818–2826.
- Chollet, F. (2017). Xception: Deep learning with depthwise separable convolutions. CVPR, 1251–1258.
- Howard, A. G., et al. (2017). MobileNets: Efficient convolutional neural networks for mobile vision applications. arXiv:1704.04861.
- Sobel, I., & Feldman, G. (1968). A 3×3 isotropic gradient operator for image processing. Talk presented at the Stanford Artificial Intelligence Project.
- Scharr, H. (2000). Optimale Operatoren in der digitalen Bildverarbeitung. PhD thesis, University of Heidelberg.
- Haralick, R. M. (1984). Digital step edges from zero crossing of second directional derivatives. IEEE TPAMI, 6(1), 58–68.
- Yuille, A. L., & Poggio, T. A. (1986). Scaling theorems for zero crossings. IEEE TPAMI, 8(1), 15–25.
- Babaud, J., Witkin, A. P., Baudin, M., & Duda, R. O. (1986). Uniqueness of the Gaussian kernel for scale-space filtering. IEEE TPAMI, 8(1), 26–33.
- Witkin, A. P. (1983). Scale-space filtering. Proceedings of IJCAI, 1019–1022.
- 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.
- Krizhevsky, A., Sutskever, I., & Hinton, G. E. (2012). ImageNet classification with deep convolutional neural networks. NeurIPS 25, 1097–1105.