现在我急需图像的边缘检测的Snake算法啊?
最好有C++的源程序,matlab的代码也行。
,麻烦你发到我的邮箱里,帮帮忙,谢谢!

解决方案 »

  1.   

    下面是一个“轮廓跟踪”的程序,在《VC++数字图像处理》上。应该就是你要的吧。/*************************************************************************
     *
     * 函数名称:
     *   TraceDIB()
     *
     * 参数:
     *   LPSTR lpDIBBits    - 指向源DIB图像指针
     *   LONG  lWidth       - 源图像宽度(象素数,必须是4的倍数)
     *   LONG  lHeight      - 源图像高度(象素数)
     * 返回值:
     *   BOOL               - 运算成功返回TRUE,否则返回FALSE。
     *
     * 说明:
     * 该函数用于对图像进行轮廓跟踪运算。
     * 
     * 要求目标图像为只有0和255两个灰度值的灰度图像。
     ************************************************************************/BOOL WINAPI TraceDIB(LPSTR lpDIBBits, LONG lWidth, LONG lHeight)
    {

    // 指向源图像的指针
    LPSTR lpSrc;

    // 指向缓存图像的指针
    LPSTR lpDst;

    // 指向缓存DIB图像的指针
    LPSTR lpNewDIBBits;
    HLOCAL hNewDIBBits; // 图像每行的字节数
    LONG lLineBytes;

    //循环变量
    long i;
    long j; //像素值
    unsigned char pixel; //是否找到起始点及回到起始点
    bool bFindStartPoint; //是否扫描到一个边界点
    bool bFindPoint; //起始边界点与当前边界点
    Point StartPoint,CurrentPoint; //八个方向和起始扫描方向
    int Direction[8][2]={{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0}};
    int BeginDirect; // 计算图像每行的字节数
    lLineBytes = WIDTHBYTES(lWidth * 8); // 暂时分配内存,以保存新图像
    hNewDIBBits = LocalAlloc(LHND, lLineBytes * lHeight); if (hNewDIBBits == NULL)
    {
    // 分配内存失败
    return FALSE;
    }

    // 锁定内存
    lpNewDIBBits = (char * )LocalLock(hNewDIBBits); // 初始化新分配的内存,设定初始值为255
    lpDst = (char *)lpNewDIBBits;
    memset(lpDst, (BYTE)255, lLineBytes * lHeight); //先找到最左上方的边界点
    bFindStartPoint = false;
    for (j = 0;j < lHeight && !bFindStartPoint;j++)
    {
    for(i = 0;i < lWidth && !bFindStartPoint;i++)
    {
    // 指向源图像倒数第j行,第i个象素的指针
    lpSrc = (char *)lpDIBBits + lLineBytes * j + i;

    //取得当前指针处的像素值,注意要转换为unsigned char型
    pixel = (unsigned char)*lpSrc;

    if(pixel == 0)
    {
    bFindStartPoint = true; StartPoint.Height = j;
    StartPoint.Width = i; // 指向目标图像倒数第j行,第i个象素的指针
    lpDst = (char *)lpNewDIBBits + lLineBytes * j + i;
    *lpDst = (unsigned char)0;
    }
    }
    } //由于起始点是在左下方,故起始扫描沿左上方向
    BeginDirect = 0;
    //跟踪边界
    bFindStartPoint = false;
    //从初始点开始扫描
    CurrentPoint.Height = StartPoint.Height;
    CurrentPoint.Width = StartPoint.Width;
    while(!bFindStartPoint)
    {
    bFindPoint = false;
    while(!bFindPoint)
    {
    //沿扫描方向查看一个像素
    lpSrc = (char *)lpDIBBits + lLineBytes * ( CurrentPoint.Height + Direction[BeginDirect][1])
    + (CurrentPoint.Width + Direction[BeginDirect][0]);
    pixel = (unsigned char)*lpSrc;
    if(pixel == 0)
    {
    bFindPoint = true;
    CurrentPoint.Height = CurrentPoint.Height + Direction[BeginDirect][1];
    CurrentPoint.Width = CurrentPoint.Width + Direction[BeginDirect][0];
    if(CurrentPoint.Height == StartPoint.Height && CurrentPoint.Width == StartPoint.Width)
    {
    bFindStartPoint = true;
    }
    lpDst = (char *)lpNewDIBBits + lLineBytes * CurrentPoint.Height + CurrentPoint.Width;
    *lpDst = (unsigned char)0;
    //扫描的方向逆时针旋转两格
    BeginDirect--;
    if(BeginDirect == -1)
    BeginDirect = 7;
    BeginDirect--;
    if(BeginDirect == -1)
    BeginDirect = 7;
    }
    else
    {
    //扫描方向顺时针旋转一格
    BeginDirect++;
    if(BeginDirect == 8)
    BeginDirect = 0; } }
    } // 复制腐蚀后的图像
    memcpy(lpDIBBits, lpNewDIBBits, lWidth * lHeight); // 释放内存
    LocalUnlock(hNewDIBBits);
    LocalFree(hNewDIBBits); // 返回
    return TRUE;
    }
      

  2.   

    不是这个的,snake算法是一种动态的算法,是用能量最小化的观点来提取图像的边缘.