A Gimp plug-in for sharpening images

Ernst Lippe

Table of Contents

What is ATLAS
How to use ATLAS
Using the plug-in
The preview
The parameters
Tips and tricks
Technical background
Modeling the convolution
The Gaussian convolution
The circular convolution
Convolutions in the plug-in
Comparison with other techniques

The refocus Gimp plug-in can be used to sharpen images. Frequently, when processing images, e.g. when scanning photo's or slides, the images become slightly blurred. This plug-in attempts to "refocus" the image. In many cases this plug-in produces much better results than similar plug-ins such as sharpen or unsharp mask.

This plug-in has a preview that helps you select the best parameters.

Instructions for installing the plug-in are described in Installation.

Instructions for using the plug-in are described in Using the plug-in.

The home page for the Refocus plug-in is located at

For installing refocus you need the following:

Installation should be simple. Untar the distribution. If you want to use ATLAS install it in lib-atlas (see Using ATLAS).

Then run ./configure in the top-level directory.

Then run make install-bin if you want to install the plug-in under your home directory or make install-admin-bin if you want to install the plug-in under your Gimp's system directory.

If you have gtk-doc installed you can build the system documentation in the gtk-doc directory. In this case you must invoke configure with the --enable-gtk-doc option. When you make it for the first time make will fail with the message No rule to make target `tmpl/*.sgml'. Running make again will fix this problem.

You can start the plug-in by clicking with the right mouse-button in the image, and then select from the Filters menu Enhance/Refocus.

The plug-in window looks something like this:

GUI screen dump

The plug-in window contains a preview of the image on the left and on the right a set of spin-buttons to change its parameters.

The bottom of the preview contains the following buttons:

A wide range of image transformations can be described mathematically as convolutions. A convolution is a linear transformation where each destination pixel is the weighted sum of the pixels in the neighborhood of the original pixel.

For example, the following matrix describes the convolution where each pixel is the average of the source pixel and its 8 immediate neighbors:


A wide range of image degradations, e.g. bad focusing and motion blur, can adequately be described with convolutions.

In this case we are interested in undo-ing the effect of a convolution. Using Fourier analysis it is possible to show that for each convolution there exists an inverse convolution.

Unfortunately, this inverse convolution is of little practical use. The reason is that image transformations virtually always introduce some form of error, e.g. due to noise in the scanner or simply round-off errors. The unmodified inverse convolution greatly amplifies these errors. In many cases the result of the inverse convolution is completely dominated by the noise. If you want to get a feeling what this means, run the plug-in with Gauss = 2 and Correlation and Noise = 0.

A standard solution is to use Wiener filtering. Wiener filtering finds an inverse convolution that attempts to minimize noise. Normally Wiener filtering is implemented with Fourier transforms.

Standard Wiener filters have two disadvantages for our purpose:

The refocus plug-in is based on a modified form of the Wiener filter, called the FIR (Finite Input Response) Wiener filter. A FIR Wiener filter only uses a limited neighborhood of the source pixels and can be easily implemented as a convolution matrix.

FIR Wiener filtering has the following advantages:

For technical background on the FIR Wiener deconvolution see [Jain89].

In most cases you don't know precisely what convolution caused the image degradation. There are two convolutions that are frequently used to model image degradation:

The refocus plug-in supports both the Gaussian and the circular convolution plus mixtures of both.

The Radius parameter determines the radius of the circular convolution. The Gauss parameter determines the width of Gaussian convolution.

The actual convolution that is used by the plug-in is in fact the result of convolving both the Gaussian and the circular convolution with one another. Both of these convolutions are identical to the identity convolution when their parameter is equal to 0. Therefore, when the Gauss parameter equals 0, the result is a circular convolution, and likewise when the Radius equals 0 the result is a Gaussian convolution.

In practice, I found that in most cases the circular convolution works much better than the Gaussian convolution. The Gaussian convolution has a very long tail, so mathematically the result of the convolution also depends on source pixels at a large distance from the original source pixel. The FIR Wiener inverse of a Gaussian convolution in most cases is heavily influenced by source pixels at a large distances, and in most cases this produces undesirable results.

The circular convolution generally produces much better results. One reason is that the FIR Wiener inverse of the circular convolution in general influenced by source pixels in the immediate neighborhood of the original source pixel. Another reason is that a circular convolution is theoretically a good mathematical model for images that are slightly unfocused.

Two other techniques that are frequently used to enhance images are:

Sharpening applies a small convolution matrix that increases the difference between a source pixel and its immediate neighbors. FIR Wiener filtering is a more general technique because it allows a much larger neighborhood and better parameterizations. Sharpening only works when your images are very slightly blurred. Furthermore, for high values of the sharpening parameter the results frequently look "noisy". With FIR Wiener filtering this noise can be greatly reduced by selecting higher values for the Correlation and Noise parameters.

Unsharp masking is another very popular image enhancement technique. From a mathematical point of view its justification is a bit obscure but many people are very fond of it. The first step is to blur the source image, hence the name unsharp masking. Then the difference between the source image and the blurred image is subtracted from the source image.

In general, unsharp masking produces better results than sharpening. This is probably caused by the fact that unsharp masking uses a larger neighborhood than sharpening.

From a theoretical point of view unsharp masking must always introduce artifacts. Even under optimal circumstances it can never completely undo the effect of blurring. For Wiener filtering it is possible to prove that it is the optimal linear filter.

In practice I found that in virtually all cases the results of the FIR Wiener filter were at least as good as those of unsharp masking. The FIR Wiener filter is frequently better in restoring small details.

As a side note, unsharp masking generally uses a Gaussian convolution, I suspect that in some cases a circular convolution should give better results.

The Gimp developers, Shawn T. Amundson for the GimpPreview widget, Lauri Alanko for the Convolution Matrix plug-in, ATLAS, CLAPACK.