Regional growth algorithms

Source: Internet
Author: User

Image segmentation is an important image processing technology, and region growth is a kind of image segmentation technology. The basic idea of regional growth is to assemble the pixels with similarity to form a region. First, a seed pixel is identified as the seven point of growth for each area that needs to be segmented, and then the pixels surrounding the seed pixel adjacent to the seed with the same or similar properties (as determined by predetermined growth or similarity criteria) are merged into the region where the seed pixels reside. And the new pixel continues to grow as a seed, until the pixels that don't meet the criteria can be included, and a region grows.


Seed area growth (region seeds growing, RSG) the key problem in practice is the selection of seeds and the determination of similar regional criterion. The selection of seeds can be selected manually, or it can be selected automatically by some methods, and the criterion of gray scale is usually expressed by the difference of gray scale to a certain threshold, and different judging criteria may produce different segmentation results.


To illustrate how the area grows, this article starts with the simplest case: using a two-value image, manually selecting the seed, and deciding whether it is a foreground pixel.


The steps for region growth are as follows:
1. Scan image sequence! Find the 1th pixel that has not yet been attributed, set the pixel as (x0, y0);
2. Take (x0, y0) as the center, consider (x0, y0) The 8 neighborhood pixels (x, y) if (x0, y0) meet the growth criteria, combine (x, y) with (x0, y0) (in the same region) and press (x, y) into the stack;
3. Remove a pixel from the stack and return it as (x0, y0) to step 2;
4. When the stack is empty! Return to step 1;
5. Repeat step 1-4 until each point in the image has a attribution. The end of growth.

#include <iostream> #include <stack> #include <opencv2\opencv.hpp>using namespace std;using Namespace cv;//8 neighbor static point connects[8] = {Point ( -1,-1), point (0,-1), point (1,-1), point (1, 0), point (1, 1), Poin T (0, 1), point ( -1, 1), point ( -1, 0)};int main () {//original mat src = imread ("Img2.jpg", 0);//Result graph Mat res = Mat::zeros (src.rows, Src.cols, cv_8u);//used to mark whether to traverse a certain point mat flagmat;res.copyto (Flagmat);//Two Value image Mat Bin;threshold (src, bin, N, 255, Cv_thresh_ BINARY);//initial 3 seed points stack<point> Seeds;seeds.push (point (0, 0)), Seeds.push (dot (186, 166)); Seeds.push ( 327);res.at<uchar> (0, 0) = 255;res.at<uchar> (166, 186) = 255;res.at<uchar> (+, 327) = 255;while (! Seeds.empty ()) {Point seed = Seeds.top (); Seeds.pop ();//mark as traversed points flagmat.at<uchar> (seed.y, seed.x) = 1;//  Traverse 8 Neighborhood for (size_t i = 0; i < 8; i++) {int tmpx = seed.x + connects[i].x;int tmpy = seed.y + connects[i].y;if (tmpx < 0 || Tmpy < 0 | | TMPX >= Src.cols | | Tmpy >= src.rows) continue;//foreground point and no marked dots if (bin.at<uchar> (Tmpy, tmpx)! = 0 && flagmat.at<uchar> (tmpy, tmpx) = = 0) { Res.at<uchar> (tmpy, tmpx) = 255; Growth flagmat.at<uchar> (tmpy, tmpx) = 1; Mark Seeds.push (Point (TMPX, tmpy)); Seed pressure Stack}}}imshow ("res", res), Imwrite ("Res.jpg", Res), Waitkey (0); return 1;}


Original:


The above code selects three seeds by hand, and their approximate position in the original is as follows (Red Cross Center):


The process of regional growth:


Engineering:


Regional growth algorithms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.