Introduction & Theory
Images can be fuzzy from random noise and blurrings.
An image can be sharpened by:
detecting the edges
combining the edges with the original image
These steps are shown in the figure below.
Edge detection
Edges can be detected using a Laplacian filter. The Laplacian \(L(x,y)\) is the second spatial derivative of the image intensity \(I(x,y)\). This means it highlights regions of rapid intensity change, i.e the edges.
In practice, the Laplacian also highlights the noise in the image and, therefore, it is sensible to apply smoothing to the image as a first step. Here we will apply a Guassian filter. The Guassian filter \(G(x,y)\) approximates each pixel as a weighted average of its neighbors.
The two operations can be combined to give the Laplacian of Gaussian filter \(L \circ G(x,y)\).
These two functions \(G(x,y)\) and \(L \circ G(x,y)\) are graphed below.
Implementation
To apply the \(L \circ G\) filter to an image the \(L \circ G\) filter must be turned into a discrete mask, that is a matrix of size 2d+1 x 2d+1 where d is an integer. We use d=8, therefore the \(L \circ G\) filter is a 17x17 square, it looks like this:
To perform the convolution of this filter with the original image, the following operation is performed on each pixel,
the sharpened image is then created by adding the edges to the original image, with a scaling factor (See the source code for the full details).