forked from LJSthu/Python-Remove-Watermark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatermark.py
68 lines (63 loc) · 2.02 KB
/
watermark.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
from skimage import io
from pdf2image import convert_from_path
import numpy as np
# imgs = io.imread('./test.png')
# io.imsave('./hh.png',imgs)
# imgs = np.array(imgs)
# print(imgs.shape)
# r = []
# g = []
# b = []
# alpha = []
def judge(x,y):
temp = -(600.0/1575.0) * x
if y > 1350 + temp and y < 1500 + temp:
return True
else:
return False
# for i in range(imgs.shape[0]):
# for j in range(imgs.shape[1]):
# if not judge(j,i):
# continue
# if imgs[i][j][1] > 100 and imgs[i][j][1] < 250 and imgs[i][j][2] > 100 and imgs[i][j][2] < 250:
# imgs[i][j][0] = imgs[i][j][1] = imgs[i][j][2] = 255
# if imgs[i][j][1] < 10 and imgs[i][j][2] < 100:
# imgs[i][j][0] = imgs[i][j][1] = imgs[i][j][2] = 0
# io.imsave('./hh.png',imgs)
# print(r)
# print(g)
# print(b)
# print(alpha)
def select_pixel(r,g,b):
if (r == 208 and g == 208 and b == 208 ) or (r == 196 and g == 196 and b == 196) \
or (r == 206 and g == 206 and b == 206 ):
return True
else:
return False
def select_pixel2(r,g,b):
if r > 175 and r < 250 and g > 175 and g < 250 and b > 175 and b < 250:
return True
else:
return False
def handle(imgs):
for i in range(imgs.shape[0]):
for j in range(imgs.shape[1]):
# if not judge(j,i):
# continue
# if imgs[i][j][1] > 100 and imgs[i][j][1] < 250 and imgs[i][j][2] > 100 and imgs[i][j][2] < 250:
if select_pixel2(imgs[i][j][0],imgs[i][j][1],imgs[i][j][2]):
imgs[i][j][0] = imgs[i][j][1] = imgs[i][j][2] = 255
# if not select_pixel(imgs[i][j][0],imgs[i][j][1],imgs[i][j][2]):
# imgs[i][j][0] = imgs[i][j][1] = imgs[i][j][2] = 0
return imgs
images = convert_from_path('./jiangyi3.pdf')
# images = np.array(images)
index = 0
for img in images:
index += 1
img = np.array(img)
print(img.shape)
img = handle(img)
io.imsave('./jiangyi3/img'+str(index)+'.jpg', img)
# break
print(index)