Files
q-tools/files/imgdiff
Ville Rantanen a9c0709055 iproved imgdiff
2017-02-08 15:39:32 +02:00

41 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
function helpexit() {
echo Diff two images.
echo 'imgdiff "img1" "img2"'
echo 'If images are of different size, the 2nd image is resized to 1st size'
exit
}
[[ -z "$1" ]] && helpexit
[[ "$1" = "-h" ]] && helpexit
DISP="display -"
which feh &> /dev/null && DISP="feh --scale-down -"
[[ -z "$DISPLAY" ]] && DISP="echo -n"
size1=$( identify -format "%wx%h" "$1" )
size2=$( identify -format "%wx%h" "$2" )
img2="$2"
if [ ! "$size1" = "$size2" ]; then
echo "Image sizes different. Resize introduces artefacts. $size2 -> $size1"
tmp2=$( mktemp --suffix .miff )
convert "$2" -resize "$size1"\! "$tmp2"
img2="$tmp2"
trap "rm -f \"$tmp2\"" 0 1 9 15
fi
diffimg=$( mktemp --suffix .miff )
trap "rm -f \"$tmp2\"" 0 1 9 15
convert -compose difference "$1" "$img2" -composite -auto-level -gamma 2 "$diffimg"
echo -n "RMSE:" >&2
compare -metric RMSE "$1" "$img2" MIFF:- | \
montage -tile 2x2 -background gray -gravity center \
-geometry +5+5 "$1" "$img2" \
- "$diffimg" PNG:- | $DISP
echo ""
rm -f "$diffimg"