Combine Ha with OIII using a Heaviside step function

I was using Adobe Photoshop for some time to combine Ha and OIII grayscale images. An alternative solution was the math function of SiriL, but I was never happy with the results when combining Ha and OIII grayscale images to an RGB image using simple formulas like R = Ha, G = x*OIII, B = (1-x)*OIII. The first step to good results was a blog in 'The Coldest Nights': PixInsight: Dynamic narrowband combinations with PixelMath, which provided a better solution for the GREEN channel.

 

This came close to a vision I had - try to boost OIII if it is above a certain level, even if the Ha signal is larger. One could do that by programming or scripting, but how can this be achieved using simple maths formulas?

 

From my physics lectures I remembered the Heaviside step function which would serve the need - y = 0 for x <= 0, y = 1 for x > 0, but this function is not implemented in PixelMath. However, there is an approximation for the step function (Logistic Function) which has a major advantage: it allows a smooth transition and thus a combination of Ha and OII values instead of a binary filtering. A parameter can be used to control the sharpness of the transition.

 

So I started to develop a PixelMath setting, based on the following requirements:

  1. RED channel should be 100% Ha
  2. GREEN channel - I was not sure, but finally ended up with the proposal from 'The Coldest Nights'
  3. BLUE channel should be OIII, but with additional boost if a) the OIII value is higher than a lower limit and b) lower than an upper limit and (most important) c) larger than the Ha value +- a selectable threshold.

 

With this, the BLUE channel can be calculated by 

 

 

Hint: Always use symbols in PixelMath. This helps a lot when playing around with the values, as they all can be set in the Symbols tab.

 

Let's have a look at the individual components:

boost - Obviously with boost = 0 we return to the standard approach of BLUE = OIII. The boost factor allows additional OIII signal, making the OIII more dominant (visible at all). In my images, I typically set the boost factor somewhere between 1.0 and 1.5.

mix - This factor controls the smoothness of decision between OIII or Ha. If we set diff = 0 and mix >> 1, the BLUE channel will be set to OIII if and only if OIII > Ha. This can result in harsh color changes in the image. A mix of 10 to 30 would be a good choice.

diff - In most of my images, OIII was hardly larger than Ha for any pixel (don't forget, that a linear fit of the grayscale images is always good practice). The Ha signal is more dominant in most nebulae. The diff factor allows raising this threshold. Assume OIII = 0.5 and Ha = 0.6, thus OIII - Ha = -0.1, resulting in a 0 (or very small) value of the approximated Heaviside function. With e.g. diff = 0.3 we can raise this threshold, allowing more OIII signal to pass. Actually, we reduce the Ha dominance as OIII - Ha + diff * Ha = OIII - Ha (1 - diff).

slope - This parameter is used to provide a smooth decision between rejection of OIII value. The include parameter defines the lower limit for OIII values to contribute to the boost, allowing very small Ha values to become visible again where OIII is too faint. The reject parameters acts the same way but as an upper limit and was implemented to avoid stars becoming part of the OIII boost. Since I am using Starnet++ for removing stars prior to the Ha/OIII combination (see here), I am setting this parameter to 1.

 

Playing around with these parameters can lead to results which are tremendously different - so why bother using this formula if it is still not exact science? For me, the major advantage is reproducibility and the integration into a PixInsight or SiriL workflow. Once I decided on a set of parameters which produces a nice result, I can always go back and create the same image again. This was hardly possible in Photoshop.