/
maek_graphics.py
171 lines (152 loc) · 5.99 KB
/
maek_graphics.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
def run_and_print(comm):
from subprocess import Popen,check_call,check_output
print 'running',' '.join(comm)
child = Popen(comm)
return child
def do_graphics(compressions):
global myinfile,myskip,mytensor
print "doing compression with ratios",compressions
map(float,compressions) # catches errors
names_fourier = map(lambda x: myinfile[:-4] + '_' + 'fourier'
+ '_' + str(x).replace('.','_') + myinfile[-4:],
compressions)
names_haar = map(lambda x: myinfile[:-4] + '_' + 'haar'
+ '_' + str(x).replace('.','_') + myinfile[-4:],
compressions)
names_db2 = map(lambda x: myinfile[:-4] + '_' + 'db2'
+ '_' + str(x).replace('.','_') + myinfile[-4:],
compressions)
names_haar_t = map(lambda x: myinfile[:-4] + '_' + 'haar_t'
+ '_' + str(x).replace('.','_') + myinfile[-4:],
compressions)
names_db2_t = map(lambda x: myinfile[:-4] + '_' + 'db2_t'
+ '_' + str(x).replace('.','_') + myinfile[-4:],
compressions)
from os.path import isfile
bullshit = ['echo','IT\'S OVER 9... ik heb geen ideeen meer man']
commlist_fourier = map(lambda x: ['python2','3chan.py','-c',x[0],'-o',x[1],myinfile]
if not isfile(x[1]) else bullshit,
zip(compressions,names_fourier))
commlist_haar = map(lambda x: ['python2','wave_img.py','-w','haar','--smooth',
'-c',x[0],'-o',x[1],myinfile]
if not isfile(x[1]) else bullshit,
zip(compressions,names_haar))
commlist_db2 = map(lambda x: ['python2','wave_img.py','-w','db2','--smooth',
'-c',x[0],'-o',x[1],myinfile]
if not isfile(x[1]) else bullshit,
zip(compressions,names_db2))
commlist_haar_t = map(lambda x: ['python2','wave_img.py','--tensor','-w','haar',
'--smooth','-c',x[0],'-o',x[1],myinfile]
if not isfile(x[1]) else bullshit,
zip(compressions,names_haar_t))
commlist_db2_t = map(lambda x: ['python2','wave_img.py','--tensor','-w','db2','--smooth',
'-c',x[0],'-o',x[1],myinfile]
if not isfile(x[1]) else bullshit,
zip(compressions,names_db2_t))
if not myskip:
ch_1 = map(run_and_print,commlist_fourier)
map(lambda x: x.wait(),ch_1)
ch_2 = map(run_and_print,commlist_haar)
map(lambda x: x.wait(),ch_2)
ch_3 = map(run_and_print,commlist_db2)
map(lambda x: x.wait(),ch_3)
ch_4 = map(run_and_print,commlist_haar_t)
map(lambda x: x.wait(),ch_4)
ch_5 = map(run_and_print,commlist_db2_t)
map(lambda x: x.wait(),ch_5)
from PSNR import do_PSNR
imges_fourier = do_PSNR(['',myinfile]+names_fourier)
imges_db2 = do_PSNR(['',myinfile]+names_db2)
imges_haar = do_PSNR(['',myinfile]+names_haar)
imges_db2_t = do_PSNR(['',myinfile]+names_db2_t)
imges_haar_t = do_PSNR(['',myinfile]+names_haar_t)
print imges_fourier
print imges_haar
print imges_db2
print imges_haar_t
print imges_db2_t
psnr_fourier = map(lambda x: x[0], imges_fourier)
psnr_haar = map(lambda x: x[0], imges_haar)
psnr_db2 = map(lambda x: x[0], imges_db2)
psnr_haar_t = map(lambda x: x[0], imges_haar_t)
psnr_db2_t = map(lambda x: x[0], imges_db2_t)
ratios = map(lambda x: x, compressions)
real_list = [
{
'label':'Fourier',
'psnr':psnr_fourier,
'ratios':ratios
},
{
'label':'Haar',
'psnr':psnr_haar,
'ratios':ratios
},
{
'label':'Daubechies 2',
'psnr':psnr_db2,
'ratios':ratios
}
]
if mytensor:
real_list += [
{
'label':'Haar (Tensor)',
'psnr':psnr_haar_t,
'ratios':ratios
},
{
'label':'Daubechies 2 (Tensor)',
'psnr':psnr_db2_t,
'ratios':ratios
}]
import matplotlib.pyplot as plt
for i in range( len( real_list )):
lst = real_list[i]
plt.plot(lst['ratios'],lst['psnr'],label=lst['label'])
plt.title(myinfile)
plt.legend(loc=2)
plt.show()
with open(myinfile[:-4]+".tbl","w") as f:
print >>f,"\\begin{array}{c c c c c}"
print >>f,"\\% & fourier & haar & db2\\\\"
for c in range(len(ratios)):
print >>f,"%.3f & %.3f & %.3f & %.3f \\\\" % (float(ratios[c]),float(psnr_fourier[c]),
float(psnr_haar[c]),float(psnr_db2[c]))
print >>f,"\\end{array}"
if __name__=="__main__":
from sys import stderr
import CLI,sys
my_opts = [
# short, long, args, description
('p','psnr',0,'skips to PSNR calc'),
('t','tensor',1,'tensor ja/nee ja!'),
('i','infile',1,"set infile to <arg>"),
('h','help',0,'print this message')
]
my_usage = CLI.usage("maek_graphics.py [-i picture] <compressions>",
"Makes fancy gaphics",
my_opts)
try:
args, opts = CLI.parse_args(sys.argv,my_opts) #throws IOError on error
except IOError:
print my_usage.short()
exit(1)
from Wavelet_Defs import wavelet_dict
mytensor = False
myinfile = None
myskip = False
for o in opts:
if o[0] == 'tensor':
mytensor = True
elif o[0] == 'psnr':
myskip = True
elif o[0] == 'infile':
myinfile = o[1]
elif o[0] == 'help':
print my_usage
exit(1)
if len(args) == 1: # additional IOError
print my_usage.short()
exit(1)
do_graphics(args[1:])