Atitit. Verification code Recognition STEP4--------binary grayscale of graphics

Source: Internet
Author: User

Atitit. Verification Code Identification step4-------- grayscale of graphic binary value

1. Summary of the method principle of common binary value 1

1.1. Method One: The method is very simple, after the RGB color image grayscale, the scanned image of each pixel value, the value is less than 127 The pixel value is set to 0 ( Black ), the pixel valuegreater than or equal to 127 is set to 255 ( white ). 1

1.2. Method Two: The most common two-value processing method is to calculate the average of the pixel K,2

1.3. Method Three: Use the Histogram method to find the value of the binary threshold, 2

1.4. Method four: Using approximate one-dimensional Means method to find the threshold value of binary,( recommended) 3

2. Using the class library ImageIO 3

3. Reference 4

1. Summary of the method principle of common binary value

The method to be discussed in this article is for RGB color space only.

1.1. Method One: The method is very simple andRGBafter the color image is grayscale, each pixel value of the scanned image is less than127To set the pixel value to0 (Black), the value is greater than or equal127The pixel value is set to255 (White).

The advantage of this method is that the calculation

A little faster. Disadvantage more first threshold value for 127 There is no reason to explain, followed by completely regardless of the image

Pixel distribution and pixel value characteristics. It can be said that this method is the most mentally retarded two value processing method is not too too.

Author:: Old Wow's paw attilax Ayron, email:[email protected]

Reprint please indicate source: Http://blog.csdn.net/attilax

1.2. Method Two: The most common two-value processing method is to calculate the average of the pixelsK,

Each pixel value of the image, such as a pixel value greater than K

The pixel value is set to 255 ( white )and the value is less than or equal to the K pixel value set to 0 ( black ) . Compared with the method one, the threshold value of the

Pick a little bit of IQ, can explain. But using the mean as a binary threshold also has a fatal disadvantage,

May cause some object pixels or background pixels to be lost. The result of binary value cannot reflect the source image information truly.

1.3. Method Three: Using the Histogram method to find the value of the binary threshold,

Histogram is an important characteristic of image, and the histogram method chooses two values

The threshold value is mainly found in the image of the two highest peaks, and then at the threshold value of two peaks between the peak and valley lowest place.

This method is a little bit more precise than the previous two methods. The results were also more acceptable.

1.4. Method Four: Use approximate one-dimensionalMeansmethod to find the threshold value of binary value,(recommended)

Http://en.wikipedia.org/wiki/Thresholding_ (image_processing)

Using the approximate one-dimensional Means method to find the binary threshold, the approximate steps of the method are as follows:

1. an initialization threshold T, which can be set by itself or generated according to a random method.

2. according to the threshold graph, each pixel data P (n,m) is divided into the object pixel data G1 and the background pixel data G2. (n is

Row,m is column )

3. the average of G1 is M1, and the average of G2 is m2

4. A new threshold T ' = (m1 + m2)/2

5. back to the second step, use the new threshold to continue to divide the pixel data into objects with the Beijing pixel data, continue 2~4 steps,

Until the new threshold value is calculated equals the last threshold.

The previous three types are covered in previous posts, and the last binary method code is as follows:

2. Using the class library ImageIO

PRJ. Atibrow

Imagedemo Demo  =  New Imagedemo ();

Demo . Binaryimage (deboxjpg,bin_jpg);

Public void binaryimage(string pathname, String pathname2 ) throws IOException {

// String pathname = System.getproperty ("User.dir")

// + "/ src /2722425974762424026. jpg ";

File file  =  New File (pathname);

BufferedImage Image = ImageIO. Read (file);

int width = image. getwidth ();

int height = image. getheight ();

BufferedImage Grayimage  =  New bufferedimage (width, height,

BufferedImage. type_byte_binary ); //Focus, tips in this parameter bufferedimage.type_byte_binary

for   ( int &NBSP; i &NBSP;=&NBSP;0;&NBSP; i &NBSP;<&NBSP; width ;&NBSP; i ++)  {

for (int j = 0; J < Height ;  J ++) {

int rgb = image. getRGB (i, J );

Grayimage . Setrgb (i, J, RGB);

}

}

File NewFile  =  New File (pathname2);

ImageIO. Write (grayimage, "jpg", newFile);

}

3. Reference

A summary of common binary methods for image processing - Wandering fish - Blog channel -CSDN.NET.htm

JAVA grayscale, binary images so simple and convenient - lazy man - Blog channel -csdn_net.htm

Atitit. Verification code Recognition STEP4--------binary grayscale of graphics

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.