Consider a solid black box (refer to Figure 13). All the pixels within the black box have similar pixel values, whereas, the pixel values on the boundary or the edge vary significantly from their neighboring pixels. Therefore, it makes sense to consider pixels with large gradient values:
The kernel used in the Sobel edge detector algorithm is as follows:
Here is a code to find edges using the scikit-image:
>>> from skimage import ...