您的位置:首页 > 其它

Bilinear图像修复

2016-05-30 22:05 281 查看

Bilinear Interpolation

标签(空格分隔): Graphics

Bilinear

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: