How to calculate a Laplacian mask or any size

terry picture terry · Oct 17, 2013 · Viewed 10.2k times · Source

I would like to know how to calculate a Laplacian mask of an arbitrary odd size kernel (2nd derivative). For example, I know a 3x3 would be:


1  1  1
1 -8  1
1  1  1

And a 5x5 mask would be:


1  1  1  1  1
1  1  1  1  1
1  1 -24 1  1
1  1  1  1  1
1  1  1  1  1

However, this is all I know. I don't know how these were calculated. I believe that all 2nd derivative masks always have a different center number surrounded by 1s. My question is, how would I calculate the center number for nxn where n is odd? (e.g. 7x7, 15x15, etc.) I am planning on implementing this in Matlab. I appreciate any help I can get.

Answer

Papouh picture Papouh · Oct 17, 2013

The Laplacian function looks like this:

Source: homeepages.inf.ed.ac.uk/rbf/HIPR2/log.htm

and is described by:

enter image description here

σ here determines the spread of the inverted bell. The digital mask is a discrete approximation of this function. And therefore for smaller values of window size (n) and σ, you get a large negative number surrounded by 1s all over. But as you increase the window size and σ, that's not going to be the case.

To calculate the digital mask correctly, you should use the function given above. The center pixel of your odd sized square (nxn) will be your origin.

For reference: http://homepages.inf.ed.ac.uk/rbf/HIPR2/log.htm