PixInsight 1.7 comes with two new image processing tools that I'll describe briefly on this forum board: Convolution and FourierTransform/InverseFourierTransform. Let's begin with Convolution. This is a long-awaited tool that fills a gap in the set of fundamental image processing tools of PixInsight.
Convolution is a mathematical operation of crucial importance in all signal processing fields. A thorough description of convolution is obviously out of the scope of this brief introduction. Interested readers can of course resort to
the corresponding Wikipedia article, which is excellent as usual.
We have designed the Convolution tool to be powerful and versatile, as is customary in all PixInsight implementations. Convolution provides three working modes:
Gaussian,
Library and
Image. Each working mode allows you to define the convolution's
response function in a different way, which I'll describe below.
Gaussian modeMost users will find the set of controls available for this mode quite familiar. They are essentially identical to the similar controls in the standard Deconvolution tool. You can define a Gaussian filter of adjustable size by varying the
StdDev parameter. The
shape parameter governs the
kurtosis of the filter (the kurtosis defines the filter's peakedness or flatness). When
shape is equal to 2 we have a Gaussian (aka
normal) distribution. When
shape is less than 2 the distribution is leptokurtic (peaked), while
shape > 2 leads to a platykurtic distribution (flat). Of course, when
shape is not 2 we don't have a Gaussian filter at all; however, since the formulation of all of these filters is essentially the same, we customarily group all of them into a single set.
Along with the standard deviation and shape of a filter, the Gaussian mode tab allows you to define the
aspect ratio of a distorted filter. When
aspect ratio is less than one, the filter has an elliptic base and the value of
aspect ratio is the quotient between the vertical and horizontal axes of the ellipse. Finally, when we have a distorted filter we can rotate it around its center; the
rotation parameter allows you to control the filter's orientation in degrees.
Library modeIn
library mode, Convolution works as a specialized database manager. A filter library is loaded and the tool's interface allows you to manage it in several ways: you can add new filters, edit existing ones, remove filters, load libraries and save/create new libraries.
A filter library is a collection of
filter objects that can be used as response functions to convolve images. Filters in a filter library can be of two types:
kernel filters and
separable filters. A kernel filter is just a matrix of filter coefficients; it is actually a (usually quite small) grayscale image. For example, the following matrix:
0 -1 0
-1 5 -1
0 -1 0is a classical high-pass filter known as
sharpen filter.
A separable filter is specified as a row vector and a column vector, whose product is equal to the filter's kernel. When a filter can be decomposed in this way (as the external product of two vectors), we say that it is a
separable filter. Separable filters allow for
separable convolution, which is an extremely efficient convolution algorithm for small and medium-sized
separable filters. For example, the classical Sobel edge-detection filter:
1 0 -1
2 0 -2
1 0 -1is separable as the following row and column vectors, respectively:
-1.316074 0.000000 1.316074-0.759836
-1.519671
-0.759836In library mode, the Convolution tool works as an interpreter of a simple language that we have created to define filters in a very flexible and powerful way as plain text files. This language is very easy to use. Instead of a formal description (which I'll provide in the official documentation of this tool), let's take a look at a couple examples to understand how this language works. First the definition of a kernel filter:
KernelFilter {
name { Kroon Derivative North (5) }
coefficients {
-0.0007 -0.0052 -0.0370 -0.0052 -0.0007
-0.0037 -0.1187 -0.2589 -0.1187 -0.0037
0 0 0 0 0
0.0037 0.1187 0.2589 0.1187 0.0037
0.0007 0.0052 0.0370 0.0052 0.0007
}
}
As you can see, a filter definition consists of a reserved work that tells the filter type,
KernelFilter in this case, and some code that provides the filter definition between curly brackets. For a kernel filter we have two mandatory items:
name and
coefficients. The value of
name is some text that will be used as the name of the filter in a filter library. Filter names must be unique within a single library.
The
coefficients item specifies the filter components as a set of numbers separated by spaces. A filter must be square and have an odd size greater than or equal to three (3, 5, 7, 9, ...). Filters must have odd sizes because they must have a unique central coefficient, so the number of coefficients must be 9, 25, 49, 81, ... or otherwise the filter compiler will issue a runtime error.
Here is an example of separable filter:
SeparableFilter {
name { Linear Interpolation (3) }
row-vector { 0.5 1 0.5 }
col-vector { 0.5 1 0.5 }
}
which corresponds to the separable filter:
0.25 0.5 0.25
0.5 1 0.5
0.25 0.5 0.25Separable filters are defined in a similar way to kernel filters, but instead of a
coeffcients item, they must have a
row-vector item and a
col-vector item.
Convolution provides a default library that includes a good bunch of classical filters. The list does not pretend to be comprehensive or exhaustive; it just provides a good starting point that can cover most basic needs, in our opinion.
Image modeIn image mode, Convolution allows you to select a view (which can be a main view or a preview) as a convolution filter. This mode is used chiefly for simulation and analysis purposes. For example, a synthetic PSF function can be generated using theoretical instrumental and seeing parameters. Then it can be used to convolve an image, as part of a simulation. We use these simulations to test deconvolution algorithms.
Filter Representation / ExportingConvolution provides a graphical representation of the current filter as a two-dimensional image. Zero or positive filter coefficients are represented as grayscale pixels, where the gray level is proportional to the filter coefficient value. Negative filter coefficients are represented as red pixels, where again, pixel intensity is proportional to the absolute value of the coefficient. This red/gray representation allows for quick visual interpretation of low-pass and high-pass filters.
Finally, a very handy feature of Convolution is its ability to export the currently selected filter as an image. This is particularly useful in Gaussian mode. To export a filter, click the blue square button close to the bottom right corner of the filter representation.