Gradient Removal with Photoshop
A number of people have been trying to eradicate gradients in their pictures and various methods have been mentioned of doing this.
Possibly the most common tool is Gradient Exterminator, closely followed nowadays by Pixinsight’s Dynamic Background Extraction. I have not used either of these but they both suffer from a similar problem; If you fail to identify the gradient accurately the software will not help you.
The method outlined below has the same basic problem but at least it is free (with Photoshop!), quick and easy to use and has many other uses. Helpful hints are in Italics.
A Quickmask selection, whether gradient or not, is merely a simple and quick
way of selecting various sized areas of the picture, in general using the brush,
gradient or paint bucket tools. You then switch back to Edit in Normal Mode
(letter 'Q' is a toggle for this function) to see the selection outline.
If you make a selection with the brush I strongly recommend using a hard brush (100% hardness) 99% of the time. Any requirement to expand, contract or feather the selection is best done in normal mode. This way you never have to worry about the selection outline having different degrees of feathering due to changing the brush size. (Note: the softer the brush the more the feathering will be visible when in normal edit mode. The brush tool outline (even in precision) does not show you the effective softness of the brush edges. That means the effective degree of feathering).
Now, to get back to the business of gradients in the finished picture and how you get rid of them!
First of all, the gradient put there by external lighting, the Moon or whatever follows the simple rule; light falls off as the inverse of the square of the distance. All you need to do is identify where the gradient starts and finishes and construct a gradient selection that tapers off to nothing in the right place.
To do this first select Quickmask and then the right type of gradient tool. At the top of the screen you should see various types of gradient, typically radial, linear, angle, reflected and diamond. All of these can be altered to Foreground to Background, Foreground to Transparent or various other less useful options. A Linear gradient and Foreground to Transparent is the one we want here.
(Note: You can use Foreground to Background and Alt Click in the picture to pick up specific colours. This can be useful when used on a layer to eradicate coloured gradients, ie, those which change colour as well as showing a gradient).
The gradient selection is made by simply placing the cursor at the brightest point due to the gradient and dragging towards the point where the gradient disappears. This can be from any edge or corner and generally towards the centre. You need to drag at right angles to the ‘edge’ of the visible lighting gradient. It can help to study the picture via the Channels Palette as this generally shows up single colour gradients better. Select either the R, G or B channel and adjust your selection to suit. This stage is really critical; it must be done right or you will add another gradient. Once you have done it once it becomes child’s play.
(you need the colour of quickmask to contrast with your picture. Default is red which is not much use for nebula so Double Click on the quickmask button near the bottom of the tool bar and click on the small coloured square. Then choose your colour from the colour picker. Green and Blue both work well for astro).
Use the Radial gradient and drag from the centre after carefully choosing the foreground and background colours. This can help to mask hot spots due to poor flat fielding.
When you release the mouse the Quickmask gradient will spring into view. Hitting ‘Q’ again will show you the conventional selection outline but be aware that this dotted line (where you released the mouse) shows where the selection is at 50%. Where you started to drag the selection is 100% and the 0% mark is well outside the selection and is not visible. Remember too that if you feather a selection to a high value the entire selection outline could disappear. That does not mean that your selection has disappeared, merely that it is all less than 50% selected.
It follows that if you reduce the opacity the selection might start at, say, 70% or some other value. You can use this feature to reduce the steepness of your gradient selection in order to tackle a weak gradient.
Once the selection is made and you have switched to normal edit mode (letter ‘Q’) you can tackle the gradient using Curves to reduce the brightness in either the composite RGB channel or any individual channel as you please.
Depending on what exactly you are trying to achieve you can make the adjustment using a straight line or use a gamma shift that might more closely follow the inverse square law.
Be sure to measure the different areas of the picture and suspected gradient using the Info Palette so as not to get carried away. I use the second set of readings in the Info Palette, the first set is in RGB, the second in HSB; it is the brightness figure you should use.
Various similar fixes can be used to lighten or darken any part of the picture,
using layers if you so choose. Sometimes adding a gradient layer and using a
gentle blend mode can work wonders. You can add slightly darker borders or brighten
a specific part of the picture to focus the viewers attention on the features
you want them to look at. Be careful, a few percent difference in brightness
is all it needs.
Shown below are some examples of how all this is done using a picture of the California nebula.

The pictures number from 1 to 5 (left to right, top to bottom) and show the
various stages.
1 The original
2 An artificial gradient introduced with the yellow arrow pointing at the 'interfering'
light source.
3 A quickmask gradient dragged from the base of the green arrow to close to
the arrowhead.
4 The selection outline on show. Note the edge is at right angles to the direction
of the gradient.
5 Same as 4 but after darkening using Curves. The Curve shown is typical and
should not be followed slavishly. Each picture will need different treatment.
So, with care you can adjust the gradient with a quickmask selection in respect of its severity, colour, and direction. None of this should be done using layers although you might like to use a duplicate. If so, do the job and then flatten using Normal blend mode.