forked from tokee/quack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
greyscale_stats.sh
executable file
·55 lines (41 loc) · 1.69 KB
/
greyscale_stats.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
#!/bin/bash
#
# Simple statistical analysis of greyscale images.
# Extracts key stats for darkest and brightest intensity, intended
# for use with greyscale_report.sh
#
# Requirements
# * ImageMagick
#
# Input: A greyscale image
# Output: Name pixel_count unique_greyscales #darkest_pixels darkest_pixels_percent darkest_greyscale #brightest_pixels brightest_pixels_percent lightest_greyscale
TMP="/tmp/tmp_crop.bmp"
if [ "." == ".$1" ]; then
echo "Usage: filename [croppercent]"
exit 2
fi
if [ "." != ".$2" ]; then
CROP=$2
convert "$1" -gravity Center -crop $CROP%x+0+0 "$TMP" 2> /dev/null
INFO=`identify -verbose "$TMP" 2> /dev/null`
rm "$TMP"
else
INFO=`identify -verbose $1 2> /dev/null`
fi
#INFO=`cat t`
SAVEIFS=$IFS
IFS=$(echo -en "\n")
UNIQUE=`echo $INFO | grep "[0-9]\\+: (" | wc -l`
FIRST_COUNT=`echo $INFO | grep "[0-9]\\+: (" | head -n 1 | grep -o " [0-9]\\+:" | grep -o "[0-9]\\+"`
FIRST_GREY=`echo $INFO | grep "[0-9]\\+: (" | head -n 1 | grep -o " ([0-9 ,]*)" | sed 's/ //g'`
LAST_COUNT=`echo $INFO | grep "[0-9]\\+: (" | tail -n 1 | grep -o " [0-9]\\+:" | grep -o "[0-9]\\+"`
LAST_GREY=`echo $INFO | grep "[0-9]\\+: (" | tail -n 1 | grep -o " ([0-9 ,]*)" | sed 's/ //g'`
GEOMETRY=`echo $INFO | grep "Geometry: [0-9]\\+x[0-9]\\+" | grep -o "[0-9]\\+x[0-9]\\+"`
X=`echo $GEOMETRY | grep -o "[0-9]\\+x" | grep -o "[0-9]\\+"`
Y=`echo $GEOMETRY | grep -o "x[0-9]\\+" | grep -o "[0-9]\\+"`
PIXELS=`echo "$X*$Y" | bc`
PERCENT_FIRST=`echo "scale=2;$FIRST_COUNT*100/$PIXELS" | bc`
PERCENT_LAST=`echo "scale=2;$LAST_COUNT*100/$PIXELS" | bc`
echo "$1 $PIXELS $UNIQUE $FIRST_COUNT $PERCENT_FIRST $FIRST_GREY $LAST_COUNT $PERCENT_LAST $LAST_GREY"
#echo "$1 $UNIQUE $LAST"
IFS=$SAVEIFS