-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
68 lines (50 loc) · 2 KB
/
run.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
#!/usr/bin/env python3
import subprocess
import argparse
from PIL import Image
import math
# parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("--denoise", type=int)
ap.add_argument("--sigma", type=int)
ap.add_argument("--lambd", type=int)
ap.add_argument("--lambd_fix", type=float)
args = ap.parse_args()
files = ['input_0', 'denoised', 'diff']
sigmaguessed = 10
#Guess noise then denoise
if args.denoise:
if not args.lambd:
#dynamic lambda
option = 3
else:
#fixed lambda
option = 4
with open('guessed_lambda.txt', 'w') as file:
subprocess.run(['chambolle_ipol', str(option), 'input_0.png', str(sigmaguessed), str(args.lambd_fix), 'noisy.png', 'denoised.png'],stdout=file)
subprocess.run(['imdiff_ipol', 'input_0.png', 'denoised.png', 'diff.png', str(args.sigma)])
#Add noise then denoise
if not args.denoise:
#dynamic lambda
if not args.lambd:
option = 1
else:
#fixed lambda
option = 2
files.append('noisy')
with open('guessed_lambda.txt', 'w') as file:
subprocess.run(['chambolle_ipol', str(option), 'input_0.png', str(args.sigma), str(args.lambd_fix),
'noisy.png', 'denoised.png'], stdout=file)
with open('rmse_noisy.txt', 'w') as file:
subprocess.run(['imdiff_ipol', 'input_0.png', 'noisy.png', 'diff.png', str(args.sigma)], stdout=file)
with open('rmse_denoised.txt', 'w') as file:
subprocess.run(['imdiff_ipol', 'input_0.png', 'denoised.png', 'diff.png', str(args.sigma)], stdout=file)
# Resize for visualization (always zoom by at least 2x)
(sizeX, sizeY) = Image.open('input_0.png').size
zoomfactor = max(1, int(math.ceil(480.0/max(sizeX, sizeY))))
if zoomfactor > 1:
(sizeX, sizeY) = (zoomfactor*sizeX, zoomfactor*sizeY)
for filename in files:
im = Image.open(filename + '.png')
im = im.resize((sizeX, sizeY))
im.save(filename + '_zoom.png')