forked from jiaxiaojunQAQ/Comdefend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
processer.py
66 lines (65 loc) · 1.51 KB
/
processer.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
import numpy as np
import math
import cv2
import csv
def change(x):
x *=255
x=x.astype('uint8')
img=x[0]
return img
def psnr(im1,im2):
mse = np.mean( (im1 - im2) ** 2 )
if mse == 0:
return 100
PIXEL_MAX = 255.0
return 20 * math.log10(PIXEL_MAX / math.sqrt(mse))
def readimage(path):
result=cv2.imread(path)
result = result.astype('float32')
result/=255
return result
def mergeimage_column(path,n):
path1=path+str(n)+'.png'
t1=cv2.imread(path1)
for i in range(1,7):
path2=path+str(n+i)+".png"
t2=cv2.imread(path2)
t1 = np.hstack((t1,t2))
return t1
def mergeimage(path):
t1=mergeimage_column(path,1)
print(t1.shape)
for i in range(1,7):
print(1+7*i)
t2=mergeimage_column(path,1+7*i)
t1 = np.vstack((t1,t2))
return t1
def Divided_Pach(path1,path2):
lena=cv2.imread(path1)
height= 224
width=224
a=0
b=0
count=0
print(width)
print(height)
path=path2
while a<height:
while b<width:
box = lena[a:a+32,b:b+32]
count=count+1
b=b+32
path2=path2+str(count)+".png"
cv2.imwrite(path2,box)
path2=path
b=0
a=a+32
print(count)
def read_file(file_name):
names=[]
labels=[]
csv_file=csv.reader(open(file_name,'r'))
for stu in csv_file:
names.append(stu[0])
labels.append(stu[1])
return names,labels