-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
56 lines (48 loc) · 1.86 KB
/
demo.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
from os import error
from PIL import Image
from quantize import quantize
from pathlib import Path
def parameterization():
img = Image.open("./demoInput.jpg")
pixels = img.load()
dims = img.size
minCellDims = [8, 8]
if(dims[0] != dims[1]):
error("The code currently only works for sqaure images.")
for minCellDims in [ [4, 4], [6, 6], [10, 10] ]:
for thresh in [ 6900, 42000, 420000, 690000 ]:
for edgeType in [ "inv", "black", "white", "darken", "lighten" ]:
print("{e} | {t} | {w}x{h}".format(e=edgeType, t=thresh, w=minCellDims[0], h=minCellDims[1]))
out = Image.new(mode="RGB", size=dims)
quantize(
cell=[ 0, 0, dims[0], dims[1] ],
inputPixels=pixels,
outputImage=out,
thresh=thresh,
minCellDims=minCellDims,
showEdges=True,
edgeType=edgeType
)
path = Path("./demoOut/out_{thresh}_{edge}_min{w}x{h}.png".format(thresh=thresh, edge=edgeType, w=minCellDims[0], h=minCellDims[1]))
out.save(path)
out.close()
def test():
img = Image.open("./laikka.jpg")
pixels = img.load()
dims = img.size
minCellDims = [6, 6]
thresh = 69420
for edgeType in [ "inv", "black", "white" ]:
out = Image.new(mode="RGB", size=dims)
quantize(
cell=[ 0, 0, dims[0], dims[1] ],
inputPixels=pixels,
outputImage=out,
thresh=thresh,
minCellDims=minCellDims,
showEdges=True,
edgeType=edgeType
)
path = Path("./demoOut/out_{thresh}_{edge}_min{w}x{h}.png".format(thresh=thresh, edge=edgeType, w=minCellDims[0], h=minCellDims[1]))
out.save(path)
out.close()