超分辨重建-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:\PythonUtils\RCAN_TestCode\LR\LRBI\B100\x4',
                    help='path to low resolution image dir')  # 待上采样图片文件夹
parser.add_argument('--hr_img_dir', type=str, default=r'D:\PythonUtils\RCAN_TestCode\LR\LRBI\B100',
                    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确实效果太差,不过实验中会经常用到进行对比 

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值