Stargazers Lounge Uses Cookies

Like most websites, SGL uses cookies in order to deliver a secure, personalised service, to provide social media functions and to analyse our traffic. Continued use of SGL indicates your acceptance of our cookie policy.

Welcome to Stargazers Lounge

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customise your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

  • Announcements




Algorithm to stack astronomical images

4 posts in this topic

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 trough 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 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. 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?

Clear Skies,


Share this post

Link to post
Share on other sites

Posted (edited)

Aren't you reinventing the wheel?

This is what stacking/alignment algorithms already do.

Have you tried searching for scientific articles on the matter? (Not necessarily astro related). Juan Conejero if Pleiades Astrophoto wrote about this. His article is burried somewhere in the PixInsight web site / forum. Most likely the latter, in the section about new updates and features.

Due to minor geometrical defects (field curvature) of the optical system, stacking involves geometrical stretching of the images, to get the triangles to fit.

This is one reason why dss users sometimes complain of 'weird behaviour' in the corners of an image.

Good luck.

Edited by wimvb

Share this post

Link to post
Share on other sites

Posted (edited)

Yeah I know that there are already programs. I just want to write my own one as some "small" free time project. I know that there is some distortion on the edge of the images. That's the reason why a create triangles out of nearby stars and allow some tolerance in the side length of those triangles.

Pixinsight uses the RANSAC algorithm, however I use a different approach. In general my version also achieves good results - see the attached image - but it has some flaws building the initial "lookup structure". And I guess that's only a questions of how to select the stars per triangle. There are a lot of papers out there, but most of them are not within my free time schedule. :D - Like it said, I guess I just need some hint on which stars I should create my triangle. I have the following data of each star: position, FWHM on x and y axis and maximum brightness (but I could also calculate average brightness over occluded pixels). The question is how to use this wisely.

2017-03-25 22_22_42-.jpg

Edited by Hellstorm

Share this post

Link to post
Share on other sites

Sorry, can't help you any further. (Other than this:)

PixInsight has a tool to calculate the point spread function of stars. When using this tool it is recommended to exclude too bright (obviously) and too dim stars. Do you do something similar in your process? Probably FWHM and brightness is a way to achieve the same.

(and THAT's really all I can think of)

Good luck with your project, and keep us informed on your results.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By artoleus
      The struggles of a beginner learning how to use the equipment.  :-)
      Pointed mount North and Levelled EQ6 pro mount 8:30 pm Attached wireless release, 2" nose and UHC filter to Nikon DSLR Attached scope and camera, balanced scope for camera use Collimated the telescope -took 40 minutes of messing around Waited until dark.  Took the dogs for a walk around the field to pass the time Polar aligned using the mobile app and sighting against Ursa major. Rebalanced DEC for eyepiece rather than camera 3 star alignment. 1st star was way off and took ages to get it in the eyepiece Restarted 3 star alignment. - Selected a star behind a house. Restarted 3 star alignment -complete. Checked collimation using a bright star - perfect (should bloody be after 40 minutes!)  Tried to fine adjust polar alignment using a method discovered online (not drift- I don't think I have the patience.)  Didn't work. Restarted 3 star alignment then used the polar alignment on SynScan Took a look at Jupiter was great to look at but not what I set out to do, I want DS images... Attached camera Used live view (LV) to try to focus stars Pointed the scope at M3 and took a 2 minute exposure Tried again with a 4 minute exposure SD card failed.  Lost some family pics, grrr Now I have to explain to my partner that it wasn't because of Astronomy, these things just happen.  Replaced SD card Took some cautious 1 minute exposures of M90 expecting the camera to explode Pictures were faint so moved to 4 minute with a little more confidence telling myself SD card failures can just happen. Noticed star trails Located a bright star Decided to give PEC training a try.  Couldn't do it with an eyepiece. Tried with the camera in LV but noticed some gradual movement in the DEC axis. Hoped PEC training would sort this.   Moved onto the Spiral Galaxy Took some 2 minute exposures of the whirlpool galaxy.  Wireless timer worked flawlessly. Still a little faint so up'd the ISO and took some more.  More detail but more noise. Took some darks with the same settings. Packed away while the camera did its thing. Viewed the pics briefly on laptop. There was star trails (DEC axis again and blurring) Went to bed 1:30 am  
      So what have I learned?  Well DEC error was probably due to the balance of the scope being off.  I never did re-balance for the camera. I've also learnt today that I should bias the balance slightly East so the gears engage better.
      PEC training is a waste of time without an illuminated reticule which I don't have the desire to buy.   I'd rather save for a guide scope and guide camera.   I've learned I can refine the polar alignment after the 3 start alignment process. 
      I've also read on forums that perhaps I should manually move the scope to the first alignment start then continue with the usual process. I've also seen that two star may be the way forward for EQ6.  So perhaps next time I'll start with a 2 star, polar align using the SynScan handset then back to 3 star with the first manual adjustment.
      I should also purchase a few SD cards that are dedicated for Astrophotography and upload them ASAP after the session.
      The Astronomik UHC Deep Sky Filter worked wonders with the images for where I live.  I can now take longer exposures.  Assuming I sort out DEC errors and invest in guiding rig. 
    • By wimvb
      Well, not really actually. For some reason the stacking process produced this strange image.

      Most likely the image registration process aligned on hot pixels. And since the camera (Liverpool Telescope) is used in two orientations (90 degrees rotation), this was the result.
      Two colliding galaxies. Or is that three colliding galaxies? Or four?
    • By mike005
      NGC 2014 and Dragon's Head nebula in the Magellanic Cloud ( LMC ) not far from the Tarantula Nebula by Mike O'Day ( ).
      This image shows multiple bright nebula and star clusters in an area adjacent to the The Tarantula Nebula ( NGC 2070 ) in the nearby irregular galaxy, the Large Magellanic Cloud ( LMC ). The largest of these are the bright pink nebula in the mid-right part of the image ( NGC 2014 ) and the blue nebula in the lower middle ( NGC 2030 ).
      Updated image - reprocessed to impove colour balance ( April 15th )

      ( please click / tap on image to see it larger and sharper )

      ( click on image to see larger and clearer ( grrr... image compression in version above  ))
      This is the first image captured as part of a new image capture and processing workflow I am trying out...
      Roger Clark ( ) has a number of articles addressing colour processing and the performance of modern DSLR sensors.  The "take homes" for me have been:
      1. With a modern sensor ( one with on-sensor dark current suppression technology ) one may not need to capture dark frames ( in order to remove the now non-significant pattern noise ).
      2. "Correct" white balance processing should start by using "daylight" RBG channel multipliers ( to get the star colour 'right') and any histogram adjustment to improve white balance of darker parts of the image should involve aligning the left side of histogram curves ( ie. not the peaks )
      So, the workflow to produce the image above involves calibraiton with Superbias & Master Flat but no dark frame subtraction (neither post nor in-camera).  Roger Clark speaks of using a "bad pixel map" as the basis of reducing hot pixels.  I have not figured out how to produce one yet.  However, with a little bit of dithering during guiding ( and the very busy image ) the hot pixels that are in the image below are not too overwhelming.
      With regard to colour balance; I tried using the "daylight" factors reported by the camera but these resulted in an image and stars that were quite blue.  This image was based on the factors reported by DXOMark for the Nikon D5300 ( R x 2.12, G x 1, B x 1.49 ( D50 standard )).  This was better but I still felt the need for a final tweak in Photoshop ( colourBalance Highlights +15 Cyan/Red, -5 Magenta/Green ) to improve the colour in the stars and mid-tones.
      { DXOMark "white balance scales" for D5300 found at: on the "color response" tab }
      Bright Nebulae:
      NGC 2014 ( upper right, pink) size 30 x 20 arcmin Mag +8
      NGC 2020 size 2.0 arcmin ( small blue-green oval nebula )
      NGC 2030 
      NGC 2032 ( Dragon's Head nebula - blue, central bottom of image )
      NGC 2035 size 3.0 x 3.0 arcmin 
      NGC 2040 size 3.0 x 3.0 arcmin 
      Open clusters:
      NGC 2004 size 2.7 arcmin Mag +9.6
      NGC 2011 size 1 arcmin Mag +10.6
      NGC 2021 size 0.9 arcmin Mag +12.1
      Annotated :

      Image centre RA 05h 33m 32.362s, Dec -67° 32' 18.145" ( 
      Orientation: up is west, right is South 
      Field of view (arcmin): 58.8 x 39.2
      Scale (full size image) 0.585 arcsec/pixel
      Telescope: Orion Optics CT12 Newtonian ( mirror 300mm, fl 120mm, f4 ).
      Corrector: ASA 2" Coma Corrector Quattro 1.175x.
      Effective Focal Length / Aperture : 1410mm f4.7
      Mount: Skywatcher AZ Eq6 GT
      Guiding: TSOAG9 Off-Axis-Guider, Starlight Xpress Lodestar X2, PHD2 
      Camera: Nikon D5300 (unmodified) (sensor 23.5 x 15.6mm, 6016x4016 3.9um pixels)
      Format: 14bit NEF
      Noise reduction: off
      Filter: none
      HDR combination of seven sets of exposures (20 & 22 Feb 2017):
      58 x 240 sec ISO 800
      8 x 120 sec ISO 800
      8 x 60 sec ISO 800
      8 x 30 sec ISO 800
      8 x 14 sec ISO 800
      8 x 7 sec ISO 800
      8 x 3 sec ISO 800
      Pixinsight: 26 Feb 2017
    • By Adaaam75
      Hi guys,

      Okay so I have a few questions regarding my AVX mount that have basically generated from me reading up on setting up my mount. Please don’t think I’m lazy, I have read up a lot regarding my new mount (hence the questions) and learned a lot so far but as I’ve only had the mount a week and due to work and time constraints I have been unable to do any more than literally unpack the mount and put it together. I should mention it took 30 minutes to flatten all the cardboard ready for Mr Recycling Man but the more packaging the better so no complaints there at all!!
      So, my questions are so I can have a one stop shop answer reference rather than trying to remember where all the tips were on this wealth of knowledge forum. Please excuse my ignorance, I’ve had my trusty Sky Watcher 130p AZ2 for 6 years so I’ve not just jumped in blind .....
      1)    Why is there a necessity to ensure the mount is facing the correct direction when setting up the scope?
      2)    I’ve heard similar comments made with regard to members permanent piers in their observatories, again, what is being referred to here and how would you ensure a circular steel pier IS facing a correct direction?
      3)    Does the peg on the tripod Base plate need to be directly over one of the legs or is it fine where it is positioned? (In between two legs)
      4)    Is there anything I should do during daylight hours other than align the (finderscope) in preparation for the alignment process?
      5)    Do I need to update my mount with the latest firmware (?) Software upgrade or can I assume as I bought it 3 weeks ago it will come up to date?
      6)    HOW do I update my firmware software?
      7)    How accurate does the declination need to be? Can I work off the (slightly crude) scale on the mong or should I be looking at getting a digital spirit level for accuracy?
      8)    With vibration in mind, until I sort out a permanent pier my scope will be on the tripod in the observatory, should I allow the tripod legs to stand on the soft flooring foam tiles or should it be on the wooden floor of the shed?
      9)    Do I need to worry about leaving my spanking new scope and mount exposed to the elements, all be it under a waterproof bike cover in the obs and secure? Slightly nervous 😐
      I really appreciate your time in both reading and hopefully replying with some useful guidance!
      All the best, looking forwards to those clear skies!
    • By Astrofriend
      I was asked on a Swedish forum to put an "Astronomical Dictionary" on my homepage. I have made a test page in an easy form. Astronomical related words linked to wikipedia.
      It aims to the beginners in astronomy so it should not be too complicated words.
      Let me know if it's useful and and I shall add more words.