Opencv _ image binarization Based on Local adaptive threshold

Source: Internet
Author: User


In image processing applications, binarization is a very common processing method, such as zero-device image processing, character extraction from text images and Verification Code images, and Character Segmentation in License Plate Recognition, and Foreground Segmentation in Moving Object Detection in video images.


Common image binarization methods include: 1) Global fixed threshold; 2) Local adaptive threshold; 3) Otsu.


The global fixed threshold is easy to understand, that is, the whole image is binarization with a unified threshold;


The Local adaptive threshold is used to determine the binarization threshold of the pixel position based on the pixel value distribution of the pixel's neighboring blocks. The advantage of doing so is that the binarization threshold at each pixel position is not fixed, but determined by the distribution of neighboring pixels. The binarization threshold of the image area with a higher brightness is usually higher, while the binarization threshold of the image area with a lower brightness is correspondingly smaller. Local image regions with different brightness, contrast, and textures will have the corresponding local binarization threshold. Common Local adaptive thresholds include: 1) mean of local neighbor blocks; 2) Gaussian weighted sum of local neighbor blocks.



Opencv implements the preceding binarization methods.


The following code compares the binarization results of the global fixed threshold and the Local adaptive threshold.

// Image binarization Based on Local adaptive threshold // Author: www.icvpr.com // blog: http://blog.csdn.net/icvpr # include <iostream> # include <opencv2/opencv. HPP> int main (INT argc, char ** argv) {CV: mat image = CV: imread (".. /test.bmp ", cv_load_image_grayscale); If (image. empty () {STD: cout <"read image failure" <STD: Endl; Return-1 ;}// globally binarization int th = 100; CV: mat global; CV: threshold (image, global, Th, 255, cv_thresh_binary_inv); // partial binarization int blocksize = 25; int constvalue = 10; CV:: mat local; CV: adaptivethreshold (image, local, 255, large, cv_thresh_binary_inv, blocksize, constvalue); CV: imwrite ("global.jpg", global); CV :: imwrite ("local.jpg", local); CV: imshow ("globalthreshold", global); CV: imshow ("localthreshold", local); CV :: waitkey (0); Return 0 ;}


Source image:

Result of global fixed threshold binarization (t = 100)

Result of partial Adaptive Threshold binarization (block size = 25)


Related content: www.icvpr.com

-------------------------------------------------------

<Reprint Please note: http://blog.csdn.net/icvpr>

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.