Skip to content
ISEGORIABenjamin Haire

Interactive image calculus

The Scharr
gradient.

The first thing I correct is this: a gradient is not an edge. It is an arrow pointing across the edge, toward the fastest increase in image intensity.

What you can see hereChange nine pixels and watch two signed derivative estimates become a magnitude, a direction, and an edge tangent.

The central idea

Smooth across one axis; differentiate along the other

Each Scharr kernel is separable. For Gx, the weights 3:10:3 smooth vertically while −1:0:1 takes a left-to-right difference. The roles swap for Gy.

Kx = (1/32) [3, 10, 3]T[−1, 0, 1]

The factor 1/32 calibrates the operator: on an exact linear ramp I(x,y) = ax + b, the normalized response is Gx = a and Gy = 0.

Why Scharr?

Less directional bias

I use Scharr rather than Sobel throughout, and this is why. Sobel uses perpendicular weights 1:2:1. Scharr's 3:10:3 weighting is tuned so a 3 × 3 derivative responds more evenly as an edge rotates through the pixel lattice.

Calculate

From components to an arrow

|G| = √(Gx² + Gy²)
θ = atan2(Gy, Gx)

atan2 preserves the signs of both components, so the direction lands in the correct quadrant.

Interpret

Gradient normal, edge tangent

The gradient is perpendicular to a level curve of intensity. The visible edge runs at θ + 90°. In image coordinates, positive y points downward, exactly as in the dial above.

The checks I insist on

Four checks before using the result

  • Convolve in signed floating point; an 8-bit output destroys negative derivatives.
  • State whether your implementation returns raw values or divides by 32.
  • Choose an explicit border rule for patches at the image boundary.
  • Threshold magnitude for edge strength; use orientation only where the magnitude is meaningful.