-
Notifications
You must be signed in to change notification settings - Fork 1
/
pixelCheck-im.sh
executable file
·68 lines (47 loc) · 1.42 KB
/
pixelCheck-im.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# Performs pixel-wise check between TIFF images in two directory trees
# Requires ImageMagick
#set -euo pipefail
set -uo pipefail
if [ "$#" -ne 3 ] ; then
echo "Usage: pixelCheck-im.sh dir1 dir2 dirOut" >&2
exit 1
fi
# Input and output directories
dir1="$1"
dir2="$2"
dirOut="$3"
if ! [ -d "$dir1" ] ; then
echo "input directory 1 does not exist" >&2
exit 1
fi
if ! [ -d "$dir2" ] ; then
echo "input directory 2 does not exist" >&2
exit 1
fi
if ! [ -d "$dirOut" ] ; then
mkdir "$dirOut"
fi
# Output file
fileOut=$dirOut/pixelCheck.csv
# Remove output file if it exists already (writing done in append mode!)
if [ -f $fileOut ] ; then
rm $fileOut
fi
# Write header to output file
echo "file1","file2","ae","psnr" >> $fileOut
# Iterate over all images in dir1, and do pixel check
# with corresponding image in dir2
while IFS= read -d $'\0' -r file ; do
file1="$file"
file2Name=$(basename "$file")
# Input path
path1=$(dirname "$file1")
# Input path, relative to dir1
inPathRel=$(realpath --relative-to=$dir1 $path1)
# Full path to corresponding file in dir2
file2="$dir2/$inPathRel/$file2Name"
ae=$(compare -quiet -metric AE "$file1""[0]" "$file2""[0]" null: 2>&1)
psnr=$(compare -quiet -metric psnr "$file1""[0]" "$file2""[0]" null: 2>&1)
echo "$file1","$file2","$ae","$psnr" >> $fileOut
done < <(find $dir1 -type f -regex '.*\.\(tiff\|TIFF\|tif\|TIF\)' -print0)