본문 바로가기

카테고리 없음

OpenCV super-resolution

OpenCV super-resolution
 

Super Resolution in OpenCV (learnopencv.com)

 
EDSR
 
 
 
---------------------------------------------------------------------------------------------------------------------
import cv2
import matplotlib.pyplot as plt
 
img1 = img.imread(
    'C:/Users/Inho Lee/testAI/data/denoising2/2021.08.09/line/Line 50x_001.tif')
# img1=img1[0:target_height,0:target_width]
plt.imshow(img1, cmap=plt.cm.gray)
 
sr = cv2.dnn_superres.DnnSuperResImpl_create()
path = "EDSR_x4.pb"
sr.readModel(path)
sr.setModel("edsr",4)
result = sr.upsample(img1)
# Resized image
resized = cv2.resize(img1,dsize=None,fx=4,fy=4)
 
plt.figure(figsize=(12,8))
plt.subplot(1,3,1)
# Original image
plt.imshow(img1[:,:,::-1])
plt.subplot(1,3,2)
# SR upscaled
plt.imshow(result[:,:,::-1])
plt.subplot(1,3,3)
# OpenCV upscaled
plt.imshow(resized[:,:,::-1])
plt.show()
 
---------------------------------------------------------------------------------------------------------------------
가운데 있는 이미지가 super resolution 이미지로 생성된 것이다.
학습에 사용된 이미지들.
---------------------------------------------------------------------------------------------------------------------
import cv2
import time
import matplotlib.pyplot as plt
 
img1 = cv2.imread('input.png')
width = img1.shape[1]
height = img1.shape[0]
bicubic = cv2.resize(img1, (width*4, height*4))
 
super_res = cv2.dnn_superres.DnnSuperResImpl_create()
start = time.time()
super_res.readModel('EDSR_x4.pb')
super_res.setModel('edsr', 4)
edsr_image = super_res.upsample(img1)
end = time.time()
print('Time taken in seconds by edsr', end-start)
 
plt.figure(figsize=(12,8))
plt.subplot(1,3,1)
# Original image
plt.imshow(img1[:,:,::-1])
plt.subplot(1,3,2)
# SR upscaled
plt.imshow(edsr_image[:,:,::-1])
plt.subplot(1,3,3)
# OpenCV upscaled
plt.imshow(bicubic[:,:,::-1])
plt.show()
 
---------------------------------------------------------------------------------------------------------------------