c++ 图像处理(十三)分水岭算法实现

分水岭算法实现

原理:以后再补

代码:

void* Watershed(QImage &image,QImage &gradiant)
{

    int width = image.width();
    int height = image.height();
    int all_size = height * width;
    int Num;
    int w,h;
    int p_conn[8][2] = {{0,-1},{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1}};
    bool p_condition[8];


    QVector seedimage(all_size);
    QVector labelimage(all_size);
    QVector originalimage(all_size);


    QVector*> vque;
    //QVector vque(900 * all_size);


    queue *pque;

    queue  qqp;


    queue qpt;  //队列


    //vectorSeedCounts;//保持每个队列种子个数的数组
    QVector> seedcounts;
    QVector seed_array(256);


    Point temp;
    int x,y;


    int currindex;
    Num = 0;
    for(y = 0 ;y 0) ? 255 : -1;
            labelimage[currindex] = 0;
            originalimage[currindex] = qGray(gradiant.pixel(x,y));
        }
    }




    int i,j;
    //初始连通盆地
    for(i = 0 ;i[256];

                vque.push_back(pque);//加入到队列数组中,对应的是本标记号Num的

                seedimage[currindex] = 127;
                labelimage[currindex] = Num;

                cout<<"Num"<=0&&currindex0)
                   {
                       seedcounts[i][WaterLevel]--; //取出一个点,个数少一
                       temp=vque[i][WaterLevel].front();    //取出该区域的一个点,清空这个边缘点
                       //灰度级该像素已经处理掉了。
                       vque[i][WaterLevel].pop();

                       //当前的种子坐标
                       m = temp.x;
                       n = temp.y;


                       //四连通
                       for(int k = 0; k<4;k++)
                       {
                           h = n +P_4[k][0];
                           w = m +P_4[k][1];
                           currindex = h * width + w;

                           //不越界
                           if(currindex>=0 && currindex

你可能感兴趣的:(图像处理)