Aligning images for KStars
Well, it took more time to debug the code than to write it!
The problem is that, with the increased number of stars that KStars is going to display, image misalignments become more vivid. Images should be rotated, scaled and offset appropriately, so that stars in the field of photos of galaxies match their corresponding catalog stars that are drawn by KStars.
I found out that it takes about an hour to manually align an image, so I had no choice but to write a program to suggest the operations automatically. This program accepts an input that looks like
!PA filename imagewidth imageheight
- basically a map between the current coordinates of a point on the image and the target coordinates. The program just uses one of those standard formulas to do a least-sum-of-squares fit and decides the correct rotation, scaling and offset to do to get the image align to the stars, and then chalks out the image magick commands required to do that.
The PA is currently redundant, and some features are not working. Comment on this blogpost if you are interested in the very dirty, badly written, make-shift code that does this.
At the other end, I patched KStars to do some tricks so that it outputs the coordinates of a point when I press a certain key. The bug that took me a long time to fix was that I had been very dumb in translating the (x, y) on screen to the (x, y) on the image, and forgot to take into account the change in orientation as time passes. So I just needed to measure position angles with the correct, standard reference (i.e. line towards NCP).