ASTROTNSTACK align and stack astro-photography pictures

Automatically align and stack astro-photography pictures
434 Downloads
Updated 16 Apr 2018

ASTROTNSTACK: automatically align and stack astro-photography pictures.
This function 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 stacked over the first image used as reference. 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 planetary imaging.

This function does not make use of the phase correlation technique, but
operates directly on the raw 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).

During the procedure, the current image and its stars/control points are
indicated, as well as the stacked image. A waitbar indicates the progress.
To abort the procedure, close the waitbar. The stacked image so far will be
saved and returned.
Supported image formats include JPG, PNG, TIFF, FITS.

The resulting stacked image is stored using the first/reference image name,
adding '_stacked', in the PNG format. This routine can stack a hundred 4k
images within 15 minutes. Memory requirements are about 2Gb for 4k images.

We recommend that you further use DarkTable or RawTherapee to enhance the low
intensity features (black, brightness, contrast).

Syntax: [stacked, output] = astrotnstack(images, dark, flat, N)
stacked = astrotnstack;

input:
images: a filename name or cell of file names, that may include wildcards, or
matrix (rgb, gray). When not given or empty, a file selector pops-up.
dark: a single dark frame which is subtracted to all images.
When not given or empty, a file selector pops-up. Use 'cancel' button
to proceed without dark subtraction.
flat: a single flat frame which is divided to all images.
When not given or empty, a file selector pops-up. Use 'cancel' button
to proceed without flat normalisation.
N: the max number of control points to use. N=20 default.

Input can also be given as a structure with fields:
N: max number of control points (default is 20)
tol_rot: rotation tolerance in degrees (default is 3 deg)
tol_trans: translation tolerance (default is 0.01 = 1% of width)
test: when 1, images are analysed, but result is not written.
silent: when 1, no image/wait bar is displayed (faster).
dark: indicates dark frame (single image)
flat: indicates flat frame (single image)
images: images to stack (filename, may use wildcard, or matrix)

or even as unsorted name/value pairs such as in:
[stacked, output] = astrotnstack('images','*.JPG', 'dark','Dark.PNG', 'N',15)

output:
stacked: stacked images.
output: a structure with the file names, rotations and translations.

Example:
astrotnstack('*.PNG', 'Dark.png', 'Flat.PNG');
astrotnstack({'*.PNG', imread('file.jpg') }, 'Dark.png', 'Flat.PNG');
astrotnstack('*.PNG', 'Dark.png', 'Flat.PNG', 'silent', 1);

Credits: http://nghiaho.com/?page_id=671

See also:
LxNstack https://sites.google.com/site/lxnstack/home
Deep Sky Stacker http://deepskystacker.free.fr/french/
Rot'n Stack http://www.gdargaud.net/Hack/RotAndStack.html
DarkTable http://www.darktable.org/
RawTherapee http://rawtherapee.com/

E. Farhi Dec 2017 GPL2. Version 1.6.3

Cite As

Emmanuel Farhi (2024). ASTROTNSTACK align and stack astro-photography pictures (https://github.com/farhi/astrotnstack), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes
1.6.3.0

fixed support for FITS images and documentation.

1.6.2.0

now hosted on GitHub.

1.6.1.0

Fix 'silent' mode.

1.6.0.0

Now also support gray images, as well as filenames and matrices from e.g. imread.

1.5.4.0

Support for uint8/uint16 images. Better search for control points (stars). Allow silent mode (faster).

1.5.3.0

Compatibility with Octave

1.5.2.0

back to a single file 'all in one' easier to carry around.

1.5.1.0

support for FITS. Indicate supported file formats.

1.5.0.0

handle flat field normalisation. Inline functions moved to 'private'.

1.4.0.0

Display metrics from the transformations

1.3.1.0

enhance contrast in stacked image

1.3.0.0

final image as PNG 16 bits

1.2.0.0

more robust rotation determination

1.1.0.0

improved search for stars/control points

1.0.0.0

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.