使用双立方插值填充矩阵的边界 [英] Fill the boundaries of a matrix using Bicubic interpolation

查看:214
本文介绍了使用双立方插值填充矩阵的边界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大小 28x22 的矩阵。第一行,最后两行,第一列和最后两列(以红色和绿色标记)为空。这些列和行应该由双三次插值填充。



我已经在SO和互联网上阅读了关于双三次插值的几篇帖子,但不幸的是,我无法理解它。此外,我读到双三次插值需要知道需要插值的像素周围的4x4网格。但是,由于行和列位于边界,所以我周围没有 4 x 4 网格。



解决方案

序幕



您需要推断未知区域。您需要决定从哪个信息推断数据。例如,您希望使用unknonw区域附近的点或使用沿整个已知区域分散的点。这两种方法都是有效的,但有不同的结果可以满足不同的需求。



我将使用未知区域的关闭点。让我从更简单的案例开始:


  1. 1D线性外推



    线性外推使用由2个已知点组成的线。所以例如假设这个向量:





    x axis是向量/数组索引,y轴是单元格的值。所以我拿了2个最后已知点(蓝色)并从中形成一条线(绿色)。它与下一个数组位置相交的位置有外推值(红色)。所以在C ++中看起来像这样:

      float a [8] = {1.0,2.0,4.0,8.0,10.0,7.0 ,0.0,0.0}; //你的向量(最后两个数字未知)
    a [6] = a [4] +((a [5] -a [4])* 2.0); // = 4.0
    a [7] = a [4] +((a [5] -a [4])* 3.0); // = 1.0


  2. 1D立方体外推



    它类似于#1 ,但您不使用直线,而是使用参数多项式形式的4控制点三次曲线。构造大多数三次曲线,如果参数 t = 0 ,您将获得第二个控制点,如果 t = 1 您将获得第三个控制点。如果您使用 t =< 0,1> ,那么您将平滑地在它们之间进行迭代。 Hove我们需要在最后一个控制点之后扩大范围,所以 t> = 3 步骤 1 下一点位置。所以:



      float a [8] = {1.0,2.0,4.0,8.0,10.0,7.0,0.0,0.0}; //你的向量(最后两个数字未知)
    float a0,a1,a2,a3; //你的三次曲线多项式系数(从4个控制点a [2],a [3],a [4],a [5]计算)
    浮点数t; //曲线参数
    //这里计算a0,a1,a2,a3
    t = 3.0;一个[6] = A0 + A1 * T + A2 * T * T + A3 * T * T * T * T;
    t = 4.0;一个[7] = A0 + A1 * T + A2 * T * T + A3 * T * T * T * T;

    现在如何获得 a0,a1,a2,a3 系数? Yo可以使用任何插值多项式。我最喜欢的是这个(项目符号#3 ):






    • 首先,您计算未知列(您可以),然后从中计算丢失的行(反之亦然)。



I have a matrix of size 28x22. The first row, last two rows, first column and last two columns (marked in red and green color) are empty. These columns and rows are supposed to be filled by bicubic interpolation.

I have read several posts on SO and internet about bicubic interpolation but unfortunately, I am not able to understand it. Furthermore, I read that bicubic interpolation need the knowledge of 4x4 grid around the pixel that need to be interpolated. However, since the rows and columns are at boundary so, I don't have a 4 x 4 grid around them.

解决方案

Prologue

you need to extrapolate the unknown areas. You need to decide from what info you want to extrapolate the data. For example you want to use points near the unknonw area or use points dispersed along the whole known area. Both approaches are valid but have different results matching different needs.

I will be using the close points to the unknown area. Let me start with simpler case:

  1. 1D Linear extrapolation

    Linear extrapolation uses line formed by 2 known points. so for example assume this vector:

    The x axis is the vector/array index and y axis is value of the cell. So I took 2 last known points (blue) and form a line from it (green). Where it intersects next array positions there are your extrapolated values (red). So in C++ it looks like this:

    float a[8]={ 1.0,2.0,4.0,8.0,10.0,7.0,0.0,0.0 }; // your vector (last two numbers are unknown)
    a[6]=a[4]+((a[5]-a[4])*2.0); // =4.0
    a[7]=a[4]+((a[5]-a[4])*3.0); // =1.0
    

  2. 1D cubic extrapolation

    It is similar to #1 but instead of line you use 4 control point cubic curve in parametric polynomial form. Most cubic curves are constructed so that if parameter t=0 you will obtain second control point and if t=1 you will obtain third control point. If you use t=<0,1> then you will iterate between them smoothly. Hove ever we need to expand the range after the last control point so t>=3 with step 1 for next point position. So:

    float a[8]={ 1.0,2.0,4.0,8.0,10.0,7.0,0.0,0.0 }; // your vector (last two numbers are unknown)
    float a0,a1,a2,a3; // your cubic curve polynomial coefficients (computed from 4 control points a[2],a[3],a[4],a[5])
    float t; // curve parameter
    // here compute the a0,a1,a2,a3
    t=3.0; a[6]=a0+a1*t+a2*t*t+a3*t*t*t*t;
    t=4.0; a[7]=a0+a1*t+a2*t*t+a3*t*t*t*t;
    

    Now how to obtain the a0,a1,a2,a3 coefficients? Yo can use any interpolation polynomial. My favorite is this (bullet #3):

    So here it is (hope I did not some silly index mistake while replacing pi with a[2+i]):

    float  d1,d2;
    d1=0.5*(a[4]-a[2]);
    d2=0.5*(a[5]-a[3]);
    a0=a[3];
    a1=d1;
    a2=(3.0*(a[4]-a[3]))-(2.0*d1)-d2;
    a3=d1+d2+(2.0*(-a[4]+a[3]));
    

  3. 2D Bi-cubic extrapolation

    This is just separating the problem into set of 1D cubic extrapolations. If you look at the graphs from #2 from above you will see for bi-cubic this:

    So first you compute unknown columns (which you can) and then from it compute the missing rows (or vice versa).

这篇关于使用双立方插值填充矩阵的边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆