Starry Vistas by Don J. McCrady

Gradient Subtraction Without Clipping

Gradients are one of the most difficult problems to deal with in an astrophoto.  One of the most effective ways to deal with them in Photoshop is to make a second image that contains only the gradient, and subtract it from your target image.  A common and mostly overlooked problem with gradient subtraction is that it can frequently clip the faint features of your image.  First I’ll discuss a couple ways to create the gradient, and then I’ll discuss a simple modification to gradient subtraction that avoids clipping.

Drawing Gradients using Photoshop’s Gradient Tool

This method makes use of Photoshop’s Gradient Tool to manually draw a gradient that approximately matches that of your target image. 

The first step is to measure the gradient in your image.  Use the Color Sampler tool to measure the background at two points:  roughly where the background is maximum, and where the background is minimum.  In this example, the gradient is linear, brightest near top-left and dimmest near bottom-right.  The two color samplers are placed such that a line connecting them follows the direction of the gradient.

Colour samplers measuring the gradient

Now look at the "Info" pane for the actual color values at the points you've sampled:

Colour sampler

To construct a roughly equivalent gradient, we now need to set the foreground color to sample #1, which is R:36, G:47, B:40.  Set the background color to sample #2, which is R:14, G:6, B:9.

Now create a new layer in Photoshop using “Layer / New / Layer…” and give it a descriptive name like "Gradient".

New layer dialog for our gradient

Now choose the Gradient tool from the, click the "Linear Gradient" button, and choose "Foreground to Background" as the style.  Make sure your "Gradient" layer is the active drawing layer.  To draw the gradient, click on sample point #1 and drag a line until it connects to sample point #2, and then release the mouse button.

Drawing a gradient line in the direction of the gradient

When you release the mouse button, the "Gradient" layer will be painted with a gradient that roughly matches that of your target image.

Artificial gradient

If your monitor is calibrated, you can probably see the chief drawback of this approach.  Although the gradient is a pretty good approximation to that of the target image, Photoshop's gradient tool suffers from an effect called banding.  This is because Photoshop's gradient tool fades from foreground to background colors in steps whose sharp boundaries are often easy to discern.  The "dither" checkbox on the tool doesn't appear to help very much either.  Nevertheless, this method of creating gradients is still useful when other methods fail.

Extracting Gradients from the Target Image

This method works very well in situations where it's easy to remove all target features from your target image, leaving only the gradient.  This example of M41 is one such target that lends itself well to this approach.  If we can remove the stars and the star cluster, then theoretically all we will be left with is the gradient.  Even better, the gradient will not be approximation as in the Gradient Tool method above, it will be an exact representation of the target image's gradient.

The first step, then, is to duplicate the target image, and paste it as a new layer.  Give this layer a descriptive name, like "Gradient".  Make sure this new gradient layer is the active layer, and then choose "Filter / Noise / Dust & Scratches".  Choose a radius somewhere around 20 so that most of the stars disappear; experiment and try not to overdo it.

Using Dust & Scratches to get a more accurate gradient

You may have a few very bright stars or dense star clusters that are not completely removed by this method, so judicious use of the "Clone Stamp" tool can be used to eliminate any remaining artifacts.  A bit of extra Gaussian blurring may also help, but again, don't overdo it.

This method produces very good gradient representations.  However, it can be extremely difficult to remove all target objects if the field contains very large nebulae or galaxies.  It can be done, but it is often easier to use the first Gradient Tool method and just deal with the banding.

Subtracting the Gradient Layer

Whichever of the above method you used, you now have a layer called "Gradient" that you need to subtract from the target image.  Here's where you should pay very close attention to the histogram.  Click the "eye" to the left of the "Gradient" layer to deactivate it and hide it.  The original target image should show through, including its gradient.  Take a look at the histogram:

Histgram before subtracting the gradient

Note the slope to the left-hand-side, rising from zero (black) to a hump where most of the image's target information lies.  The slope on the left-hand-side means that the image hasn't been clipped.

Now activate your "Gradient" layer, and change its blending mode to "Difference".  Here's where most gradient subtraction methods end.  Looking at the resulting image, the gradient does seem to be under control now and the background is relatively flat.

Simple gradient subtraction can cause clipping

However, the background is now a little too black.  And if we now examine the histogram, we find that it's been pulled right up to the left-hand-side.

Simple gradient subtraction can cause clipping

The rising slope on the left-hand-side is gone, and there's a good chance we've clipped some faint detail.  The problem with this simple subtraction is that it doesn't leave us enough "headroom" prior to subtraction.  Fortunately, there's a very simple solution.  Prior to subtracting the gradient layer, we must add a small constant amount to the original target image to prevent the gradient subtraction from producing dead black pixels.

Select the "background" layer containing your target image, and then create a new layer using “Layer / New / Layer…” and give it a descriptive name like "Offset".  The "Offset" layer must come after your background layer and before your "Gradient" layer.

Adding an offset layer prevents clipping

Now change the foreground color to a low gray color like R:10, G:10, B:10.

Choosing the offset amount

Choose the "Paint Bucket Tool" from the toolbox.  Click on the new "Offset" layer and paint it with the foreground color.  Now change the blending mode on the "Offset" layer to "Linear Dodge".  This will, in effect, add 10 to every pixel in the original target image.  Now, with all three layers active, the histogram looks much better:

Histgram with offset: no more clipping

The slope is back, very little if anything has been clipped.  The background is still very even, just a bit brighter.  You might choose to darken it a bit in final processing if it's noisy, but that entirely depends on your image.

You can choose higher values for the offset layer if you want more headroom for further processing. Note, however, that if your image contains very bright details, such as the core of a galaxy or the trapezium region of M42, adding too much in the offset layer can actually cause clipping on the other side of the histogram.  It goes without saying, then, that you should pay close attention to the histogram at every step of your processing.