Created
May 12, 2018 22:11
-
-
Save Two9A/fe341063139349d03112c3153a10f714 to your computer and use it in GitHub Desktop.
Vertical stitch: Take a set of (in this case 598) frames from a phone scroll recording, and rebuild the original list being scrolled
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 | |
BLOBH=256 | |
BLOBX=0 | |
BLOBY=0 | |
convert az0001.jpg final.png | |
BLOBW=$(identify -format "%w" final.png) | |
FULLWIDTH=$(identify -format "%w" final.png) | |
for filenum in {1..597}; do | |
filenun=$(($filenum+1)) | |
INA=$(printf "az%04d.jpg" $filenum) | |
INB=$(printf "az%04d.jpg" $filenun) | |
convert $INA -crop ${BLOBW}x+${BLOBX}+0 a.png | |
convert $INB -crop ${BLOBW}x${BLOBH}+${BLOBX}+0 b.png | |
XHEIGHT=$(identify -format "%h" a.png) | |
FULLHEIGHT=$(identify -format "%h" final.png) | |
lines=0 | |
mindiff=1048576 | |
minlines=0 | |
while [ 1 == 1 ]; do | |
OFFSET=$((XHEIGHT-BLOBH-1-lines)) | |
if [ $OFFSET -lt 0 ]; then break; fi | |
diff=$(convert a.png -crop ${BLOBW}x${BLOBH}+${BLOBX}+${OFFSET} +repage \ | |
b.png \ | |
-compose difference -composite \ | |
\( +clone -evaluate set 0 \) -metric RMSE -compare -format "%[distortion]" info:) | |
if [ $(echo "${diff} < ${mindiff}" | bc) == '1' ]; then | |
mindiff=$diff | |
minlines=$lines | |
fi | |
echo $diff:$lines | |
((lines++)) | |
done | |
rm a.png b.png | |
fulloffs=$((FULLHEIGHT-BLOBH-1-minlines)) | |
echo $INA:$minlines:$fulloffs | |
if [ $fulloffs -gt 0 ]; then | |
convert final.png -crop ${FULLWIDTH}x${fulloffs}+0+0 $INB -append final.png | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment