Skip to content

Instantly share code, notes, and snippets.

@vi

vi/pseudohdr.sh

Created Jun 9, 2014
Embed
What would you like to do?
ImageMagick-based pseudo-HDR merger script
#!/bin/bash
# Photos must be perfectly aligned
# Warning: slow
# Created by amateur, don't expect much.
k=0
D=pseudohdr_data
rm -Rf $D/
mkdir -p $D
set -e
INPUTFILES=""
FORMULA_NUMERATOR="0"
FORMULA_DENOMINATOR="0.0001"
for i in "$@"; do
echo "Converting $i to png"
convert "$i" -quality 0 $D/input_$k.png
echo "Deducing exposure for $i"
convert $D/input_$k.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"' | \
perl -ne '$_+=0.0001; $_ = 533.555424592237/$_ - atan2(590.948204361954, $_); print "$_\n"' \
> $D/exposure_$k.txt
echo "Making intermediate picture $k"
convert $D/input_$k.png \
-channel A -fx 'lightness*(1-lightness)*4' \
-channel RGB -fx "u*sqrt($(<$D/exposure_$k.txt))" \
-quality 0 $D/intermediate_$k.png
# -blur 2x3
INPUTFILES+=" $D/intermediate_$k.png"
FORMULA_NUMERATOR+=" + u[$k]*u[$k].a"
FORMULA_DENOMINATOR+=" + u[$k].a"
k=$((k+1))
done
echo "Making final picture of $k pieces: output.png"
convert $INPUTFILES \
-channel RGB -fx "($FORMULA_NUMERATOR ) / ( $FORMULA_DENOMINATOR )" \
-channel A -fx 'not(not(a))' \
-quality 0 output.png
echo Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.