Grayscale image--local threshold value of image segmentation threshold processing

Source: Internet
Author: User

Study Dip 57th 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.

The crap started, today. Regional thresholds (local thresholds), the thresholds described above are global thresholds, that is, thresholds are generated based on global information, and the objects are all pixels of the entire image, while local thresholds are generated as a central pixel c ( x , Y ) Some properties of the neighborhood to calculate one or more thresholds and the discriminant of the threshold values. This sentence is more difficult to understand, for example, suppose that the neighborhood R of C, based on the neighborhood R to calculate the threshold value T 1 , T 2 , T 3 ..... T n We can represent them as vectors. T =( T 1 , T 2 , T 3 .... T n ) , Design threshold discriminant Q(T ,PIx V al ue) Where the value of Pix_value is the pixel c ( x , Y ) Gray value, discriminant return True or FALSE, true if the pixel is set to bright, otherwise set to dark.

Algorithm content

The key point of the algorithm is to design discriminant Q and calculate the threshold vector T, because this algorithm is not very common, but the advantage is flexible, can be based on different picture properties to design different execution plan, such as the following example uses the simplest two statistical parameters, mean and standard deviation, When the center pixel is greater than n times the mean and is greater than the standard deviation of M times. Set the window size, that is, the neighborhood size, parameter n, parameter m, and finally get a better threshold result.

Code implementation
/* Local threshold * use mean and standard deviation as criteria * Input parameters include neighborhood size, mean factor, and standard deviation factor * * * /voidLocalthreshold (Double*SRC,Double*DST,intWidthintHeightintW_size,DoubleMean_param,DoubleStd_dev_param) {Double*temp= (Double*)malloc(sizeof(Double) *width*height); Zero (temp, width,height);DoubleMean_g=matrixmean (src, width, height); for(intj=w_size/2; j2; j + +) { for(inti=w_size/2; i<width-w_size/2; i++) {DoubleDeta=0.0;Doublemean=0.0;DoublePix_value=src[j*width+i];//local mean             for(intm=-w_size/2; m<w_size/2+1; m++) { for(intn=-w_size/2; n<w_size/2+1; n++) {mean+=src[(j+m) *width+i+n]; }} mean/= (Double) (w_size*w_size);//local Deta             for(intm=-w_size/2; m<w_size/2+1; m++) { for(intn=-w_size/2; n<w_size/2+1; n++) {deta+= (src[(j+m) *width+i+n]-mean) * (src[(j+m) *width+i+n]-mean); }} deta/= (Double) (w_size*w_size); Deta=sqrt(DETA);if(Pix_value>mean_param*mean_g&&pix_value>std_dev_param*deta) {temp[j*width+i]=255.0; }}} matrixcopy (temp, DST, width, height); Free(temp);}
Algorithm effect


Summarize

Compared to the global threshold, local thresholds on the target size, and noise sensitivity is strong, but its disadvantage is that the design is strong, there is no general algorithm, and the input parameters most need to analyze the experiment to produce, can not achieve automatic threshold processing, its advantages are powerful.
Cond...

Grayscale image--local threshold value of image segmentation threshold processing

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.