<p>Have a look at <a href="https://www.astromatic.net/software/scamp" rel="nofollow noreferrer">SCAMP</a> for astrometry and <a href="https://www.astromatic.net/software/swarp" rel="nofollow noreferrer">SWarp</a> for stacking. Like the software mentioned in the other answer, both are open source, so you can check what algorithms they use.</p>

<p>SCAMP documentation is <a href="https://www.astromatic.net/pubsvn/software/scamp/trunk/doc/scamp.pdf" rel="nofollow noreferrer">here</a>, with an explanation of the algorithm in chapter 6.7 (page 25). There's also a short <a href="http://adsabs.harvard.edu/abs/2006ASPC..351..112B" rel="nofollow noreferrer">paper</a>, but the manual seems more thorough.</p>

<p>Note that the software is written with wide-field multi-CCD mosaic detectors in mind, so what they do might be overkill for what you have in mind.</p>

CC BY-SA 3.0
2017-05-21T09:07:32.870Z
2017-05-21T09:07:32.870Z
Alex
<p><a href="https://pixinsight.com/doc/tools/StarAlignment/StarAlignment.html#description_003" rel="nofollow noreferrer">This page about a commercial product</a> goes into some detail about their algorithm.  It does the triangle matching you describe, with something like simulated annealing to get a more optimal solution.</p>

<p>The accepted answer to <a href="https://astronomy.stackexchange.com/q/14551/14434">this closely related question</a> recommends <a href="http://hugin.sourceforge.net" rel="nofollow noreferrer">Hugin panorama software</a>; it's open source, so you should be able to glean the algorithms used.</p>

CC BY-SA 4.0
2019-01-26T00:27:42.583Z
slightly related; ImageJ and its plugins are used for biology mostly but may work on astronomical images. The fluorescent imaging techniques often produce images with many tiny dots on a black background. https://biology.stackexchange.com/a/80795/27918
uhoh
CC BY-SA 3.0
2017-05-20T18:12:07.493Z
2017-05-20T18:12:07.493Z
antlersoft
<p>I'm looking for a simple algorithm to compare astronomical images (of the same sky region) against each other, compute their movement and rotation, to finally stack them.</p>

<p>At the moment I'm already having a more or less working algorithm. First I extract all the stars out of an image (including information like brightness and FWHM), and then I walk through all the resulting "points" and create triangles out of the current point and those two other stars that have the shortest distance to this star.</p>

<p>This list of triangles is created for every image. After this I take one image as a reference and then I walk through the list of triangles in the reference image to find a triangle in the other image with the same length of each side of the triangle (I also "allow" some tolerance due minimal relative differences of the star positions in each image). For this matches I calculate movement and rotation relative to the reference image. The last step is to find the matched triangles that have to same relative movement and rotation like the other matches. This is done by calculating the standard deviation, sorting out triangles that are not within 1 or 2 sigma and repeat this process until I have a very small standard deviation.</p>

<p>The last part, finding "valid" triangles with the same movement/rotation, is working fine. The problem is that sometimes I have only like 2 or 3 "valid" triangles out of 300 initial triangles. All other triangles have side lengths different to those of the reference image. </p>

<p>So I assume it's the way I generate my initial triangles which causes the problem. Sortings stars by their brightness and using this data to generate the triangles also doesn't work. So is there a better way to create the initial triangles in all the images?</p>

CC BY-SA 3.0
2017-05-19T20:08:33.157Z
When you say it is the same sky region, does this mean you have significant overlap between the images (like if you are trying to remove atmospheric jitter), or are you trying to do something like stitch images together to make a mosaic out of a lot of partially-overlapping images?
Dave
CC BY-SA 3.0
2017-05-20T08:47:16.163Z
Yes they overlap significantly. I could also say it's exact the same region with normally less than 10 pixels movement. You can also compare different recording sessions where you have a bit more movement and also some rotation - but the major part of the area is visible in each image. By stacking the images I want to minimize the background noise (high SNR) and also get a higher value of color bits per channel.
HellstormDe
<star><photography><algorithm><alignment>
Algorithm to stack astronomical images
HellstormDe
# Algorithm to stack astronomical images

(Asked by: username_0 on 2017-05-19)

I'm looking for a simple algorithm to compare astronomical images (of the same sky region) against each other, compute their movement and rotation, to finally stack them.

At the moment I'm already having a more or less working algorithm. First I extract all the stars out of an image (including information like brightness and FWHM), and then I walk through all the resulting "points" and create triangles out of the current point and those two other stars that have the shortest distance to this star.

This list of triangles is created for every image. After this I take one image as a reference and then I walk through the list of triangles in the reference image to find a triangle in the other image with the same length of each side of the triangle (I also "allow" some tolerance due minimal relative differences of the star positions in each image). For this matches I calculate movement and rotation relative to the reference image. The last step is to find the matched triangles that have to same relative movement and rotation like the other matches. This is done by calculating the standard deviation, sorting out triangles that are not within 1 or 2 sigma and repeat this process until I have a very small standard deviation.

The last part, finding "valid" triangles with the same movement/rotation, is working fine. The problem is that sometimes I have only like 2 or 3 "valid" triangles out of 300 initial triangles. All other triangles have side lengths different to those of the reference image.

So I assume it's the way I generate my initial triangles which causes the problem. Sortings stars by their brightness and using this data to generate the triangles also doesn't work. So is there a better way to create the initial triangles in all the images?

**Tags:** star, photography, algorithm, alignment
> **Comments:**
> **username_1**: When you say it is the same sky region, does this mean you have significant overlap between the images (like if you are trying to remove atmospheric jitter), or are you trying to do something like stitch images together to make a mosaic out of a lot of partially-overlapping images?  
> **username_0**: Yes they overlap significantly. I could also say it's exact the same region with normally less than 10 pixels movement. You can also compare different recording sessions where you have a bit more movement and also some rotation - but the major part of the area is visible in each image. By stacking the images I want to minimize the background noise (high SNR) and also get a higher value of color bits per channel.  

---

## 2 answers

### Answer by username_2 on 2017-05-21. Score: 3

Have a look at [SCAMP](https://www.astromatic.net/software/scamp) for astrometry and [SWarp](https://www.astromatic.net/software/swarp) for stacking. Like the software mentioned in the other answer, both are open source, so you can check what algorithms they use.

SCAMP documentation is [here](https://www.astromatic.net/pubsvn/software/scamp/trunk/doc/scamp.pdf), with an explanation of the algorithm in chapter 6.7 (page 25). There's also a short [paper](http://adsabs.harvard.edu/abs/2006ASPC..351..112B), but the manual seems more thorough.

Note that the software is written with wide-field multi-CCD mosaic detectors in mind, so what they do might be overkill for what you have in mind.


---

### Answer by username_3 on 2017-05-20. Score: 3

[This page about a commercial product](https://pixinsight.com/doc/tools/StarAlignment/StarAlignment.html#description_003) goes into some detail about their algorithm. It does the triangle matching you describe, with something like simulated annealing to get a more optimal solution.

The accepted answer to [this closely related question](https://astronomy.stackexchange.com/q/14551/14434) recommends [Hugin panorama software](http://hugin.sourceforge.net); it's open source, so you should be able to glean the algorithms used.

> **Comments:**
> **username_4**: slightly related; ImageJ and its plugins are used for biology mostly but may work on astronomical images. The fluorescent imaging techniques often produce images with many tiny dots on a black background. https://biology.stackexchange.com/a/80795/27918  

---

