Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aswintechguy
GitHub Repository: aswintechguy/Deep-Learning-Projects
Path: blob/main/Super Resolution - OpenCV/Super Resolution - OpenCV.ipynb
569 views
Kernel: Python 3

Import Modules

import cv2 from cv2 import dnn_superres
# links to download models # https://github.com/Saafke/EDSR_Tensorflow/blob/master/models/ # https://github.com/fannymonori/TF-LapSRN/blob/master/export/LapSRN_x8.pb

EDSR

# initialize super resolution object sr = dnn_superres.DnnSuperResImpl_create() # read the model path = 'EDSR_x4.pb' sr.readModel(path) # set the model and scale sr.setModel('edsr', 4)
# if you have cuda support sr.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) sr.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
# load the image image = cv2.imread('test.png')
# upsample the image upscaled = sr.upsample(image) # save the upscaled image cv2.imwrite('upscaled_test.png', upscaled)
True
# traditional method - bicubic bicubic = cv2.resize(image, (upscaled.shape[1], upscaled.shape[0]), interpolation=cv2.INTER_CUBIC) # save the image cv2.imwrite('bicubic_test.png', bicubic)
True

LapSRN

# initialize super resolution object sr = dnn_superres.DnnSuperResImpl_create() # read the model path = 'LapSRN_x8.pb' sr.readModel(path) # set the model and scale sr.setModel('lapsrn', 8)
# if you have cuda support sr.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) sr.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
# load the image image = cv2.imread('test.png')
# upsample the image upscaled = sr.upsample(image) # save the upscaled image cv2.imwrite('upscaled_test_lapsrn.png', upscaled)
True
# traditional method - bicubic bicubic = cv2.resize(image, (upscaled.shape[1], upscaled.shape[0]), interpolation=cv2.INTER_CUBIC) # save the image cv2.imwrite('bicubic_test_8x.png', bicubic)
True