BackgroundSub plugin

Background subtraction on an image.

Plugin Type: Local

BackgroundSub is a local plugin, which means it is associated with a channel. An instance can be opened for each channel.


This plugin is used to calculate and subtract background value. User draws a shape (e.g., annulus) to define the region from which background is calculated. In the “Attributes” box, parameters controlling the calculation can be adjusted. As user modifies the region or changes the parameters, background value would be recalculated accordingly. Optionally, if a data quality (DQ) extension is available, pixels marked as “not good” can be excluded from calculations as well. Subtraction parameters can be saved to a JSON file, which then can be reloaded.

Finally, if desired, the calculated background can be subtracted off the displayed image in Ginga. However, the subtracted image only exists in an in-memory cache in Ginga; if the cache fills up, Ginga will eventually eject the image if it is not being viewed. To save the subtracted image out to a different file, use the SaveImage (Save File) plugin in Ginga. Currently, this only handles constant background, therefore unsuitable for when background has a gradient or a pattern.

It is customizable using ~/.ginga/plugin_BackgroundSub.cfg, where ~ is your HOME directory:

# BackgroundSub plugin preferences file
# Place this in file under ~/.ginga with the name "plugin_BackgroundSub.cfg"

# Color of the background region outline and label
bgsubcolor = 'magenta'

# Default background region properties. Can also be changed in the GUI.
# bgtype can be 'annulus', 'box', or 'constant'
bgtype = 'annulus'
annulus_width = 10

# Default calculation parameters. Can also be changed in the GUI.
# algorithm can be 'mean', 'median', or 'mode'
algorithm = 'median'
sigma = 1.8
niter = 10

# If set to True, only use good pixels for calculations.
# This is only applicable if there is an associated DQ extension.
# Can also be changed in the GUI.
ignore_bad_pixels = False