-
Notifications
You must be signed in to change notification settings - Fork 7
/
intensity_sort.sh
executable file
·65 lines (56 loc) · 1.57 KB
/
intensity_sort.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
#!/bin/bash
#
# Image sorter by intensity that supports meta-data in the image-list
# Meta-data are separated from the images themselved by a bar |
# Sample-line:
# clothes/rainbow_feathers.png|My beautiful socks
#
# Requires ImageMagick
#
# Note: This does not work especially well. A more interesting sorter
# would sort by rainbow order or something like that.
# See http://imagemagick.org/Usage/quantize/#extract for further ideas of
# extracting image statistics that are sortable.
#
: ${REVERSE_SORT:=false}
usage() {
echo "Usage: ./intensity_sort.sh in_imagelist.dat out_imagelist.dat"
exit $1
}
IN="$1"
OUT="$2"
if [ ! -s "$IN" ]; then
>&2 echo "Unable to open image list '$IN'"
usage 1
fi
if [ "." == ".$OUT" ]; then
>&2 echo "An output file must be provided"
usage 2
fi
echo "- Image intensity sorting $IN"
TOTAL=`cat "$IN" | wc -l`
UNSORTED=`mktemp /tmp/juxta_intensity_sort.XXXXXXXX`
COUNTER=1
while read IMAGE; do
IFS=$'|'
TOKENS=($IMAGE)
IPATH=${TOKENS[0]}
IMETA=${TOKENS[1]}
unset IFS
echo " - Analyzing $COUNTER/$TOTAL: $IPATH"
INTENSITY=`convert "$IPATH" -type Grayscale -format "%[mean]" info:`
echo -n "$INTENSITY $IPATH" >> $UNSORTED
if [ "." == ".$IMETA" ]; then
echo "" >> $UNSORTED
else
echo "|$IMETA" >> $UNSORTED
fi
COUNTER=$((COUNTER+1))
done < "$IN"
if [ "true" == "$REVERSE_SORT" ]; then
cat $UNSORTED | sort -n -r | sed 's/^[0-9.]* //' > "$OUT"
else
cat $UNSORTED | sort -n | sed 's/^[0-9.]* //' > "$OUT"
fi
rm $UNSORTED
echo "- Sorting finished, result in $OUT"