An edge is a place where brightness changes quickly. Sobel finds them by measuring the rate of change in two directions at once, using a pair of fixed 3×3 kernels:
Gx responds to vertical edges (brightness changing left-to-right) and Gy to horizontal ones. Combine the two into a single strength with Pythagoras:
Task: write sobel_magnitude(image) returning the edge strength at every position where the 3×3 window fits, each rounded to 4 decimal places.
H × W image gives an (H-2) × (W-2) result. The output's top-left entry corresponds to the window anchored at the image's top-left.0.0 everywhere: the weights in each kernel sum to zero, so constant brightness cancels exactly.The 2 in the middle of each kernel is the Sobel part. It weights the pixels directly adjacent to the centre more heavily than the diagonal ones, which smooths slightly in the direction along the edge while differentiating across it — the reason Sobel is less noise-sensitive than a bare difference of neighbours.