-
Notifications
You must be signed in to change notification settings - Fork 0
/
high_resolution.py
49 lines (33 loc) · 1.21 KB
/
high_resolution.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
import cv2
from cv2 import dnn_superres
def upscale(img_path = None, scale = 8):
# upscale times 4 or 8
# !requires download pretrained models!
image = cv2.imread(img_path)
# for example: "./CAN/plots/99.png"
if scale == 8:
# Create an SR object
sr = dnn_superres.DnnSuperResImpl_create()
# Read the desired model
model_path = "./upsampling_models/LapSRN_x8.pb"
sr.readModel(model_path)
# Set the desired model and scale to get correct pre- and post-processing
sr.setModel("lapsrn", 8)
# Upscale the image
result = sr.upsample(image)
else:
# Create an SR object
sr = dnn_superres.DnnSuperResImpl_create()
# Read the desired model
model_path = "./upsampling_models/EDSR_x4.pb"
sr.readModel(model_path)
# Set the desired model and scale to get correct pre- and post-processing
sr.setModel("edsr", 4)
# Upscale the image
result = sr.upsample(image)
# show the image
#cv2.imshow("Original", image)
#cv2.imshow("Result_Upscale", result)
# Save the image
cv2.imwrite(img_path.rsplit('.', 1)[0] + '_upscale.png', result)
return result