-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbatch-augment.sh
More file actions
executable file
·78 lines (72 loc) · 1.78 KB
/
batch-augment.sh
File metadata and controls
executable file
·78 lines (72 loc) · 1.78 KB
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
#!/bin/bash
DIR=$1
N=$2
count=0
flip() {
for file in $(ls -1 $DIR | egrep '(.png)$' | egrep -v '(flop)');
do
if [ "$count" -ge "$N" ]; then
break
fi
file_name=${file%.*}
file_ext=${file#*.}
new_filename=$file_name"-flop."$file_ext
new_file=$DIR/$new_filename
if [ ! -f $new_file ]; then
echo "Flopping: $file"
convert $DIR/$file -flop $new_file
((count=count+1))
((augmented=1))
fi
done
}
crop() {
PCT=$1
for file in $(ls -1 $DIR | egrep '(.png)$' | egrep -v '(crop)');
do
if [ "$count" -ge "$N" ]; then
break
fi
file_name=${file%.*}
file_ext=${file#*.}
new_filename=$file_name"-"$PCT"crop."$file_ext
new_file=$DIR/$new_filename
if [ ! -f $new_file ]; then
echo "Cropping: $file"
convert $DIR/$file -gravity Center -crop $PCT%\! $new_file
((count=count+1))
((augmented=1))
fi
done
}
shear() {
for file in $(ls -1 $DIR | egrep '(.png)$' | egrep -v '(shear)');
do
if [ "$count" -ge "$N" ]; then
break
fi
file_name=${file%.*}
file_ext=${file#*.}
new_filename=$file_name"-shear."$file_ext
new_file=$DIR/$new_filename
if [ ! -f $new_file ]; then
echo "Shearing: $file"
convert $DIR/$file -shear $1 -shear $2 $new_file
((count=count+1))
((augmented=1))
fi
done
}
while [ "$count" -le "$N" ];
do
((augmented=0))
# do horizontal flip ("flop")
flip
# crop 85% from center (95%..75%)
crop 85
# shear
shear "-4x0" "0x6"
if [ $augmented -eq 0 ]; then
break
fi
done