图像&视频编辑工具箱MMEditing使用示例:图像超分辨率(super-resolution)

Posted fengbingchun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图像&视频编辑工具箱MMEditing使用示例:图像超分辨率(super-resolution)相关的知识,希望对你有一定的参考价值。

      MMEditing的介绍及安装参考:https://blog.csdn.net/fengbingchun/article/details/126331541,这里给出图像超分的测试代码,论文:《Learning Continuous Image Representation with Local Implicit Image Function》:

      (1).下载模型(checkpoint):

def download_checkpoint(path, name, url):
	if os.path.isfile(path+name) == False:
		print("checkpoint(model) file does not exist, now download ...")
		subprocess.run(["wget", "-P", path, url])

path = "../../data/model/"
checkpoint = "liif_edsr_norm_c64b16_g1_1000k_div2k_20210715-ab7ce3fc.pth"
url = "https://download.openmmlab.com/mmediting/restorers/liif/liif_edsr_norm_c64b16_g1_1000k_div2k_20210715-ab7ce3fc.pth"
download_checkpoint(path, checkpoint, url)

      (2).根据配置文件和checkpoint文件构建模型:

config = "../../src/mmediting/configs/restorers/liif/liif_edsr_norm_c64b16_g1_1000k_div2k.py"
model = init_model(config, path+checkpoint, device)

      (3).准备测试图像:源图来自于MMEditing

image_path = "../../src/mmediting/tests/data/gt/"
image_name = "baboon.png"

     

      (4).进行推理产生超分图:

result = restoration_inference(model, image)
print(f"result shape: result.shape; max value: torch.max(result)") # result shape: torch.Size([1, 3, 1920, 2000]); max value: 1.0

      (5).显示执行结果及保存图像:

def crop_save_image(srcimage, dstimage, name):
	crop_height, crop_width = int(srcimage.shape[1]/2), int(srcimage.shape[0]/2)
	print(f"crop height: crop_height; crop width: crop_width, data type: type(crop_height)")

	mat = cv2.resize(srcimage, (dstimage.shape[1], dstimage.shape[0]))
	srccrop = mat[0:crop_height, 0:crop_width]
	dstcrop = dstimage[0:crop_height, 0:crop_width]

	path = "../../data/"
	cv2.imwrite(path+"src_"+name, srccrop)
	cv2.imwrite(path+"result_"+name, dstcrop)

	cv2.imshow("show_src", srccrop)
	cv2.waitKey(0)
	cv2.imshow("show_result", dstcrop)
	cv2.waitKey(0)

result = tensor2img(result)
srcimage = cv2.imread(image)
crop_save_image(srcimage, result, "restoration_liif.png")

      结果如下图所示:左图为源图,右图为结果图,仅显示图像的部分结果

                       

       GitHubhttps://github.com/fengbingchun/PyTorch_Test

 

以上是关于图像&视频编辑工具箱MMEditing使用示例:图像超分辨率(super-resolution)的主要内容,如果未能解决你的问题,请参考以下文章

图像&视频编辑工具箱MMEditing使用示例:图像抠图(matting)

图像&视频编辑工具箱MMEditing使用示例:图像超分辨率(super-resolution)

<图形图像,动画,多媒体> 读书笔记 --- 录制与编辑视频

Jitsi 开源视频会议远程桌面共享&&文档共享工具

在 C# 中裁剪和编辑图像

手机上的好工具分享,不能错过的清爽视频编辑!