# Why Are There Two Different Common $3 \times 3$ Kernels for the Laplacian?

I find both of these 3x3 Laplacian kernels to be commonly used:

 0 -1  0
-1  4 -1
0 -1  0


and:

-1 -1 -1
-1  8 -1
-1 -1 -1


Is there a reason to choose one or the other? What's the difference between them?

(My math is not good enough to understand the Wikipedia article, so I can't figure it out myself from reading that. Googling is failing me for this one.)

On a regular 2D grid of pixels, there are essentially two possibilities to look at the neighborhood of a given pixel (in black below), or pixel connectivity: the 8-pixel connectivity (left, or Moore neighborhood), and the 4-pixel connectivity (right, von Neumann neighborhood). Four- and eight-adjacencies are other common terms. The first one gives the same weight to all eight surrounding pixels, the second considers that the North, East, South, West gray pixels are closer (distance 1) than the ones in the corners (distance $$\sqrt{2}$$). Indeed, there are topological reasons. One is based on the $$\ell_\infty$$, $$\max$$ or Chebyshef distance, the other on the $$\ell_1$$, Taxicab or Manhattan distance.

Which regions are connected, how to design filters, are question with a different answer, and different results (see for instance 4-Neighbour vs. 8-Neighbour Graph Models of an Image).

The two $$3\times 3$$ Laplacian kernels are two possibilities in discretizing the continuous Laplacian along the two above options, while keeping integer values, useful with integer valued-pixels.

The Laplacian kernel is used for edge detection, that is a high pass filter. The 2D convolution of an image with it will "detect" or highlight big differences between pixel intensities (that is why it has negative values around a bigger positive one).

The basic difference between the kernels you wrote is that the first one will only highlight horizontal and vertical intensity differences in the image, while the second one will also detect diagonal differences.

Another important characteristic is that all its values should add to zero, so that portions of an image which had uniform values should stay uniform after the filtering.