# 各种插值算法的金字塔算法

//

//

//        para

//

double power ( double base, int para )
{
double tmp=1;
int i=0;
for ( i=0; i<para; ++i )
tmp *= base;
return tmp;
}

//

//

//         dec

//

//

double Normalize ( double value, int dec )
{
int tmp = value * power ( 10, dec );
return tmp/power ( 10, dec );
}

//

//

//           t

//           PolynomialsValues

//

bool LagrangePolynomials ( int num, double t, std::deque<double>& PolynomialsValues )
{
double        parentL, parentR, delta, cPL, cPR, value;
double        bakLeft, tCurLeft = 1, tCurRight = 0;
int                i, j, oldLength;

delta = 1.0/(num-1);
PolynomialsValues.push_back ( 1 );
//

for ( i=0; i<num-1; ++i ){
bakLeft = tCurLeft;
oldLength = PolynomialsValues.size();

if ( oldLength == 1 )
parentL = parentR = PolynomialsValues[0];
else{
parentL = PolynomialsValues[0];
parentR = PolynomialsValues[1];
}
//

cPL = tCurLeft - tCurRight;
value = Normalize( parentL * (tCurLeft-t) / cPL, 4 );
PolynomialsValues.push_back ( value );
//

tCurLeft += delta;
for ( j=0; j<oldLength-1; ++j ){
parentL = PolynomialsValues[j];
parentR = PolynomialsValues[j+1];
cPL = tCurLeft - delta - tCurRight;
cPR = tCurLeft - tCurRight - delta;

value = ((t-tCurRight)*parentL)/cPL + ((tCurLeft-t)*parentR)/cPR;
PolynomialsValues.push_back ( Normalize( value, 4 ) );

tCurLeft += delta;
tCurRight += delta;
}
//

tCurLeft -= delta;
cPR = tCurLeft - tCurRight;
value = Normalize( parentR * (t - tCurRight) / cPR, 4 );
PolynomialsValues.push_back ( value );

//

PolynomialsValues.erase(PolynomialsValues.begin(), PolynomialsValues.begin()+oldLength );

//

tCurLeft = bakLeft - delta;
tCurRight = 0;
}

return true;
}

bersteinlagrange间的差别很小,当利用lagrange进行线性插值时,每次使用的插值参数都是不同的,berstein则刚好 相反,berstein却不要求曲线必过控制点,所以berstein的多项式是逼近方法而不是插值方法,所以实现和lagrange的差不多,只是更简 单些:)
//

//

//        t

//        PolynomialsValues

//

bool BernsteinBase ( int num, double t, std::deque<double>& PolynomialsValues )
{
double        parentL, parentR, delta, value;
double        tCurLeft = 1, tCurRight = 0;
int            i, j, oldLength;
//

delta = 1.0/(num-1);
PolynomialsValues.push_back ( 1 );
//

for ( i=0; i<num-1; ++i ){
oldLength = PolynomialsValues.size();

if ( oldLength == 1 )
parentL = parentR = PolynomialsValues[0];
else{
parentL = PolynomialsValues[0];
parentR = PolynomialsValues[1];
}
//

value = Normalize( parentL * (tCurLeft-t), 4 );
PolynomialsValues.push_back ( value );
//

for ( j=0; j<oldLength-1; ++j ){
parentL = PolynomialsValues[j];
parentR = PolynomialsValues[j+1];

value = ((t-tCurRight)*parentL) + ((tCurLeft-t)*parentR);
PolynomialsValues.push_back ( Normalize( value, 4 ) );

}
//

value = Normalize( parentR * (t - tCurRight), 4 );
PolynomialsValues.push_back ( value );

//

PolynomialsValues.erase(PolynomialsValues.begin(),        PolynomialsValues.begin()+oldLength );

}

return true;
}

/* B-样条基函数,金字塔算法通式
@remark

@para num

@para t

@para SectNum            B-

@para PolynomialsValues

@return

*/
bool BSplineBase ( int stage, double t, int SectNum, std::deque<double>& PolynomialsValues )
{
double        parentL, parentR, delta, cPL, cPR, value;
double        tCurLeft, tCurRight;
int            i, j, oldLength;
//

delta = 1.0/(2*stage-1);

tCurLeft = (3+SectNum) * delta;
tCurRight = tCurLeft - delta;
PolynomialsValues.push_back ( 1 );
//

for ( i=0; i<stage; ++i ){
oldLength = PolynomialsValues.size();

if ( oldLength == 1 )
parentL = parentR = PolynomialsValues[0];
else{
parentL = PolynomialsValues[0];
parentR = PolynomialsValues[1];
}
//

cPL = tCurLeft - tCurRight;
value = Normalize( parentL * (tCurLeft-t) / cPL, 4 );
PolynomialsValues.push_back ( value );
//

tCurLeft += delta;
for ( j=0; j<oldLength-1; ++j ){
parentL = PolynomialsValues[j];
parentR = PolynomialsValues[j+1];
cPL = tCurLeft - delta - tCurRight;
cPR = tCurLeft - tCurRight - delta;

value = ((t-tCurRight)*parentL)/cPL + ((tCurLeft-t)*parentR)/cPR;
PolynomialsValues.push_back ( Normalize( value, 4 ) );

tCurLeft += delta;
tCurRight += delta;
}
//

tCurLeft -= delta;
cPR = tCurLeft - tCurRight;
value = Normalize( parentR * (t - tCurRight) / cPR, 4 );
PolynomialsValues.push_back ( value );

//

PolynomialsValues.erase(PolynomialsValues.begin(), PolynomialsValues.begin()+oldLength );

//

tCurLeft = (3+SectNum) * delta;
tCurRight = tCurLeft - (i+2)*delta;
}

return true;
}

#### 图像金字塔分层算法

2016-09-18 13:35:51

#### 图像算法之十：图像金字塔

2016-10-06 16:48:16

#### 金字塔图像分割原理解析与示例[opencv]

2015-05-19 08:47:15

#### 金字塔实现

2017-04-22 10:38:53

#### 图像处理之高斯金字塔

2013-06-18 06:58:59

#### 金字塔分组算法

2016-10-14 17:57:05

#### 图像金字塔算法matlab

2010年04月14日 542B 下载

#### Opencv图像识别从零到精通（29）-----图像金字塔，向上上下采样，resize插值

2016-08-16 15:50:53

#### 图像处理中的高斯金字塔和拉普拉斯金字塔

2016-09-22 23:29:09

#### 图像处理之图像快速插值放缩算法

2012-09-24 19:51:49