Convolution and directional edge responses
Calculate a directional edge response, one coefficient at a time.
On this page
An edge is associated with a change across neighboring values. Subtracting one side of a neighborhood from the other suppresses a uniform region and produces a response at a transition. A convolution kernel encodes this comparison as a small table of weights, so the relation between its coefficients and its behavior can be calculated exactly.
A local linear filter computes a weighted sum over neighboring values. Its response depends on the coefficient pattern, spatial direction, boundary treatment and numerical scale. A fixed edge detector provides an explicit example of this operation before its coefficients are made trainable in a convolutional network.
1. Cross-correlation and convolution
For a single-channel input and a kernel indexed around its center, cross-correlation is:
Mathematical convolution instead reverses the spatial offsets:
Equivalently, convolution can be implemented as cross-correlation with a spatially flipped kernel. Many neural-network libraries call the unflipped operation convolution; the convention must therefore be specified before comparing coefficients or response signs. [1]
The numerical example below uses cross-correlation, stride one and one-pixel replicate padding. Replicate padding extends the nearest boundary value. These choices preserve the input's spatial size and fully determine the computation at its edges.
2. A directional Sobel operator
The horizontal Sobel kernel is:
Its factorization combines a horizontal difference with a vertical weighted sum. The coefficients sum to zero, so a constant patch produces zero response. For a horizontal ramp , each row's difference is ; weighting the three rows by gives:
For unit grid spacing, division by eight therefore returns the slope of this particular ramp. The unnormalized operator has a scale factor, which matters when interpreting magnitudes. Its response is strong for a vertical boundary because the intensity changes along the horizontal coordinate. [2]
3. A complete local calculation
Consider the patch:
Multiplying corresponding entries and summing gives:
The middle row contributes twice as much because its nonzero weights have magnitude two. Reversing the intensity transition reverses the response sign to . This sign distinguishes transition direction; the absolute magnitude alone does not retain that distinction.
4. Numerical input and response visualization
The test input has height 128 and width 192. Its value is 220 for coordinates , , and 20 elsewhere. The patch centered at is exactly the patch used above. These values define a synthetic numerical input, rather than an observed model output.

For this input, the maximum absolute horizontal response is 800. The displayed image is computed using:

The denominator 800 is specific to this input. For arbitrary values between zero and 255, the sum of positive kernel weights is four, giving a maximum possible absolute response of . Display normalization should not be confused with the filter's raw numerical output.
5. Direction and interpretation
The vertical operator is . A two-direction gradient magnitude can be formed as , but the image above displays only . A zero horizontal response is therefore not evidence that no boundary exists; a horizontal boundary may respond to the other operator.
Nor does a large response establish an object's identity. The filter measures a local directional variation according to fixed coefficients. In a CNN, coefficients can instead be fitted to a task, while the underlying sliding weighted-sum computation remains available as a building block. [2]