-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgreyscale_report.sh
executable file
·133 lines (123 loc) · 4.27 KB
/
greyscale_report.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
#
# Fully independent from the quack.sh script.
#
# Generates a report of outputs from greyscale_stats.sh.
# Lists the images with the most absolute white and absolute black pixels.
# Lists the number of unique greyscale values in the images.
#
# Usage
# * Generate a log from a collection of images with
# find myimages/ -name "*.tif" -exec ./greyscale_stats.sh {} \; > myimages.log
# * Generate a report with
# ./greyscale_report.sh myimages.log
#
# Optional usage
# * Ignore 5% of the outer edges of the images when calculating stats by only
# analyzing the inner 90% of the images.
# find myimages/ -name "*.tif" -exec ./greyscale_stats.sh {} 90 \; > myimages.log
# * Generate a report suitable for displaying in a browser
# ./greyscale_report.sh myimages.log html
#
# TODO: This should definitely be configurable in an external file ala quack.sh
TOPX=20
WEBROOT="http://pc254.sb.statsbiblioteket.dk/quack/tilbud2/"
LOG=$1
if [ "." == ".$LOG" ]; then
echo "Usage: ./greyscale_report.sh logfile [html]"
exit -1
fi
TYPE=$2
if [ "." != ".$TYPE" ]; then
if [ "html" != "$TYPE" ]; then
echo "The only valid type is html. $TYPE was specified"
exit -1
fi
fi
if [ "html" == "$TYPE" ]; then
echo "<html>"
echo "<head><title>Report for $LOG</title></head>"
echo "<body>"
echo "<h1>Report for $LOG with `cat $LOG | wc -l` analyzed images</h1>"
else
echo "Report for $LOG with `cat $LOG | wc -l` analyzed images"
fi
echo ""
# Stats for unique greyscales as well as brightest greyscale
if [ "html" == "$TYPE" ]; then
echo "<h2>Distribution by number of unique greyscales</h2>"
echo "<table>"
echo "<tr><th>#occurrences</th> <th>#uniques</th> <th>brightest greyscale</th></tr>"
else
echo "Distribution by number of unique greyscales"
echo "#occurrences #uniques brightest_greyscale"
fi
# 1. Bucket #unique
UNIQUES=`cat "$LOG" | cut -d " " -f 3 | sort | uniq`
# 2. Extract brightest as well as count for each #unique
for U in $UNIQUES; do
COUNT=`cat "$LOG" | cut -d " " -f 3,9 | grep "$U (" | wc -l`
if [ "html" == "$TYPE" ]; then
echo -n "<tr><td>$COUNT</td> <td>$U</td> <td>"
echo -n `cat "$LOG" | cut -d " " -f 3,9 | grep "$U (" | cut -d " " -f 2 | sort -u`
echo "</td></tr>"
else
echo -n "$COUNT $U "
echo `cat "$LOG" | cut -d " " -f 3,9 | grep "$U (" | cut -d " " -f 2 | sort -u`
fi
done
if [ "html" == "$TYPE" ]; then
echo "</table>"
fi
echo ""
if [ "html" == "$TYPE" ]; then
echo "<h2>Percent of image with darkest greyscale, top $TOPX</h2>"
echo "<table>"
echo "<tr><th>percent</th> <th>darkest greyscale</th> <th>link</th></tr>"
else
echo "Percent of image with darkest greyscale, top $TOPX"
fi
for P in `cat "$LOG" | cut -d " " -f 5 | sort -n -r | head -n $TOPX`; do
LINE=`cat "$LOG" | cut -d " " -f 1,5,6 | grep " $P (" | cut -d " " -f 1,3 | head -n 1`
if [ "html" == "$TYPE" ]; then
C=`echo "$LINE" | cut -d " " -f 2`
I=`echo "$LINE" | cut -d " " -f 1`
REF=${I##*/}
REF="${REF%.*}"
LINK="$WEBROOT${I%.*}.html"
echo "<tr><td>${P}%</td> <td>$C</td> <td><a href=\"$LINK\">$REF</a></td></td></tr>"
else
echo "${P}% `echo "$LINE" | cut -d " " -f 2` `echo "$LINE" | cut -d " " -f 1`"
fi
done
if [ "html" == "$TYPE" ]; then
echo "</table>"
fi
echo ""
if [ "html" == "$TYPE" ]; then
echo "<h2>Percent of image with brightest greyscale, top $TOPX</h2>"
echo "<table>"
echo "<tr><th>percent</th> <th>brightest greyscale</th> <th>link</th></tr>"
else
echo "Percent of image with brightest greyscale, top $TOPX"
fi
for P in `cat "$LOG" | cut -d " " -f 8 | sort -n -r | head -n $TOPX`; do
LINE=`cat "$LOG" | cut -d " " -f 1,8,9 | grep " $P (" | cut -d " " -f 1,3 | head -n 1`
if [ "html" == "$TYPE" ]; then
C=`echo "$LINE" | cut -d " " -f 2`
I=`echo "$LINE" | cut -d " " -f 1`
REF=${I##*/}
REF="${REF%.*}"
LINK="$WEBROOT${I%.*}.html"
echo "<tr><td>${P}%</td> <td>$C</td> <td><a href=\"$LINK\">$REF</a></td></td></tr>"
else
echo "${P}% `echo "$LINE" | cut -d " " -f 2` `echo "$LINE" | cut -d " " -f 1`"
fi
done
if [ "html" == "$TYPE" ]; then
echo "</table>"
fi
if [ "html" == "$TYPE" ]; then
echo "</body>"
echo "</html>"
fi