Vinnie Garcia

How a computer finds edges ๐Ÿ“

1. Grayscale

An edge is a place where brightness changes fast, so the first step drops color and keeps only brightness. Each pixel becomes one number from 0 (black) to 255 (white):

Y = 0.299 R + 0.587 G + 0.114 B

The weights match human vision: we see green as the brightest color and blue as the dimmest.

Tap ๐Ÿ”, then tap or drag on the picture to see the math at one pixel. With ๐Ÿ” off, tap the picture to hide or show this panel.
How it worksBack to the demo

Finding an edge, one pixel at a time

A dark object against a light wall gives this detector something obvious to find. Move through Gray, Blur, Gx, Gy, |G|, and Edges, and you can watch the picture turn into a set of lines.

The code never needs to know what the object is. It measures how much neighboring pixels change. A shadow, reflection, or patch of texture can produce a line too.

Two directions of change

First the image becomes gray: 0.299 R + 0.587 G + 0.114 B. These Rec. 601 luma weights give green more influence than blue. They operate on the camera values, with an 8-bit intermediate image, rather than measuring physical light.

Blur ฯƒ controls a Gaussian blur. Nearby pixels count more than distant ones, with samples reaching about three sigma in each direction. One pass works horizontally, another vertically. This removes some noise before looking for edges, but a small real feature can disappear along with it.

Then the Sobel filters compare opposite sides of a 3 by 3 neighborhood. Gx compares right with left; Gy compares bottom with top. The middle sample on each side counts twice. Written as rows, the weights are:

A vertical boundary stands out in Gx, a horizontal boundary in Gy. Orange marks positive change (rightward or downward), blue marks negative change. The magnifying-glass tool opens the pixel probe, so you can tap or drag to inspect the actual neighborhood and arithmetic.

Turning those numbers into lines

|G| combines the two measurements with sqrt(Gxยฒ + Gyยฒ). A strong change counts whatever direction it points. Show direction colors the gradient angle instead of showing only strength.

Threshold removes weaker responses, with a short soft transition at the cutoff. Thin lines (Canny-lite) checks along the gradient and removes a response when its neighbor is stronger. This non-maximum suppression narrows a broad edge. It doesn't include the full Canny detector's double-threshold edge linking.

In Use, Robot view and Cartoon ink put the lines back over the camera picture. The names describe the display, not object recognition or a navigation system.

Two colors with nearly the same luma can lose their boundary in the grayscale step. More blur and a higher threshold make a simpler drawing, but neither can decide which detail matters. Cel Shade uses RGB edges to retain more color boundaries, while Assist Cam widens detected edges into bold outlines.