Page 1 of 1

Solar animation automatic alignment tool - imgalt

Posted: Sat Apr 26, 2014 4:10 pm
by GreatAttractor
New solar imaging season has started and I'd rather avoid the least pleasant aspect – manual alignment of tens of time-lapse animation frames. Fortunately I've recently found an elegant algorithm (http://en.wikipedia.org/wiki/Phase_correlation) for detecting image translation, which can be widely varying, the images severly cropped, in other words – exactly what we get after a few hour solar session with telescope buffeted by wind, drift due to imperfect polar alignment and lack of manual correction in time etc.

I've created a tool implementing this approach, and so far results are satisfying, both for white light and H-alpha.

before:
unaligned1.gif
unaligned1.gif (473.56 KiB) Viewed 13164 times
after:
aligned1.gif
aligned1.gif (527.92 KiB) Viewed 13164 times
before (animation by warpal http://astropolis.pl/topic/39586-slonce ... ntry533305):
unaligned2.gif
unaligned2.gif (853.73 KiB) Viewed 13164 times
after:
aligned2.gif
aligned2.gif (902.57 KiB) Viewed 13164 times

The program takes all BMP files (mono or color, 8- or 24-bit) found in input directory (folder), aligns them and saves with new names (with "_aligned" suffix). It's a command-line program, but can also be run directly without using the command prompt (console):

- either copy BMP files to be aligned into the the directory where imgalt.exe is located, then run imgalt.exe: output (aligned) files will appear in the same directory,

OR

- drag folder with input BMPs and drop it onto imgalt.exe icon; after a moment the aligned files will appear in whatever directory was current at the time (e.g. under Windows, when dragging the folder "d:\astro\sequence1", output images should appear in "d:\astro")

Detailed usage description and building instructions can be found in the README file.

Latest Windows version (imgalt.zip) and source code (imgalt-src.zip) can be found here:
http://stargazerslounge.com/blog/1400/e ... 54-imgalt/

Binaries and source code may be freely distributed and used for any purpose.

Re: Solar animation automatic alignment tool - imgalt

Posted: Sat Apr 26, 2014 4:13 pm
by GreatAttractor
The workflow I use:

- align animation frames (i.e. sharpened stacks) with imgalt
- open aligned frames in GIMP (File->Open as Layers...)
- crop (select area, Image->Crop to Selection, this crops all layers), equalize layers' brightness if needed etc.
- export (File->Export as..., choose GIF, use "As Animation" option)

If you have frames in format other than BMP, they can be quickly mass-converted in IrfanView (File->Batch Conversion/Rename...). If you only have an animated GIF you'd like to reprocess, it can be split into BMP frames in VirtualDub (open the GIF, then File->Export->Image sequence...).

Re: Solar animation automatic alignment tool - imgalt

Posted: Sat Apr 26, 2014 6:09 pm
by marktownley
Good stuff! Thanks for this.

I'll let the thread get a bit of exposure in the main forum and then put it in the library in a day or so...

Re: Solar animation automatic alignment tool - imgalt

Posted: Sat Apr 26, 2014 6:38 pm
by Wah
Hi GreatAttractor,

I have roughly looked into the source code, I wonder why using the last frame as reference rather than the first frame as reference?

Thanks!

Wah!

Re: Solar animation automatic alignment tool - imgalt

Posted: Sat Apr 26, 2014 8:14 pm
by robert
Many thanks for sharing, it looks very interesting
Robert

Re: Solar animation automatic alignment tool - imgalt

Posted: Sat Apr 26, 2014 8:26 pm
by GreatAttractor
Wah,
Actually no single frame is used as reference. Translation is always detected between two subsequent frames. Indeed, the translation vector for n-th frame is always stored with respect to the first frame, but that's just for knowing what's the bounding box of all (translated) frames in the end. Then, on the second pass, each frame is loaded again, translated and padded to have the size of the bounding box. (In the next update I might add an option to automatically crop all images to the smallest common area instead of padding).

Re: Solar animation automatic alignment tool - imgalt

Posted: Sat Apr 26, 2014 10:37 pm
by swisswalter
Hi Filip

that is fantastic and when I read you are planing to automatically crop the images to the smallest common aerea my hart jumped up. Please have me to have the Gamma or Beta Version at least ;)

Re: Solar animation automatic alignment tool - imgalt

Posted: Sun Apr 27, 2014 2:59 am
by James0057
SUNTASTIC animation ...great job !!

Re: Solar animation automatic alignment tool - imgalt

Posted: Sun Apr 27, 2014 3:18 am
by Wah
Hi GreatAttractor, what I mean should be "last / previous processed frame" vs. "first frame of the whole sequence".
I can see some shift in one of your demo animations, which should be caused by the current algorithm, can this be solved by using the first frame?
Or the rapid change of solar surface will destroy the accuracy of alignment by using the first frame as reference only?

Maybe you can consider giving user an option to choose using which algorithm :roll:

Re: Solar animation automatic alignment tool - imgalt

Posted: Sun Apr 27, 2014 7:10 am
by Houghy
do they have to be BMP files - can the software handle Tiffs and jpegs?

Re: Solar animation automatic alignment tool - imgalt

Posted: Sun Apr 27, 2014 8:38 am
by GreatAttractor
Wah,
You're right, I think that if I tried to find the translation always with respect to the first frame, the shifts would be even worse - due to surface features changing. I will be testing some other ideas for better alignment though, perhaps a second pass with "block matching" or another phase correlation on a small, most contrasty fragment.

Houghy,
Only BMPs, I wanted to keep the file-operating part small and w/o dependence on ext. libraries. (I might add them some time later).

Neo,
But you'd still need to end up with 8-bit depth for final publication. Of course, you do all processing in 16-bit, but then you can just use imgalt as one of the final steps.

Re: Solar animation automatic alignment tool - imgalt

Posted: Sun Apr 27, 2014 12:29 pm
by Wah
Another thought, can there be a parameter that change reference frame after every k (eg. 10) frames being processed? Maybe larger the number, less the shift?

BTW, can the shift value be sub-pixel?

Re: Solar animation automatic alignment tool - imgalt

Posted: Sun Apr 27, 2014 2:33 pm
by GreatAttractor
Wah,
I might try the parameter. As for detecting subpixel translation, I'm already working on it; at first to just refine the current 1-pixel translation, later I'd like to add a true subpixel translation (with neccessary interpolation) of output images.

Re: Solar animation automatic alignment tool - imgalt

Posted: Fri May 02, 2014 9:14 pm
by GreatAttractor
New version 0.4:

- cropping output images to their intersection, i.e. the largest common area (for padding to bounding box instead, use --no-crop parameter)
- fixed translation of output images, which caused chaotic 1-pixel jittering

Coming soon: reading and saving of 8- and 16-bit TIFFs (not compressed).
Coming not so soon: subpixel alignment and "stabilize using the limb" mode for prominence and limb sunspot animations.

Download from http://stargazerslounge.com/blog/1400/e ... 54-imgalt/

Re: Solar animation automatic alignment tool - imgalt

Posted: Sat May 03, 2014 5:45 am
by swisswalter
Hi Filip

thank for running a head. Soon I'll have to jump in too ;)

Re: Solar animation automatic alignment tool - imgalt

Posted: Sat May 03, 2014 6:50 am
by edobosz
Good job! This looks like a very useful tool.
Ted

Re: Solar animation automatic alignment tool - imgalt

Posted: Sat May 03, 2014 6:52 am
by marktownley
I can see i'm going to have to give this a try at some point ;)

Re: Solar animation automatic alignment tool - imgalt

Posted: Sun May 04, 2014 2:46 pm
by Montana
Excellent :bow :bow :bow

Alexandra

Re: Solar animation automatic alignment tool - imgalt

Posted: Mon May 05, 2014 9:32 pm
by GreatAttractor
I had some TIFF code lying around, so here it comes...

New version 0.4.1:
- support for TIFF files (8 and 16 bits per channel, mono or RGB, not compressed)

Download from http://stargazerslounge.com/blog/1400/e ... 54-imgalt/


Mark, perhaps this thread could be now moved to the Solar Reference Library section?

Re: Solar animation automatic alignment tool - imgalt

Posted: Mon May 05, 2014 10:06 pm
by marktownley
Sure, no problem :)

imgalt - version 0.5

Posted: Thu May 22, 2014 6:28 pm
by GreatAttractor
New version 0.5 of imgalt can be downloaded from http://stargazerslounge.com/blog/1400/e ... 54-imgalt/. New feature: sub-pixel alignment. Processing time is unaffected (sub-pixel translation is deduced from the data that was already calculated), though saving of output images takes a bit longer.

The difference in alignment is not huge; the output is still fluid frame-to-frame, however the long-term "drift" of the image is somewhat reduced.
Also, the interpolation required for sub-pixel translation results in some slight blurring of output images (only if you have sharp, 1-pixel details), though in most cases this shouldn't be an issue. Example:
example.gif
example.gif (326.44 KiB) Viewed 12937 times
Sub-pixel alignment can be disabled by using --no-subpixel parameter.



Mark, could you add this post to the main imgalt thread: http://solarchat.natca.net/viewtopic.php?f=7&t=11283

Also, is it possible to give users permission to reply there? I intended that thread to be also a place for any features/issues discussion.

Re: Solar animation automatic alignment tool - imgalt

Posted: Thu May 22, 2014 6:50 pm
by marktownley
Thanks for the update, and thanks for sharing on solarchat!

Merged as requested, as far as I can see replies are active - well I can - can other people?