Study Dip 59th Day
Reprint please indicate the source of this article: Http://blog.csdn.net/tonyshengtan, out of respect for the work of the author, reprint please indicate the source! Article code is hosted, Welcome to co-development: Https://github.com/Tony-Tan/DIPpro
The opening crap.
Nonsense began, today originally only wanted to write an article, but at night feel still quick to introduce the division of the region, after the beginning of the color image class knowledge learning and code implementation, the next introduction of watershed algorithm, this is a headache algorithm, today's regional separation (merger) relatively good understanding.
Algorithm principle
First of all, the algorithm is still based on the region, the nature of the area used is the mean and standard deviation of the region, a simple description of the algorithm, if a region to meet the set mean range and standard deviation range, set the entire area is bright, otherwise the secondary region is divided into four parts, each continues to recursive, until the smallest pre-set.
From the structure can be abstracted into a four-fork tree:
The core of the algorithm is to design a discriminant, the above-mentioned discriminant is the mean and mean-square joint, but also can use other discriminant, according to the actual situation can be specifically designed.
Algorithm:
- initialization, input parameters, including mean upper and lower bounds m1,m2, standard deviation upper and lower bounds d1,d2
- Calculates the area mean and standard deviation, if the condition is met, the output corresponds to a set to bright no, the area is divided into four parts
- Take one of the copies into step 2 recursively for calculation
- If the zone split is less than the set minimum value end recursion.
Code
/*******************************************************************************// * Region segmentation algorithm, recursive judgment * If the region does not meet the criteria, divide the region * into four parts, recursively judge each area * know the region is divided into the minimum set value */voidFindsplitregion (Double*SRC,Double*DST,intWidthintHeightintXintYintW_width,intW_height,DoubleMEAN_PARAM1,DoubleMEAN_PARAM2,DoubleVARIANCE_PARAM1,DoubleVARIANCE_PARAM2) {DoubleMean=regionmean (src, width, height, x, y, W_width, w_height);DoubleVariance=regionstddeviation (src, width, height, x, y, W_width, w_height);if(mean>mean_param1&& mean<=mean_param2&& variance>variance_param1&& vari ANCE<=VARIANCE_PARAM2) {Regionsetone (DST, width, height, x, y, W_width, w_height); }Else{#define Minimal_cell3 if(W_width>=minimal_cell&&w_height>=minimal_cell) {findsplitregion (src, DST, width,height, X, Y, w_width/2+1, w_height/2+1, mean_param1, Mean_param2, variance_param1, variance_param2); Findsplitregion (SRC, DST, width,height, x+w_width/2, Y, w_width/2+1, w_height/2+1, mean_param1, Mean_param2, variance_param1, variance_param2); Findsplitregion (SRC, DST, width,height, x+w_width/2, y+w_height/2+1, w_width/2+1, w_height/2, mean_param1, Mean_param2, variance_param1, variance_param2); Findsplitregion (SRC, DST, width,height, X, y+w_height/2, w_width/2+1, w_height/2+1, mean_param1, Mean_param2, variance_param1, variance_param2); } }}voidRegionsplit (Double*SRC,Double*DST,intWidthintHeightDoubleMEAN_PARAM1,DoubleMEAN_PARAM2,DoubleVARIANCE_PARAM1,DoubleVARIANCE_PARAM2) {Double*dsttemp= (Double*) malloc (sizeof (Double) *width*height); Findsplitregion (SRC, dsttemp, width, height,0,0, width, height, mean_param1, mean_param2, variance_param1,variance_param2); Matrixcopy (dsttemp, DST, width, height); Free (dsttemp);}
Experimental results
Original:
To separate the surrounding nebula, the parameters are shown in the figure:
Original:
Also separate the surrounding nebula, the parameters are shown in the figure:
Summarize
This algorithm runs very fast, but is not accurate enough because the minimum region value set determines the accuracy of the region segmentation, so there will be jagged edges, which is a disadvantage.
Cond...
Gray image--region separation of image segmentation