-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample1.py
58 lines (44 loc) · 1.6 KB
/
example1.py
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
import sys
from ppg.codec import SciKitCodec
from ppg.filter import *
def main(infile=None, outfile=None, scale=None, quiet=""):
# Check command-line arguments
if infile is None or outfile is None:
print("usage: %s <infile> <outfile> [scalar] [quiet]" % (sys.argv[0]))
return 1
# Default scalar if None
if scale is None:
scale = 1.0
else:
scale = float(scale)
# Set quiet flag
quiet = (quiet in ["quiet", "q"])
# Instantiate a wrapper around skimage to make encoding/decoding files easy
codec = SciKitCodec()
# Load the file
f = codec.decode(infile)
# Define a filter chain
chain = FilterChain(
# First, we will do a randomized set of PNG-style filters with 95% line
# correlation, altering pixels at a rate of 0.04%.
FilterStack(
RandomLineFilter(correlation=0.95, candidates=["Average","Paeth","Null","Up","Sub"]),
UniformGlitchFilter(rate=0.00040*scale)
),
# Next, apply our BrokenPaethFilter and alter pixels at 0.001%.
FilterStack(
BrokenPaethFilter(),
UniformGlitchFilter(rate=0.00001*scale)
),
# Finally, apply the BrokenAverageFilter and alter pixels at 0.025%.
FilterStack(
BrokenAverageFilter(),
UniformGlitchFilter(rate=0.00025*scale)
)
)
# Apply the filter chain, then save the glitched image
f = chain.encode(f, not quiet)
codec.encode(f, outfile)
return 0
if __name__ == "__main__":
sys.exit(main(*sys.argv[1:]))