Skip to content

Instantly share code, notes, and snippets.

@vi
Created July 22, 2015 23:42
Show Gist options
  • Save vi/f6183c269a11eec713a4 to your computer and use it in GitHub Desktop.
Save vi/f6183c269a11eec713a4 to your computer and use it in GitHub Desktop.
Make pseudo-HDR photo from a bunch of input JPEGs using GraphicsMagick, ImageMagick, pfsalign, enfuse and bash
#!/bin/bash
INS=("$@")
OUTNAME="${INS}_${INS[${#INS[@]}-1]}.png"
# 1. Sort images in order of increasing brightness
declare -a LEVS
for i in "${INS[@]}"; do
LEVS+=($(
gm convert -quality 0 "$i" png:- |
convert png:- -scale 1x1 txt: |
perl -ne '/^\s*0\s*,\s*0\s*:\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)[0-9,\s.]*\)/ and print $1+$2+$3,"\n"'
))
done
ORDER=($(echo "${LEVS[@]}" | tr ' ' '\n' | nl -v 0 -p -ba -s ' ' -w 1 | sort -k2 -n | awk '{print $1}'))
declare -a SORTED_INS
for i in ${ORDER[@]}; do
SORTED_INS+=("${INS[$i]}")
done
TIFFS=("${SORTED_INS[@]/%/.tiff}")
echo Sorted ins: "${SORTED_INS[@]}"
echo Sorted tiffs: "${TIFFS[@]}"
# 2. Align images
pfsin "${SORTED_INS[@]}" | pfsalign -v --crop=min -s 8 -f | pfsouttiff "${TIFFS[@]}"
# 3. Enfuse
enfuse --output=$OUTNAME "${TIFFS[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment