Author Topic: PixInsight 1.7 — New Convolution Tool / Filter Definition Language  (Read 13681 times)

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
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 mode

Most 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 mode

In 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  0


is 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 -1


is separable as the following row and column vectors, respectively:

-1.316074  0.000000  1.316074

-0.759836
-1.519671
-0.759836


In 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:

Code: [Select]
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:

Code: [Select]
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.25


Separable 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 mode

In 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 / Exporting

Convolution 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.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
This is a verbatim copy/paste of a brand new page in the PI manual right?  >:D This is fascinating stuff but it'll quickly get lost in the noise (pun intended). Actually I just checked. The convolution tool does not have a manual page. The Fourier tools don't either.

Please consider -first- writing the in-PI documentation and then copying them to the forum if so desired.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
I do what I can. We are trying to write more documentation ASAP, but I thought that at least some information about the new tools should be provided on this forum. I wouldn't call this text 'documentation' by any means; it is a simple overall introduction. Please note that I wrote the above post today at nearly 2 am, after a nice Sunday of bug fixing and user support work. Give me some slack!
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Juan,

I think you could provide preliminary documentation, for example by adding a simple documentation page that links to this forum entry. I think that would be better than the current "no documentation" entry, and it would save users the tedious (and sometimes unsuccessful) search in the forum.

I would certainly encourage you to work this way, instead of hoping to produce lots of perfect documentation in the near future.

Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline sigurd

  • Newcomer
  • Posts: 35
    • The Lambda Conspiracy
I think you're selling yourself short Juan. That introductory paragraph you just dashed out made clear to me something i've been wondering over for at least a year!

I agree this belongs in the manual (perhaps treat it as a topic overview). These sort of topic surveys are extremely useful in giving the landscape around a concept in PI.

-esy
”My punctuality is well known. When The Revolution takes place, I'll be late, and I'll be shot as a traitor.”

Offline RBA

  • PixInsight Guru
  • ****
  • Posts: 511
    • DeepSkyColors
Sorry to hijack this topic - move it somewhere else if you think it might contaminate this thread...
But...

Give me some slack!

My interpretation of this problem Juan is that I feel when you go and write OFFICIAL documentation, you write a document that is extremely professional, detailed, and at a level that I don't remember seeing before as "online documentation", and unless you've got that done, you won't present anything else as such. From that perspective, the above post is not near close to YOUR standards, yet, it's already, believe it or not, of much higher quality than the best chapter in the documentation of any other "competing" software - that's why people suggest you could throw that in for the time being regardless of whether it meets your standards of what PixInsight's formal documentation should be.

Fact is, you've written the entire PixInsight documentation manual already, but it's not in a single location but spread all over the place, and as you know, sometimes a bit outdated. 

Also, sometimes I've asked you a simple question and received such a detailed answer that even I didn't feel I deserve! That honors you from the perspective that you may rather take care of a user's "support" issue than writing formal documentation. Yet remember, formal documentation at this stage is some of the best user's support tasks you could be doing.

In the meantime you'll have to weather the storm, but try to be clear about the difference between pure noise makers, and "legitimate" comments that may also sound like noise but are posted with very different intentions than the noise makers of the world.

Just my view on this constantly dragging issue...

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Exactly.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline Astrodoc

  • PixInsight Old Hand
  • ****
  • Posts: 379
    • AstroDoc - Astrophotography by Ron Brecher
In simple terms, what might I use the convolution operation for?
Clear skies,
Ron

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Quote
In simple terms, what might I use the convolution operation for?

Convolution is a fundamental mathematical operation. It has uncountable applications to signal processing. The new Convolution tool is a basic tool for experimentation and image analysis that we were lacking for a long time. Some examples of use are:

- Low-pass filtering (for example, with Gaussian filters). This allows you to remove high frequencies from your image. High frequencies correspond to small-scale structures, such as the noise and sharp image features. Low-pass filtering is a common operation to generate image masks, since by removing small-scale structures a mask can be made less dependent on local irregularities, a property that is usually desirable for masks.

- High-pass filtering. This is the opposite to low-pass filtering: the low frequencies are removed, or large-scale structures, to isolate small-scale structures. This can be used to enhance small-scale contrast, which has a sharpening visual effect.

- Band-pass filtering. By subtracting the results of two low-pass filters you can isolate a specific range of frequencies, or structures within a prescribed range of dimensional scales. The same task can be achieved more easily with special filters in the frequency domain (with the new FourierTransform tools). This can be used to implement multiscale processing procedures. Wavelets can also be used to this purpose, but a band-pass filter bank is an interesting alternative (although requiring much more manual work, or scripting).

- Edge detection and gradient extraction (note: the term gradient is used here meaning the first derivative of a two-dimensional function, which is unrelated to sky gradients). Some high-pass filters can be used to isolate the edges of some image structures. Some examples are the classical Sobel, Prewitt, Scharr and Fei-Chen filters, all of them available in the default filter library (Library tab of Convolution).

- Laplacian operators. The Laplacian filter is a building block of many image processing algorithms, such as more sophisticated edge detection algorithms (the Canny algorithm for example).

- Simulating the effects of seeing to test deconvolution and other image restoration algorithms.

- Generation of synthetic PSF functions, also for deconvolution tests.

... and many more. Hope this helps.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline georg.viehoever

  • PTeam Member
  • PixInsight Jedi Master
  • ******
  • Posts: 2132
Some examples can be found in http://www.cs.toronto.edu/~jepson/csc320/notes/linearFilters2.pdf. Simply Google/Yahoo/Bing/... a bit for Fourier 2D to get more examples on how it can be used.
Georg
Georg (6 inch Newton, unmodified Canon EOS40D+80D, unguided EQ5 mount)

Offline RobF2

  • PixInsight Addict
  • ***
  • Posts: 189
  • Rob
    • Rob's Astropics
My interpretation of this problem Juan is that I feel when you go and write OFFICIAL documentation, you write a document that is extremely professional, detailed, and at a level that I don't remember seeing before as "online documentation", and unless you've got that done, you won't present anything else as such. From that perspective, the above post is not near close to YOUR standards, yet, it's already, believe it or not, of much higher quality than the best chapter in the documentation of any other "competing" software - that's why people suggest you could throw that in for the time being regardless of whether it meets your standards of what PixInsight's formal documentation should be.

I'd just like to 2nd this.  I personally keep an Excel page in my Astrophotography notes document that's nothing but links to threads where Juan has described how to use a certain tool or technique.   They're ALWAYS fabulously useful...... :footinmouth:
FSQ106/8" Newt on NEQ6/HEQ5Pro via EQMOD | QHY9 | Guiding:  ZS80II/QHY5IIL | Canon 450D | DBK21 and other "stuff"
Rob's Astropics