Artificial Intelligence Super Image Resolution
Upscale From 565 x 559 To 2260 x 2236
import cv2
from cv2 import dnn_superres
# 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('../MessageMP3/lowimg.jpg')
# upsample the image
upscaled = sr.upsample(image)
# save the upscaled image
cv2.imwrite('../MessageMP3/high.jpg', upscaled)
# traditional method - bicubic
bicubic = cv2.resize(image, (upscaled.shape[1], upscaled.shape[0]), interpolation=cv2.INTER_CUBIC)
# save the image
cv2.imwrite('../MessageMP3/highbicube.jpg', bicubic)
Super Resolution Image By Deep Learning Library LapSRN_x8 :-
import cv2
from cv2 import dnn_superres
# 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('MessageMP3/lowimg.jpg')
# upsample the image
upscaled = sr.upsample(image)
# save the upscaled image
cv2.imwrite('MessageMP3/high.jpg', upscaled)
# traditional method - bicubic
bicubic = cv2.resize(image, (upscaled.shape[1], upscaled.shape[0]), interpolation=cv2.INTER_CUBIC)
# save the image
cv2.imwrite('MessageMP3/highbicube.jpg', bicubic)
Super Resolution Image By Deep Learning Library FSRCNN_x3 :-
import cv2
import matplotlib.pyplot as plt
img = cv2.imread("../MessageMP3/lowimg.jpg")
sr = cv2.dnn_superres.DnnSuperResImpl_create()
path = "FSRCNN_x3.pb"
sr.readModel(path)
sr.setModel("fsrcnn",3)
result = sr.upsample(img)
cv2.imwrite("../MessageMP3/highimg1.jpg",result)
Super Resolution Image By Deep Learning Library FSRCNN_x4 :-
import cv2
import matplotlib.pyplot as plt
img = cv2.imread("../MessageMP3/lowimg.jpg")
sr = cv2.dnn_superres.DnnSuperResImpl_create()
path = "FSRCNN_x4.pb"
sr.readModel(path)
sr.setModel("fsrcnn",4)
result = sr.upsample(img)
cv2.imwrite("../MessageMP3/highimg1.jpg",result)