-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
46 lines (36 loc) · 980 Bytes
/
main.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# @author: https://chenjiehua.me
# @date: 2016-12-24
#
"""
Usage:
python main.py a.png
"""
import sys
import numpy as np
from PIL import Image
def main():
img_file = sys.argv[1]
img = Image.open("image/" + img_file)
w, h = img.size
for y in range(h):
line = []
for x in range(w):
pix = img.getpixel((x, y))
pix = (pix[0]*299+pix[1]*587+pix[2]*114)/1000 # gray
line.append(pix)
lmean, lvar = np.mean(line), np.var(line)
print lmean, lvar
if 40 < lmean and lmean < 70 and lvar < 500:
fix_row(img, y, y-4)
img.save("image/out_" + img_file)
def fix_row(img, drt, src):
print "fix row: %s with %s" % (drt, src)
w, h = img.size
if 0 <= drt and drt < h and 0 <= src and src < h:
for x in range(w):
img.putpixel((x, drt), img.getpixel((x, src)))
if __name__ == "__main__":
main()