Region growth algorithm (with MATLAB code implementation)

Source: Internet
Author: User

First, the theoretical concept

Area growth is the process of aggregating a single pixel or sub-region into a fully independent connected region, in accordance with the predefined growth criteria. For the image of interest in the target area R,Z for the region R pre-discovered seed point, according to the prescribed growth criteria gradually and the seed point Z within a certain neighborhood of the similarity criterion of the pixels into a seed group for the next stage of growth, In this way, continuous cyclic growth is carried out until the growth stop condition is satisfied, thus completing the process of growing an area of interest from a seed point to an independent connected region. The similarity criterion can be image information such as pixel gray value, color, texture feature and so on.

Therefore, the region growth algorithm is generally divided into three steps to achieve:

(1) Determine the seed point of growth

(2) Prescribed growth criteria

(3) Determine the growth stop condition

The region growth algorithm is often used for the segmentation of two-valued images in practical engineering applications. Figure 1 illustrates the three steps of the region growth algorithm in a graphic way:

① the pixels in the red dimension of the original binary image (a) are the specified growing point;

② images (b) and (c) are the results of regional growth using different growth criteria, where figure (b) is a set of pixels equal to the gray value of the pixel in the 4 neighborhood. In the middle of the 1th growth, pixels equal to the growing point of the pixel have the upper, lower, left, and right four pixels, and then the second growth, the previous growth of the pixel according to the same criteria to continue, until the image boundary or background area when the growth stopped. Figure (c) is a set of pixels equal to the gray value of the pixel in the 8 neighborhood.

Second, MATLAB Sample Code Implementation

2.1 Main function file

2.2 Function Module 1

function Fsrregiongrow (x0,y0,mode)% functions: The two-valued image is specified in the connected region by the function recursive method to achieve the region growth input parameter: x0,y0                                                                             Represents the pixel coordinates of the growing point, mode indicates how large the neighborhood is for region growth, and often takes mode = 4;mode = 8;% output parameter: void % Author & time: Run on Xiang Bian ——— May 6, 2016 global R            BW Counter Row col if 8 = = Mode for i = -1:1 for j = -1:1 X1 = x0 + i;            Y1 = y0 + j; % growth criteria: Determine whether the respective gray values of the pixels in the 8 neighborhood are equal to the pixel gray value of the growing point if x1 > 0 && x1 <= row && y1 > 0 && y1                <= Col && BW (x1,y1) = = BW (x0,y0) && 0 = = R (x1,y1) r (x1,y1) = 255;                Counter = counter + 1;                                 Fsrregiongrow (X1,y1,mode);        End end Endelseif 4 = = Mode for i = -1:1 x1 = x0 + i;        y1 = y0; If x1 > 0 && x1 <= row && y1 > 0 &&Y1 <= Col && BW (x1,y1) = = BW (x0,y0) && 0 = = R (x1,y1) r (x1,y1) = 255;            Counter = counter + 1;               Fsrregiongrow (X1,y1,mode);    End end x1 = x0;    y1 = y0-1; If x1 > 0 && x1 <= row && y1 > 0 && y1 <= col && bw (x1,y1) = = BW (x0,y0) && Amp        0 = = R (x1,y1) r (x1,y1) = 255;        Counter = counter + 1;           Fsrregiongrow (X1,y1,mode);    End x1 = x0;    Y1 = y0 + 1; If x1 > 0 && x1 <= row && y1 > 0 && y1 <= col && bw (x1,y1) = = BW (x0,y0) && Amp        0 = = R (x1,y1) r (x1,y1) = 255;        Counter = counter + 1;           Fsrregiongrow (X1,y1,mode); Endendend

2.3 function Module 2

function FsrRegiongrow1 (x0,y0,mode)% functions: Advanced post-out thinking of simulation stack to achieve region growth by specifying a connected region for a two-valued Image: X0,y0 indicates the growing point pixel                                                                               Coordinates, mode means region growth in a large neighborhood, often mode = 4;mode = 8;% output parameter: void % Author & time: Run on Xiang Bian ——— May 6, 2016 global R BW counter Row Co              L Zhan = zeros (row*col,2);% Create stack array Pzhan = 1; % stack Count Zhan (pzhan,1) = X0;zhan (pzhan,2) = y0; R (x0,y0) = 255;counter = 1;        If 8 = = mode while Pzhan > 0 x1 = zhan (pzhan,1);% out of stack y1 = Zhan (pzhan,2); Pzhan = pzhan-1;                % stack count minus one for i = -1:1 for j = -1:1% growth guideline: Determine whether the respective grayscale values of the pixels in the growing point 8 neighborhood are equal to the gray values of the pixels in the region If x1+i > 0 && x1+i <= row && y1+j > 0 && y1+j <= col && BW (x1+i,y1+j) = = B                    W (x1,y1) && R (x1+i,y1+j) ~= R (x1,y1) r (x1+i,y1+j) = R (x1,y1);                Counter = counter + 1;    Pzhan = Pzhan + 1;                The% stack count increases by one zhan (pzhan,1) = x1 + i;% into the stack zhan (pzhan,2) = y1 + j;        End End End Endelseif 4 = = mode while Pzhan > 0 x1 = zhan (pzhan,1);        Y1 = Zhan (pzhan,2);        Pzhan = pzhan-1;            For i = -1:2: 1 j = 0; If x1+i > 0 && x1+i <= row && y1+j > 0 && y1+j <= col && bw (x1+i,y1+j) = = BW (x                1,Y1) && R (x1+i,y1+j) ~= R (x1,y1) r (x1+i,y1+j) = R (x1,y1);                Counter = counter + 1;                Pzhan = Pzhan + 1;                Zhan (pzhan,1) = x1 + i;                       Zhan (pzhan,2) = y1 + j;            End end for j = -1:2: 1 i = 0; If x1+i > 0 && x1+i <= row && y1+j > 0 && y1+j <= col && bw (x1+i,y1+j) = = BW (x 1,Y1) && R (x1+i,y1+j) ~= R (x1,y1) R (x1+i,y1+J) = R (x1,y1);                Counter = counter + 1;                Pzhan = Pzhan + 1;                Zhan (pzhan,1) = x1 + i;                       Zhan (pzhan,2) = y1 + j; End End Endendend

Third, the description

When calling function module Fsrregiongrow based on the MATLAB7.11.0 (r2010b) platform, Matlab pops up the following warning

??? Maximum recursion limit of reached. Use Set (0, ' recursionlimit ', N)

To change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer.

Error in ==> Fsrregiongrow

The above warning indicates that the recursion number exceeds the MATLAB default, which means that there are too many pixels in the connected area of interest to be processed (greater than 500), at which point the user can attempt to modify the recursive number of functions by prompting the set function. However, the test finds that if the recursion number exceeds 1591 (the value may be different on different platforms), MATLAB software will automatically shut down immediately. In short, a large number of recursive calls will establish a copy of the function, consuming a lot of time and memory, but recursion can make the program structure clear and understandable, so this paper gives a recursive method of function to achieve regional growth is only to provide a way of thinking, if the number of connected areas to be processed in a number of pixels, call The FsrRegiongrow1 function is available! The fsrRegiongrow1 function module is the advanced idea to create stack array simulation stack on the heap, which can realize the region growth quickly.

Iv. Results of the experiment

Region growth algorithm (with MATLAB code implementation)

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.