Gimp-Forum.net
Wavelets for gradient removal and star reduction - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Tutorials and tips (https://www.gimp-forum.net/Forum-Tutorials-and-tips)
+--- Thread: Wavelets for gradient removal and star reduction (/Thread-Wavelets-for-gradient-removal-and-star-reduction)



Wavelets for gradient removal and star reduction - HenkSB - 11-07-2021

Gradient removal and star reduction are some of the main issues when processing astrophotography images.  While other editors may have specialized features for this, Gimp does not.  Or perhaps it does but which ones and how to use them, are not entirely clear.  My first take on this was to write a plugin for gradient removal using Scilab but yesterday I found a quicker way just using native Gimp features that I want to share.

I should first mention why the standard gradient removal tool does not work well for this.  I have used it quite a bit but it is specialized for gradients that are parallel perpendicular to the selected gradient removal line, and this is limiting.  Many (most) gradients do not satisfy that model.  As a result one has to try multiple gradient removals in different directions, which has the side effect of creating new gradients.  Thus, it requires a lot of work with non-optimal results.  I wrote a Scilab script that can read a .jpg file, chops up the data in chunks based on the number of data points per polynomial parameter, then estimates a polynomial from Chebyshev base polynomials.  This works much better and gets me the right answer in one shot.  The gradient estimation is done on the non-black area so there is a useful selectivity.  Forging a plugin that calls Scilab, or rewriting this in Gimp's Python 2.7 without numpy, are both difficult to accomplish (allowing an external Anaconda release v 2 or 3 would help!)

Secondly, why can't we use Erode or Value propagation for resucing the stars?  I tried that in the most straightforward way without making a selection.  After one or two iterations the whole image shows rectangular-like blobs, which is more or less unacceptable.  I recently found that by reducing the selection area to just around the stars, the results are much better.  So how do we select those areas easily for the numerous stars?  A stright forward Threshold will not work due to gradients and nebulosity.

Wavelets to the rescue!  The reason for this is that the error layer along with perhaps base layers 6 and 7, are good approximations for the "low frequency" parts.  By "low frequency" I mean blurry blobs representing the over all luminosity that can be used to capture the gradient, and also allows for a better use of Threshold and Erode.

I illustrate the workflow with an image from an Astrocat51 on an AVX, 60 times 2 minute exposures.  The initial image is a bit rough, stacked and edited in DSS, size reduced in Paint but it serves the purpose:

[attachment=7017]

First we use wavelets to estimate the gradient.  For this we deselect the nebulosity and fill it with black:

[attachment=7018]

Decompose this image using wavelets (Filters->Enhance->Wavelet-decompose...) and select scale 7. Deselecting everything except the error we get:

[attachment=7019]

This is already a pretty good gradient but the edge is a bit sharp. Apply a Gaussian blur of 100 pixels:

[attachment=7020]

Now subtract it from the original (and save it as a "new layer from visible"):

[attachment=7021]

That was pretty easy with a good result!

To be continued in the next post because of the attachment limit of 5 files.

Next, to reduce the stars, we need an effective way to apply Threshold to define a mask.  The stars can be made to opo out better by first reducing the image with the main low frequency behavior, by decomposing this image with wavelets. We select the error and scales 6 and 7:

[attachment=7022]

Subtract this from the layer that we created them from (the gradient free M31) and save this as a "new layer from visible":

[attachment=7023]

This will be the basis for our star mask that we create using Colors->Threshold. Adjust the slider enough to exclude speckles at the center:

[attachment=7024]

Using Select->Grow grow it by 2 pixels. Deselect the mask and select the gradient-free M31 zoom in to see the selection:

[attachment=7025]

Reduce the stars by Filters->Distorts->Value propagate... and select the option to make it darker:

[attachment=7026]

Continued in the next post.

Let's shrink the selection by Select->Shrink... by 2 pixels and do the Value propagate again. Zooming out the result is:

[attachment=7027]

There is some speckling in the lower right that we must despeckle. Since despeckling has side effects on the nebulosity we deselect this first; free-select around the nebulosity select its complement then apply Filters->Ennhance->Despeckle... with the sliders set appropriately by looking at the results in the preview window:

[attachment=7028]

This is quite a difference from the original. When zooming in you can see some minor artifacts but over all it's not too bad. I'm sure there are ways to tweak this but I find it pretty encouraging for a first wavelet experience!  One improvement would be to perhaps let some of the intermittent stages shine through, for instance so the background is not entirely black, using partial opacity.  This may make it look a bit more realistic.  Also, maybe the result looks better if not all stars are removed.  I just wanted to show how far you can go in removing them using wavelets.

Thank you, Gimp developers, for providing this great tool!  I hope this post helps fellow astrophotographers who want to use Gimp.


RE: Wavelets for gradient removal and star reduction - HenkSB - 11-07-2021

Correction: It's not an Astrocat51, it's a Redcat51. A wide field Petzval design by Williams Optics.


RE: Wavelets for gradient removal and star reduction - nelo - 11-08-2021

Maybe this guy's homepage for GIMP astronomy plugins is interesting to you?
http://www.hennigbuam.de/georg/gimp.html


RE: Wavelets for gradient removal and star reduction - HenkSB - 11-08-2021

(11-08-2021, 10:01 AM)nelo Wrote: Maybe this guy's homepage for GIMP astronomy plugins is interesting to you?
http://www.hennigbuam.de/georg/gimp.html

I had noticed his pages before, pretty impressive stuff.  His gradient removal works like the polynomial trend removal like I wrote in Scilab.  Trouble is, calculating a polynomial for a 4000 x 6000 image is time consuming, even in Scilab where everything is vectorized and the underlying loop is in a C coded binary.  The wavelet decomposition is much faster.  Being able to avoid dealing with the various data types that Gimp passes in is also worth something.  So I like the wavelets better, the result is also quite good.  I have no need for the other utilities.

I have been contemplating writing my own plugins but (1) Gimp has no public C api, you have to build all of it and pick what you need, and (2) Gimp's internal Python is 2.7 and has no numpy or scipy.  Since the world has moved to 3 this is not really good.  It would help greatly if the user could configure Gimp to use an external Anaconda release, 2 or 3.