(Python)制作超分重建效果对比图

17 篇文章 44 订阅 ¥19.90 ¥99.00

Python制作超分重建效果对比图

使用python绘制超分重建中的重建效果对比图(调用matplotlib库中的pyplot)

一、运行效果

二、实现过程

1、鼠标点击读取图片位置

1.实现代码:
import cv2

img = cv2.imread(r"D:\SR\demo\baby.png")     # 图片的路径
a = []
b = [<
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
分辨率重建中,bicubic像是通过对原始低分辨率像进行插值得到的。具体地,bicubic插值是一种高阶插值方法,它利用原始像素周围的16个像素点进行插值计算,生成更加平滑的像。 下面是使用Python中的PIL库实现bicubic插值的代码: ```python from PIL import Image import numpy as np # 定义bicubic插值函数 def bicubic_interp(img, x, y): x = np.asarray(x) y = np.asarray(y) H, W = img.shape[:2] x = np.clip(x, 1, W-2) y = np.clip(y, 1, H-2) x0 = np.floor(x).astype(int) y0 = np.floor(y).astype(int) x1 = x0 + 1 y1 = y0 + 1 wx = x - x0 wy = y - y0 wx2 = wx ** 2 wx3 = wx ** 3 wy2 = wy ** 2 wy3 = wy ** 3 img0 = img[y0, x0] img1 = img[y0, x1] img2 = img[y0, x0+1] img3 = img[y0, x0+2] img4 = img[y1, x0] img5 = img[y1, x1] img6 = img[y1, x0+1] img7 = img[y1, x0+2] res = img0*(1-wx2*(2-wx)) + img1*(1-wx2*wx) + img2*(wx3-2*wx2+1) + img3*(wx3-wx2) + \ img4*(1-wx2*(2-wx)) + img5*(1-wx2*wx) + img6*(wx3-2*wx2+1) + img7*(wx3-wx2) res = res*(1-wy2*(2-wy)) + img1*(1-wy2*wy) + img5*(1-wy2*wy) + img6*(wy3-2*wy2+1) + img7*(wy3-wy2) + \ img0*(1-wy2*(2-wy)) + img2*(1-wy2*wy) + img4*(1-wy2*wy) + img3*(wy3-2*wy2+1) return res # 加载低分辨率像并进行bicubic插值 img_lr = Image.open('low_res_image.png') img_lr = np.array(img_lr) H, W = img_lr.shape[:2] scale = 4 # 放大倍数 img_hr = np.zeros((H*scale, W*scale, 3), dtype=np.uint8) for h in range(H*scale): for w in range(W*scale): h_lr = h / scale w_lr = w / scale img_hr[h, w] = bicubic_interp(img_lr, w_lr, h_lr) # 将像保存为文件 Image.fromarray(img_hr).save('bicubic_image.png') ``` 上述代码中,`bicubic_interp`函数实现了bicubic插值算法,输入参数为低分辨率像和目标像素点坐标,输出为插值后的像素值。`img_lr`是低分辨率像,`img_hr`是通过bicubic插值得到的高分辨率像,`scale`表示放大倍数。在实现过程中,我们先遍历高分辨率像的每个像素点,然后计算其对应的低分辨率像中的坐标,并利用`bicubic_interp`函数进行插值计算,得到其像素值。最后,将插值后的像保存为文件。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

加斯顿工程师

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值