超分辨率重建双三次插值Bicubic生成高分辨率图像

目录

一背景

二代码

三注意


一背景

在超分任务中,为了做对比实验,需要双三次插值算法生成高分辨率图像。为此写了简单代码实现。

二代码

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'C:\Users\Administrator\Desktop\dunhuangchaofen\Testset\Set5\X2',
                    help='path to low resolution image dir') #待上采样图片文件夹
parser.add_argument('--hr_img_dir', type=str, default=r'C:\Users\Administrator\Desktop\bicubic',
                    help='path to desired output path for Upsampled images') #结果保存路径,会自动生成存储结果的文件夹,如  X2result
parser.add_argument('--scale', type=int, default=2,
                    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"\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"\X{args.scale}result", f"x{args.scale}_"+filename.split('.')[0]  + ext), lr_image) #保存高分辨率图像

三注意

使用时,修改输入图像的文件夹,修改生成结果保存的位置,修改双三次插值上采样的倍率。

相关链接:

超分辨率重建中,生成低分辨率数据集

超分辨率重建数据集制作:生成低分辨率数据集_Alocus_的博客-CSDN博客_超分辨率数据集背景超分辨率重建任务需要高清和对应的低质图像。由于需要自己制作超分辨率重建数据集,需要将高分辨率图像按照公认的方式(DIV2k)制作为低分辨率图像,我根据网上代码进行了改造可运行代码如下:代码import osimport argparseimport cv2#parse argsparser = argparse.ArgumentParser(description='Downsize images at 2x using bicubic interpolation')parhttps://blog.csdn.net/Crystal_remember/article/details/122899283

  • 9
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Alocus_

如果我的内容帮助到你,打赏我吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值