Last active
June 20, 2023 17:44
-
-
Save ge0rg/b3176203feb50accdcb662ce0ef63080 to your computer and use it in GitHub Desktop.
Convert left+right pictures from a stereo MPO into a left-right diptych picture
This file contains hidden or 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
#!/usr/bin/env bash | |
# | |
# ***** Warning: this is not production-quality! ***** | |
# | |
# this will extract the left + right images from all passed | |
# .MPO files, crop them to a percentage of the width (75% by | |
# default), and stitch them together into a diptych. | |
# | |
# Based on https://photo.stackexchange.com/a/100402/57928 | |
percent=75 | |
# if the first argument is a number, use it for crop percentage | |
if [[ $1 =~ ^[0-9]+$ ]] ; then | |
percent=$1 | |
shift 1 | |
fi | |
for i in "$@" ; do | |
j="${i#*/}" | |
k="${j%.[mM][pP][oO]}" | |
width=$(identify -format "%w" "$i") | |
# offset from the left to the beginning of the 75% image | |
offset=$((width*(100-percent)/200)) | |
# extract left images | |
exiftool -trailer:all= "$i" -o "${k}.left.jpg" | |
exiftool -TagsFromFile "$i" "${k}.left.jpg" | |
# extract right images | |
if exiftool "$i" | grep "MP Image 3" ; then | |
# Samsung NX 45mm f/1.8 2D/3D | |
exiftool "$i" -mpimage3 -b > "${k}.right.jpg" | |
exiftool -TagsFromFile "$i" "${k}.right.jpg" | |
else | |
# Fujifilm Real 3D W3 | |
exiftool "$i" -mpimage2 -b > "${k}.right.jpg" | |
exiftool -TagsFromFile "$i" "${k}.right.jpg" | |
fi | |
# crop the left + right images to allow for easier vertical viewing | |
convert "$k.right.jpg" -crop $percent%x100%+$offset+0 +repage "$k.right.crop.jpg" | |
convert "$k.left.jpg" -crop $percent%x100%+$offset+0 +repage "$k.left.crop.jpg" | |
# combine l+r into one diptych | |
montage "$k.left.crop.jpg" "$k.right.crop.jpg" -tile 2x1 -geometry +0+0 "$k.stereo.jpg" | |
# remove the intermediates | |
rm -f "$k".{left,right}{,.crop}.jpg "$k".{left,right}.jpg_original | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment