Skip to content

Instantly share code, notes, and snippets.

@vaslabs
Last active January 14, 2022 06:58
Show Gist options
  • Save vaslabs/30efb1cd9361291509f1862f009f924c to your computer and use it in GitHub Desktop.
Save vaslabs/30efb1cd9361291509f1862f009f924c to your computer and use it in GitHub Desktop.
Astronomy image stacking scripts
# I'm running fedora but these tools are available on all OSes
# Hugin: http://hugin.sourceforge.net/
# Gimp: https://www.gimp.org/
# ImageMagick: https://www.imagemagick.org
dnf install hugin
dnf install gimp
dnf install imagemagick
# do merge_images Plus/Bumpmap/Screen etc (http://www.imagemagick.org/Usage/compose/)
merge_images() {
merge_mode="$1"
image_pattern="$2"
image_list=$(ls $image_pattern)
first_image=$(echo $image_list | cut -d ' ' -f 1)
cp $first_image temp.jpg
for img in $image_list; do
composite temp.jpg ${img} -compose "$merge_mode" temp.jpg
done
mv temp.jpg result.jpg
}
#I found that this is the best way so far to automate image cropping
simple_fuzz() {
sensitivity=$1
image_pattern=$2
for img in $(ls $image_pattern); do
convert $img -flatten -fuzz $sensitivity -trim +repage OUT_$img
done
}
#So if you put all the images in a specific folder you can do for example
simple_fuzz 65% *.JPG
merge_images Plus OUT*.JPG
# These two simple commands merge multiple images together (it's called image stacking).
# I've found that these parameters take care of the alignment of the point of interest.
# The out is the prefix for the resulting tiff images
# I've only tried a handful of parameters, the one I'm showing here I've found after I got
#a big light-trail instead of the point of interest. This combination worked quite well.
# -C Auto crop the image to the area covered by all images
# -i Optimize image center shift for all images, except for first.
align_image_stack -m -a OUT ${IMAGES} -C -i
# When the script finishes, you can combine all the stacks in one image with enfuse which comes with hugin installation
# I haven't played yet with the enfuse parameters but I'll update as soon as I find more.
enfuse --exposure-weight=0 --saturation-weight=0 --contrast-weight=1 --hard-mask --output=final_result.tif OUT*.tif
# Then you can use gimp to try some filters to further enhance the image.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment