i’m doing a project that implements image filters.
My problem is, the user say to apply a laplace filter in a image, the kernel is nxn size.
I know the laplace uses the following matrix 3×3:
0 1 0
1 -4 1
0 1 0
but if he wants a nxn matrix how do i create it?
The “Laplace filter” in image processing is called that because you can derive it exactly from the formal definition of the discrete Laplacian on graphs. This approach leads to two convolution kernels that immediately make sense,
and
, depending on whether you consider the diagonally adjacent pixels as neighbours or not.
You can of course use other matrices as convolution kernels (the convolution works exactly the same way, the operation is independent of matrix dimensions), but those are no longer “Laplacians”. You can calculate larger convolution kernels that approximate other continuous operators, but imho there is no one “right definition” for an
nxnLaplacian matrix.Either rely on user input and trust the user to enter a sensible kernel for your purpose, or do some research into how to approximate other operators. An example for an approximation of a Laplacian-of-Gaussian is given here: http://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm