Author Topic: background gradient removal  (Read 12123 times)

Offline avan1

  • Newcomer
  • Posts: 23
background gradient removal
« on: 2012 January 01 05:14:35 »
Hi ,

      I am a new user of Pixinsight .My friend just send an image of M42  with a "wave like" background  , he would like me to remove it.
? have tried to use DBE and failed. I also tried to use multiscaleMedian Transform to extract the background and use pixel math to subtract it  without success.Can anyone suggest a way to remove these annoying pattern ?
here is the link of the image :


alan :)

Offline Harry page

  • PTeam Member
  • PixInsight Jedi Knight
  • *****
  • Posts: 1458
    • http://www.harrysastroshed.com
Re: background gradient removal
« Reply #1 on: 2012 January 01 05:24:50 »
Hi

DBE will remove this but you must put on many samples and lower smoothing factor ( try 0.05)

Harry
Harry Page

Offline avan1

  • Newcomer
  • Posts: 23
Re: background gradient removal
« Reply #2 on: 2012 January 01 05:35:53 »
?hank you :)
?'ll try it again with ??? :)

Offline avan1

  • Newcomer
  • Posts: 23
Re: background gradient removal
« Reply #3 on: 2012 January 01 05:48:54 »
 Harry ,  thank you   :)
just tried  DBE with lot of sampling points  and it can remove most of the gradient .
I'll try to fine tune the parameter to see if I can remove all the  pattern.

Thank you !

alan:)

Offline Harry page

  • PTeam Member
  • PixInsight Jedi Knight
  • *****
  • Posts: 1458
    • http://www.harrysastroshed.com
Re: background gradient removal
« Reply #4 on: 2012 January 01 05:50:37 »
Hi

The samples must cover all the changes in illumination so it will mean hundreds of samples  ;)

Harry
Harry Page

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: background gradient removal
« Reply #5 on: 2012 January 01 10:28:17 »
Hi Alan,

Welcome to PixInsight Forum. These 'wave like' artifacts are approximately periodic, that is, the distance between two successive wave maxima is approximately constant for the whole image. Periodic image features are easily characterizable in the frequency domain, so this is a good candidate to find an efficient solution based on the Fourier transform. I have made a quick try with good results.

The screenshot below shows the magnitude of the Fourier transform with automatic screen stretch applied. I've used the standard FourierTransform tool in PixInsight. As you can see, the wave artifacts are very well represented as two bright structures near the center of the transform, on the second and fourth quadrants:


The phase component of the FT is normally left intact in these procedures (who on Earth could understand it? :) ); you can see it iconized at the top right corner of the workspace above. We'll need it later, when we perform the inverse Fourier transform.

To fix the wave artifacts we want to remove the corresponding structures in the Fourier transform. An easy way to achieve this is by replacing them with the mean values of their surrounding areas on the transform. There are better and more accurate techniques, but in the present example I've wanted to keep things as simple as possible. First I've defined a small preview ('sample') close to one of the structures, which I've extracted as an independent image:


The Fourier transform has central symmetry. This means that the first and third quadrants are identical. In the same way, the second and fourth quadrants are also identical. What we want in this example is to replace the artifact structures with the mean value of the 'sample' preview. Because of the transform symmetry, we have to perform the same actions on the second and fourth quadrants. This task is relatively easy with PixelMath:


The PixelMath expression is the following:

Code: [Select]
dx = x() - width()/2;
dy = y() - height()/2;
rx = abs( dx );
ry = abs( dy );
iif( sign( dx ) == sign( dy ) && rx >= 2 && rx <= 12 && ry >= 3 && ry <= 7, med( sample ), $T )

where dx, dy, rx and ry must be defined as symbols. This expression replaces small rectangular areas covering the artifact structures with the median of the 'sample' image. I've found the correct coordinates with a bit of trial-error work. The result can be seen below:


Finally, we apply the inverse Fourier transform to the modified magnitude and phase components, which provides the corrected image:


I think the result is rather good with very little effort. The remaining gradient can be fixed very easily with DBE or ABE (AutomaticBackgroundExtractor). This is a very nice example of practical image processing in the frequency domain. Can we use it for the documentation of the FourierTransform tool?

Hope this helps. Despite this procedure can seem somewhat intimidating at first, due to the mathematical devices involved, believe me that the practical use of these tools is very intuitive. All it takes is a little practice.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline avan1

  • Newcomer
  • Posts: 23
Re: background gradient removal
« Reply #6 on: 2012 January 01 15:44:17 »
wow....
    I noticed the periodic structure of the pattern too , I used  the FFT tool to get the phase and magnitude component. But I don't know how to due with the "pattern" in the magnitude component.
The pixel math processing is a little bit complicated for me . ;)
 Is there any way to export the magnitude or phase component so that I can use  PS or other editor to do the touch up and import back to Pixinsight ? The FFT tool and pixel math processing are very "powerful"  tools but it's a bit hard to use  .
 I'll ask my friend  for his permission for using his image  :)

thank you for your detail demonstration :)

Offline avan1

  • Newcomer
  • Posts: 23
Re: background gradient removal
« Reply #7 on: 2012 January 01 21:23:37 »
  Hi ,
   
              just got the reply from my friend , he is glad to have his picture to be used in the pixinsight documentation.

alan :)

Offline Ioannis Ioannou

  • PixInsight Addict
  • ***
  • Posts: 202
Re: background gradient removal
« Reply #8 on: 2012 January 05 01:07:47 »
Periodic image features are easily characterizable in the frequency domain, so this is a good candidate to find an efficient solution based on the Fourier transform.

YES !! The exact reason why I was looking for FFT process/script at the first time  ;)

Quote
This task is relatively easy with PixelMath:

Whooops, that hurts !!  :-[
I'm pretty sure I can figure out the above, if I spend some time looking with an empty look ( but for the moment I lost you)
.
How about using CloneStamp and ensure that both quadrants get the same corrections  ?
(or, better, a process/script that does what FFILL does in Iris ? - maybe with a preview ? >:D )

Clear Skies
John (Ioannis)

FSQ106N+Robofocus+QHY-22+SX USB wheel+Baader filters
SX OAG+DSI Pro guiding a NEQ6
PI for the rest :)

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: background gradient removal
« Reply #9 on: 2012 January 05 13:16:02 »
Quote
The FFT tool and pixel math processing are very "powerful"  tools but it's a bit hard to use

As Ioannis has pointed out, this can also be done with the CloneStamp tool in PixInsight. You'll find this tool under the Painting category on Process Explorer.

I realize that PixelMath can be difficult to use, especially with relatively complex expressions like the one I have used in this example. However, PixelMath is much easier to understand than what may seem at first. Here is a tutorial that I wrote some centuries ago:

http://pixinsight.com/tutorials/PixelMath/en.html

This tutorial is severely outdated but still provides good information to start using this powerful tool.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: background gradient removal
« Reply #10 on: 2012 January 05 13:17:41 »
Quote
or, better, a process/script that does what FFILL does in Iris ? - maybe with a preview ?

We have an interactive tool for Fourier transform manipulation in the to-do list. So many things to do, so little time...  :angel:
Juan Conejero
PixInsight Development Team
http://pixinsight.com/