Astro Stacking with G'MIC?

I just took some photos of the Milky Way, expecting to align/stack with Registax for better SNR, but Registax keeps telling me I’m out of memory, and I cannot get it to stack.

So now I’m wondering whether G’MIC has any such capabilities. I’m basically looking for a semi-automated way to align/rotate the pictures so that the Milky Way lines up correctly, then set the blending mode to Average or Median, or something along that line. Is there any such thing?

I would give align_image_stack from the Hugin suite a try, or use Hugin directly if the images are too problematic and align_image_stack does not give you a good result.

You can start with this command:

align_image_stack -s 0 -x -y -a aligned_ [list_of_files_to_align]

You might want to add the -d switch if the input images are not corrected for lens distortion, however I am not sure if the distortion can be estimated precisely from a set of images that overlap by a large extent…

Maybe I’m just too dumb, but I’ve never gotten Hugin’s CLI to work for me… :frowning: Of course, it’s been a while since I tried it.

YAY! I actually made it work! It remember now that I always got the error “C:\Program File” is not a command" or something like that. My quick and dirty workaround was to copy the necessary .exe and .dll files to the same folder as the photos, then run them all from the same folder. I’m sure that’s not the recommended way, but it worked for me!

Now does G’MIC have a way to set the blending mode for all layers, or will I have to do it all manually one-by-one in GIMP?

I have never done that myself, but I guess that @David_Tschumperle and @patdavid have some experience in averaging or median stacking several images… I remember a thread about that in this forum, but I could not find it again…

Yes, search for “super resolution”… I think the most recent discussion was my post about image stacking to simulate long exposure though… Anyway, the truck is to do the blending with imagemagick, using and averaged or median blend mode. Don’t have time to look it up for you now, but will be back later and can post then (if someone else doesn’t do it before then!)

G’MIC can do median stacking which I’d recommend if you have just a few images (maybe up to 10), you can find it under layers/Blend [median] set input layers to all. If you have more images you want to use more advanced techniques for calculating the true value while rejecting outliers/noise. Look at Siril for doing that.

align_image_stack never worked for my astro shots either and I haven’t found a way to mask off the foreground so I just use hugin to mask and align. A bit of a pain but it works decently well. Reminds me that I should still write that astro tutorial. -.-

Edit: Just read that you are memory constrained, try Siril in that case, they do some more clever batching to work with the memory that’s available IIRC.

Thanks, @Jonas_Wagner, I did find G’MIC’s median/average blend filters. The “Average” filter chokes with a memory error if I try to do all 13 full-res files. I guess I can do a couple of pictures at a time till they’re all done though…

align_image_stack seems to work pretty well for me!

If it meets your stacking needs, I would suggest enfuse, also in the Hugin suite CLI, documentation on Have been using it for improving resolution and exposure and have not experienced it failing due to lack of memory.

To average/median a stack with several images without having memory issues with G’MIC, you should try commands -average_files and -median_files, as described in this post :

Thanks David, that’s what I needed! Just one small problem: It works just fine for .jpg files, but I could not get it to work with .tiff files. :frowning: Hugin’s align_image_stack outputs .tiff files, so it would be nice to be able to stack those files without having to convert back to .jpg.

@RT-Noob whenever reporting problems, always make sure that you have provided enough information for others to go by. Here you said “I could not get it to work”, but you didn’t say what the problem was - that’s not helpful. Show your command, and upload the TIFF in question using e.g.

I suspect your tiff files to be 16bits tiffs ?
I’ll probably have to handle this specific case in these commands.

Thanks for the reminder, @Morgan_Hardwood, I should have thought of that myself! :blush:

Now this is weird! I tried it again so that I could get a screenshot to show what was wrong, and now it works! :frowning:

I can get it to average the .tif files and output a perfectly good .jpg file. However, when I try to output a .tif file, it puts out a 250MB file that is blank. GIMP just shows it as transparency. (The input files are 25-26MB each.)

@David_Tschumperle, I don’t think the .tif files from Hugin are 16-bit, but I could be wrong. Does G’MIC have a way to identify whether it’s 8-bit or 16-bit?

Hugin will output whatever bit depth is input; 16 bits in will result in 16 bits out.

1 Like

ImageMagick/GraphicsMagick do:
identify foo.tif

1 Like

Thanks, that’s good to know! The Hugin output is 8-bit, but the G’MIC output is 32-bit! That’s why I can’t read it!

Can G’MIC average 16-bit files and output to another 16-bit file? It would be nice to keep all the data I can, since I’m working with 14-bit RAW files in the first place.

This is the case if you use imagemagick too. I believe it has something to do with the way tiff handles alpha channels. Tiff images can have color/channel information interleaved in three ways, by pixel, by line, or by band. These result in the data being stored very differently in the actual file. I don’t know if interleaving is the culprit here, but that was my first idea when I found this while averaging over an series innimagemagick. My main experience is from mulriband satellite imagery, and interleaving is often a source of these problems. But since I found it worked with jpeg or PNG, I never delved any deeper…

The command -average_files and -median_files were indeed buggy with 16bits files. This should be fixed now, after an update of the G’MIC commands :

$ gmic -update

(I assume you are using version 1.7.5_pre, otherwise, it won’t work).
After the update, computing the average and median of a sequence of 16bits tiff should work as expected.

Also, please note that by default, G’MIC saves .tiff files as 32bits float-valued files, and unfortunately, there are very few viewers that recognize this format (it is still a mystery for me, as this is a legacy tiff format).
You can force the output tiff files to be saved in 16bits in G’MIC, by specifying ushort after the filename, like this :

$ gmic -w -median_files test16bits\*.tiff -o result_16bits.tiff,ushort

Let me know if all work as I hope it will :slight_smile: