Algorithm to stack astronomical images

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?

• 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 May 19 '17 at 20:08
• 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 May 20 '17 at 8:47
• I assume you're familiar with astrometry.net? It doesn't answer your question but may help. – user21 May 20 '17 at 15:19