An image binarization processing method and device
By preprocessing and adaptive binarization of the image, the optimal threshold is determined using the maximum inter-class variance method, which solves the character segmentation accuracy problem of special scene images and improves the accuracy of character recognition.
Patent Information
- Application Number
- CN202211562829.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-07
- Publication Date
- 2025-07-29
- Estimated Expiration
- 2042-12-07
AI Technical Summary
In the field of character recognition, the prior art cannot be compatible with special scene images, resulting in low accuracy of character recognition and segmentation.
The image preprocessing method is used to determine the optimal binarization threshold through the maximum inter-class variance method, and adaptive binarization is performed to improve the accuracy of character segmentation.
It improves the character segmentation accuracy of special scene images and enhances the accuracy of character recognition.
Smart Images

Figure CN115909353B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, in particular to the field of artificial intelligence technology, and more particularly to an image binarization processing method and apparatus. Background Art
[0002] In recent years, the development and popularization of intelligent devices and optical character recognition software have made character recognition a hot issue in the field of image recognition. In related technologies, only images with a single background, regular characters, no noise or less interference have relatively high recognition and segmentation accuracy, and cannot be compatible with special scenarios. However, in actual production, most images do not meet the recognition and segmentation standards, resulting in relatively low accuracy of subsequent character recognition and character segmentation. Summary of the Invention
[0003] One object of the present invention is to provide an image binarization processing method, which can preprocess an image and perform image binarization, and determine an optimal target binarization threshold through an improved maximum between-class variance method, so as to be compatible with special scenario images, thereby improving the accuracy of subsequent character segmentation of the image. Another object of the present invention is to provide an image binarization processing apparatus. Still another object of the present invention is to provide a computer-readable medium. Yet another object of the present invention is to provide a computer device.
[0004] To achieve the above objects, on the one hand, the present invention discloses an image binarization processing method, including:
[0005] Obtain an original image;
[0006] Perform image preprocessing on the original image to obtain a target grayscale image and an initial binarization threshold;
[0007] Perform adaptive binarization on the target grayscale image through the maximum between-class variance method and the initial binarization threshold to obtain a target binarization threshold;
[0008] Perform binarization processing on the target grayscale image according to the target binarization threshold to obtain a target binarized image.
[0009] Preferably, performing image preprocessing on the original image to obtain a target grayscale image and an initial binarization threshold includes:
[0010] Perform grayscale preprocessing on the original image to obtain an initial grayscale image and an initial binarization threshold;
[0011] Perform blank and border removal preprocessing on the initial grayscale image to obtain a target grayscale image.
[0012] Preferably, performing grayscale preprocessing on the original image to obtain an initial grayscale image and an initial binarization threshold includes:
[0013] The original image is subjected to grayscale conversion to obtain an initial grayscale image, and the initial grayscale image includes a plurality of pixel points and the grayscale value corresponding to each pixel point;
[0014] An initial binarization threshold is obtained according to the plurality of pixel points and the grayscale value corresponding to each pixel point.
[0015] Preferably, obtaining an initial binarization threshold according to the plurality of pixel points and the grayscale value corresponding to each pixel point includes:
[0016] According to the set grayscale value range, the grayscale values corresponding to each pixel point are statistically analyzed through a histogram to obtain a pixel point array, and the pixel point array includes a plurality of grayscale value ranges and the number of pixel points corresponding to each grayscale value range;
[0017] An inversion judgment is performed on the initial grayscale image according to the pixel point array.
[0018] According to the inversion judgment result, calculations are performed on the total number of pixel points, the plurality of grayscale value ranges, and the number of pixel points corresponding to each grayscale value range to obtain an initial binarization threshold.
[0019] Preferably, performing calculations on the total number of pixel points, the plurality of grayscale value ranges, and the number of pixel points corresponding to each grayscale value range according to the inversion judgment result to obtain an initial binarization threshold includes:
[0020] If it is determined to be inverted, each pixel point in the initial grayscale image is subjected to an inversion process according to the specified number of grayscale bits to obtain an inverted initial grayscale image, and the inverted initial grayscale image includes the grayscale value corresponding to each inverted pixel point;
[0021] According to the grayscale value range, the grayscale values corresponding to each inverted pixel point are statistically analyzed through a histogram to obtain an inverted pixel point array, and the inverted pixel point array includes a plurality of grayscale value ranges and the number of inverted pixel points corresponding to each grayscale value range;
[0022] An initial binarization is obtained according to the total number of pixel points, the plurality of grayscale value ranges, and the number of inverted pixel points corresponding to each grayscale value range;
[0023] If it is determined not to be inverted, an initial binarization is obtained according to the total number of pixel points, the plurality of grayscale value ranges, and the number of pixel points corresponding to each grayscale value range.
[0024] Preferably, the initial grayscale image includes a plurality of pixel points and the grayscale value corresponding to each pixel point;
[0025] Preprocessing the initial grayscale image to remove blanks and borders to obtain a target grayscale image, including:
[0026] Preprocess the initial grayscale image to remove blanks and borders based on the pixel point array and the initial binarization threshold, obtaining the target grayscale image.
[0027] Preferably, preprocessing the initial grayscale image to remove blanks and borders based on the pixel point array and the initial binarization threshold to obtain the target grayscale image includes:
[0028] Perform binarization processing on the initial grayscale image through the initial binarization threshold to obtain the initial binarized image;
[0029] Traverse from both ends of the initial binarized image row by row of pixels until the pixel coordinates of the black pixel points at the edge are obtained;
[0030] Perform blank removal processing on the initial grayscale image according to the pixel coordinates of the black pixel points at the edge to obtain the initial grayscale image after blank removal;
[0031] Update the initial binarization threshold according to the set intermediate parameter to obtain the intermediate threshold;
[0032] Perform binarization processing on the initial grayscale image after blank removal through the intermediate threshold to obtain the enhanced binarized image;
[0033] Start traversing from the central pixel point of the enhanced binarized image to obtain the row coordinates where all pixel points in the row where the black pixel points are located are black pixel points, and / or obtain the column coordinates where all pixel points in the column where the black pixel points are located are black pixel points;
[0034] Perform border removal processing on the initial grayscale image after blank removal according to the row coordinates and / or column coordinates to obtain the target grayscale image.
[0035] Preferably, perform adaptive binarization on the target grayscale image through the maximum inter-class variance method and the initial binarization threshold to obtain the target binarization threshold, including:
[0036] Obtain the segmentation threshold according to the preset threshold range;
[0037] Divide the target grayscale image into a foreground image and a background image according to the segmentation threshold;
[0038] Statistically calculate the average grayscale of the foreground image through the pixel point array;
[0039] Construct a constraint condition according to the initial binarization threshold and the average grayscale of the foreground image;
[0040] Perform maximum variance calculation on the foreground image and the background image through the maximum inter-class variance method and the constraint condition to determine the target binarization threshold corresponding to the maximum variance.
[0041] Preferably, by using the Otsu method and constraint conditions, the maximum variance calculation is performed on the foreground image and the background image to determine the target binary threshold corresponding to the maximum variance, including:
[0042] Through the pixel point array, count the first pixel ratio of the foreground pixel points in the foreground image to the target grayscale image, the second pixel ratio of the background pixel points in the background image to the target grayscale image, and the average grayscale of the background image;
[0043] Generate the total average grayscale of the image according to the first pixel ratio, the second pixel ratio, the average grayscale of the foreground image, and the average grayscale of the background image;
[0044] According to the constraint conditions, generate the target binary threshold according to the total average grayscale of the image, the first pixel ratio, and the average grayscale of the foreground image.
[0045] Preferably, the method further includes:
[0046] Perform enhancement judgment on the initial grayscale image according to the pixel point array;
[0047] If it is determined to be enhanced, perform grayscale enhancement on the grayscale values of the pixel points in the initial grayscale image that meet the enhancement requirements according to the preset enhancement bits to obtain the enhanced initial grayscale image.
[0048] Preferably, after performing binary processing on the target grayscale image according to the target binary threshold to obtain the target binary image, it further includes:
[0049] Perform character segmentation on the target binary image to obtain the segmented character image.
[0050] The present invention also discloses an image binary processing device, including:
[0051] An acquisition unit for acquiring the original image;
[0052] An image preprocessing unit for performing image preprocessing on the original image to obtain the target grayscale image and the initial binary threshold;
[0053] A threshold optimization unit for adaptively binaryizing the target grayscale image through the Otsu method and the initial binary threshold to obtain the target binary threshold;
[0054] A binaryization unit for performing binary processing on the target grayscale image according to the target binary threshold to obtain the target binary image.
[0055] The present invention also discloses a computer-readable medium, on which a computer program is stored, and when the program is executed by a processor, the above-mentioned method is implemented.
[0056] The present invention also discloses a computer device, including a memory and a processor. The memory is used to store information including program instructions, and the processor is used to control the execution of the program instructions. When the processor executes the program, the above-mentioned method is implemented.
[0057] The present invention also discloses a computer program product, including a computer program / instructions. When the computer program / instructions are executed by a processor, the above-mentioned method is implemented.
[0058] The present invention acquires an original image; performs image preprocessing on the original image to obtain a target grayscale image and an initial binarization threshold; performs adaptive binarization on the target grayscale image through the Otsu method and the initial binarization threshold to obtain a target binarization threshold; performs binarization processing on the target grayscale image according to the target binarization threshold to obtain a target binarized image, which can preprocess the image and perform image binarization, and determines the optimal target binarization threshold through the improved Otsu method, and can be compatible with special scene images, thereby improving the accuracy of subsequent character segmentation of the image. Description of the Drawings
[0059] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required to be used in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0060] Figure 1 It is a flowchart of an image binarization processing method provided by an embodiment of the present invention;
[0061] Figure 2 It is a flowchart of another image binarization processing method provided by an embodiment of the present invention;
[0062] Figure 3 It is a schematic diagram of an initial grayscale image provided by an embodiment of the present invention;
[0063] Figure 4 It is a schematic diagram of an initial grayscale image after removing blanks provided by an embodiment of the present invention;
[0064] Figure 5 It is a schematic diagram of a target grayscale image after removing blanks and borders provided by an embodiment of the present invention;
[0065] Figure 6 It is a schematic diagram of a target binarized image provided by an embodiment of the present invention;
[0066] Figure 7Schematic diagram of a segmented character image provided by an embodiment of the present invention;
[0067] Figure 8 Schematic diagram of the structure of an image binarization processing device provided by an embodiment of the present invention;
[0068] Figure 9 Schematic diagram of the structure of a computer device provided by an embodiment of the present invention. Detailed implementation manners
[0069] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0070] It should be noted that an image binarization processing method and device disclosed in the present application can be used in the field of artificial intelligence technology, and can also be used in any field other than the field of artificial intelligence technology. The application fields of the image binarization processing method and device disclosed in the present application are not limited.
[0071] To facilitate understanding of the technical solutions provided in the present application, the relevant content of the technical solutions in the present application will be described first. In the current field of image recognition, whether it is a traditional eigenvalue extraction algorithm or a convolutional neural network, the accuracy of character segmentation is still the core step to improve the character recognition rate. The present invention mainly aims at the case of a dark background, pre-processes the image in a special scenario by means of image processing technology, and uses an improved maximum inter-class variance method to select an appropriate threshold for the pre-processed image, so as to improve the recognition accuracy of subsequent character segmentation. The simulation results show that this method can effectively handle the case of dark background images. The present invention processes the image of a special scenario based on image processing technology, is compatible with special scenarios, thereby can improve the accuracy of text segmentation, and thus improve the recognition accuracy.
[0072] Next, taking the image binarization processing device as the execution subject as an example, the implementation process of the image binarization processing method provided by the embodiment of the present invention will be described. It can be understood that the execution subject of the image binarization processing method provided by the embodiment of the present invention includes but is not limited to the image binarization processing device.
[0073] Figure 1 Flowchart of an image binarization processing method provided by an embodiment of the present invention, as Figure 1 shown, the method includes:
[0074] Step 101, obtain an original image.
[0075] Step 102: Perform image preprocessing on the original image to obtain a target grayscale image and an initial binarization threshold.
[0076] Step 103: Perform adaptive binarization on the target grayscale image by the Otsu method and the initial binarization threshold to obtain a target binarization threshold.
[0077] Step 104: Perform binarization processing on the target grayscale image according to the target binarization threshold to obtain a target binarized image.
[0078] It should be noted that in the technical solution of this application, the acquisition, storage, use, processing, etc. of data all comply with the relevant provisions of national laws and regulations. The user information in the embodiments of this application is obtained through legal and compliant channels, and the acquisition, storage, use, processing, etc. of user information have obtained the authorization and consent of the customers.
[0079] In the technical solution provided by the embodiment of the present invention, an original image is acquired; image preprocessing is performed on the original image to obtain a target grayscale image and an initial binarization threshold; adaptive binarization is performed on the target grayscale image by the Otsu method and the initial binarization threshold to obtain a target binarization threshold; binarization processing is performed on the target grayscale image according to the target binarization threshold to obtain a target binarized image, which can preprocess the image and perform image binarization, and determine the best target binarization threshold through the improved Otsu method, and can be compatible with special scene images, thereby improving the accuracy of subsequent character segmentation of the image.
[0080] Figure 2 It is a flowchart of another image binarization processing method provided by the embodiment of the present invention. As Figure 2 shown, the method includes:
[0081] Step 201: Acquire an original image.
[0082] In the embodiment of the present invention, each step is executed by an image binarization processing device.
[0083] In the embodiment of the present invention, the original image can be a pre-captured image or an image sent by other terminals. The embodiment of the present invention does not limit the environment and scene of the original image, that is: the original image can be a dark background with light-colored fonts, or a light background with dark-colored fonts, and there can be interference such as noise, blank edges, and borders in the original image.
[0084] Step 202: Perform grayscale preprocessing on the original image to obtain an initial grayscale image and an initial binarization threshold.
[0085] In the embodiment of the present invention, the original image is a true color (RGB) image, the original image includes multiple pixel points, and each pixel point includes three-component brightness.
[0086] In the embodiment of the present invention, step 202 specifically includes:
[0087] Step 2021: Perform grayscale conversion on the original image to obtain an initial grayscale image, which includes a plurality of pixel points and the grayscale value corresponding to each pixel point.
[0088] Specifically, by using the average value method, perform grayscale conversion on the original image, calculate the average value of the three-component brightness of each pixel point in the true-color image to obtain the grayscale value of the pixel point; according to the grayscale values of a plurality of pixel points, obtain the initial grayscale image. The grayscale value of any pixel point in the initial grayscale image can be expressed as:
[0089] Gray(i,j) = [R(i,j) + G(i,j) + B(i,j)] / 3
[0090] where Gray(i,j) is the grayscale value of the pixel point, R(i,j) is the brightness of the red component, G(i,j) is the brightness of the green component, and B(i,j) is the brightness of the blue component.
[0091] Figure 3 is a schematic diagram of an initial grayscale image provided by an embodiment of the present invention. As Figure 3 shown, the initial grayscale image includes the character 88000.00, and also includes a border and an edge part, and each pixel point is presented with a different grayscale value.
[0092] Step 2022: Obtain an initial binarization threshold according to a plurality of pixel points and the grayscale value corresponding to each pixel point.
[0093] In the embodiment of the present invention, step 2022 specifically includes:
[0094] Step 22a: According to the set grayscale value interval, statistically analyze the grayscale value corresponding to each pixel point through a histogram to obtain a pixel point array, which includes a plurality of grayscale value intervals and the number of pixel points corresponding to each grayscale value interval.
[0095] In the embodiment of the present invention, since the background pixel points in the initial grayscale image are more than the character pixel points, a grayscale value interval can be set to facilitate subsequent statistics. The grayscale value interval can be set according to actual needs, and the embodiment of the present invention does not limit this. As an optional solution, the range of the grayscale value is from 0 to 255, and it is divided into intervals with 10 values each. The obtained grayscale value intervals include: [0, 9], [10, 19], [20, 29]... [250, 255], a total of 26 groups.
[0096] In the embodiment of the present invention, the histogram can reflect the gray-scale distribution information of the initial gray-scale image. The gray-scale values corresponding to each pixel point are statistically summarized through the histogram according to the set gray-scale value intervals, and the number of pixel points corresponding to each gray-scale value interval is obtained. According to multiple gray-scale value intervals and the number of pixel points corresponding to each gray-scale value interval, a pixel point array is generated. The length of the pixel point array is 26, denoted as Arr 26 。
[0097] Step 22b: Perform flipping judgment on the initial gray-scale image according to the pixel point array.
[0098] In the embodiment of the present invention, a flipping ratio is preset according to actual needs. As an optional solution, the flipping ratio is 15%. Multiply the flipping ratio by the total number of pixel points to obtain the flipping pixel point threshold. Start accumulating and calculating from the number of pixel points corresponding to the first gray-scale value interval of the pixel point array until the accumulation stops when it is greater than the flipping pixel point threshold. Obtain the number of intervals participating in the accumulation calculation in the pixel point array when the accumulation stops. Judge whether the number of intervals is greater than the set flipping interval threshold. If so, it indicates that the gray-scale values of most pixel points in the pixel point array are relatively high, and the initial gray-scale image has a dark background, so the initial gray-scale image is determined not to be flipped. If not, it indicates that the gray-scale values of most pixel points in the pixel point array are relatively low, and the initial gray-scale image has a light background. To facilitate subsequent blank and border processing and further improve the segmentation character recognition accuracy, the initial gray-scale image is determined to be flipped.
[0099] It should be noted that the flipping interval threshold can be set according to actual needs, and the embodiment of the present invention does not limit this. As an optional solution, since the array length is 26, the flipping interval threshold is set to 13.
[0100] Specifically, by accumulating and calculating and comparing the flipping pixel ratio, the total number of pixel points, and the number of pixel points corresponding to multiple gray-scale value intervals, the number of intervals participating in the accumulation calculation is obtained, where N is the total number of pixel points, Arr j is the pixel point array, f(m) is the accumulation result of the number of pixel points corresponding to the first m gray-scale value intervals of the pixel point array, m is the number of intervals participating in the accumulation calculation, α is the flipping pixel ratio, and αN is the flipping pixel point threshold. It should be noted that m is not any m gray-scale value intervals in the pixel point array, but the first m gray-scale value intervals in the pixel point array.
[0101] Step 22c: Calculate the initial binarization threshold according to the flipping judgment result for the total number of pixel points, multiple gray-scale value intervals, and the number of pixel points corresponding to each gray-scale value interval.
[0102] In the embodiments of the present invention, the flipping judgment result includes determining flipping or determining non-flipping. The initial binarization thresholds calculated for the two results are different. The following will separately describe the two flipping judgment results.
[0103] If it is determined to flip:
[0104] Step 22c1: Flip each pixel point in the initial grayscale image according to the specified number of grayscale bits to obtain the flipped initial grayscale image. The flipped initial grayscale image includes the grayscale values corresponding to each flipped pixel point.
[0105] As an optional solution, the specified number of grayscale bits is 255, and the specific formula is as follows:
[0106]
[0107] where I is the grayscale value corresponding to the flipped pixel point, G o is the grayscale value corresponding to the pixel point before flipping, and m is the number of intervals participating in the cumulative calculation. Generate the flipped initial grayscale image according to multiple flipped pixel points and the grayscale values corresponding to each flipped pixel point.
[0108] In the embodiments of the present invention, the images with light backgrounds and dark fonts are unified into images with dark backgrounds and light fonts, which is convenient for subsequent blank and border processing, thereby further improving the recognition accuracy of segmented characters.
[0109] Furthermore, in order to further enhance the dark fonts and thus further improve the recognition accuracy of segmented characters, the gray levels of the pixel points that meet the enhancement requirements can be enhanced. Specifically, according to the pixel point array, perform an enhancement judgment on the flipped initial grayscale image; if it is determined to enhance, enhance the gray levels of the pixel points that meet the enhancement requirements in the flipped initial grayscale image according to the preset enhancement bits to obtain the enhanced initial grayscale image.
[0110] Among them, both the enhancement requirements and the enhancement bits can be set according to actual needs, and the embodiments of the present invention do not limit this. As an optional solution, the enhancement requirement is that the number of pixel points corresponding to the last k gray level intervals in the pixel point array is greater than the enhanced pixel point threshold, where the enhanced pixel point threshold is the product of the total number of pixel points and the preset enhanced pixel ratio. The enhanced pixel ratio can be set according to actual needs, and the embodiments of the present invention do not limit this. As an optional solution, the enhanced pixel ratio is 15%. As an optional solution, the enhancement bits can be set to 35, that is: add 35 to the gray levels of the pixel points that meet the enhancement requirements to obtain the gray levels of the enhanced pixel points.
[0111] Step 22c2: According to the gray value intervals, use a histogram to count the gray values corresponding to each pixel point after flipping, obtaining an array of pixel points after flipping. The array of pixel points after flipping includes multiple gray value intervals and the number of pixel points after flipping corresponding to each gray value interval.
[0112] In the embodiment of the present invention, the statistical method in Step 22c2 is the same as that in Step 22a. The only difference is that Step 22c2 counts the gray values corresponding to each pixel point after flipping, while Step 22a counts the gray values corresponding to each pixel point before flipping. Therefore, it will not be repeated here.
[0113] Step 22c3: Obtain the initial binarization based on the total number of pixel points, multiple gray value intervals, and the number of pixel points after flipping corresponding to each gray value interval.
[0114] Specifically, through calculate the total number of pixel points and the number of pixel points after flipping corresponding to each gray value interval to obtain the initial binarization. Where N is the number of pixel points, L is the total number of gray value ranges which is 256, i is the gray value, n(i) is the number of pixel points with gray value i, and ThresholdA is the initial binarization.
[0115] If it is determined not to flip:
[0116] Obtain the initial binarization based on the total number of pixel points, multiple gray value intervals, and the number of pixel points corresponding to each gray value interval.
[0117] Specifically, through calculate the total number of pixel points and the number of pixel points corresponding to each gray value interval to obtain the initial binarization. Where N is the total number of pixel points, L is the total number of gray value ranges which is 256, i is the gray value, n(i) is the number of pixel points with gray value i, and ThresholdA is the initial binarization.
[0118] Furthermore, if it is determined not to flip, before calculating the initial binarization, in order to further strengthen the dark fonts and thus further improve the recognition accuracy of segmented characters, the gray values of the pixel points meeting the enhancement requirements can be enhanced. Specifically, based on the pixel point array, perform an enhancement judgment on the initial gray scale image; if it is determined to enhance, enhance the gray values of the pixel points meeting the enhancement requirements in the initial gray scale image according to the preset enhancement bits to obtain the enhanced initial gray scale image.
[0119] In the embodiment of the present invention, the gray-scale enhancement in step 22c1 is the same as the enhancement method herein. The only difference is that in step 22c1, the gray-scale value corresponding to the pixel points that meet the enhancement requirements after flipping is enhanced, while herein, before calculating the initial binarization, the gray-scale value corresponding to the pixel points that meet the enhancement requirements is enhanced, which will not be repeated here.
[0120] Step 203: Perform preprocessing on the initial gray-scale image to remove blanks and borders, and obtain a target gray-scale image.
[0121] In the embodiment of the present invention, the initial gray-scale image includes a plurality of pixel points and the gray-scale value corresponding to each pixel point.
[0122] Specifically, according to the pixel point array and the initial binarization threshold, perform preprocessing on the initial gray-scale image to remove blanks and borders, and obtain a target gray-scale image.
[0123] In the embodiment of the present invention, step 203 specifically includes:
[0124] Step 2031: Perform binarization processing on the initial gray-scale image through the initial binarization threshold to obtain an initial binarized image.
[0125] Specifically, compare the gray-scale value corresponding to each pixel point in the initial gray-scale image with the initial binarization threshold, set the gray-scale value of the pixel points less than the initial binarization threshold to 0, and set the gray-scale value of the pixel points greater than or equal to the initial binarization threshold to 255 to obtain the initial binarized image.
[0126] Step 2032: Traverse from both ends of the initial binarized image row by row of pixels until the pixel coordinates of the black pixel points located at the edge are obtained.
[0127] Specifically, traverse from the left and right ends of the initial binarized image row by row of pixels respectively, and determine whether there are black pixel points, that is, whether there are pixel points with a gray-scale value of 255. If there are, record the pixel coordinates of the black pixel points, start traversing the next row until all pixel rows in the initial binarized image are traversed; if not, continue to traverse the next pixel point and / or the next row until a black pixel point is obtained. The recorded black pixel points are the black pixel points located at the edge.
[0128] As another alternative, traverse from the upper and lower ends of the initial binarized image column by column of pixels respectively, and determine whether there are black pixel points, that is, whether there are pixel points with a gray-scale value of 255. If there are, record the pixel coordinates of the black pixel points, start traversing the next column until all pixel columns in the initial binarized image are traversed; if not, continue to traverse the next pixel point and / or the next column until a black pixel point is obtained. The recorded black pixel points are the black pixel points located at the edge.
[0129] Step 2033: Perform blank removal processing on the initial grayscale image according to the pixel coordinates of the black pixel points located at the edge, and obtain the initial grayscale image after blank removal.
[0130] Specifically, from the initial grayscale image, screen out the grayscale image surrounded by the pixel coordinates of the recorded black pixel points to obtain the initial grayscale image after blank removal.
[0131] Figure 4 It is a schematic diagram of an initial grayscale image after blank removal provided by an embodiment of the present invention. As Figure 4 shown, compared with Figure 3 , Figure 4 the initial grayscale image shown has removed the blank edge.
[0132] Step 2034: Update the initial binarization threshold according to the set intermediate parameter to obtain an intermediate threshold.
[0133] In order to save noise points and border information as much as possible, the initial binarization threshold is updated. Specifically, calculate the intermediate parameter and the initial binarization threshold through Threshold B = Threshold A - C to obtain the intermediate threshold. Where Threshold B is the intermediate threshold, Threshold A is the initial binarization threshold, and C is the intermediate parameter. It should be noted that the intermediate parameter can be set according to actual needs, and the embodiment of the present invention does not limit this. As an optional solution, the intermediate parameter is 20.
[0134] Step 2035: Perform binarization processing on the initial grayscale image after blank removal through the intermediate threshold to obtain an enhanced binarized image.
[0135] Specifically, compare the grayscale value corresponding to each pixel point in the initial grayscale image after blank removal with the intermediate threshold, set the grayscale value of the pixel points less than the intermediate threshold to 0, and set the grayscale value of the pixel points greater than or equal to the intermediate threshold to 255 to obtain the enhanced binarized image.
[0136] Step 2036: Start traversing from the central pixel point of the enhanced binarized image, and obtain the row coordinates where all pixel points in the row where the black pixel points are located are black pixel points, and / or obtain the column coordinates where all pixel points in the column where the black pixel points are located are black pixel points.
[0137] Specifically, starting from the central pixel of the enhanced binary image, traverse upward, downward, left, and right directions respectively to determine whether there is a complete row and / or a complete column of black pixel points, that is: whether the grayscale values of all pixel points in a complete row and / or a complete column are 255. If so, record the row coordinates of this row and / or the column coordinates of this column. If not, continue to traverse the next row and / or the next column until all rows and columns of the enhanced binary image are traversed. If after traversing all rows and columns of the enhanced binary image, there is no case where a complete row or a complete column is all black pixel points, it indicates that the image has no border; if there is a case where a complete row and / or a complete column is all black pixel points, it indicates that the image has a border. The recorded row coordinates and / or column coordinates are the positions where the border is located.
[0138] Step 2037: Perform border removal processing on the initial grayscale image after blank removal according to the row coordinates and / or column coordinates to obtain the target grayscale image.
[0139] Specifically, filter out the recorded row coordinates and / or column coordinates from the initial grayscale image after blank removal to obtain the target grayscale image.
[0140] Figure 5 is a schematic diagram of a target grayscale image after blank removal and border removal provided by an embodiment of the present invention. As Figure 5 shown, compared with Figure 4 , Figure 5 the border of the shown target grayscale image is removed.
[0141] After performing fixed binarization processing on the image, there will be errors in segmenting the text image. For example, two connected black pixel points of numbers are segmented into the same number. To avoid character adhesion during character segmentation, through an improved maximum inter-class variance method, adaptive binarization is performed on the segmentation threshold, and the best threshold is selected to maximize the variance between the foreground image and the background image.
[0142] Step 204: Obtain the segmentation threshold according to the preset threshold range.
[0143] In the embodiment of the present invention, according to the gray-scale characteristics of the image, the image can be divided into a foreground image and a background image. Denote the segmentation threshold between the foreground image and the background image as T, and the threshold value range of the segmentation threshold is from 0 to 255.
[0144] Step 205: Divide the target grayscale image into a foreground image and a background image according to the segmentation threshold.
[0145] Specifically, compare the grayscale value corresponding to each pixel point in the target grayscale image with the segmentation threshold T, set the grayscale value of the pixel points less than the segmentation threshold T to 0, and set the grayscale value of the pixel points greater than or equal to the segmentation threshold T to 255 to obtain the initial binary image.
[0146] Step 206: Count the average grayscale of the foreground image through the pixel array.
[0147] Specifically, through The total number of pixels, grayscale value, and the number of pixels with grayscale value i are calculated to obtain the average grayscale of the foreground image. Where h0 is the average grayscale of the foreground image, i is the grayscale value, n(i) is the number of pixels with grayscale value i, N is the total number of pixels, and T is the segmentation threshold.
[0148] Step 207: Construct constraint conditions based on the initial binarization threshold and the average grayscale of the foreground image.
[0149] When the size ratio of the target to the background is significantly different (due to factors such as a complex background), the inter-class variance criterion function may exhibit bimodal or multimodal behavior, resulting in poor segmentation. Based on this, the maximum inter-class variance method is further optimized. To achieve the goal of slender text character lines that facilitate segmentation, constraints are added when calculating the maximum variance between the foreground and background of the image.
[0150] Specifically, a constraint condition is constructed according to the initial binarization threshold and the average grayscale of the foreground image. The constructed constraint condition is h0-ThreasholdA<0, where h0 is the average grayscale of the foreground image and Threshold A is the initial binarization threshold.
[0151] Step 208: Using the maximum inter-class variance method and the constraint conditions, the maximum variance calculation is performed on the foreground image and the background image to determine the target binarization threshold corresponding to the maximum variance.
[0152] In the embodiment of the present invention, step 208 specifically includes:
[0153] Step 2081: Using the pixel array, count the first pixel ratio of the number of foreground pixels in the foreground image to the target grayscale image, the second pixel ratio of the number of background pixels in the background image to the target grayscale image, and the average grayscale of the background image.
[0154] Specifically, through Calculate the total number of pixels and the number of pixels with grayscale value i to obtain the ratio of the number of foreground pixels to the first pixel of the target grayscale image. Where w0 is the first pixel ratio, n(i) is the number of pixels with grayscale value i, N is the total number of pixels, and T is the segmentation threshold.
[0155] Specifically, through Calculate the total number of pixel points and the number of pixel points with gray value i to obtain the second pixel ratio of the background pixel points in the target gray-scale image. Among them, w1 is the second pixel ratio, n(i) is the number of pixel points with gray value i, N is the total number of pixel points, T is the segmentation threshold, and L is the total number of gray value ranges.
[0156] Specifically, through Calculate the total number of pixel points, the gray value, and the number of pixel points with gray value i to obtain the average gray value of the background image. Among them, h1 is the average gray value of the background image, i is the gray value, n(i) is the number of pixel points with gray value i, N is the total number of pixel points, T is the segmentation threshold, and L is the total number of gray value ranges.
[0157] Step 2082: Generate the total average gray value of the image according to the first pixel ratio, the second pixel ratio, the average gray value of the foreground image, and the average gray value of the background image.
[0158] Specifically, through h = w0×h0 + w1×h1, calculate the first pixel ratio, the second pixel ratio, the average gray value of the foreground image, and the average gray value of the background image to obtain the total average gray value of the image. Among them, w0 is the first pixel ratio, w1 is the second pixel ratio, h0 is the average gray value of the foreground image, h1 is the average gray value of the background image, and h is the total average gray value of the image.
[0159] Step 2083: Generate the target binary threshold according to the total average gray value of the image, the first pixel ratio, and the average gray value of the foreground image according to the constraint conditions.
[0160] Specifically, through Determine the target binary threshold for the total average gray value of the image, the first pixel ratio, and the average gray value of the foreground image, that is: traverse the image matrix to obtain the segmentation threshold T corresponding to the maximum variance and when h0 - ThreasholdA < 0; determine the obtained segmentation threshold T as the target binary threshold.
[0161] Step 209: Perform binary processing on the target gray-scale image according to the target binary threshold to obtain the target binary image.
[0162] Specifically, compare the gray value corresponding to each pixel point in the target gray-scale image with the target binary threshold, set the gray value of the pixel points less than the target binary threshold to 0, and set the gray value of the pixel points greater than or equal to the target binary threshold to 255 to obtain the target binary image.
[0163] Figure 6 This is a schematic diagram of a target binary image provided by an embodiment of the present invention, as Figure 6 shown, compared with Figure 5The character part is at the connection of two digital black pixel points (the last two digits are 0). Figure 6 There is a white pixel point between the two digital black pixel points in the corresponding part shown, achieving the effect that the text character lines are thin and conducive to segmentation.
[0164] Step 210: Perform character segmentation on the target binary image to obtain the segmented character image.
[0165] It should be noted that the character segmentation technology is an existing technology, and the specific method adopted for character segmentation in the embodiments of the present invention is not limited.
[0166] Figure 7 This is a schematic diagram of a segmented character image provided by the embodiments of the present invention. Figure 7 The shown segmented character image is an image obtained by performing character segmentation based on Figure 6 As shown in Figure 7 there is no adhesion between characters, and the character recognition accuracy is relatively high.
[0167] In the technical solution of the image binarization processing method provided by the embodiments of the present invention, the original image is obtained; the original image is preprocessed to obtain the target grayscale image and the initial binarization threshold; the target grayscale image is adaptively binarized by the maximum inter-class variance method and the initial binarization threshold to obtain the target binarization threshold; the target grayscale image is binarized according to the target binarization threshold to obtain the target binary image, which can preprocess the image and perform image binarization, and determine the optimal target binarization threshold through the improved maximum inter-class variance method, and can be compatible with special scene images, thereby improving the accuracy of subsequent character segmentation of the image.
[0168] Figure 8 This is a schematic structural diagram of an image binarization processing device provided by the embodiments of the present invention. This device is used to execute the above image binarization processing method. As shown in Figure 8 it includes: an acquisition unit 11, an image preprocessing unit 12, a threshold optimization unit 13, and a binarization unit 14.
[0169] The acquisition unit 11 is used to acquire the original image.
[0170] The image preprocessing unit 12 is used to preprocess the original image to obtain the target grayscale image and the initial binarization threshold.
[0171] The threshold optimization unit 13 is used to adaptively binarize the target grayscale image by the maximum inter-class variance method and the initial binarization threshold to obtain the target binarization threshold.
[0172] The binarization unit 14 is configured to binarize the target grayscale image according to the target binarization threshold to obtain the target binarized image.
[0173] In an embodiment of the present invention, the image preprocessing unit 12 is specifically configured to perform grayscale preprocessing on the original image to obtain an initial grayscale image and an initial binarization threshold; perform blank and border removal preprocessing on the initial grayscale image to obtain the target grayscale image.
[0174] In an embodiment of the present invention, the image preprocessing unit 12 is specifically configured to perform grayscale conversion on the original image to obtain an initial grayscale image, where the initial grayscale image includes a plurality of pixel points and the grayscale value corresponding to each pixel point; obtain the initial binarization threshold according to the plurality of pixel points and the grayscale value corresponding to each pixel point.
[0175] In an embodiment of the present invention, the image preprocessing unit 12 is specifically configured to statistically analyze the grayscale value corresponding to each pixel point through a histogram according to the set grayscale value range to obtain a pixel point array, where the pixel point array includes a plurality of grayscale value ranges and the number of pixel points corresponding to each grayscale value range; perform a flip determination on the initial grayscale image according to the pixel point array; calculate the total number of pixel points, the plurality of grayscale value ranges, and the number of pixel points corresponding to each grayscale value range according to the flip determination result to obtain the initial binarization threshold.
[0176] In an embodiment of the present invention, if it is determined to flip, the image preprocessing unit 12 is specifically configured to flip each pixel point in the initial grayscale image according to the specified number of grayscale bits to obtain the flipped initial grayscale image, where the flipped initial grayscale image includes the grayscale value corresponding to each flipped pixel point; statistically analyze the grayscale value corresponding to each flipped pixel point through a histogram according to the grayscale value range to obtain the flipped pixel point array, where the flipped pixel point array includes a plurality of grayscale value ranges and the number of flipped pixel points corresponding to each grayscale value range; obtain the initial binarization according to the total number of pixel points, the plurality of grayscale value ranges, and the number of flipped pixel points corresponding to each grayscale value range; if it is determined not to flip, obtain the initial binarization according to the total number of pixel points, the plurality of grayscale value ranges, and the number of pixel points corresponding to each grayscale value range.
[0177] In an embodiment of the present invention, the initial grayscale image includes a plurality of pixel points and the grayscale value corresponding to each pixel point; the image preprocessing unit 12 is specifically configured to perform blank and border removal preprocessing on the initial grayscale image according to the pixel point array and the initial binarization threshold to obtain the target grayscale image.
[0178] In the embodiment of the present invention, the image preprocessing unit 12 is specifically configured to perform binarization processing on the initial grayscale image through an initial binarization threshold to obtain an initial binarized image; traverse from both ends of the initial binarized image according to pixel rows until the pixel coordinates of the black pixel points located at the edge are obtained; perform blank removal processing on the initial grayscale image according to the pixel coordinates of the black pixel points located at the edge to obtain the initial grayscale image after blank removal; update the initial binarization threshold according to the set intermediate parameter to obtain an intermediate threshold; perform binarization processing on the initial grayscale image after blank removal through the intermediate threshold to obtain an enhanced binarized image; traverse from the central pixel point of the enhanced binarized image to obtain the row coordinates where all pixel points in the row where the black pixel points are located are black pixel points, and / or obtain the column coordinates where all pixel points in the column where the black pixel points are located are black pixel points; perform border removal processing on the initial grayscale image after blank removal according to the row coordinates and / or column coordinates to obtain a target grayscale image.
[0179] In the embodiment of the present invention, the threshold optimization unit 13 is specifically configured to obtain a segmentation threshold according to a preset threshold range; divide the target grayscale image into a foreground image and a background image according to the segmentation threshold; count the average grayscale of the foreground image through a pixel point array; construct a constraint condition according to the initial binarization threshold and the average grayscale of the foreground image; perform maximum variance calculation on the foreground image and the background image through the maximum between-class variance method and the constraint condition to determine the target binarization threshold corresponding to the maximum variance.
[0180] In the embodiment of the present invention, the threshold optimization unit 13 is specifically configured to count, through a pixel point array, the first pixel ratio of the number of foreground pixel points in the foreground image to the target grayscale image, the second pixel ratio of the number of background pixel points in the background image to the target grayscale image, and the average grayscale of the background image; generate the total average grayscale of the image according to the first pixel ratio, the second pixel ratio, the average grayscale of the foreground image, and the average grayscale of the background image; generate the target binarization threshold according to the total average grayscale of the image, the first pixel ratio, and the average grayscale of the foreground image according to the constraint condition.
[0181] In the embodiment of the present invention, the device further includes: an enhancement judgment unit 15 and a grayscale enhancement unit 16.
[0182] The enhancement judgment unit 15 is configured to perform enhancement judgment on the initial grayscale image according to the pixel point array.
[0183] The grayscale enhancement unit 16 is configured to, if it is determined to be enhanced, perform grayscale enhancement on the grayscale values of the pixel points in the initial grayscale image that meet the enhancement requirements according to the preset enhancement bits to obtain the enhanced initial grayscale image.
[0184] In the embodiment of the present invention, the device further includes: a character segmentation unit 17.
[0185] The character segmentation unit 17 is used to segment characters from the target binary image to obtain the segmented character images.
[0186] In the solution of the embodiment of the present invention, an original image is obtained; image preprocessing is performed on the original image to obtain a target grayscale image and an initial binary threshold; the target grayscale image is adaptively binaryzied by the maximum between-class variance method and the initial binary threshold to obtain a target binary threshold; the target grayscale image is binaryzied according to the target binary threshold to obtain a target binary image. It can preprocess the image and perform image binaryzation, and determine the optimal target binary threshold through the improved maximum between-class variance method, which can be compatible with special scene images, thereby improving the accuracy of subsequent character segmentation of the image.
[0187] The systems, devices, modules or units illustrated in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer device. Specifically, the computer device can be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or any combination of these devices.
[0188] The embodiment of the present invention provides a computer device, including a memory and a processor. The memory is used to store information including program instructions, and the processor is used to control the execution of the program instructions. When the program instructions are loaded and executed by the processor, the steps of the above embodiment of the image binaryzation processing method are implemented. For specific descriptions, reference can be made to the above embodiment of the image binaryzation processing method.
[0189] Next, refer to Figure 9 , which shows a schematic structural diagram of a computer device 600 suitable for implementing the embodiments of the present application.
[0190] As Figure 9 shown, the computer device 600 includes a central processing unit (CPU) 601, which can perform various appropriate operations and processes according to the program stored in the read-only memory (ROM) 602 or the program loaded from the storage section 608 into the random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the computer device 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other through a bus 604. The input / output (I / O) interface 605 is also connected to the bus 604.
[0191] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including, for example, a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed so that a computer program read therefrom is installed in the storage section 608 as needed.
[0192] Specifically, according to an embodiment of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, an embodiment of the present invention includes a computer program product that includes a computer program tangibly embodied on a machine-readable medium, the computer program including program code for performing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 609, and / or installed from the removable medium 611.
[0193] Computer-readable media includes both permanent and non-permanent, removable and non-removable media implemented by any method or technology for storage of information such as computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technologies, compact disc read only memory (CD-ROM), digital versatile discs (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices, or any other non-transitory medium that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0194] For convenience of description, the above-described apparatus is described by functionally dividing it into various units. Of course, when implementing the present application, the functions of the various units can be implemented in one or more software and / or hardware.
[0195] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing devices produce a means for implementing the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or means for implementing the functions specified in one block or multiple blocks.
[0196] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory produce a manufactured article including an instruction means that implements the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or means for implementing the functions specified in one block or multiple blocks.
[0197] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one flow Figure 1 one flow or multiple flows and / or blocks Figure 1 or means for implementing the functions specified in one block or multiple blocks.
[0198] It should also be noted that the term "comprising", "including" or any other variation thereof is intended to cover non-exclusive inclusion, such that a process, method, commodity or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed, or elements inherent to such process, method, commodity or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, commodity or device including the said element.
[0199] In the technical solution of this application, the acquisition, storage, use, processing, etc. of data all comply with the relevant provisions of national laws and regulations.
[0200] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0201] The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in a distributed computing environment where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0202] Each embodiment in this specification is described in a progressive manner. For the same or similar parts among the embodiments, reference can be made to each other. The key point of each embodiment is to illustrate the differences from other embodiments. In particular, for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and reference can be made to the relevant parts of the method embodiment for the related content.
[0203] The above description is only for the embodiments of the present application and is not intended to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. An image binarization method, characterized in that, The method includes: Obtaining an original image; Performing grayscale conversion on the original image to obtain an initial grayscale image, where the initial grayscale image includes a plurality of pixel points and the grayscale value corresponding to each pixel point; According to the set grayscale value intervals, statistically analyzing the grayscale value corresponding to each pixel point through a histogram to obtain a pixel point array, where the pixel point array includes a plurality of grayscale value intervals and the number of pixel points corresponding to each grayscale value interval; Performing a flip judgment on the initial grayscale image according to the pixel point array; Calculating the total number of pixel points, a plurality of grayscale value intervals, and the number of pixel points corresponding to each grayscale value interval according to the flip judgment result to obtain an initial binary threshold; Performing preprocessing on the initial grayscale image to remove blanks and borders to obtain a target grayscale image; Obtaining a segmentation threshold according to a preset threshold range; Dividing the target grayscale image into a foreground image and a background image according to the segmentation threshold; Statistically analyzing the average grayscale of the foreground image through the pixel point array; Constructing a constraint condition according to the initial binary threshold and the average grayscale of the foreground image; where the constraint condition is that the average grayscale of the foreground image is less than the initial binary threshold; Statistically analyzing the first pixel ratio of the number of foreground pixel points in the foreground image to the target grayscale image, the second pixel ratio of the number of background pixel points in the background image to the target grayscale image, and the average grayscale of the background image through the pixel point array; Generating an overall average grayscale of the image according to the first pixel ratio, the second pixel ratio, the average grayscale of the foreground image, and the average grayscale of the background image; By , the target binarization threshold is determined for the total average gray level of the image, the first pixel ratio, and the average gray level of the foreground image; the target binarization threshold is the segmentation threshold corresponding to the maximum variance and satisfying the constraint condition; wherein, is the average gray level of the foreground image, is the first pixel ratio, is the total average gray level of the image, and Threshold A is the initial binarization threshold; Performing binary processing on the target grayscale image according to the target binary threshold to obtain a target binary image.
2. The image binarization processing method according to claim 1, wherein, The calculating the total number of pixel points, a plurality of grayscale value intervals, and the number of pixel points corresponding to each grayscale value interval according to the flip judgment result to obtain an initial binary threshold includes: If it is determined to be flipped, performing a flip process on each pixel point in the initial grayscale image according to the specified number of grayscale bits to obtain a flipped initial grayscale image, where the flipped initial grayscale image includes the grayscale value corresponding to each flipped pixel point; According to the grayscale value intervals, statistically analyzing the grayscale value corresponding to each flipped pixel point through a histogram to obtain a flipped pixel point array, where the flipped pixel point array includes a plurality of grayscale value intervals and the number of flipped pixel points corresponding to each grayscale value interval; Obtaining an initial binary threshold according to the total number of pixel points, a plurality of grayscale value intervals, and the number of flipped pixel points corresponding to each grayscale value interval; If it is determined not to be flipped, obtaining an initial binary threshold according to the total number of pixel points, a plurality of grayscale value intervals, and the number of pixel points corresponding to each grayscale value interval.
3. The image binarization processing method according to claim 1, wherein, The performing preprocessing on the initial grayscale image to remove blanks and borders to obtain the target grayscale image includes: Performing preprocessing on the initial grayscale image to remove blanks and borders according to the pixel point array and the initial binary threshold to obtain the target grayscale image.
4. The image binarization processing method according to claim 3, wherein Performing preprocessing on the initial grayscale image to remove blanks and borders according to the pixel point array and the initial binarization threshold to obtain the target grayscale image includes: Performing binarization processing on the initial grayscale image through the initial binarization threshold to obtain an initial binarized image; Traversing from both ends of the initial binarized image row by row of pixels until the pixel coordinates of the black pixel points located at the edge are obtained; Performing blank removal processing on the initial grayscale image according to the pixel coordinates of the black pixel points located at the edge to obtain the initial grayscale image after blank removal; Updating the initial binarization threshold according to the set intermediate parameter to obtain an intermediate threshold; Performing binarization processing on the initial grayscale image after blank removal through the intermediate threshold to obtain an enhanced binarized image; Traversing from the central pixel point of the enhanced binarized image to obtain the row coordinates where all pixel points in the row where the black pixel points are located are black pixel points, and / or obtain the column coordinates where all pixel points in the column where the black pixel points are located are black pixel points; Performing border removal processing on the initial grayscale image after blank removal according to the row coordinates and / or column coordinates to obtain the target grayscale image.
5. The image binarization processing method according to claim 1, wherein, The method further includes: Performing enhancement judgment on the initial grayscale image according to the pixel point array; If it is determined to be enhanced, performing gray-scale enhancement on the gray-scale values of the pixel points in the initial grayscale image that meet the enhancement requirements according to the preset enhancement bits to obtain the enhanced initial grayscale image.
6. The image binarization processing method according to claim 1, wherein After performing binarization processing on the target grayscale image according to the target binarization threshold to obtain a target binarized image, it further includes: Performing character segmentation on the target binarized image to obtain segmented character images.
7. An image binarization processing device, characterized in that, The device includes: An acquisition unit, configured to acquire an original image; An image preprocessing unit, configured to perform gray-scale conversion on the original image to obtain an initial grayscale image, where the initial grayscale image includes a plurality of pixel points and the gray-scale value corresponding to each pixel point; performing statistics on the gray-scale value corresponding to each pixel point through a histogram according to the set gray-scale value range to obtain a pixel point array, where the pixel point array includes a plurality of gray-scale value ranges and the number of pixel points corresponding to each gray-scale value range; performing flip judgment on the initial grayscale image according to the pixel point array; calculating the total number of pixel points, a plurality of gray-scale value ranges, and the number of pixel points corresponding to each gray-scale value range according to the flip judgment result to obtain an initial binarization threshold; performing preprocessing on the initial grayscale image to remove blanks and borders to obtain a target grayscale image; A threshold optimization unit is configured to obtain a segmentation threshold according to a preset threshold range; divide the target grayscale image into a foreground image and a background image according to the segmentation threshold; calculate the average grayscale of the foreground image through the pixel point array; construct a constraint condition according to the initial binary threshold and the average grayscale of the foreground image; wherein, the constraint condition is that the average grayscale of the foreground image is less than the initial binary threshold; calculate the first pixel ratio of the number of foreground pixel points in the foreground image to the target grayscale image, the second pixel ratio of the number of background pixel points in the background image to the target grayscale image, and the average grayscale of the background image through the pixel point array; generate the total average grayscale of the image according to the first pixel ratio, the second pixel ratio, the average grayscale of the foreground image, and the average grayscale of the background image; through , determine a target binary threshold for the total average grayscale of the image, the first pixel ratio, and the average grayscale of the foreground image; the target binary threshold is the segmentation threshold corresponding to the maximum variance and satisfying the constraint condition; wherein, is the average grayscale of the foreground image, is the first pixel ratio, is the total average grayscale of the image, and Threshold A is the initial binary threshold; A binarization unit, configured to perform binarization processing on the target grayscale image according to the target binarization threshold to obtain a target binarized image.
8. A computer-readable medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the image binarization processing method according to any one of claims 1 to 6.
9. A computer device, comprising a memory and a processor, the memory being used for storing information including program instructions, and the processor being used for controlling the execution of the program instructions, characterized in that, When the program instructions are loaded and executed by a processor, it implements the image binarization processing method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by a processor, it implements the image binarization processing method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Fabric defect detection method based on improved threshold segmentation
CN106780464A
Adaptive ferrographic wear particle image binarization processing method
CN107967690A