Bilinear图像修复
2016-05-30 22:05
281 查看
Bilinear Interpolation
标签(空格分隔): GraphicsBilinear
Bilinear interpolation is an extension of linear interpolation for interpolating functions of two variables (e.g., x and y) on a rectilinear 2D grid1。Suppose that we want to find the value of the unknown function ff at the point P(x,y)P(x, y). It is assumed that we know the value of ff at the four points Q11(x1,y1),Q12(x1,y2),Q21(x2,y1),Q22(x2,y2) ~Q_{11}(x_1,y_1), Q_{12}(x_1,y_2),Q_{21}(x_2,y_1),Q_{22}(x_2,y_2)~.
We first do linear interpolation in the x-direction. This yields
f(R1)≈x2−xx2−x1f(Q11)+x−x1x2−x1f(Q21),R1=(x,y1)f(R_1)\approx {x_2-x\over{x_2-x_1}}f(Q_{11})+{x-x_1\over{x_2-x_1}}f(Q_{21}), R_1=(x,y_1) f(R2)≈x2−xx2−x1f(Q12)+x−x1x2−x1f(Q22),R2=(x,y2)f(R_2)\approx {x_2-x\over{x_2-x_1}}f(Q_{12})+{x-x_1\over{x_2-x_1}}f(Q_{22}), R_2=(x,y_2)
We proceed by interpolating in the y-direction to obtain the desired estimate
f(P)=≈y2−yy2−y1f(R1)+y−y1y2−y1f(R2)(x2−x)(y2−y)(x2−x1)(y2−y1)f(Q11)+(x−x1)(y2−y)(x2−x1)(y2−y1)f(Q21)+(x2−x)(y−y1)(x2−x1)(y2−y1)f(Q12)+(x−x1)(y−y1)(x2−x1)(y2−y1)f(Q22)\begin{align}
f(P)&\approx {y_2-y\over{y_2-y_1}}f(R_1) + {y-y_1\over{y_2-y_1}}f(R_2)\\
= & {{(x_2-x)(y_2-y)}\over{(x_2-x_1)(y_2-y_1)}}f(Q_{11})\\
&+ {{(x-x_1)(y_2-y)}\over{(x_2-x_1)(y_2-y_1)}}f(Q_{21})\\
&+ {{(x_2-x)(y-y_1)}\over{(x_2-x_1)(y_2-y_1)}}f(Q_{12})\\
&+ {{(x-x_1)(y-y_1)}\over{(x_2-x_1)(y_2-y_1)}}f(Q_{22})
\end{align}
To restore damaged pixels in the image using the bilinear interpolation, we should first find the good pixels at both four directions near the specific pixel, and then we can calculate the rgb value of it by
f=⎧⎩⎨⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪afright+bfdown+cfleft+dfupa+b+c+d,bfdown+dfupb+d,afright+cflefta+c,if |(a+c)−(b+d)|≤20if a+c>b+d+20if b+d>a+c+20
f =
\begin{cases}
\frac{a f_{right} + b f_{down} + c f_{left} + d f_{up}}{a + b + c + d}, & \text{if $|(a+c) - (b+d)|\le 20$} \\[2ex]
\frac{b f_{down} + d f_{up}}{b + d}, & \text{if $a + c > b + d + 20$} \\[2ex]
\frac{a f_{right} + c f_{left}}{a + c}, & \text{if $b + d > a + c + 20$}
\end{cases}
Now, for our test, we take a photo of mine shown below(
dong.jpg):
And then, we can damage it by adding tons of characters, just like this(
dong_dmg.jpg):
In order to restore the damaged photo, firstly we mark out the damage parts in the photo by PhotoShop(
dong_font.jpg):
After the bilinear interpolation, the output image would be:
Also, it is somewhere diffrent from the source photo, but is still effective enough for damage restore.
bilinear-Wikipedia ↩
相关文章推荐
- c++实验6
- 手机开发实战43——手机字符编码介绍1
- LeetCode-199.Binary Tree Right Side View
- 手机开发实战42——手机功能分类
- utf8编码表
- 继承(二)
- R语言实战之高级数据管理
- 算法基础 - 2-sat问题
- gbk编码表
- 第一篇博文
- 安装tushare库
- 关于PDB与DLL
- html5--canvas学习
- Scala隐式转换之隐式参数(1)
- ListView优化整理
- hive的学习笔记2-hive源码的编译
- 转的!转的!!!
- php 修改上传文件大小 (max_execution_time post_max_size)
- [BZOJ2162]男生女生(二分图带权独立集+dp)
- android httpclient 设置超时