机器学习笔记 - 使用opencv的基于深度学习的超分辨率图像处理

OpenCV超分辨率模型

理论参考和模型下载地址见下表,github上提供了模型训练的程序以及图像等。

  描述 论文地址 github地址
EDSR 用于单图像超分辨率的增强型深度残差网络 https://arxiv.org/abs/1707.02921 https://github.com/Saafke/EDSR_Tensorflow
ESPCN 卷积神经网络进行实时单图像和视频超分辨率 https://arxiv.org/abs/1609.05158 https://github.com/fannymonori/TF-ESPCN
FSRCNN 加速超分辨率卷积神经网络 https://arxiv.org/abs/1608.00367 https://github.com/Saafke/FSRCNN_Tensorflow
LapSRN 使用拉普拉斯金字塔网络实现 https://github.com/fannymonori/TF-LAPSRN https://github.com/fannymonori/TF-LAPSRN

为了应用OpenCV超分辨率,您必须在系统上安装OpenCV 4.3(或更高版本)。而dnn_superes 早在OpenCV 4.1.2中,该是用C ++实现的,直到OpenCV 4.3才实现Python版本。

Python参考代码

# import the necessary packages
import argparse
import time
import cv2
import os

# extract the model name and model scale from the file path
modelName = args["model"].split(os.path.sep)[-1].split("_")[0].lower()
modelScale = args["model"].split("_x")[-1]
modelScale = int(modelScale[:modelScale.find(".")])

# initialize OpenCV's super resolution DNN object, load the super
# resolution model from disk, and set the model name and scale
print("[INFO] loading super resolution model: {}".format(args["model"]))
print("[INFO] model name: {}".format(modelName))
print("[INFO] model scale: {}".format(modelScale))
sr = cv2.dnn_superres.DnnSuperResImpl_create()
sr.readModel(args["model"])
sr.setModel(modelName, modelScale)

# load the input image from disk and display its spatial dimensions
image = cv2.imread(args["image"])
print("[INFO] w: {}, h: {}".format(image.shape[1], image.shape[0]))
# use the super resolution model to upscale the image, timing how
# long it takes
start = time.time()
upscaled = sr.upsample(image)
end = time.time()
print("[INFO] super resolution took {:.6f} seconds".format(end - start))
# show the spatial dimensions of the super resolution image
print("[INFO] w: {}, h: {}".format(upscaled.shape[1],upscaled.shape[0]))

# resize the image using standard bicubic interpolation
start = time.time()
bicubic = cv2.resize(image, (upscaled.shape[1], upscaled.shape[0]),interpolation=cv2.INTER_CUBIC)
end = time.time()
print("[INFO] bicubic interpolation took {:.6f} seconds".format(end - start))

# show the original input image, bicubic interpolation image, and
# super resolution deep learning output
cv2.imshow("Original", image)
cv2.imshow("Bicubic", bicubic)
cv2.imshow("Super Resolution", upscaled)
cv2.waitKey(0)

EDSR

从左到右,依次是原始图像、输入的图像、三次插值、EDSR_x4输出的图,看起来比原始图片要平滑一些。EDSR超分辨率模型的缺点是速度有点慢。

ESPCN_x4

下面图片从上到下依次是原始图、三次插值的图、ESPCN_x4输出的图。超分辨率图像看起来“更平滑”。

FSRCNN 

LapSRN 

猜你喜欢

转载自blog.csdn.net/bashendixie5/article/details/110679543
今日推荐