-
-
Save briansorahan/6757065 to your computer and use it in GitHub Desktop.
run magic lantern bash files to enfuse images
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 | |
# Run magic lantern bash files | |
function run_scripts { | |
local -i n=$1; shift | |
local scripts="$@" | |
while [[ $(echo $scripts | tr ' ' '\n' | wc -l) -gt $n ]] | |
do | |
local head=$(echo $(echo $scripts | tr ' ' '\n' | head -"$n")) | |
for script in $head | |
do | |
./$script & | |
done | |
wait | |
scripts=$(echo $scripts | tr ' ' '\n' | tail -n + `expr $n + 1`) | |
done | |
for script in $scripts | |
do | |
./$script & | |
done | |
wait | |
} | |
function no_align { | |
local -i n=$1; shift | |
local scripts="$@" | |
for script in $scripts | |
do | |
local images=$(grep align_image_stack $script | sed 's/^align_image_stack -m -a HDR_AIS_[[:digit:]][[:digit:]]* //') | |
local output=$(echo $images | awk '{ print $1; }' | sed 's/IMG/HDR/') | |
local tmpfile=${script}.tmpbash | |
echo '#!/bin/bash' >$tmpfile | |
echo "enfuse --output=$output $images" >>$tmpfile | |
chmod +x $tmpfile | |
done | |
local scripts=$(ls *.tmpbash) | |
run_scripts $n $scripts | |
rm $scripts | |
} | |
function main { | |
local -i do_align_image_stack=1 | |
local -i ncpu=$(sysctl hw.ncpu | awk '{ print $2; }') | |
while getopts "hnc:" opt | |
do | |
case "$opt" in | |
h) | |
echo "usage: $0 [options]" | |
echo "options" | |
echo " -n no align image stack" | |
echo " -c cpu core override" | |
exit | |
;; | |
n) do_align_image_stack=0 ;; | |
c) ncpu=$OPTARG ;; | |
esac | |
done | |
local shs=$(ls *.SH) | |
chmod +x $(echo "$shs" | tr '\n' ' ') | |
if [[ $do_align_image_stack -eq 1 ]]; then | |
run_scripts $ncpu "$shs" | |
else | |
no_align `expr $ncpu / 2` "$shs" | |
fi | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment