OpenCV:区域生长法实现( 三 )


                     }
              }
       }
       markImg.copyTo(dstImg);
}
int main()
{
       Mat srcImg = imread("1.jpg",0);
       if (srcImg.empty())
              printf("image read error");
       Mat srcImg1=srcImg.clone();
       Mat outImg1,outImg2;
       RegionGrowing(srcImg1,outImg1,Point(241,258),10);
       RegionGrowing(srcImg1,outImg2,Point(302,118),80);
       add(outImg1,outImg2,outImg1);
       imshow("p1p2",outImg1);
       Mat resultImg;
       srcImg.copyTo(resultImg,~outImg1);
       imshow("outImg",resultImg);
       waitKey(0);
       return 0;
}

OpenCV:区域生长法实现

文章插图

OpenCV:区域生长法实现

文章插图

5算法结果:
这里起首报酬拔取一个种子点 ,
在其八邻域内 , 由相似性准则进行判定并更新种子点;
当不再发生新的种子点时 , 截止;
当区分多方针是 , 可以认为拔取多个种子点 , 然后将每个种子点朋分区域归并;
即可朋分出多方针 。

OpenCV:区域生长法实现

文章插图

6给出一个比力好区域发展法的法式:
//仅按照纹理朋分图像 , 纹理特征是四维调集;
void segmentTexture(Mat texture)
{
    Mat regions(texture.rows, texture.cols, CV_8UC1, 0.0);
    Mat mark(texture.rows, texture.cols, CV_8UC1, 0.0);
    int min_regions = 10;
    RNG rng(25);
    Point seedPoint, now;
    Vec4b curr, next, seed;
    queue<Point> Q;
    vector<pair<pair<Point, Vec3b>, int> > Points;
    int pixelCount=0;//pixel covered in a segment
    for(int i =250; i>10; i -= 250/min_regions)
    {
        rng(12345);
        do
        {
            seedPoint.x = rng.uniform(0, texture.cols);
            seedPoint.y = rng.uniform(0, texture.rows);
            seed = texture.at<Vec4b>(seedPoint.y, seedPoint.x);
        }
        while(mark.at<uchar>(seedPoint.y, seedPoint.x) !=0 );
        mark.at<uchar>(seedPoint.y, seedPoint.x) = i;
        Q.push(seedPoint);

推荐阅读