Gray image--the average threshold value of image segmentation threshold processing

Source: Internet
Author: User

Study Dip 52nd 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.

Haven't written a blog for a long time, has not been skilled, after the whole people are not good, haha, to just so far as the image segmentation learning a bit, these two days to learn the results and code simple summary.
The basic concepts of edge detection, edge repair, and threshold processing are described earlier. Threshold processing speed, simple algorithm, so the application is relatively broad, the basic problem of the algorithm is to calculate threshold processing threshold, in the next few I can, introduce several algorithms to determine the threshold, the basic mathematical knowledge from statistics, including the simplest average, p-division number, square poor mathematical knowledge.
The following is an introduction from the simplest mean threshold.

Average threshold value

Mean processing is one of the simplest of thresholds, which uses an image of all gray values as thresholds for segmenting images.
According to statistical knowledge, the probability method can be used to calculate the mean value:
1. Calculate Image Grayscale Histogram
2. Normalized histogram to derive the probability of each item of the histogram
3. Histogram of the horizontal and probability of the score and then sum

T hR eshol d =meaN=< span class= "Mo" id= "mathjax-span-54" style= "font-family:stixgeneral-regular; Vertical-align:0.003em; " >∑ < Span class= "Texatom" id= "mathjax-span-55" >l ? 1 i=0 P(I)xI

The threshold is obtained according to the above mean value, and then the whole image is processed according to the threshold value.

Code
/*********************************************************************************//*********************************************************************************/////calculates the average of the histogram from start to end, hist not normalized double getmeaninhist (int start,int end,int *hist) {int hist_count=0;double hist_value=0;for (int i=start;i<end;i++) {Hist_count+=hist[i];hist_value+= (double) hist[i]*i;    }return hist_value/(double) hist_count;}/*********************************************************************************//*********************************************************************************///mean method to find the threshold value//threshold equal to the average value of pixels in the full graph void meanthreshold (double*src,double *Dst,int width,int height,int type) {int hist[gray_level];double threshold_value=0.0;Inithistogram (hist);Sethistogram (src, hist, width,height); threshold_value=getmeaninhist (0, Gray_level, hist);Threshold (src,dst, width, height, threshold_value,type);}
Results

Take a look at the results:

Original:

Original histogram:

Average threshold value:

Threshold processing Results:

Add 1% Gaussian noise to the original
Not processed:

Histogram:

Average threshold value:

Threshold processing Results:

Add 5% Gaussian noise to the original
Not processed:

Histogram:

Average threshold value:

Threshold processing Results:

Add 7% Gaussian noise to the original
Not processed:

Histogram:

Average threshold value:

Threshold processing Results:

Lena graph mean threshold processing:
Original:

Results after processing:

Threshold value:

Summarize

Mean threshold can be done some relatively simple processing, but the target and the background of the size sensitive, that is, the histogram of the two peaks of the area, if the relative size of the two peaks is not much, then the average relative effect is better, if two peaks differ too much, that is, the background is much larger than the target or the opposite target is much larger The result is invalid. The second is also affected by the noise, but there is no significant impact on one factor.

Gray image--the average 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.