-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembed.py
executable file
·77 lines (71 loc) · 3.14 KB
/
embed.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
import numpy as np
import cv2
# def embed(imArray,imWater,x,y,w,h):
# waterHeight,waterWidth=imWater.shape[:2]
# if w<waterWidth or h<waterHeight:
# if waterHeight>waterWidth:
# print waterHeight/h
# imWater = cv2.resize(imWater,(0,0), fx=float(h/waterHeight), fy=float(h/waterHeight))
# else :
# # print str(w) + "/" + str(waterWidth) +" = "+ str(float(w)/waterWidth)
# imWater = cv2.resize(imWater,(0,0), fx = float(w)/waterWidth, fy = float(w)/waterWidth)
#
# waterHeight,waterWidth=imWater.shape[:2]
# crop_imArray = imArray[y:waterHeight+y,x:waterWidth+x]
# resultWater = (0.8*crop_imArray) + (0.2 *imWater)
# imArray[y:waterHeight+y,x:waterWidth+x]=resultWater
# else :
# crop_imArray = imArray[y:waterHeight+y,x:waterWidth+x]
# resultWater = (0.8*crop_imArray) + (0.2 * imWater)
# imArray[y:waterHeight+y,x:waterWidth+x]=resultWater
# resultImgWater=resultWater.astype(np.uint8)
# resultImgArray=imArray.astype(np.uint8)
#
# cv2.waitKey(0)
# return resultImgArray
def embed(imArray, imWater, x, y, w, h, alpha):
imArray = imArray.astype(np.float)
imWater = imWater.astype(np.float)
waterHeight, waterWidth = imWater.shape[:2]
if w < waterWidth or h < waterHeight:
if waterHeight > waterWidth:
print waterHeight / h
imWater = cv2.resize(imWater, (0, 0), fx=float(
h / waterHeight), fy=float(h / waterHeight))
else:
# print str(w) + "/" + str(waterWidth) +" = "+
# str(float(w)/waterWidth)
imWater = cv2.resize(imWater, (0, 0), fx=float(
w) / waterWidth, fy=float(w) / waterWidth)
waterHeight, waterWidth = imWater.shape[:2]
crop_imArray = imArray[y:waterHeight + y, x:waterWidth + x]
resultWater = crop_imArray.astype(
np.float) + alpha * imWater.astype(np.float)
imArray[y:waterHeight + y, x:waterWidth + x] = resultWater
else:
crop_imArray = imArray[y:waterHeight + y, x:waterWidth + x]
resultWater = crop_imArray.astype(
np.float) + alpha * imWater.astype(np.float)
imArray[y:waterHeight + y, x:waterWidth + x] = resultWater
resultImgWater = resultWater.astype(np.uint8)
resultImgArray = imArray.astype(np.uint8)
imArray = imArray.astype(np.uint8)
imWater = imWater.astype(np.uint8)
return resultImgArray
def extract(img, imgcover, alpha):
watermark = ((img.astype(np.double) -
imgcover.astype(np.double)) / alpha).astype(np.uint8)
return watermark
if __name__ == '__main__':
image = cv2.imread(
"/home/as3mbus/Screenshot_2017-04-09_22-30-51.png")
imageWater = cv2.imread(
"/media/DATA/UDINUS/SMT 6/Advanced Image Processing/Project/tes.jpeg")
height, width = image.shape[:2]
print "A"
# imWater = cv2.resize(imageWater,(0,0), fx = float(height/200), fy = float(height/200))
resultWater = embed(image, imageWater, 0, 0, 500, 500,0.5)
# cv2.imshow("ori", imageWater)
cv2.imshow("resiz", resultWater)
cv2.waitKey(0)
cv2.destroyAllWindows()