【python】OpenCV—Image Super Resolution

在这里插入图片描述

1、背景介绍

图像超分,即图像超分辨率(Image Super Resolution,简称SR),是指由一幅低分辨率图像或图像序列恢复出高分辨率图像的技术。这种技术可以显著提升图像的清晰度和细节,使其更加接近原始高分辨率图像的质量。图像超分辨率技术主要可以分为超分辨率复原和超分辨率重建两大类

  • 超分辨率复原:主要侧重于从单幅低分辨率图像中恢复出高分辨率图像,但这一过程往往受限于低分辨率图像本身的信息量,难以完全恢复所有细节。

  • 超分辨率重建:通过利用多幅低分辨率图像(通常是通过同一场景的不同视角、时间或光照条件下拍摄得到)来重建出高分辨率图像。这种方法的核心思想是用时间带宽(即获取同一场景的多帧图像序列)换取空间分辨率,实现时间分辨率向空间分辨率的转换。

EDSR、ESPCN、FSRCNN、LapSRN是四种不同的深度学习图像超分辨率(Super Resolution, SR)算法,它们在图像处理领域各有特点和应用场景。以下是对这四种算法的详细介绍:

1)EDSR(Enhanced Deep Super-Resolution Network)

EDSR是一种增强型深度超分辨率网络,旨在通过深度学习技术提高图像的分辨率。它借鉴了ResNet网络中的残差学习机制,但移除了批归一化(Batch Normalization, BN)层,以适应超分辨率这一low-level视觉任务的需求。

特点:

  • 无BN层:移除BN层以避免高频信息的丢失,确保像素点绝对值的准确性。
  • 残差学习:采用残差学习机制,通过跳过连接(Skip Connection)帮助网络更好地学习高分辨率图像的细节。
  • 高效性能:在多个基准数据集上表现出色,能够生成具有丰富细节的高分辨率图像。

应用场景:

  • EDSR广泛应用于图像和视频的超分辨率重建,包括但不限于数字图像修复、视频监控、医学影像等领域。

2)ESPCN(Efficient Sub-Pixel Convolutional Neural Network)

ESPCN是一种高效子像素卷积神经网络,用于在低分辨率图像上直接计算得到高分辨率图像。它避免了传统上采样方法(如双线性插值、双三次插值)带来的计算复杂性和信息损失。

特点:

  • 亚像素卷积层:核心在于亚像素卷积层,该层通过重新排列卷积层的输出来生成高分辨率图像。
  • 计算效率高:只需要一次卷积运算和一次反卷积运算,大大减少了计算量和时间成本。
  • 适用性强:适用于各种类型的低分辨率图像和不同的超分辨率应用场景。

应用场景:

  • ESPCN在数字图像识别、遥感图像分析、医学图像诊断等领域具有广泛应用。

3)FSRCNN(Fast Super-Resolution Convolutional Neural Network)

FSRCNN是对SRCNN(Super-Resolution Convolutional Neural Network)的改进版本,旨在提高超分辨率重建的速度和质量。它通过减少网络参数和引入更高效的卷积核来实现这一目标。

特点:

  • 直接处理低分辨率图像:与SRCNN不同,FSRCNN直接对原始低分辨率图像进行操作,避免了上采样过程带来的计算负担。
  • 非线性映射:使用多个中等大小的卷积核(3×3)代替SRCNN中的大卷积核(5×5),提高了非线性映射能力。
  • 快速重建:通过优化网络结构和参数,实现了更快的超分辨率重建速度。

应用场景:

  • FSRCNN适用于需要快速超分辨率重建的场景,如实时视频处理、移动设备图像处理等。

4)LapSRN(Laplacian Pyramid Super-Resolution Network)

LapSRN是一种基于拉普拉斯金字塔的超分辨率网络,它通过递归的方式对图像进行逐层上采样和细节恢复。

特点:

  • 递归网络结构:采用递归网络结构,通过拉普拉斯金字塔的方式对图像进行分层处理。
  • 高效性:分阶段处理不同级别的高频信息,减少了计算复杂性,提高了运算效率。
  • 高质量:通过多层次的细节恢复,生成的高分辨率图像具有丰富的细节和良好的整体结构。

应用场景:

  • LapSRN适用于需要高质量超分辨率重建的场景,如高清视频制作、医学影像处理、游戏图形渲染等。

2、准备工作

pip install opencv-contrib-python

3、EDSR

import cv2
import matplotlib.pyplot as plt

time = 4
# 读取图片
img = cv2.imread("opencv.jpg")

sr = cv2.dnn_superres.DnnSuperResImpl_create()
path = f"EDSR_x{time}.pb"
sr.readModel(path)
sr.setModel("edsr", time)
result = sr.upsample(img)

# 调整图像大小
resized = cv2.resize(img, dsize=None, fx=time, fy=time)
plt.figure(figsize=(6, 2))

# 原始图像
plt.subplot(1, 3, 1)
plt.title("Ori")
plt.imshow(img[:, :, ::-1])

# SR上采样图像
plt.subplot(1, 3, 2)
plt.title(f"SRx{time}")
plt.imshow(result[:, :, ::-1])

# OpenCV 上采样图像
plt.subplot(1, 3, 3)
plt.title("Resize")
plt.imshow(resized[:, :, ::-1])

plt.show()

EDSR_x2.pb

在这里插入图片描述

EDSR_x3.pb

在这里插入图片描述

EDSR_x4.pb

在这里插入图片描述

在这里插入图片描述

输入图片

在这里插入图片描述

输出结果 2x,与插值对比
在这里插入图片描述
输出结果 3x,与插值对比

在这里插入图片描述
输出结果 4x,与插值对比

在这里插入图片描述

4、ESPCN

import cv2
import matplotlib.pyplot as plt

time = 4

# 读取图片
img = cv2.imread("opencv.jpg")
sr = cv2.dnn_superres.DnnSuperResImpl_create()
path = f"ESPCN_x{time}.pb"
sr.readModel(path)
sr.setModel("espcn", time)
result = sr.upsample(img)

# 调整图像大小
resized = cv2.resize(img, dsize=None, fx=time, fy=time)
plt.figure(figsize=(6, 2))

# 原始图像
plt.subplot(1, 3, 1)
plt.title("Ori")
plt.imshow(img[:, :, ::-1])

# SR上采样图像
plt.subplot(1, 3, 2)
plt.title(f"SRx{time}")
plt.imshow(result[:, :, ::-1])

# OpenCV 上采样图像
plt.subplot(1, 3, 3)
plt.title("Resize")
plt.imshow(resized[:, :, ::-1])

plt.show()

ESPCN_x2.pb
在这里插入图片描述

ESPCN_x3.pb

在这里插入图片描述

ESPCN_x4.pb

在这里插入图片描述
在这里插入图片描述

超分结果

2x,与插值对比
在这里插入图片描述
3x,与插值对比

在这里插入图片描述
4x,与插值对比
在这里插入图片描述

5、FSRCNN

import cv2
import matplotlib.pyplot as plt

time = 4
# 读取图片
img = cv2.imread("opencv.jpg")

sr = cv2.dnn_superres.DnnSuperResImpl_create()
path = f"FSRCNN_x{time}.pb"
sr.readModel(path)
sr.setModel("fsrcnn", time)
result = sr.upsample(img)

# 调整图像大小
resized = cv2.resize(img, dsize=None, fx=time, fy=time)
plt.figure(figsize=(6, 2))

# 原始图像
plt.subplot(1, 3, 1)
plt.title("Ori")
plt.imshow(img[:, :, ::-1])

# SR上采样图像
plt.subplot(1, 3, 2)
plt.title(f"SRx{time}")
plt.imshow(result[:, :, ::-1])

# OpenCV 上采样图像
plt.subplot(1, 3, 3)
plt.title("Resize")
plt.imshow(resized[:, :, ::-1])

plt.show()

FSRCNN_x2.pb

在这里插入图片描述

FSRCNN_x3.pb

在这里插入图片描述

FSRCNN_x4.pb

在这里插入图片描述
在这里插入图片描述

输出结果,与插值对比

2x

在这里插入图片描述

3x
在这里插入图片描述

4x

在这里插入图片描述

6、LapSRN

import cv2
import matplotlib.pyplot as plt

time = 8
# 读取图片
img = cv2.imread("opencv.jpg")

sr = cv2.dnn_superres.DnnSuperResImpl_create()
path = f"LapSRN_x{time}.pb"
sr.readModel(path)
sr.setModel("lapsrn", time)
result = sr.upsample(img)

# 调整图像大小
resized = cv2.resize(img, dsize=None, fx=time, fy=time)
plt.figure(figsize=(6, 2))

# 原始图像
plt.subplot(1, 3, 1)
plt.title("Ori")
plt.imshow(img[:, :, ::-1])

# SR上采样图像
plt.subplot(1, 3, 2)
plt.title(f"SRx{time}")
plt.imshow(result[:, :, ::-1])

# OpenCV 上采样图像
plt.subplot(1, 3, 3)
plt.title("Resize")
plt.imshow(resized[:, :, ::-1])

plt.show()

LapSRN_x2.pb

在这里插入图片描述

LapSRN_x4.pb

在这里插入图片描述

LapSRN_x8.pb

在这里插入图片描述

在这里插入图片描述
输出结果,与插值对比

2x

在这里插入图片描述

4x

在这里插入图片描述

8x
在这里插入图片描述

7、汇总对比

import cv2
import matplotlib.pyplot as plt

# 读取图片
# img = cv2.imread("image.png")
# img = img[130:290, 150:360]

img = cv2.imread("opencv.jpg")


plt.figure(figsize=(12, 8))

# ori
plt.subplot(2, 3, 1)
plt.xticks([])
plt.yticks([])
plt.xlabel("Ori")
plt.imshow(img[:, :, ::-1])


# resize
resize = cv2.resize(img, dsize=None, fx=4, fy=4)
plt.subplot(2, 3, 2)
plt.xticks([])
plt.yticks([])
plt.xlabel("Resize_x4")
plt.imshow(resize[:, :, ::-1])


# EDSR_x4
sr = cv2.dnn_superres.DnnSuperResImpl_create()
path = "./EDSR/EDSR_x4.pb"
sr.readModel(path)
sr.setModel("edsr", 4)
result_edsr = sr.upsample(img)
plt.subplot(2, 3, 3)
plt.xticks([])
plt.yticks([])
plt.xlabel("EDSR_x4")
plt.imshow(result_edsr[:, :, ::-1])


# ESPCN_x4
sr = cv2.dnn_superres.DnnSuperResImpl_create()
path = "./ESPCN/ESPCN_x4.pb"
sr.readModel(path)
sr.setModel("espcn", 4)
result_espcn = sr.upsample(img)
plt.subplot(2, 3, 4)
plt.xticks([])
plt.yticks([])
plt.xlabel("ESPCN_x4")
plt.imshow(result_espcn[:, :, ::-1])


# FSRCNN_x4
sr = cv2.dnn_superres.DnnSuperResImpl_create()
path = "./FSRCNN/FSRCNN_x4.pb"
sr.readModel(path)
sr.setModel("fsrcnn", 4)
result_fsrcnn = sr.upsample(img)
plt.subplot(2, 3, 5)
plt.xticks([])
plt.yticks([])
plt.xlabel("FSRCNN_x4")
plt.imshow(result_fsrcnn[:, :, ::-1])


# LapSRN_x4
sr = cv2.dnn_superres.DnnSuperResImpl_create()
path = "./LapSRN/LapSRN_x4.pb"
sr.readModel(path)
sr.setModel("lapsrn", 4)
result_lapsrn = sr.upsample(img)
plt.subplot(2, 3, 6)
plt.imshow(result_lapsrn[:, :, ::-1])
plt.xticks([])
plt.yticks([])
plt.xlabel("LapSRN_x4")
plt.show()

输入图片

在这里插入图片描述

输出图片

在这里插入图片描述

输入图片

在这里插入图片描述
输出图片

在这里插入图片描述

EDSR 好像不错,大力出奇迹

8、参考

OpenCV进阶(1)基于OpenCV的超分辨率

链接:https://pan.baidu.com/s/1M0l63vxYbS7zrF3Pn9IYaQ
提取码:123a

  • 18
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值