Kumita← Open visual lesson

Edges as Steepest Change

The math behind the picture

An edge is where brightness changes quickly, and two filters measure that change along two perpendicular directions.

Connection 1 of 4

Measure change along x and along y

On the watermelon picture, Sobel x multiplies the patch [3 3 0; 0 0 8; 8 8 8] by [−1 0 1; −2 0 2; −1 0 1] and adds the products to get Gx = 13. Sobel y, its transpose, gives Gy = 23. y grows downward, so Gy = 23 means brighter below.

Gx = Σ Sx · patch,  Gy = Σ Sy · patch

Read it as: Each filter is a weighted sum of the nine pixels under it.

Gx13
Gy23

Connection 2 of 4

Combine them into strength

Two Sobel measurements on one patch of the watermelon, Gx = +13 and Gy = +23, combine into a single gradient arrow.
From guided stage 7 · Static lesson frame

Two Sobel measurements on one patch of the watermelon, Gx = +13 and Gy = +23, combine into a single gradient arrow.

The components are the legs of a right triangle. The gradient's length is the hypotenuse: √(13² + 23²) = √698 ≈ 26.4. Squaring hides the sign, so the signed components are kept for direction.

|G| = √(Gx² + Gy²)

Read it as: Square each component, add, and take the square root.

Magnitude≈ 26.4

Connection 3 of 4

Read the direction

atan2(Gy, Gx) uses both signs to find the right quadrant. Here atan2(23, 13) ≈ 60.5°, measured from +x toward +y: steeply down and a little to the right, toward the bright background. The edge itself runs at right angles to this arrow.

θ = atan2(Gy, Gx)

Read it as: The angle of the arrow from the x axis, turning toward y.

Direction≈ 60.5°

Connection 4 of 4

Keep the strong changes, but treat them as candidates

Gradient magnitude at every position of the watermelon; cells of at least 16 are edge candidates, with gaps where the outline is faint.
From guided stage 10 · Static lesson frame

Gradient magnitude at every position of the watermelon; cells of at least 16 are edge candidates, with gaps where the outline is faint.

Keeping magnitudes of at least 16 leaves 58 of 240 positions on the melon's outline and rind. Noise, texture and shadows would pass too, and weak-contrast boundaries would not.

candidate  ⇔  |G| ≥ 16

Read it as: A threshold selects candidates; it does not decide what is a real boundary.

Candidates58 of 240

Connect it back to the picture

An edge candidate is a place where brightness changes sharply: Gx and Gy measure the change along two axes, and together they give how strong it is and which way brightness rises fastest.

Full notation and technical reference

The expressions below collect the operations discussed above. You can return here when you want the compact notation.

Gx = Σ Sx · patch,  Gy = Σ Sy · patch
|G| = √(Gx² + Gy²)
θ = atan2(Gy, Gx)
  • x runs to the right and y runs DOWN the screen, so Gx = right − left and Gy = below − above; both are raw weighted sums, never rescaled.
  • Sx = [−1 0 1; −2 0 2; −1 0 1] and Sy is its transpose. Each is a difference across one axis plus 1-2-1 smoothing along the other.
  • θ is measured from +x toward +y (clockwise on screen) and points toward brighter pixels, at right angles to the edge.

Numerical reference

On the watermelon picture, the patch at the melon's lower-right rim is [3 3 0; 0 0 8; 8 8 8]. The x products sum to Gx = 13 and the y products to Gy = 23. Then |G| = √(13² + 23²) = √698 ≈ 26.4 and θ = atan2(23, 13) ≈ 60.5°, down and a little to the right, toward the bright background.

Where this explanation stops

A large gradient is only an edge candidate: noise, texture and shadows also produce one, and a real boundary with weak contrast may not. Real detectors such as Canny smooth first, thin the ridges and use two thresholds.

Follow the same idea in the Python or JavaScript notebook →