mastrostack: a class to automatically align and stack astro-photography images
This class gets a list of images, and automatically determines bright stars as
control points. These are followed along pictures, and used to build an affine
transformation at constant scale (e.g. a rotation and translation). All images
are then stacked. The images can be given as file names (may include wildcards),
or matrices from e.g. imread, and support both RGB and gray images. As stars are
used for the alignment, this method is suited for deep sky images, but not for
This function does not make use of the phase correlation technique, but operates
directly on the images. It assumes that at least two bright stars remain on each
picture, but tolerate translations and rotations, as well as stars/control
points that appear/disappear on the field of view. The procedure also ignores
very sharp peaks, assuming they originate from dead pixels (and would then be
static over images, leading to traces).
It is highly recommended to specify a dark frame filename, which will be
subtracted to all images, in order to e.g. remove most hot/dead pixels. To get
such a 'dark', use your camera alone and shot once with the cap on, same
settings as the other pictures (duration, ISO). Image should be full black.
You may as well specify a flat frame filename, which will be divided to all
images, in order to counter vignetting (darker borders). To get such a 'flat',
shot once with the scope pointing at a uniform view (sky, white wall). Adapt the
duration so that you get a rather gray image (not full black or white).
ma = mastrostack;
start the user interface, without loading images (can be done afterwards)
ma = mastrostack(light, dark, flat)
loads light, dark (background) and flat (scope response) images, and label them.
Start with: ma=mastrostack;
Then press the Return key on the main interface. A Drop Files Here button
appears in the lower left side. Drag and drop your Dark, Flat and Light images
there. Images having 'dark' or 'flat' in their path/file name are marked as such
automatically. You may alternatively use the File menu items.
Supported image formats include JPG, PNG, TIFF, FITS. If you have installed
readraw, you may as well directly import RAW camera images. This is highly
recommended, as it retains much more information from the camera shot than the
generated JPEG images, which prooves to be essential for subtracting the Dark
image (background), and revealing faint objects.
Preparing the Stacking
After importing the files, you should label them using the 'Image/Mark as...'
menu items. You can navigate within images with the Image/Goto menu item, and
the arrow keys, or the mouse wheel. 'Bad' images can be skipped (ignored). To
use them back, set their type to 'light'. You should then compute the master
Dark and Flat images (Compute menu).
It is recommended to zoom onto specific features (e.g. a set of stars) to check
visually for their sharpness. Deselect the Zoom tool, and scan through images
using the left arrow key, and press the 'I' key to mark images to be ignored,
such as those blurred. To reset the plot, press the Return key.
You can select the Reference image, which will be used as template for stacking.
If not defined, the first image in the list will be used as such when stacking.
When ready, use the Compute/Stack menu item. If the Alignment has not been
executed previously, it is achieved for each image. The final image is then
shown and written to disk. Use e.g. Lightroom, RawTherapee, DarkTable to enhance
If you have difficulties in stacking (some images do not have enough control
points), relax e.g. the translation tolerance, using the menu item 'Compute/Set
tolerances'. You can also increase the number of control points. In case the
main interface is closed, get it back with: plot(ma)
Using commands (scripting)
% create Ma(e)stroStack and import images
% stack. The first 'light' image will be used as Reference for stacking
(c) E. Farhi, 2018. GPL2.
Compatibility with Matlab > 2014b. Fix for hot/dead pixels and peak width.
Compatibility for Matlab > 2014b
much faster initial import. Improved sharpness selection tool.
Win cash prizes and have your live script featured on our websiteLearn more
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.