-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample2.py
More file actions
38 lines (28 loc) · 986 Bytes
/
example2.py
File metadata and controls
38 lines (28 loc) · 986 Bytes
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
import sys
from ppg.codec import SciKitCodec
from ppg.filter import *
from ppg.parser import LoadFilter
def main(infile=None, outfile=None, filterdef=None, quiet=""):
# Check command-line arguments
if infile is None or outfile is None:
print("usage: %s <infile> <outfile> [filterdef] [quiet]" % (sys.argv[0]))
return 1
# Default filterdef if None
if filterdef is None:
filterdef = "testfilter.txt"
# 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)
# Load the filter chain
fh = open(filterdef, "r")
chain = LoadFilter(fh.read())
fh.close()
# 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:]))