Created
June 9, 2014 13:20
-
-
Save vi/5dc94732496f13df0fb0 to your computer and use it in GitHub Desktop.
ImageMagick-based pseudo-HDR merger script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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