This filter extracts and enhances edges and contours in an image by expressing intensity differences (gradients) between neighboring pixels as an intensity value. This is done by combining the difference between the top and bottom rows in a neighborhood, with the difference between the left and right columns, using the following formula:
where: X = (C + 2F + I) - (A + 2D +G) Y = (A + 2B + C) - (G + 2H +I)
and where the neighborhood is arranged as a row of pixels A, B and C, followed by a row of pixels D, E and F, followed by a row of pixels G, H and I.
In neighborhoods where there is no difference among values in the neighborhood, the pixel's intensity is set to 0 (black); where there is the greatest possible difference, the pixel is set to 255 (white).
The results are similar to the Roberts filter, highlighted edges against a dark background, but the Sobel filter is less sensitive to image noise. This generally results in an image with smoother outlines of only the principle edges.