1. 一阶差分:
2. 二阶偏导数的推导和近似:
3. 上式以点(i+1,j)为中心,用i代换i+1可得以(i,j)为中心的二阶偏导数则有:
4. 同理:
5. 进而可推导:
6. 这样我们就可以很好的运用其他的一阶偏导的定义,如SIFT特征OpenCV实现版本中的一阶以及二阶偏导:
/* Computes the partial derivatives in x, y, and scale of a pixel in the DoG scale space pyramid. @param dog_pyr DoG scale space pyramid @param octv pixel's octave in dog_pyr @param intvl pixel's interval in octv @param r pixel's image row @param c pixel's image col @return Returns the vector of partial derivatives for pixel I { dI/dx, dI/dy, dI/ds }^T as a CvMat* */ static CvMat* deriv_3D( IplImage*** dog_pyr, int octv, int intvl, int r, int c ) { CvMat* dI; double dx, dy, ds; dx = ( pixval32f( dog_pyr[octv][intvl], r, c+1 ) - pixval32f( dog_pyr[octv][intvl], r, c-1 ) ) / 2.0; dy = ( pixval32f( dog_pyr[octv][intvl], r+1, c ) - pixval32f( dog_pyr[octv][intvl], r-1, c ) ) / 2.0; ds = ( pixval32f( dog_pyr[octv][intvl+1], r, c ) - pixval32f( dog_pyr[octv][intvl-1], r, c ) ) / 2.0; dI = cvCreateMat( 3, 1, CV_64FC1 ); cvmSet( dI, 0, 0, dx ); cvmSet( dI, 1, 0, dy ); cvmSet( dI, 2, 0, ds ); return dI; } /* Computes the 3D Hessian matrix for a pixel in the DoG scale space pyramid. @param dog_pyr DoG scale space pyramid @param octv pixel's octave in dog_pyr @param intvl pixel's interval in octv @param r pixel's image row @param c pixel's image col @return Returns the Hessian matrix (below) for pixel I as a CvMat* / Ixx Ixy Ixs /
| Ixy Iyy Iys |
/ Ixs Iys Iss / */ 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; }
参考:
(1)http://hi.baidu.com/shareshow/blog/item/34abdf544725cf54d109069b.html
(2)SIFT的OpenCV实现