forked from Antinomy20001/zf_checkcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandle_image.py
More file actions
31 lines (27 loc) · 846 Bytes
/
handle_image.py
File metadata and controls
31 lines (27 loc) · 846 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
from PIL import Image
def depoint(img): # input: gray image
pixdata = img.load()
w, h = img.size
for i in [0, h - 1]:
for j in range(w):
pixdata[j, i] = 255
for i in [0, w - 1]:
for j in range(h):
pixdata[i, j] = 255
for y in range(1, h - 1):
for x in range(1, w - 1):
count = 0
if pixdata[x, y - 1] > 245:
count = count + 1
if pixdata[x, y + 1] > 245:
count = count + 1
if pixdata[x - 1, y] > 245:
count = count + 1
if pixdata[x + 1, y] > 245:
count = count + 1
if count > 2:
pixdata[x, y] = 255
return img
if __name__ == '__main__':
import sys
depoint(Image.open(sys.argv[1]).convert('1')).save('temp.png')