2018-08-07 15:52:26 Kedongyu_ 阅读数 454

      1. X轴方向

矩阵是离散的,所以:

 

      编写代码:

def gradx(Img, sx = 1.0):          
    return sx * (Img[1: , : ] - Img[ :-1, : ]) 

      2. Y轴方向

      编写代码:

def grady(Img, sy = 1.0):
    return sy * (Img[ : , 1: ] - Img[ : , : -1])
2010-11-20 14:14:00 xiaofengsheng 阅读数 17489

 1. 一阶差分:

 

2. 二阶偏导数的推导和近似:

 

3. 上式以点(i+1,j)为中心,用i代换i+1可得以(i,j)为中心的二阶偏导数则有:

 

4. 同理:

 

5. 进而可推导:

 

6. 这样我们就可以很好的运用其他的一阶偏导的定义,如SIFT特征OpenCV实现版本中的一阶以及二阶偏导:

 

参考:

(1)http://hi.baidu.com/shareshow/blog/item/34abdf544725cf54d109069b.html

(2)SIFT的OpenCV实现

2015-02-11 15:40:20 xiaoxin_ling 阅读数 4067

1. 一阶差分:

2. 二阶偏导数的推导和近似:

3. 上式以点(i+1,j)为中心,用i代换i+1可得以(i,j)为中心的二阶偏导数则有:

4. 同理:

5. 进而可推导:

6. 这样我们就可以很好的运用其他的一阶偏导的定义,如SIFT特征OpenCV实现版本中的一阶以及二阶偏导:

  1. /*
  2. Computes the partial derivatives in x, y, and scale of a pixel in the DoG
  3. scale space pyramid.
  4. @param dog_pyr DoG scale space pyramid
  5. @param octv pixel's octave in dog_pyr
  6. @param intvl pixel's interval in octv
  7. @param r pixel's image row
  8. @param c pixel's image col
  9. @return Returns the vector of partial derivatives for pixel I
  10.     { dI/dx, dI/dy, dI/ds }^T as a CvMat*
  11. */ 
  12. static CvMat* deriv_3D( IplImage*** dog_pyr, int octv, int intvl, int r, int c ) 
  13.     CvMat* dI; 
  14.     double dx, dy, ds; 
  15.  
  16.     dx = ( pixval32f( dog_pyr[octv][intvl], r, c+1 ) - 
  17.         pixval32f( dog_pyr[octv][intvl], r, c-1 ) ) / 2.0; 
  18.     dy = ( pixval32f( dog_pyr[octv][intvl], r+1, c ) - 
  19.         pixval32f( dog_pyr[octv][intvl], r-1, c ) ) / 2.0; 
  20.     ds = ( pixval32f( dog_pyr[octv][intvl+1], r, c ) - 
  21.         pixval32f( dog_pyr[octv][intvl-1], r, c ) ) / 2.0; 
  22.  
  23.     dI = cvCreateMat( 3, 1, CV_64FC1 ); 
  24.     cvmSet( dI, 0, 0, dx ); 
  25.     cvmSet( dI, 1, 0, dy ); 
  26.     cvmSet( dI, 2, 0, ds ); 
  27.  
  28.     return dI; 
  29.  
  30.  
  31.  
  32. /*
  33. Computes the 3D Hessian matrix for a pixel in the DoG scale space pyramid.
  34. @param dog_pyr DoG scale space pyramid
  35. @param octv pixel's octave in dog_pyr
  36. @param intvl pixel's interval in octv
  37. @param r pixel's image row
  38. @param c pixel's image col
  39. @return Returns the Hessian matrix (below) for pixel I as a CvMat*
  40.     / Ixx  Ixy  Ixs / <BR>
  41.     | Ixy  Iyy  Iys | <BR>
  42.     / Ixs  Iys  Iss /
  43. */ 
  44. static CvMat* hessian_3D( IplImage*** dog_pyr, int octv, int intvl, int r, int c ) 
  45.     CvMat* H; 
  46.     double v, dxx, dyy, dss, dxy, dxs, dys; 
  47.  
  48.     v = pixval32f( dog_pyr[octv][intvl], r, c ); 
  49.     dxx = ( pixval32f( dog_pyr[octv][intvl], r, c+1 ) +  
  50.             pixval32f( dog_pyr[octv][intvl], r, c-1 ) - 2 * v ); 
  51.     dyy = ( pixval32f( dog_pyr[octv][intvl], r+1, c ) + 
  52.             pixval32f( dog_pyr[octv][intvl], r-1, c ) - 2 * v ); 
  53.     dss = ( pixval32f( dog_pyr[octv][intvl+1], r, c ) + 
  54.             pixval32f( dog_pyr[octv][intvl-1], r, c ) - 2 * v ); 
  55.     dxy = ( pixval32f( dog_pyr[octv][intvl], r+1, c+1 ) - 
  56.             pixval32f( dog_pyr[octv][intvl], r+1, c-1 ) - 
  57.             pixval32f( dog_pyr[octv][intvl], r-1, c+1 ) + 
  58.             pixval32f( dog_pyr[octv][intvl], r-1, c-1 ) ) / 4.0; 
  59.     dxs = ( pixval32f( dog_pyr[octv][intvl+1], r, c+1 ) - 
  60.             pixval32f( dog_pyr[octv][intvl+1], r, c-1 ) - 
  61.             pixval32f( dog_pyr[octv][intvl-1], r, c+1 ) + 
  62.             pixval32f( dog_pyr[octv][intvl-1], r, c-1 ) ) / 4.0; 
  63.     dys = ( pixval32f( dog_pyr[octv][intvl+1], r+1, c ) - 
  64.             pixval32f( dog_pyr[octv][intvl+1], r-1, c ) - 
  65.             pixval32f( dog_pyr[octv][intvl-1], r+1, c ) + 
  66.             pixval32f( dog_pyr[octv][intvl-1], r-1, c ) ) / 4.0; 
  67.  
  68.     H = cvCreateMat( 3, 3, CV_64FC1 ); 
  69.     cvmSet( H, 0, 0, dxx ); 
  70.     cvmSet( H, 0, 1, dxy ); 
  71.     cvmSet( H, 0, 2, dxs ); 
  72.     cvmSet( H, 1, 0, dxy ); 
  73.     cvmSet( H, 1, 1, dyy ); 
  74.     cvmSet( H, 1, 2, dys ); 
  75.     cvmSet( H, 2, 0, dxs ); 
  76.     cvmSet( H, 2, 1, dys ); 
  77.     cvmSet( H, 2, 2, dss ); 
  78.  
  79.     return H; 

2019-04-02 09:28:40 baidu_38172402 阅读数 489

 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 / &lt;BR&gt;
	| Ixy  Iyy  Iys | &lt;BR&gt;
	/ 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;
}

转载自:https://blog.csdn.net/xiaofengsheng/article/details/6023368

2017-11-23 10:05:11 qccz123456 阅读数 3300

http://www.cnblogs.com/dengdan890730/p/6145585.html


一阶导数与二阶导数的计算

图像I可以看作(x,y)∈N2→N的映射: i=f(x,y). 其中N为正整数.很明显f在定义域上是不连续的.
不连续函数f(x,y)的导数, 严格来说不算能算作导数, 只是形式上与真正的导数相似. 取Δx=1, 一阶与二阶偏导数分别为:


为简单起见, f(x,y)简写成f(x), 因为求关于x的偏导数时y是恒定的.

作为Spatial Domain Filter的特点

  • 一阶导数提取出来的边缘较粗,
  • 二阶导数对细节更敏感, 如细线, 噪声等. 它提取出来的边缘更细更强(sharp)
  • 二阶导数的符号可用来判断一个转变(transition)是从亮到暗或者相反.
  • 应用二阶导数时容易出现double-line effect. (中间位置的二阶导数值与两边的往往不同). 出现双线效应的前提是线本身的宽度小于mask, 否则就不当作线, 而是region了.(见10.2.3)

    注意, 上面的中间和两边的含义是: 只在一条水平线考察图片, x处理edge上为中间位置, x−1,x+1为两边位置.


Reference

  • Digital Image Processing, 3rd edition, Chapter 10



关于导数总结如下:

(1)一阶导数通常图像中产生较粗的边缘

(2)二阶导数对精细细节,如细线、孤立点和噪声有较强的响应

(3)二阶导数在灰度斜坡和灰度台阶过度处会产生双边沿响应

(4)二阶导数的符号可以确定边缘的过渡是从亮到暗还是从暗到亮

(5)选导数提取边沿之前最好是做下图像的平滑,导数对噪声比较敏感



没有更多推荐了,返回首页