-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpreprocessor.py
115 lines (88 loc) · 2.7 KB
/
preprocessor.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from PIL import Image
def _bellabook(im):
im = im.convert("P")
im2 = Image.new("P", im.size,255)
for x in range(im.size[0]):
for y in range(im.size[1]):
pix = im.getpixel((x,y))
if pix < 50:
im2.putpixel((x,y),0)
return im2
def _easyphp(im):
im = im.convert("P")
im2 = Image.new("P", im.size,255)
for x in range(im.size[0]):
for y in range(im.size[1]):
pix = im.getpixel((x,y))
if pix == 215:
im2.putpixel((x,y),0)
return im2
def _phpfox(im):
im = im.convert("P")
im2 = Image.new("P", im.size,255)
for x in range(im.size[0]):
for y in range(im.size[1]):
pix = im.getpixel((x,y))
if pix < 200:
im2.putpixel((x,y),0)
return im2
def _phpld(im):
im = im.convert("P")
im2 = Image.new("P", im.size,255)
for x in range(im.size[0]):
for y in range(im.size[1]):
pix = im.getpixel((x,y))
if pix < 100:
im2.putpixel((x,y),0)
return im2
def _ricar(im):
im = im.convert("P")
im2 = Image.new("P", im.size,255)
for x in range(im.size[1]):
for y in range(im.size[0]):
pix = im.getpixel((y,x))
temp[pix] = pix
if mylist[2]== 1 or mylist[0]==174:
if pix==mylist[3]:
im2.putpixel((y,x),0)
else:
if pix==mylist[3] or pix==mylist[2]:
im2.putpixel((y,x),0)
return im2
def _tikiwiki(im):
im = im.convert("P")
im2 = Image.new("P", im.size,255)
for x in range(im.size[0]):
for y in range(im.size[1]):
pix = im.getpixel((x,y))
if pix < 10:
im2.putpixel((x,y),0)
return im2
def _evood(im):
im=im.convert("P")
im2 =Image.new("P", im.size,255)
for x in range(im.size[1]):
for y in range(im.size[0]):
pix = im.getpixel((y,x))
if pix==0 or pix<100:
im2.putpixel((y,x),0)
return im2
def process_image(im):
width = im.size[0]
height = im.size[1]
if width == 110 and height == 35:
return _bellabook(im)
elif width == 55 and height == 20:
return _easyphp(im)
elif width == 128 and height == 40:
return _phpfox(im)
elif width == 125 and height == 30:
return _phpld(im)
elif width == 100 and height == 30:
return _ricar(im)
elif width == 95 and height == 30:
return _tikiwiki(im)
elif width == 142 and height == 52:
return _evood(im)
else:
return im