如何将taylor系列扩展应用于opencv中的图像?

时间:2017-11-05 14:44:02

标签: python numpy opencv sift taylor-series

对于计算机视觉项目,我正在尝试实施D.Lowe paper(SIFT)。我被困在将此(检查ppt图像)转换为代码。你能告诉我如何将泰勒系列扩展应用到代码中(公式如下)。你知道我可以用来计算这个D(x)的numpy中的任何函数吗?你能在python中为D(x)提供一个简短的代码。

Taylor series expansion

Video Credits

1 个答案:

答案 0 :(得分:0)

要更好地了解SIFT Taylor Expansion working out subpixel locations, 后来找到下面的c ++代码,它是SIFT的真正实现。

static void interp_step( IplImage*** dog_pyr, int octv, int intvl, int r, int c,
             double* xi, double* xr, double* xc )
{
  CvMat* dD, * H, * H_inv, X;
  double x[3] = { 0 };

  dD = deriv_3D( dog_pyr, octv, intvl, r, c );
  H = hessian_3D( dog_pyr, octv, intvl, r, c );
  H_inv = cvCreateMat( 3, 3, CV_64FC1 );
  cvInvert( H, H_inv, CV_SVD );
  cvInitMatHeader( &X, 3, 1, CV_64FC1, x, CV_AUTOSTEP );
  cvGEMM( H_inv, dD, -1, NULL, 0, &X, 0 );

  cvReleaseMat( &dD );
  cvReleaseMat( &H );
  cvReleaseMat( &H_inv );

  *xi = x[2];
  *xr = x[1];
  *xc = x[0];
}


static CvMat* hessian_3D( IplImage*** dog_pyr, int octv, int intvl, int r,
              int c )
{
  CvMat* H;
  double v, dxx, dyy, dss, dxy, dxs, dys;

  v = pixval32f( dog_pyr[octv][intvl], r, c );
  dxx = ( pixval32f( dog_pyr[octv][intvl], r, c+1 ) + 
      pixval32f( dog_pyr[octv][intvl], r, c-1 ) - 2 * v );
  dyy = ( pixval32f( dog_pyr[octv][intvl], r+1, c ) +
      pixval32f( dog_pyr[octv][intvl], r-1, c ) - 2 * v );
  dss = ( pixval32f( dog_pyr[octv][intvl+1], r, c ) +
      pixval32f( dog_pyr[octv][intvl-1], r, c ) - 2 * v );
  dxy = ( pixval32f( dog_pyr[octv][intvl], r+1, c+1 ) -
      pixval32f( dog_pyr[octv][intvl], r+1, c-1 ) -
      pixval32f( dog_pyr[octv][intvl], r-1, c+1 ) +
      pixval32f( dog_pyr[octv][intvl], r-1, c-1 ) ) / 4.0;
  dxs = ( pixval32f( dog_pyr[octv][intvl+1], r, c+1 ) -
      pixval32f( dog_pyr[octv][intvl+1], r, c-1 ) -
      pixval32f( dog_pyr[octv][intvl-1], r, c+1 ) +
      pixval32f( dog_pyr[octv][intvl-1], r, c-1 ) ) / 4.0;
  dys = ( pixval32f( dog_pyr[octv][intvl+1], r+1, c ) -
      pixval32f( dog_pyr[octv][intvl+1], r-1, c ) -
      pixval32f( dog_pyr[octv][intvl-1], r+1, c ) +
      pixval32f( dog_pyr[octv][intvl-1], r-1, c ) ) / 4.0;

  H = cvCreateMat( 3, 3, CV_64FC1 );
  cvmSet( H, 0, 0, dxx );
  cvmSet( H, 0, 1, dxy );
  cvmSet( H, 0, 2, dxs );
  cvmSet( H, 1, 0, dxy );
  cvmSet( H, 1, 1, dyy );
  cvmSet( H, 1, 2, dys );
  cvmSet( H, 2, 0, dxs );
  cvmSet( H, 2, 1, dys );
  cvmSet( H, 2, 2, dss );

  return H;
}

参考: https://github.com/robwhess/opensift/blob/master/src/sift.c