Removing Light Pollution Gradients Without Eating Your Target
Background extraction is the step most likely to damage an image while appearing to improve it. Here's what goes wrong, and the one rule that prevents it.
Gradient removal is the step where more astrophotographs are quietly damaged than any other. Not because it is hard, but because when it goes wrong the result still looks processed — flatter, cleaner, more deliberate — and the damage hides inside the improvement.
Here is what the step actually does, the specific way it fails, and how to tell the difference.
What a gradient is
Your sky is not uniformly bright. A town on one horizon, the moon somewhere, twilight not quite gone, your own optics delivering less light to the corners than the centre. All of it lands as a smooth, slowly varying brightness across the frame.
Two things make this worth removing rather than living with.
Stretching amplifies it. A gradient barely visible in linear data becomes dominant once you have pulled the faint end up. The stretch does not know which brightness is sky glow and which is nebula; it lifts both.
It corrupts the black point. The final background level is set by moving the image’s median to a target. With a gradient there is no single sky level to move — half the frame ends up too dark and the other half too bright, whatever value you pick.
The one rule
Fit the surface to sky, and only to sky.
That sounds obvious and is the entire difficulty. Background extraction works by sampling the frame, deciding what the sky level is at each sample, fitting a smooth surface through those samples, and subtracting it.
A sample taken in the middle of a nebula reports the nebula’s brightness as “the sky level there.” Fit a surface through those and the surface rises to meet your target. Subtract it, and you have dug a bowl out of the object.
If you have ever run background extraction and ended up with a dark halo around your galaxy, or a nebula that looks like it is sitting in a shallow crater, that is exactly what happened. The correction did precisely what it was told; it was told to treat the target as sky.
The fix is not a gentler setting. It is excluding the samples that are standing on the object — take the low envelope of the sample levels, since sky is the darkest thing in any frame, and drop the samples that sit significantly above it.
Why low order is the right answer
Once your samples are sky, the second question is how much freedom the fitted surface gets.
A first-degree surface is a plane: one tilt across the frame. Second-degree handles a dome — vignetting, or a single light source off one corner. Third-degree handles an off-centre dome. Beyond that you are giving the model enough freedom to start following your target.
That is the trade. Too little freedom and a complex gradient survives. Too much and the surface follows real structure and removes it.
Low order wins because light pollution genuinely is smooth. It is a broad glow from a source many kilometres away, and it does not have edges, filaments or dust lanes. Anything in your frame with structure at that scale is signal. A polynomial that cannot express structure is a feature: it cannot eat your nebula, whatever the samples say.
I have tried the more flexible alternative — a surface smoothed through the sky samples with no assumed polynomial form. On a sky with two light domes pulling from opposite corners it genuinely beat a cubic, leaving the background substantially flatter. But at a bandwidth narrow enough to do that, it also followed a large nebula and dug the crater described above. Widening it until that could not happen left it worse than the cubic on the very sky it was built for.
That is a real result and worth stating plainly: flexibility you cannot control is not an improvement. Unless you have a genuine object mask, low order is the honest choice.
Subtract the slope, keep the level
One more detail that separates a natural result from an obviously processed one.
The correction should remove the surface’s deviation from its own mean, not the surface itself. Remove the slope; keep the overall level.
A pure subtraction drives your background toward zero, and a black background is one of the clearest tells of over-processing. Real sky is never black. It is dark grey with faint structure emerging from it, and an image whose background reads as pure black has usually had its faintest real signal removed along with the gradient.
The nightscape exception
If your frame contains a landscape — a Milky Way shot over a ridge, a foreground of trees or buildings — everything above needs qualifying.
The gradient model describes the sky. The ground is a different subject that happens to share the frame. Subtracting a sky gradient from a silhouetted ridge just darkens the ridge in a pattern that has nothing to do with it.
Worse, the ground corrupts the fit. A dark silhouette across the bottom third reads as “very dark sky” and drags the surface down there, which then over-brightens the actual sky above it.
The horizon has to be found before the gradient is fitted — and not by brightness. A moonlit hillside is brighter than the sky above it; a silhouette is darker than any part of it. Brightness gets it backwards in both directions.
The reliable discriminator is stars. Sky has point sources scattered through it at whatever density your lens and exposure reached. Foreground does not — a ridge, a tree or a building is a large connected region with no points in it, however bright or dark it happens to be.
Telling a gradient from a cast
These two get confused constantly, and the fixes are different.
A gradient is spatial. One region brighter than another. Fixed by fitting and subtracting a surface.
A cast is uniform. The whole frame tinted, because one channel sits above the others everywhere. Fixed by a per-channel shift — and it must be a shift, not a scale. Shifting moves the sky to a common level and leaves every difference above it exactly as it was, so your nebula keeps its colour while the sky loses its tint. Scaling drains the object along with the background, which is why “just turn down the red” produces a grey, lifeless nebula.
Most light-polluted frames have both at once. Correct the cast first, then the gradient, then set the black point — because setting a level against a background that is about to move is wasted work.
Do it on linear data
All of this belongs before the nonlinear stretch.
A gradient is an additive property of linear data. Once you have applied a stretch, that addition has been mapped through a curve, and subtracting a smooth surface afterwards no longer removes it cleanly — you are fitting a distorted version of the problem.
The practical version: calibrate, remove the gradient, correct the colour, then stretch. If your workflow stretches first because that is when you can finally see what you are doing, the corrections will never quite land, and you will spend the rest of the session fighting residuals that a different ordering would have removed outright.
A checklist
- Linear data. Before any stretch.
- Sky samples only. Exclude anything standing on the object.
- Low order. Linear, quadratic or cubic. Not more.
- Keep the level. Remove the slope, add the mean back.
- Nightscapes: find the horizon first, from where the stars are.
- Once, not twice. A second pass fits mostly noise and object, and starts removing signal.
That last one catches people. If a gradient survives one properly-fitted pass, another pass is not the answer — the surface is the wrong shape, or your samples were contaminated. Running it again just takes a bite out of the target.
Try it on your own data
Akastroid does everything in this guide automatically, and tells you what it did.
Download Akastroid — free