-
Notifications
You must be signed in to change notification settings - Fork 32
/
utils.py
62 lines (46 loc) · 1.79 KB
/
utils.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
import numpy as np
import math
def psnr(img1, img2):
mse = np.mean( (img1 - img2) ** 2 )
if (mse == 0):
return (100)
PIXEL_MAX = 1.0
return (20 * math.log10(PIXEL_MAX / math.sqrt(mse)))
def split2(dataset,size,h,w):
newdataset=[]
nsize1=256
nsize2=256
for i in range (size):
im=dataset[i]
for ii in range(0,h,nsize1): #2048
for iii in range(0,w,nsize2): #1536
newdataset.append(im[ii:ii+nsize1,iii:iii+nsize2,:])
return np.array(newdataset)
def merge_image2(splitted_images, h,w):
image=np.zeros(((h,w,1)))
nsize1=256
nsize2=256
ind =0
for ii in range(0,h,nsize1):
for iii in range(0,w,nsize2):
image[ii:ii+nsize1,iii:iii+nsize2,:]=splitted_images[ind]
ind=ind+1
return np.array(image)
def getPatches(watermarked_image,clean_image,mystride):
watermarked_patches=[]
clean_patches=[]
h = ((watermarked_image.shape [0] // 256) +1)*256
w = ((watermarked_image.shape [1] // 256 ) +1)*256
image_padding=np.ones((h,w))
image_padding[:watermarked_image.shape[0],:watermarked_image.shape[1]]=watermarked_image
for j in range (0,h-256,mystride): #128 not 64
for k in range (0,w-256,mystride):
watermarked_patches.append(image_padding[j:j+256,k:k+256])
h = ((clean_image.shape [0] // 256) +1)*256
w = ((clean_image.shape [1] // 256 ) +1)*256
image_padding=np.ones((h,w))*255
image_padding[:clean_image.shape[0],:clean_image.shape[1]]=clean_image
for j in range (0,h-256,mystride): #128 not 64
for k in range (0,w-256,mystride):
clean_patches.append(image_padding[j:j+256,k:k+256]/255)
return np.array(watermarked_patches),np.array(clean_patches)