# Bilinear Interpolation

### 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 f$f$ at the point P(x,y)$P(x, y)$. It is assumed that we know the value of f$f$ 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)x2xx2x1f(Q11)+xx1x2x1f(Q21),R1=(x,y1)
f(R2)x2xx2x1f(Q12)+xx1x2x1f(Q22),R2=(x,y2)

We proceed by interpolating in the y-direction to obtain the desired estimate

f(P)=y2yy2y1f(R1)+yy1y2y1f(R2)(x2x)(y2y)(x2x1)(y2y1)f(Q11)+(xx1)(y2y)(x2x1)(y2y1)f(Q21)+(x2x)(yy1)(x2x1)(y2y1)f(Q12)+(xx1)(yy1)(x2x1)(y2y1)f(Q22)

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

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图像修复 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)