双线性插值 Bilinear Interpolation

Definition

  1. In mathematics, bilinear interpolation is an extension of linear interpolation for interpolating functions of two variables (e.g. x and y) on a rectilinear 2D grid.
  2. Bilinear interpolation is performed using linear interpolation first in one direction and then again in the other direction. Although each step is linear in the sampled values and in the position, the interpolation as a whole is not linear but rather quadratic in the sample location.
  3. It’s one of the basic resampling techniques in computer vision and image processing, where it is also called bilinear filtering or bilinear texture mapping.
  4. red: data points; green: point at which we want to interpolate.
    在这里插入图片描述
  5. A geometric visualisation of bilinear interpolation. The product of the value at the desired point (black) and the entire area is equal to the sum of the products of the value at each corner and the partial area diagonally opposite the corner (corresponding colours).在这里插入图片描述

Algorithm

Suppose we want to find the value of the unknown function f at the point (x,y). It is assumed that we know the value of f f f at the four points Q 11 = ( x 1 , y 1 ) , Q 12 = ( x 1 , y 2 ) , Q 21 = ( x 2 , y 1 ) , Q 22 = ( x 2 , y 2 ) . Q_{11} = (x_1, y_1), Q_{12} = (x_1, y_2), Q_{21} = (x_2, y_1), Q_{22} = (x_2, y_2). Q11=(x1,y1),Q12=(x1,y2),Q21=(x2,y1),Q22=(x2,y2).

We first do linear interpolation in the x x x-direction. This yields:

f ( x , y 1 ) ≈ x 2 − x x 2 − x 1 f ( Q 11 ) + x − x 1 x 2 − x 1 f ( Q 21 ) f(x,y_1)\approx \frac{x_2-x}{x_2-x_1} f(Q_{11}) + \frac{x-x_1}{x_2-x_1}f(Q_{21}) f(x,y1)x2x1x2xf(Q11)+x2x1xx1f(Q21)

f ( x , y 2 ) ≈ x 2 − x x 2 − x 1 f ( Q 12 ) + x − x 1 x 2 − x 1 f ( Q 22 ) f(x,y_2)\approx \frac{x_2-x}{x_2-x_1} f(Q_{12}) + \frac{x-x_1}{x_2-x_1}f(Q_{22}) f(x,y2)x2x1x2xf(Q12)+x2x1xx1f(Q22)

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

在这里插入图片描述

Alternative algorithm

An alternative way to write the solution to the interpolation problem is

f ( x , y ) ≈ a 0 + a 1 x + a 2 y + a 3 x y f(x,y) \approx a_0 + a_1x+a_2y+a_3xy f(x,y)a0+a1x+a2y+a3xy

where the coefficients are found by solving the linear system

在这里插入图片描述
yielding the result

在这里插入图片描述

Unit square

If we choose a coordinate system in which the four points where f f f is know are ( 0 , 0 ) , ( 1 , 0 ) , ( 0 , 1 ) , ( 1 , 1 ) (0,0), (1,0), (0,1), (1,1) (0,0),(1,0),(0,1),(1,1), then the interpolation formula simplifies to

f ( x , y ) ≈ f ( 0 , 0 ) ( 1 − x ) ( 1 − y ) + f ( 1 , 0 ) x ( 1 − y ) + f ( 0 , 1 ) ( 1 − x ) y + f ( 1 , 1 ) x y f(x,y) \approx f(0,0)(1-x)(1-y)+f(1,0)x(1-y)+f(0,1)(1-x)y+f(1,1)xy f(x,y)f(0,0)(1x)(1y)+f(1,0)x(1y)+f(0,1)(1x)y+f(1,1)xy

or equivalently, in matrix operations:

$f(x,y) \approx $

Nonlinear

As the name suggests, the bilinear interpolant is not linear, but the product of two linear functions. For example, the bilinear interpolation derived above is a product of the values of x x x and y y y.

Alternatively, the interpolant on the unit square can be written as

f ( x , y ) = ∑ i = 1 2 ∑ j = 1 2 a i j x i − 1 y i − 1 = a 11 + a 21 x + a 12 y + a 22 x y f(x,y) = \sum_{i=1}^2\sum_{j=1}^2a_{ij}x^{i-1}y^{i-1}=a_{11}+a_{21}x+a_{12}y+a_{22}xy f(x,y)=i=12j=12aijxi1yi1=a11+a21x+a12y+a22xy

where

a 11 = f ( 1 , 1 ) a_{11}=f(1,1) a11=f(1,1)
a 21 = f ( 2 , 1 ) − f ( 1 , 1 ) a_{21}=f(2,1)-f(1,1) a21=f(2,1)f(1,1)
a 12 = f ( 1 , 2 ) − f ( 1 , 1 ) a_{12}=f(1,2)-f(1,1) a12=f(1,2)f(1,1)
a 22 = f ( 2 , 2 ) + f ( 1 , 1 ) − ( f ( 2 , 1 ) + f ( 1 , 2 ) ) a_{22}=f(2,2)+f(1,1)-\left(f(2,1)+f(1,2)\right) a22=f(2,2)+f(1,1)(f(2,1)+f(1,2))

In both cases, the number of constants (four) correspond to the number of data points where f f f is given. The interpolant is linear along lines parallel to either the x or the y direction, equivalently if x x x or y y y is set constant. Along any other straight line, the interpolant is quadratic. However, even if the interpolation is not linear in the position (x and y), it is linear in the amplitude, as it is apparent from the equations above: all the coefficients a j , j ∈ { 1 , 2 , 3 , 4 } a_j, j \in \{1,2,3,4\} aj,j{1,2,3,4} are proportional to the value of the function f f f.

The result of bilinear interpolation is independent of which axis is interpolated first and which second. If we had first performed the linear interpolation in the y direction and then in the x direction, the resulting approximation would be the same.

The obvious extension of bilinear interpolation to three dimensions is called trilinear interpolation.

Application in image processing

In computer vision and image processing, bilinear interpolation is used to resample images and textures. An algorithm is used to map a screen pixel location to a corresponding point on the texture map. A weighted average of the attributes (color, transparency, etc.) of the four surrounding texels is computed and applied to the screen pixel. This process is repeated for each pixel forming the object being textured.

When an image needs to be scaled up, each pixel of the original image needs to be moved in a certain direction based on the scale constant. However, when scaling up an image by a non-integral scale factor, there are pixels (i.e., holes) that are not assigned appropriate pixel values. In this case, those holes should be assigned appropriate RGB or grayscale values so that the output image does not have non-valued pixels.

Bilinear interpolation can be used where perfect image transformation with pixel matching is impossible, so that one can calculate and assign appropriate intensity values to pixels. Unlike other interpolation techniques such as nearest-neighbor interpolation and bicubic interpolation, bilinear interpolation uses values of only the 4 nearest pixels, located in diagonal directions from a given pixel, in order to find the appropriate color intensity values of that pixel.

Bilinear interpolation considers the closest 2 × 2 neighborhood of known pixel values surrounding the unknown pixel’s computed location. It then takes a weighted average of these 4 pixels to arrive at its final, interpolated value.

Texel: In computer graphics, a texel, texture element, or texture pixel is the fundamental unit of a texture map. Textures are represented by arrays of texels representing the texture space, just as other images are represented by arrays of pixels.

Example

在这里插入图片描述
As shown in the image above, the intensity value at the pixel computed to be at row 20.2, column 14.5 can be calculated by first linearly interpolating between the values at column 14 and 15 on each rows 20 and 21, giving

在这里插入图片描述

and then the interpolating linearly between these values, giving

在这里插入图片描述
This algorithm reduces some of the visual distortion caused by resizing an image to a non-integral zoom factor, as opposed to nearest-neighbor interpolation, which will make some pixels appear larger than others in the resized image.

Reference

  1. WIKIPEDIA - Bilinear interpolation
  2. BL-ALM: A Blind Scalable Edge-Guided Reconstruction Filter for Smart Environmental Monitoring Through Green IoMT-UAV Networks
  3. DIGITAL IMAGE INTERPOLATION
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Bilinear interpolation双线性插值)是一种用于在离散数据点之间进行插值的方法。它通过在两个方向上进行线性插值来估计未知点的值。这种插值方法常用于图像处理和计算机图形学中。 双线性插值的原理是基于两个相邻的数据点之间的线性插值。首先,根据给定的坐标找到四个最近的数据点,然后在水平和垂直方向上进行线性插值,以获得未知点的值。 以下是一个使用双线性插值的示例代码[^1]: ```python import numpy as np def bilinear_interpolation(x, y, points): x1, y1 = points[0] x2, y2 = points[1] q11 = points[2] q12 = points[3] q21 = points[4] q22 = points[5] f = 1 / ((x2 - x1) * (y2 - y1)) value = f * ( q11 * (x2 - x) * (y2 - y) + q21 * (x - x1) * (y2 - y) + q12 * (x2 - x) * (y - y1) + q22 * (x - x1) * (y - y1) ) return value # 示例数据点 points = np.array([ [0, 0, 1, 3, 2, 4], [0, 1, 6, 8, 7, 9] ]) # 插值点坐标 x = 0.5 y = 0.5 # 进行双线性插值 result = bilinear_interpolation(x, y, points) print("Interpolated value:", result) ``` 这段代码中,我们定义了一个`bilinear_interpolation`函数,它接受插值点的坐标和四个最近的数据点的值作为输入。然后,根据双线性插值的公式计算出插值点的值,并返回结果。 在上面的示例中,我们使用了一个简单的二维数组作为示例数据点,然后对坐标为(0.5, 0.5)的点进行双线性插值。最后,输出插值点的值。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值