栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

超分辨重建-Bicubic双三次线性插值opencv实现

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

超分辨重建-Bicubic双三次线性插值opencv实现

论文实验中经典方法Bicubic的Python实现 

 使用时更改文件夹、保存路径、重建倍数即可

import os
import argparse
import cv2

# parse args
parser = argparse.ArgumentParser(description='Upsize images using bicubic interpolation')
parser.add_argument("-k", "--keepdims", help="keep original image dimensions in downsampled images",
                    action="store_true")
##############################需要修改的部分#############################
parser.add_argument('--lr_img_dir', type=str, default=r'D:PythonUtilsRCAN_TestCodeLRLRBIB100x4',
                    help='path to low resolution image dir')  # 待上采样图片文件夹
parser.add_argument('--hr_img_dir', type=str, default=r'D:PythonUtilsRCAN_TestCodeLRLRBIB100',
                    help='path to desired output path for Upsampled images')  # 结果保存路径,会自动生成存储结果的文件夹,如  X2result
parser.add_argument('--scale', type=int, default=4,
                    help='path to desired output dir for Upsampled images')  # 上采样倍率
##########################################################
args = parser.parse_args()

lr_image_dir = args.lr_img_dir
hr_image_dir = args.hr_img_dir

print(args.hr_img_dir)
print(args.lr_img_dir)

# create LR image dirs
os.makedirs(hr_image_dir + f"Bicubic-x{args.scale}-result", exist_ok=True)  # 创建保存结果的文件夹

supported_img_formats = (".bmp", ".dib", ".jpeg", ".jpg", ".jpe", ".jp2",
                         ".png", ".pbm", ".pgm", ".ppm", ".sr", ".ras", ".tif",
                         ".tiff")

# Upsample LR images
for filename in os.listdir(lr_image_dir):
    if not filename.endswith(supported_img_formats):
        continue

    name, ext = os.path.splitext(filename)
    # Read LR image
    lr_img = cv2.imread(os.path.join(lr_image_dir, filename))
    hr_img_dims = (lr_img.shape[1], lr_img.shape[0])

    # Upsample image
    lr_image = cv2.resize(lr_img, (0, 0), fx=int(f"{args.scale}"), fy=int(f"{args.scale}"),
                          interpolation=cv2.INTER_CUBIC)
    if args.keepdims:
        lr_image = cv2.resize(lr_image, hr_img_dims, interpolation=cv2.INTER_CUBIC)

    cv2.imwrite(os.path.join(hr_image_dir + f"Bicubic-x{args.scale}", f"x{args.scale}_" + filename.split('.')[0] + ext),
                lr_image)  # 保存高分辨率图像
4x下的重建效果  Bicubic

RCAN 

 Bicubic

RCAN   Bicubic

RCAN

和现在的方法相比,Bicubic确实效果太差,不过实验中会经常用到进行对比 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/929678.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号