← Scripts

PixInsight script

Continuum Subtraction

Removes the starlight (continuum) from narrowband images (CSub = narrowband − k · (broadband reference − median)) and blends it into your color image. Method A for galaxies with Hα knots, Method B for emission nebulae with several lines and a palette; embedded preview, magnifier, histogram, color result.

Preview: window of the Continuum Subtraction script in PixInsight
The script in PixInsight (click to enlarge).

The minimum version 1.8.9 is an assumption and has not been tested. I work with PixInsight 1.9.6. I cannot judge older versions.

Download ZIP (342 KB) Manual as PDF (1.3 MB)

Installation

Option 1: via the repository (recommended)

Set it up once and get updates directly inside PixInsight.

  1. In PixInsight open Resources › Updates › Manage Repositories.

    PixInsight: Resources > Updates > Manage Repositories.
    PixInsight: Resources > Updates > Manage Repositories.
  2. Copy the repository address (with the trailing slash):

    Copy the repository address from this page with “Copy”.
    Copy the repository address from this page with “Copy”.
  3. In the window click Add, paste the address and confirm with OK.

    Choose Add, paste the address and confirm with OK.
    Choose Add, paste the address and confirm with OK.
  4. The new entry is at the end of the list. Close the window with OK.

    The new entry is at the end of the list. Close with OK.
    The new entry is at the end of the list. Close with OK.
  5. Then choose Resources › Updates › Check for Updates. PixInsight downloads the repository information; the warning that the repository is unsigned is expected (see below).

    Resources > Updates > Check for Updates.
    Resources > Updates > Check for Updates.
    PixInsight downloads the repository information. Then tick the AoP packages you want and install them.
    PixInsight downloads the repository information. Then tick the AoP packages you want and install them.
  6. Tick the AoP packages you want and start the installation. Then quit PixInsight with File › Quit PixInsight: updates are applied only when it quits.

    Updates take effect only after a restart: File > Quit PixInsight, then start it again.
    Updates take effect only after a restart: File > Quit PixInsight, then start it again.
  7. Start PixInsight again. The script is now under Script > AoP Astro Suite > Continuum Subtraction. If the entry is missing, run Script › Feature Scripts › Regenerate once.

    After the update: Script > AoP Astro Suite lists the installed scripts.
    After the update: Script > AoP Astro Suite lists the installed scripts.

PixInsight warns that the repository is unsigned. That is expected: I do not (yet) have a signature from the PixInsight developers. PixInsight additionally verifies every package with a checksum. Do not also add the same script from another folder via “Feature Scripts › Add”, or the menu entry will appear twice.

Option 2: ZIP file by hand

  1. Download the ZIP and unpack it to a permanent location (not the Downloads folder: the script is loaded from there at every start).

  2. In PixInsight open Script › Feature Scripts….

    Without the repository: open Script > Feature Scripts…
    Without the repository: open Script > Feature Scripts…
  3. In the window choose Add and select the unpacked folder with the .js file, then Regenerate and Done.

    Feature Scripts: Add (choose the folder with the script), then Regenerate and Done.
    Feature Scripts: Add (choose the folder with the script), then Regenerate and Done.
  4. Start it via Script > AoP Astro Suite > Continuum Subtraction.

    After the update: Script > AoP Astro Suite lists the installed scripts.
    After the update: Script > AoP Astro Suite lists the installed scripts.

Update

  • Repository: Resources › Updates › Check for Updates, tick the package, install, and restart PixInsight. The update does not take effect without a restart.
  • ZIP: Unpack the new ZIP into the same folder and overwrite the old file, then run Script › Feature Scripts › Regenerate. Desktop icons belong to one specific file version and have to be created again afterwards.

Videos

The videos are hosted on YouTube. Only when you click “Load video” a connection to YouTube (youtube-nocookie.com) is made and data is sent there.

AoP Pixinsight ContinuumSubtraction Skript

Manual

The manual is on this page and as a PDF (German and English in one file). Download PDF

1. What the script is for

The script removes the starlight (continuum) from narrowband images so that only the pure emission signal remains: CSub = narrowband − k · (broadband reference − median). It guides you step by step through two workflows in one window and blends the result into your color image at the end.

  • Method A is for galaxies with fine Hα knots and plenty of empty sky. The CSub is blended into R, B (and optionally G and L).
  • Method B is for emission nebulae, also with little empty sky. Each line (Hα, OIII, SII) is processed separately and mixed into a palette.

An embedded preview with magnifier, histogram and A/B comparison shows every step before you calculate it at full size. Every field has a hover hint.

2. Requirements

  • PixInsight 1.8.9 or newer (developed and used with 1.9.6).
  • Linear images, all the same size: a color image (RGB) with stars and at least one narrowband image (Hα, optionally OIII and SII, each mono). Optionally your own mono images R, G, B as broadband reference and a luminance. Stretched images do not work; the script warns when the median is above 0.1.
  • Optional, depending on what you use: StarXTerminator or StarNet V2 for star removal; BlurXTerminator, NoiseXTerminator or MLDenoise as process icons that you created beforehand (the parameters come from your icon, the script does not set them). Without these tools you can skip the steps or choose an image you processed yourself.
  • All images must be open in PixInsight.

3. Installation

  1. Put the folder with AoP-ContinuumSubtraction.js at a permanent location (any folder; the script needs no particular path).
  2. In PixInsight: Script > Feature Scripts > Add, choose this folder, then Done. Alternatively run it once via Script > Execute Script File.
  3. Start it from Script > AoP Astro Suite > Continuum Subtraction.
  4. After an update, or if the menu entry is missing or outdated: Script > Feature Scripts > Regenerate (or restart PixInsight).
  5. A desktop icon (drag the triangle at the bottom right of the window, left of "show/hide preview", onto the PixInsight desktop) stores all settings, but belongs to exactly this file version. Create the icon again after an update.

The script is not signed; PixInsight may show a message at the first start.

4. Operation

Window and basic principle

The window has three parts: on the left the settings and the list of steps, in the middle the large preview with the display row above it, on the right the histogram, the magnifier with the values, the sections Background, White balance and Match, and at the very bottom the buttons and symbols. At the top right you choose Deutsch / English and the color design AoP Theme / PI Theme; the window reopens, all settings and results are kept, and the choice is saved.

Every step has a status: open, calculated (green), outdated (orange: something before it was changed, please recalculate) or skipped (grey). Every step creates its own image with an editable ID. The main buttons are Calculate step, Undo step (closes the result images of this step) and Next step (only switches, does not calculate). While a calculation runs, the status line shows an orange "Calculating …"; PixInsight does not respond for a moment (10 to 30 seconds per step at full resolution depending on image size, 1 to 3 seconds for the preview).

The window after step 1: steps and inputs on the left, preview with measurement area in the middle, chart and magnifier on the right.
The window after step 1: steps and inputs on the left, preview with measurement area in the middle, chart and magnifier on the right.

Step by step: Method A

  1. Choose and check inputs. Choose RGB (with stars), Hα and, if you have them, OIII and SII. Optionally mono R, G, B as reference and a luminance ("Blend in luminance"). At start the script looks for names such as "Ha", "OIII", "SII"; every field has a selector with all open images. The choice only swaps the image, all settings stay; intermediate results that depend on the old image are discarded and the steps become "outdated". "Reload image lists" reads the list again.
  2. Remove stars (optional). StarXTerminator or StarNet V2. Without star removal the script calculates with stars.
  3. Subtract continuum (CSub). Here you set the factor k (see section 6). The button "Suggest k from the image" measures a starting value.
  4. Denoise CSub (recommended). With a process icon, with an image you denoised yourself (for example from GraXpert), or skip.
  5. Background to zero. Subtracts the median (measured in the measurement area or in the whole image).
  6. Artifact threshold. Cuts off a small residue in the background. Start value 0 (no effect); the suggestion comes from the maximum of the background in the measurement area.
  7. Blend into R, B, G and L. CSub is added to the color image with factors: R + a · CSub (a = 2), B + b · CSub (b = 0.2), optionally G + g · CSub and L + c · CSub. You set the factors a, b, g, c (0 to 20) per line with the line buttons. The ratio b to a determines the hue: b = 0 gives pure red, one tenth to one third of a gives pink to magenta. All lines with a calculated CSub go into one common color image. The result names follow the lines (for example hARGB_CSub and LhA_CSub for Hα, hAO3RGB_CSub for Hα + OIII); a name you type yourself is kept. The selector "Combination" also offers HOO, HSO, SHO and OHS.

Afterwards, Finalize creates the finished images at full resolution (the button is in the last step next to "Undo step"). When all steps are calculated or skipped, a "Done" message with the image names appears once. The result images stay open in PixInsight.

Step by step: Method B

Above the preview are the line buttons (Hα – R, OIII – G+B, SII – G). Each line keeps its own settings and results. The checkbox "All lines" next to "Calculate step" runs the current step for all lines that have an image; check k and the reference of each line first.

  1. Choose and check inputs. As in Method A. Hα is required, OIII and SII are optional; a luminance is needed for the HaRGB luminance.
  2. Remove stars (per line). On by default: narrowband and reference are calculated without stars.
  3. Subtract broadband / PCS (per line). CSub = line − k · (reference − median). Start values: Hα k = 0.126 against R, OIII k = 0.158 against G+B, SII k = 0.129 against G. The stars must disappear in the CSub.
  4. Sharpen: BlurXTerminator (optional). Through your process icon (default BTX_Starless; if your icon has a different name, enter it). The script measures the median FWHM of the stars and enters it as PSF Diameter in the icon.
  5. Denoise: NXT / MLDenoise. Through your icon, with an image you denoised yourself, or skipped.
  6. LinearFit (optional, off by default). Matches a line to the reference line (default Hα); the reference line itself stays unchanged.
  7. Background level matching. Sets the median of every line to a common target level (0.0001). For nebulae that fill the whole image, set the measurement area to an empty part.
  8. Palette. Every line gets a hue and a contribution, and the lines are mixed per color channel. Palettes: SHO, HSO, HOO, OHS, HaRGB and custom hues; optionally the RGB image with the stars is mixed in with a midtone value.
  9. HaRGB luminance (optional). L + c · (Hα − level), default c = 0.5.

You can switch the method at any time; the state of the other method is kept.

Measurement area

By default the script measures median and level in an area on empty sky that it chooses itself (outlined in yellow in the preview). It looks for the calmest part without stars, nebulae and gradients and checks the RGB image and all lines at the same time. Further options in the section "Measurement of the median / level" (click to expand): Whole image (for almost empty sky), Take visible section, Take preview (a preview rectangle from PixInsight) and Choose automatically. An area that you set yourself stays. If the script finds no suitable sky, the info line gives the reason; then set the area yourself or switch to Whole image.

With the mouse: press Drag area and draw a rectangle in the preview (or Ctrl + drag for measurement area or background, Ctrl + Shift + drag for the white balance). Grab the frame in the middle to move it, grab edges and corners to resize. Minimum size 8 × 8 pixels. Green = measurement area or background, cyan = white balance. Show measurement areas hides the frames without deleting them.

Preview, magnifier and chart

  • Preview: zoom with the mouse wheel, pan by dragging, zoom rectangle with Shift + drag, right click = whole image. Also auto-stretch (display only, the result images stay linear), A/B comparison with blinking, clipping marks and Section 1:1.
  • Original resolution: the button "switch to original resolution" calculates the whole image at full size and zooms to 100 %. This is slow; from 36 megapixels the script asks first. A second click returns to the reduced resolution.
  • Magnifier: move the mouse over the preview; the magnifier shows the area enlarged (200 to 1600 %) with the position and the values R, G, B, L before the auto-stretch.
  • Chart: follows the step (CSub: scatter plot "line against reference (k)", denoise and sharpen: profile through the crosshair, otherwise histogram). The histogram follows the HistogramTransformation with zoom, panning, channels R, G, B, L and your own black and white points (white triangles; changes only the display).
  • Maps "share of CSub": show on a fixed scale how much of the signal above the sky comes from CSub.
  • Stretch A and B equally: when blending, the display stretch is determined from image A (without CSub) and applied to image B (with CSub), so the comparison shows exactly what CSub adds.

Color result

In the steps "Blend into R, B, G and L" (Method A) and "Palette" (Method B) the sections of the color result appear. They act only on the color result, not on the linear intermediate steps. Order: LinearFit → mixing → background → white balance → exposure → color controls (with SCNR). With the checkbox "also in the result image" a setting also applies to the created image, otherwise only to the preview.

  • Background neutralization: subtracts the difference of the sky levels from every channel so the background becomes neutral grey. In the "Background" row you can also choose the measurement area from an open preview.
  • White balance: aligns the mean values of R, G and B in an area (nebula or galaxy, without bright single stars). The area is chosen automatically, can be dragged with the mouse (cyan) or taken from a preview.
  • Exposure: sliders Exposure (EV) (−4 to +4) and a pair Offset | Gamma. Auto sets the values so that highlights and shadows are clipped as little as possible; Reset sets everything neutral.
  • Color controls: gain, gamma and one pair each brightness | contrast and saturation | vibrance (like the image adjustment in the Image Combination script). A double click on a slider resets it.
  • SCNR: three sliders R, G, B (0 to 100 %), method "average neutral". G at 50 % helps against the green cast of an Hα nebula.
  • Match (LinearFit): matches the channels to each other; only for linear data. The section is greyed out when it is not possible for the current combination, and the text gives the reason.

Templates and help

You can save your own settings as a template, load and delete it (without image names, stored in the PixInsight settings). The help field at the bottom left in some steps explains why and how; the help symbol at the bottom right (book) opens the complete help in its own scrollable window.

Warnings when blending

When blending, a grey line shows key figures, and a yellow warning triangle appears if you overdo it: Clipping (pixels run into white), Hα dominates (CSub is over 90 % of the signal of the knots), Oversaturation (knots almost single-colored), Luminance (CSub over 60 % of the signal). The limits are guide values; the check does not change the image.

Log file

Every session writes a log file for troubleshooting (AoP_ContinuumSubtraction_<date>_<time>.log, the last 10 are kept). Default folder: AoP-ContinuumSubtraction-logs in your user directory; it is created if it is missing. The path is shown in the PixInsight console at start. The button Show log (bottom right) shows the log in a window; Copy all puts it on the clipboard. In this window the row Log folder (from the next start) shows the path; Choose folder … changes it and Default restores it; the choice applies from the next start and is saved in the PixInsight settings. If a folder cannot be written, the script uses the default folder and then the temporary folder of the system; an error while writing the log never stops the script. The log is plain ASCII and stays in German.

5. Judging the result

  • Stars in the CSub: medium-bright stars should sink into the grey background. Stayed bright = k too small. Black or with a dark ring = k too large (too much subtracted). The brightest and saturated stars never cancel completely (seeing, halos, saturation); do not use them as a yardstick.
  • Real Hα structures: red itself contains Hα. A k that is too large takes real structures out of the CSub. Compare with A/B or blinking against the input to see whether filaments and knots are kept. When in doubt, use the smaller k.
  • Color: the ratio of the factors (Method A) or of the hues (Method B) determines the hue. The warning triangle and the "share of CSub" maps show whether you overdo it.
  • Done: the status line turns green with "DONE" when all steps are calculated or skipped.

6. The most important values

ValueMeaningStart value
khow bright the starlight in the narrowband is compared to the referenceMethod A: 0.42 (Hα against R); Method B: Hα 0.126, OIII 0.158, SII 0.129
Referencebroadband channel to subtract againstHα: R; OIII: G+B (mean); SII: G
Median / levelsky level, measured in the measurement areaautomatic area
Artifact thresholdcuts off a residue in the background0 (no effect)
a, b, g, cshare of CSub in R, B, G and L (0 to 20)Hα: a = 2, b = 0.2, g = 0; OIII: g = 1, b = 1; SII: a = 1
Target level (Method B)common background level of the lines0.0001
c (HaRGB luminance)share of Hα in the luminance0.5

Setting k correctly: k balances how bright the starlight in the narrowband is compared to the reference. In the step "CSub" tick "For setting k: preview with stars" (only needed if you removed the stars), set "Section 1:1" to an area with several medium-bright, unsaturated stars and change k until the stars vanish into the background. Untick again and "Calculate step"; the calculation always uses the starless images. The start values belong to the author's sample data; other filters, exposures and stacks need a different k. The values for OIII and SII are suggestions derived from the position of the lines in the spectrum and have not been verified.

Why SII against green? SII (672 nm) lies in the red filter. For Hα-strong objects, red itself contains Hα and is therefore not a clean reference for SII; green contains neither Hα nor SII. OIII (501 nm) lies between green and blue, hence the mean G+B.

7. Result images and settings

  • Result images: every step creates an image; the finished images (for example RGB_CSub, L_CSub or the palette images such as HOORGB_CSub) are created at full resolution with "Finalize". The names can be changed.
  • Helper images: intermediate preview images are named AoPCS_… and are removed when you close the script. For the mean G+B the script briefly creates a helper image AoPCS_ref_….
  • Stored settings (PixInsight settings): AoP_ContinuumSubtraction/language, …/theme, …/templates, …/logDir.
  • Script icon: the triangle at the bottom right (new instance) stores all settings in the icon.

8. Limits and known quirks

  • All input images must be the same size and linear. The script warns for stretched images and for images that are not 32-bit floating point.
  • The preview is a separate embedded preview; a script cannot drive PixInsight's Real-Time Preview.
  • The script does not set the parameters of BlurXTerminator, NoiseXTerminator, MLDenoise and StarXTerminator; they come from your process icons. If your BXT icon is not named BTX_Starless, enter its name.
  • The magnifier shows pixels of the preview image, not a live calculation.
  • Background neutralization and LinearFit in the color result measure on cropped copies (helper windows AoPCS_bn…, removed afterwards).
  • The k values are start values, not an automatic match. The suggestion "Suggest k from the image" tends to be too high for emission nebulae.
  • Typical messages and solutions: "All images must have the same size": crop or re-register the input images. "The script could not find a measuring area on free sky": set the area yourself or choose Whole image. "No process icon given" or "The process icon … was not found": check the icon name in the step. a message about no stars detected ("not linear, or too little signal"): use the linear version of the image. Stars remain in the CSub: raise k; black rings: lower k.
  • The English texts have not been reviewed by a native speaker.
  • The script was tested outside PixInsight with a mock (logic, formulas, interface, language switch, log). Some parts of the interface are not yet confirmed inside PixInsight for this version (layout and start size, frames with the mouse, white balance, SCNR, exposure with Auto, preview selection, log folder dialog).

9. Change log

  • v0.6.4 (21 Nov 2026) Even more space between rows and between section title bars and their fields; the preview lines up with the histogram after every step change.
  • v0.6.3 (21 Nov 2026) More space between the rows in all steps; all input and selection fields in the left column line up (including "Luminance (optional)" in step 1); three console warnings fixed.
  • v0.6.2 (21 Nov 2026) In the measurement section all four buttons are in one row; the German button label was shortened (English "Take visible section" unchanged).
  • v0.6.1 (21 Nov 2026) "Measurement of the median / level" is always expanded at start, "Drag area" sits above "Delete area", and all labels in the left column have the same width so that selectors and input fields start on one line.
  • v0.6.0 (21 Nov 2026) Layout, look and operation aligned with the Image Combination script (v0.16.1); calculation and outputs unchanged: dark violet section title bars (AoP Theme), all selectors and buttons without keyboard focus, color controls and exposure in pairs (brightness | contrast, saturation | vibrance, offset | gamma), triangle "new instance" at the bottom right, help in its own window, row "Log folder" in the log window as there.
  • v0.5.1 (21 Nov 2026) No fixed log path any more: the log goes to your user directory by default (AoP-ContinuumSubtraction-logs) and the folder can be set in the window "Show log". License line in the header. Release folder with this manual.
  • v0.5.0 (21 Nov 2026) Section "Exposure" (EV, offset, gamma, Auto). Rows "Background" and "White balance" with preview selection. Fewer frames and patterns in the interface (buttons and selectors without focus frame in the AoP Theme).
  • v0.4.0 to v0.4.2 (21 Nov 2026) Color design AoP Theme / PI Theme, measurement areas with the mouse, white balance, SCNR, Match (LinearFit), image selector for every input image.
  • v0.3.x (November 2026) All lines (Hα, OIII, SII) at once, color result, histogram, magnifier, warning triangle, log, German/English, color combinations HOO, HSO, SHO, OHS.
  • v0.1 and v0.2 (November 2026) Method A and Method B.

10. Author and license

Script by Thomas ArtOfPix Großschmidt · Vibecoding with ClaudeAI. Free of charge, no warranty and no liability. Redistribution only unchanged and with attribution.

The methods are own implementations without borrowed code. "Method A" and "Method B" are own names for two approaches seen in tutorials. Models for the calculation paths are PhotometricContinuumSubtraction (Charles Hagen / NightPhotons) and NarrowbandHueCombination (Jürgen Bätz).

Licence and liability

Free to use, without warranty and without liability: I accept no liability for damage or data loss. Redistribution only unmodified and with attribution (Script by Thomas ArtOfPix Großschmidt · Vibecoding with ClaudeAI). All other rights remain with me. This is not an open-source licence. For bugs or wishes please write to me via the contact page.

Checksum (SHA-256) of the ZIP file: 09ac9b67c4f27b2c56df14fa872bf0474efa5628dfc1185ae00332f1137736c6

← Scripts