zoukankan      html  css  js  c++  java
  • OPENCV用户手册之图像处理部分(之一):梯度、边缘与角点(中文翻译)

    2004年09月03日 09:23:00

    下面是OPENCV用户手册之图像处理部分:梯度、边缘与角点(中文翻译),有错误欢迎指正,原文在:

    http://www.assuredigit.com/incoming/sourcecode/opencv/chinese_docs/ref/opencvref_cv.htm

    注意:
    本章描述图像处理和分析的一些函数。大多数函数是针对二维数组的。所以我们用数组来描述“图像”,而图像不必是 IplImage,还可以是 CvMat's 或 CvMatND。


    梯度、边缘和角点

    翻译:HUNNISH, 阿须数码


    Sobel

    使用扩展 Sobel 算子计算一阶、二阶、三阶或混合图像差分

    void cvSobel( const CvArr* src, CvArr* dst, int xorder, int yorder, int aperture_size=3 );
    
    src
    输入图像.
    dst
    输出图像.
    xorder
    x? 方向上的差分阶数
    yorder
    y? 方向上的差分阶数
    aperture_size
    扩展 Sobel 核的大小,必须是 1, 3, 5 或 7。 除了尺寸为 1, 其它情况下, aperture_size ×aperture_size 可分离内核将用来计算差分。对 aperture_size=1的情况, 使用 3x1 或 1x3 内核 (不进行高斯平滑操作)。有一个特殊变量? CV_SCHARR (=-1),对应 3x3 Scharr 滤波器,可以给出比 3x3 Sobel 滤波更精确的结果。Scharr 滤波器系数是:
    | -3 0  3||-10 0 10|| -3 0  3|
    
    x-方向 以及转置矩阵对 y-方向。

    函数 cvSobel 通过对图像用相应的内核进行卷积操作来计算图像差分:

    dst(x,y) = dxorder+yodersrc/dxxorder"dyyorder |(x,y)
    

    Sobel 算子结合 Gaussian 平滑和微分,以提高计算结果对噪声的抵抗能力。通常情况,函数调用采用如下参数 (xorder=1, yorder=0, aperture_size=3) 或 (xorder=0, yorder=1, aperture_size=3) 来计算一阶 x- 或 y- 方向的图像差分。第一种情况对应:

      |-1  0  1|  |-2  0  2|  |-1  0  1|
    

    核。第二种对应

      |-1 -2 -1|  | 0  0  0|  | 1  2  1|or  | 1  2  1|  | 0  0  0|  |-1 -2 -1|
    

    核,它依赖于图像原点的定义 (origin 来自 IplImage 结构的定义)。不进行图像尺度变换。所以输出图像通常比输入图像大。为防止溢出,当输入图像是 8 位的,要求输出图像是 16 位的。产生的图像可以用函数 cvConvertScale cvConvertScaleAbs 转换为 8 位的。除了 8-比特 图像,函数也接受 32-位 浮点数图像。所有输入和输出图像都必须是单通道,且图像大小或ROI尺寸一致。


    Laplace

    计算图像的 Laplacian?

    void cvLaplace( const CvArr* src, CvArr* dst, int aperture_size=3 );
    
    src
    输入图像.
    dst
    输出图像.
    aperture_size
    核大小 (与 cvSobel 中定义一样).

    函数 cvLaplace 计算输入图像的 Laplacian,方法是对用 sobel 算子计算的二阶 x- 和 y- 差分求和:

    dst(x,y) = d2src/dx2 + d2src/dy2
    

    aperture_size=1 则给出最快计算结果,相当于对图像采用如下内核做卷积:

    |0  1  0||1 -4  1||0  1  0|
    

    类似于 cvSobel 函数,也不作图像的尺度变换,而且支持输入、输出图像类型一致。


    Canny

    采用 Canny 算法做边缘检测

    void cvCanny( const CvArr* image, CvArr* edges, double threshold1,              double threshold2, int aperture_size=3 );
    
    image
    输入图像.
    edges
    输出的边缘图像
    threshold1
    第一个阈值
    threshold2
    第二个阈值
    aperture_size
    Sobel 算子内核大小 (见 cvSobel).

    函数 cvCanny 采用 CANNY 算法发现输入图像的边缘而且在输出图像中标识这些边缘。小的阈值 threshold1 用来控制边缘连接,大的阈值用来控制强边缘的初始分割。


    PreCornerDetect

    计算特征图,用于角点检测

    void cvPreCornerDetect( const CvArr* image, CvArr* corners, int aperture_size=3 );
    
    image
    输入图像.
    corners
    保存角点坐标的数组
    aperture_size
    Sobel 算子的核大小(见cvSobel).

    函数 cvPreCornerDetect 计算函数 Dx2Dyy+Dy2Dxx - 2DxDyDxy 其中 D? 表示一阶图像差分,D?? 表示二阶图像差分。 角点被认为是函数的局部最大值:

    // assuming that the image is 浮点数IplImage* corners = cvCloneImage(image);IplImage* dilated_corners = cvCloneImage(image);IplImage* corner_mask = cvCreateImage( cvGetSize(image), 8, 1 );cvPreCornerDetect( image, corners, 3 );cvDilate( corners, dilated_corners, 0, 1 );cvSubS( corners, dilated_corners, corners );cvCmpS( corners, 0, corner_mask, CV_CMP_GE );cvReleaseImage( &corners );cvReleaseImage( &dilated_corners );
    

    CornerEigenValsAndVecs

    计算图像块的特征值和特征向量,用于角点检测

    void cvCornerEigenValsAndVecs( const CvArr* image, CvArr* eigenvv,                               int block_size, int aperture_size=3 );
    
    image
    输入图像.
    eigenvv
    保存结果的数组。必须比输入图像宽 6 倍。
    block_size
    邻域大小 (见讨论).
    aperture_size
    Sobel 算子的核尺寸(见 cvSobel).

    对每个象素,函数 cvCornerEigenValsAndVecs 考虑 block_size × block_size 大小的邻域 S(p),然后在邻域上计算差分的相关矩阵:

        | sumS(p)(dI/dx)2   sumS(p)(dI/dx"dI/dy)|M = |                                 |    | sumS(p)(dI/dx"dI/dy)  sumS(p)(dI/dy)2 |
    

    然后它计算矩阵的特征值和特征向量,并且按如下方式1, λ2, x1, y1, x2, y2)存储这些值到输出图像中,其中

    λ1, λ2 - M 的特征值,没有排序
    (x1, y1) - 特征向量,对 λ1
    (x2, y2) - 特征向量,对 λ2


    CornerMinEigenVal

    计算梯度矩阵的最小特征值,用于角点检测

    void cvCornerMinEigenVal( const CvArr* image, CvArr* eigenval, int block_size, int aperture_size=3 );
    
    image
    输入图像.
    eigenval
    保存最小特征值的图像. 与输入图像大小一致
    block_size
    邻域大小 (见讨论 cvCornerEigenValsAndVecs).
    aperture_size
    Sobel 算子的核尺寸(见 cvSobel). 当输入图像是浮点数格式时,该参数表示用来计算差分的浮点滤波器的个数.

    函数 cvCornerMinEigenVal cvCornerEigenValsAndVecs 类似,但是它仅仅计算和存储每个象素点差分相关矩阵的最小特征值,即前一个函数的 min(λ1, λ2)


    FindCornerSubPix

    精确角点位置

    void cvFindCornerSubPix( const CvArr* image, CvPoint2D32f* corners,                         int count, CvSize win, CvSize zero_zone,                         CvTermCriteria criteria );
    
    image
    输入图像.
    corners
    输入角点的初始坐标,也存储精确的输出坐标
    count
    角点数目
    win
    搜索窗口的一半尺寸。如果 win=(5,5) 那么使用 5*2+1 × 5*2+1 = 11 × 11 大小的搜索窗口
    zero_zone
    死区的一半尺寸,死区为不对搜索区的中央位置做求和运算的区域。它是用来避免自相关矩阵出现的某些可能的奇异性。当值为 (-1,-1) 表示没有死区。
    criteria
    求角点的迭代过程的终止条件。即角点位置的确定,要么迭代数大于某个设定值,或者是精确度达到某个设定值。 criteria 可以是最大迭代数目,也可以是精确度

    函数 cvFindCornerSubPix 通过迭代来发现具有子象素精度的角点位置,或如图所示的放射鞍点(radial saddle points)。

    Sub-pixel accurate corner locator is based on the observation that every vector from the center q to a point p located within a neighborhood of q is orthogonal to the image gradient at p subject to image and measurement noise. Consider the expression_r:

    εi=DIpiT"(q-pi)
    

    where DIpi is the image gradient at the one of the points pi in a neighborhood of q. The value of q is to be found such that εi is minimized. A system of equations may be set up with εi' set to zero:

    sumi(DIpi"DIpiT)"q - sumi(DIpi"DIpiT"pi) = 0
    

    where the gradients are summed within a neighborhood ("search window") of q. Calling the first gradient term G and the second gradient term b gives:

    q=G-1"b
    

    The algorithm sets the center of the neighborhood window at this new center q and then iterates until the center keeps within a set threshold.


    GoodFeaturesToTrack

    确定图像的强角点

    void cvGoodFeaturesToTrack( const CvArr* image, CvArr* eig_image, CvArr* temp_image,                            CvPoint2D32f* corners, int* corner_count,                            double quality_level, double min_distance,                            const CvArr* mask=NULL );
    
    image
    输入图像,8-位或浮点32-比特,单通道
    eig_image
    临时浮点32-位图像,大小与输入图像一致
    temp_image
    另外一个临时图像,格式与尺寸与 eig_image 一致
    corners
    输出参数,检测到的角点
    corner_count
    输出参数,检测到的角点数目
    quality_level
    最大最小特征值的乘法因子。定义可接受图像角点的最小质量因子。
    min_distance
    限制因子。得到的角点的最小距离。使用 Euclidian 距离
    mask
    ROI:感兴趣区域。函数在ROI中计算角点,如果 mask 为 NULL,则选择整个图像。

    函数 cvGoodFeaturesToTrack 在图像中寻找具有大特征值的角点。该函数,首先用cvCornerMinEigenVal 计算输入图像的每一个象素点的最小特征值,并将结果存储到变量 eig_image 中。然后进行非最大值压缩(仅保留3x3邻域中的局部最大值)。下一步将最小特征值小于 quality_level"max(eig_image(x,y)) 排除掉。最后,函数确保所有发现的角点之间具有足够的距离,(最强的角点第一个保留,然后检查新的角点与已有角点之间的距离大于 min_distance )。



    Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=93171


  • 相关阅读:
    UICollectionView 布局
    ios 调用支付宝
    iOS POST 上传图片
    ios 判断字符串是否为空
    让写代码成为每天的习惯
    gocron_跨平台定时任务管理器
    monkey做安卓APP的黑盒自动化测试
    Android自动化测试框架分析
    联合查询中where 和and的区别
    JIRA中导出BUG列表是CSV格式的,打开后是乱码
  • 原文地址:https://www.cnblogs.com/feisky/p/1586565.html
Copyright © 2011-2022 走看看