Skip to content

Instantly share code, notes, and snippets.

@technopagan
Created May 25, 2016 08:04
Show Gist options
  • Save technopagan/a1087fac589a4b34bc599ddeda9126bd to your computer and use it in GitHub Desktop.
Save technopagan/a1087fac589a4b34bc599ddeda9126bd to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Set locales to C (raw uninterpreted byte sequence) to avoid illegal byte sequence errors and invalid number errors
export LANG=C LC_NUMERIC=C LC_COLLATE=C
# Check for proper input parameters
# Filename and selected JPEG compressor should both be set
if [ -z $1 ] || [ -z $2 ]; then
echo "Please select 2 JPEGs to compare"
exit 1
elif [ -n $1 ] && [ -n $2 ]; then
INPUTFILE1="$1"
INPUTFILE2="$2"
else
exit 1
fi
# Convert the original JPEGs to PNG for DSSIM comparison
# Also base64 them so we can safely store the result in variables without needing to write to disk
inputfile1_png_base64=$(convert "${INPUTFILE1}" png:- | base64)
inputfile2_png_base64=$(convert "${INPUTFILE2}" png:- | base64)
# Base64 decode the two files on the fly and feed them to DSSIM via Bash input redirection (saving the necessity to write files to disk), then grab the output via awk for clean output
dissimilarity=$(dssim <(echo "${inputfile2_png_base64}" | base64 --decode) <(echo "${inputfile1_png_base64}" | base64 --decode) | awk '{print $1}')
echo ${dissimilarity}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment