Image preprocessing method, device, electronic device and readable storage medium
By performing equalized brightness and contrast processing on the grayscale image and combining grayscale closing operation and enhancement processing, the problems of background interference and uneven lighting are solved, and accurate segmentation and recognition of character areas are achieved.
Patent Information
- Application Number
- CN202011351584.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-26
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2040-11-26
AI Technical Summary
In the existing technology, background interference and uneven lighting lead to poor image segmentation and binarization effects, affecting the accuracy of character recognition.
By equalizing the brightness and improving the contrast of the grayscale image, using grayscale closing operation and enhancement processing, the connected domain of the character strokes is determined, the background interference is removed, and the character area is segmented.
The binarization effect of the image is improved, the influence of illumination on the distinction between foreground and background is suppressed, and accurate character area segmentation is achieved.
Smart Images

Figure CN114550173B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet technology, and in particular to an image preprocessing method, device, electronic device, and readable storage medium. Background Art
[0002] With the increasing demand for automation in factories, optical character recognition (OCR) technology, based on image preprocessing, has become increasingly widely used in recent years. OCR typically segments an entire string of characters contained in an image into individual characters for recognition, making single-character recognition the foundation and key to OCR. However, segmented images may contain background information in addition to the characters, which can interfere with recognition and reduce accuracy. Furthermore, lighting conditions at industrial sites can also affect recognition accuracy. Summary of the Invention
[0003] The present invention provides an image preprocessing method, device, electronic device and readable storage medium to solve the problem that the area containing only character strokes cannot be effectively segmented due to background interference, and the binarization effect is poor due to uneven lighting, thereby failing to obtain an image with balanced grayscale in the same area and high grayscale contrast between different areas.
[0004] According to a first aspect of the present invention, the present invention provides an image preprocessing method, which includes: converting an original image into a grayscale image; obtaining a first image by equalizing the brightness and improving the contrast of the grayscale image; obtaining a second image by enhancing the first image; determining a connected domain corresponding to character strokes in the second image; and obtaining a character area based on the connected domain.
[0005] In some embodiments, the step of obtaining a first image by equalizing the brightness and improving the contrast of the grayscale image includes: performing a grayscale closing operation on the grayscale image to obtain a template subimage of the same size as the grayscale image; increasing the size of the closing operation structure and calculating the grayscale variance of each pixel in the image; and dividing the grayscale image by the target template subimage to obtain an enhanced first image.
[0006] In some embodiments, the step of performing a grayscale closing operation on the grayscale image to obtain a template subimage of the same size as the grayscale image includes: performing a grayscale closing operation on the grayscale image to obtain a template subimage of the same size as the grayscale image using the following formula;
[0007]
[0008] Among them, I orig is a grayscale image, Istruct_element is the structural element, I gray_close is the template subgraph, represents grayscale expansion, Represents grayscale erosion.
[0009] In some embodiments, the step of increasing the size of the closed operation structure and calculating the grayscale variance of each pixel in the image includes: calculating the grayscale variance of each pixel in the grayscale image and the template subimage to obtain a first variance and a second variance; calculating the quotient of the first variance and the second variance; when the quotient is less than or equal to a preset value, increasing the size of the structural element in the closed operation and recalculating the second variance; when the quotient is greater than a preset value, obtaining the target template subimage.
[0010] In some embodiments, the step of enhancing the first image to obtain the second image includes: binarizing the first image to obtain a binary image; performing an erosion operation on the binary image to obtain a seed image; performing an expansion operation on the seed image to obtain an expanded image; and performing an AND operation on the expanded image and the first image to obtain a second image.
[0011] In some embodiments, in determining the connected domain corresponding to the character strokes in the second image, and obtaining the character area based on the connected domain, the steps include: extracting all the connected domains, calculating the position and size of the circumscribed rectangle corresponding to each of the connected domains; obtaining the first center point of the corresponding connected domain based on the position and size of each circumscribed rectangle; determining the second center point based on all the first center points; calculating the deviation between the second center point and the third center point of the second image; translating the second image based on the deviation, and recalculating the position and size of the circumscribed rectangle corresponding to each of the connected domains; determining the initial character area based on the positions and sizes of all the recalculated circumscribed rectangles; and searching based on the initial character area to obtain the character area.
[0012] In some embodiments, the step of searching based on the initial character area to obtain the character area includes: searching in a preset direction with the initial character area as the center; when the searched pixel point has a preset grayscale value or the search length is greater than the preset length, stopping the search and marking the connected domain corresponding to the pixel point as the target character area; searching in multiple directions with each target character area as the center until the total number of the target character areas no longer changes; and obtaining the character area based on the set of all the target character areas.
[0013] According to the second aspect of the present invention, the present invention provides an image preprocessing device, which includes: a conversion module for converting an original image into a grayscale image; a first obtaining module for obtaining a first image by equalizing the brightness and improving the contrast of the grayscale image; a second obtaining module for obtaining a second image by enhancing the first image; and a determination module for determining a connected domain corresponding to character strokes in the second image, and obtaining a character area based on the connected domain.
[0014] According to the third aspect of the present invention, the present invention provides an electronic device, comprising a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the image preprocessing method as described above.
[0015] According to a fourth aspect of the present invention, the present invention provides a readable storage medium, on which a program or instruction is stored, and when the program or instruction is executed by a processor, the image preprocessing method as described above is implemented.
[0016] Compared with the existing technology, the beneficial effects of the present invention are as follows: the present invention balances the brightness and improves the contrast of the grayscale image, so that the grayscale of pixels belonging to the same area is concentrated, and the grayscale value difference between pixels in different areas is increased, thereby suppressing the influence of lighting in different environments on the distinction between the foreground and background of the image, thereby improving the binarization effect. In addition, the present invention removes small areas of background interference by reconstructing the image, thereby achieving accurate segmentation of character areas. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 A schematic flow chart of the steps of an image preprocessing method provided by an embodiment of the present invention.
[0018] Figure 2 for Figure 1 The specific step flow chart of step S12 is shown.
[0019] Figure 3 for Figure 2 The specific step flow chart of step S22 is shown.
[0020] Figure 4 for Figure 1 The specific step flow chart of step S13 is shown.
[0021] Figure 5 for Figure 1 The specific step flow chart of step S14 is shown.
[0022] Figure 6 for Figure 5The specific step flow chart of step S57 is shown.
[0023] Figure 7 A schematic structural diagram of an image preprocessing device provided by an embodiment of the present invention.
[0024] Figure 8 A schematic structural diagram of an electronic device provided by an embodiment of the present invention.
[0025] Figure 9a The grayscale histogram of the grayscale image provided by the embodiment of the present invention.
[0026] Figure 9b Grayscale histogram of the target template sub-image provided by the embodiment of the present invention.
[0027] Figure 10 Schematic diagram of image structure at each stage of image preprocessing provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0028] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0029] like Figure 1 As shown, an embodiment of the present invention provides an image preprocessing method, which includes steps S11 to S14.
[0030] Step S11, converting the original image into a grayscale image.
[0031] In the embodiment of the present invention, when using a color camera, the original color image should be converted into a grayscale image for subsequent processing. The commonly used calculation formula for converting the original color image into a grayscale image is as follows:
[0032] Gray=R*0.299+G*0.587+B*0.114,
[0033] Among them, R, G, and B represent the component values of the three channels of the color image, and Gray represents the grayscale value.
[0034] In some embodiments, a monochrome camera may be used to capture the character image, and the original image itself is a grayscale image.
[0035] Step S12: performing brightness equalization and contrast enhancement processing on the grayscale image to obtain a first image.
[0036] In an embodiment of the present invention, by performing brightness equalization and contrast enhancement processing on a grayscale image, the grayscales of pixels belonging to the same area are concentrated, and the grayscale value differences between pixels in different areas are increased, thereby suppressing the influence of lighting in different environments on the distinction between the foreground and background of the image.
[0037] See Figure 2 In some embodiments, step S12 includes steps S21 to S23.
[0038] Step S21 , performing a grayscale closing operation on the grayscale image to obtain a template sub-image of the same size as the grayscale image.
[0039] In an embodiment of the present invention, a grayscale closing operation is performed on the grayscale image using the following formula to obtain a template subimage of the same size as the grayscale image:
[0040]
[0041] Among them, I orig is a grayscale image, I struct_element is the structural element, I gray_close is the template subgraph, represents grayscale expansion, Represents grayscale erosion. In a grayscale image, the brightness of darker pixels increases after grayscale closing, while the brightness of brighter pixels remains unchanged.
[0042] Step S22: Increase the size of the closed operation structure and calculate the grayscale variance of each pixel in the image.
[0043] See Figure 3 In some embodiments, step S22 includes steps S31 to S34.
[0044] Step S31 , calculating the grayscale variance of each pixel in the grayscale image and the template sub-image to obtain a first variance and a second variance.
[0045] Step S32: Calculate the quotient of the first variance and the second variance.
[0046] Step S33: When the quotient is less than or equal to a preset value, the size of the structure element in the closing operation is increased, and the second variance is recalculated.
[0047] Step S34: when the quotient is greater than a preset value, the target template subgraph is obtained.
[0048] In the embodiment of the present invention, the initial size of the structure element is 3 and the step size is 1. The preset value can be 2, but is not limited thereto. When the variance of the template sub-image is twice the variance of the original image, the grayscale values of pixels in the same area are concentrated, and the grayscale value differences between pixels in different areas become larger. Figure 9a As shown in , it is the grayscale histogram of the grayscale image; Figure 9b The figure shows the grayscale histogram of the target template sub-image. From the area relationship between the two, we can see that the variance of the template sub-image is twice the variance of the original image.
[0049] Continue reading Figure 2 .
[0050] Step S23: Divide the grayscale image by the target template sub-image to obtain an enhanced first image.
[0051] In the embodiment of the present invention, the brightness in the same area of the first image is balanced, and the contrast between different areas (foreground and background) is large.
[0052] Continue reading Figure 1 .
[0053] Step S13: Obtain a second image by performing enhancement processing on the first image.
[0054] In some embodiments, step S13 includes steps S41 to S44.
[0055] Step S41 : binarize the first image to obtain a binary image.
[0056] In the embodiments of the present invention, binarization is the process of assigning a value of 0 to pixels with a grayscale below a threshold and a value of 255 to pixels with a grayscale greater than or equal to the threshold, thereby producing a black and white image. This threshold is automatically selected using a local adaptive thresholding method, which can overcome the problem of poor binarization results caused by uneven illumination.
[0057] Step S42: performing an erosion operation on the binary image to obtain a seed image.
[0058] Step S43: performing a dilation operation on the seed image to obtain a dilated image.
[0059] Step S44: performing an AND operation on the dilated image and the first image to obtain a second image.
[0060] In an embodiment of the present invention, a small area of interference is removed from the eroded binary image but a portion of the character area is retained. A dilation operation is performed and an AND operation is performed with the first image to obtain a reconstructed image. The above method is continuously repeated until the reconstructed image no longer grows. The reconstructed image at this time is the second image.
[0061] Continue reading Figure 1 .
[0062] Step S14: determining a connected domain corresponding to the character strokes in the second image, and obtaining a character region according to the connected domain.
[0063] In the embodiment of the present invention, the connected domain of the character strokes is determined by removing part of the background interference, so as to accurately segment the character area.
[0064] In some embodiments, step S14 includes steps S51 to S57.
[0065] Step S51 : extract all the connected domains, and calculate the position and size of the circumscribed rectangle corresponding to each connected domain.
[0066] Step S52: Obtain the first center point of the corresponding connected region for the position and size of each circumscribed rectangle.
[0067] Step S53: determining a second center point based on all of the first center points.
[0068] In the embodiment of the present invention, the second center point is located at the center of all the first center points.
[0069] Step S54: Calculate the deviation between the second center point and the third center point of the second image.
[0070] Step S55 : translating the second image according to the deviation, and recalculating the position and size of the circumscribed rectangle corresponding to each connected region.
[0071] In the embodiment of the present invention, the second image is translated according to the deviation between the second center point and the third center point of the second image, so that the character falls at the center position of the second image.
[0072] Step S56: determining the initial character area according to the positions and sizes of all recalculated circumscribed rectangles.
[0073] In the embodiment of the present invention, the distance between each connected domain and the second image is obtained according to the positions and sizes of all recalculated circumscribed rectangles, and the connected domain with the closest distance is used as the initial character area.
[0074] Step S57: Search according to the initial character area to obtain the character area.
[0075] In some embodiments, see Figure 6 , step S57 includes steps S61 to S64.
[0076] Step S61 : searching in a preset direction with the initial character area as the center.
[0077] In the embodiment of the present invention, the preset directions may include four directions: up, down, left, and right, but are not limited thereto.
[0078] Step S62: When the pixel point found is a preset grayscale value or the search length is greater than a preset length, the search is stopped and the connected domain corresponding to the pixel point is marked as a target character area.
[0079] In this embodiment of the present invention, the preset grayscale value is 255. When a pixel with a grayscale value of 255 is found, it indicates that another connected domain has been found. This connected domain is marked as the target character region, and the search in that search direction is stopped. The step length of the search is s, and the number of steps is n, where s and n are both integers. When s*n exceeds the preset length (the length of the long side of the rectangle circumscribing the initial character region), the search in that search direction is stopped.
[0080] Step S63: Search in multiple directions with each target character region as the center until the total number of target character regions does not change.
[0081] In the embodiment of the present invention, the search is performed again with the marked target area as the center until the total number of target character areas no longer changes, that is, all target character areas (all connected domains) are obtained through the search.
[0082] Step S64: obtaining the character region according to the set of all the target character regions.
[0083] In the embodiment of the present invention, the set of all target character regions is the character region with character strokes in the image.
[0084] like Figure 10 As shown, an embodiment of the present invention provides a structural schematic diagram of each stage of image preprocessing.
[0085] See Figure 7 An embodiment of the present invention provides an image preprocessing device, which includes a conversion module 71, a first obtaining module 72, a second obtaining module 73 and a determination module 74.
[0086] The conversion module 71 is used to convert the original image into a grayscale image.
[0087] In the embodiment of the present invention, when using a color camera, the original color image should be converted into a grayscale image for subsequent processing. The commonly used calculation formula for converting the original color image into a grayscale image is as follows:
[0088] Gray=R*0.299+G*0.587+B*0.114,
[0089] Among them, R, G, and B represent the component values of the three channels of the color image, and Gray represents the grayscale value.
[0090] In some embodiments, a monochrome camera may be used to capture the character image, and the original image itself is a grayscale image.
[0091] The first obtaining module 72 is configured to obtain a first image by performing brightness equalization and contrast enhancement processing on the grayscale image.
[0092] In an embodiment of the present invention, by performing brightness equalization and contrast enhancement processing on a grayscale image, the grayscales of pixels belonging to the same area are concentrated, and the grayscale value differences between pixels in different areas are increased, thereby suppressing the influence of lighting in different environments on the distinction between the foreground and background of the image.
[0093] The first obtaining module 72 is further configured to perform a grayscale closing operation on the grayscale image to obtain a template sub-image of the same size as the grayscale image.
[0094] In an embodiment of the present invention, a grayscale closing operation is performed on the grayscale image using the following formula to obtain a template subimage of the same size as the grayscale image:
[0095]
[0096] Among them, I orig is a grayscale image, I struct_element is the structural element, I gray_close is the template subgraph, represents grayscale expansion, Represents grayscale erosion. In a grayscale image, the brightness of darker pixels increases after grayscale closing, while the brightness of brighter pixels remains unchanged.
[0097] The first obtaining module 72 is further configured to increase the size of the closed operation structure and calculate the grayscale variance of each pixel in the image. Specifically, the grayscale variance of each pixel in the grayscale image and the template subimage is calculated to obtain a first variance and a second variance. The quotient of the first variance and the second variance is calculated. When the quotient is less than or equal to a preset value, the size of the structural element in the closed operation is increased and the second variance is recalculated. When the quotient is greater than a preset value, the target template subimage is obtained.
[0098] In the embodiment of the present invention, the preset value may be, but is not limited to, 2. When the variance of the template sub-image is twice the variance of the original image, the grayscale values of pixels in the same region are concentrated, and the grayscale value differences between pixels in different regions become larger.
[0099] The first obtaining module 72 is further configured to divide the grayscale image by the target template sub-image to obtain an enhanced first image. The brightness in the same region of the first image is balanced, and the contrast between different regions (foreground and background) is large.
[0100] The second obtaining module 73 is configured to obtain a second image by performing enhancement processing on the first image.
[0101] In some embodiments,
[0102] The second obtaining module 73 is further used to perform binarization processing on the first image to obtain a binary image; perform an erosion operation on the binary image to obtain a seed image; perform an expansion operation on the seed image to obtain an expanded image; and perform an AND operation on the expanded image and the first image to obtain a second image.
[0103] In an embodiment of the present invention, binarization is the process of assigning a value of 0 to pixels with a grayscale below a threshold and a value of 255 to pixels with a grayscale greater than or equal to the threshold, to obtain a black and white image. The threshold is automatically selected by a local adaptive threshold device, which can overcome the problem of poor binarization effect caused by uneven illumination. The eroded binary image removes small areas of interference but retains a portion of the character area. A dilation operation is performed and the image is ANDed with the first image to obtain a reconstructed image. The above device is continuously cycled until the reconstructed image no longer grows. The reconstructed image at this time is the second image.
[0104] The determination module 74 is configured to determine a connected domain corresponding to character strokes in the second image, and obtain a character region based on the connected domain.
[0105] In the embodiment of the present invention, the connected domain of the character strokes is determined by removing part of the background interference, so as to accurately segment the character area.
[0106] In some embodiments,
[0107] The determination module 74 is further configured to extract all the connected domains and calculate the position and size of the circumscribed rectangle corresponding to each connected domain.
[0108] The determination module 74 is further configured to obtain the first center point of the corresponding connected region based on the position and size of each circumscribed rectangle.
[0109] The determination module 74 is further configured to determine a second center point based on all of the first center points.
[0110] In the embodiment of the present invention, the second center point is located at the center of all the first center points.
[0111] The determination module 74 is further configured to calculate a deviation between the second center point and a third center point of the second image.
[0112] The determination module 74 is further configured to translate the second image according to the deviation, and recalculate the position and size of the circumscribed rectangle corresponding to each connected region.
[0113] In the embodiment of the present invention, the second image is translated according to the deviation between the second center point and the third center point of the second image, so that the character falls at the center position of the second image.
[0114] The determination module 74 is further configured to determine the initial character area according to the positions and sizes of all recalculated circumscribed rectangles.
[0115] In the embodiment of the present invention, the distance between each connected domain and the second image is obtained according to the positions and sizes of all recalculated circumscribed rectangles, and the connected domain with the closest distance is used as the initial character area.
[0116] The determination module 74 is further configured to search based on the initial character region to obtain the character region.
[0117] In some embodiments,
[0118] The determination module 74 is further configured to search in a preset direction with the initial character area as the center.
[0119] In the embodiment of the present invention, the preset directions may include four directions: up, down, left, and right, but are not limited thereto.
[0120] The determination module 74 is further configured to stop searching and mark the connected domain corresponding to the pixel point as a target character area when the pixel point found has a preset grayscale value or the search length is greater than a preset length.
[0121] In this embodiment of the present invention, the preset grayscale value is 255. When a pixel with a grayscale value of 255 is found, it indicates that another connected domain has been found. This connected domain is marked as the target character region, and the search in that search direction is stopped. The step length of the search is s, and the number of steps is n, where s and n are both integers. When s*n exceeds the preset length (the length of the long side of the rectangle circumscribing the initial character region), the search in that search direction is stopped.
[0122] The determination module 74 is further configured to search in multiple directions with each target character region as the center until the total number of the target character regions no longer changes.
[0123] In the embodiment of the present invention, the search is performed again with the marked target area as the center until the total number of target character areas no longer changes, that is, all target character areas (all connected domains) are obtained through the search.
[0124] The determination module 74 is further configured to obtain the character region according to the set of all the target character regions.
[0125] In the embodiment of the present invention, the set of all target character regions is the character region with character strokes in the image.
[0126] See Figure 8 , the embodiment of the present invention further provides an electronic device 800, which can be a mobile phone, a tablet, a computer and other devices. Figure 8 As shown, the electronic device 800 includes a processor 801 and a memory 802. The processor 801 is electrically connected to the memory 802.
[0127] The processor 801 is the control center of the electronic device 800. It uses various interfaces and lines to connect various parts of the entire electronic device. By running or loading applications stored in the memory 802 and calling data stored in the memory 802, it executes various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole.
[0128] In this embodiment, the electronic device 800 is provided with multiple storage partitions, including a system partition and a target partition. The processor 801 in the electronic device 800 loads instructions corresponding to one or more application processes into the memory 802 according to the following steps, and the processor 801 runs the application stored in the memory 802 to implement various functions:
[0129] Convert the original image to a grayscale image;
[0130] Obtaining a first image by performing brightness equalization and contrast enhancement processing on the grayscale image;
[0131] Obtaining a second image by performing enhancement processing on the first image;
[0132] A connected domain corresponding to the character strokes in the second image is determined, and a character region is obtained according to the connected domain.
[0133] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments can be accomplished through instructions, or by controlling related hardware through instructions. The instructions can be stored in a computer-readable storage medium and loaded and executed by a processor. To this end, an embodiment of the present invention provides a computer-readable storage medium storing a plurality of instructions that can be loaded by a processor to execute the steps of any of the image preprocessing methods provided in the embodiments of the present invention.
[0134] The readable storage medium may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0135] Since the instructions stored in the readable storage medium can execute the steps of any of the image preprocessing methods provided in the embodiments of the present invention, the beneficial effects achievable by any of the image preprocessing methods provided in the embodiments of the present invention can be achieved. For details, see the previous embodiments and will not be repeated here. The specific implementation of each of the above operations can be found in the previous embodiments and will not be repeated here.
[0136] The present invention balances the brightness and improves the contrast of the grayscale image, so that the grayscale of pixels belonging to the same area is concentrated, and the grayscale value difference between pixels in different areas is increased, thereby suppressing the influence of lighting in different environments on the distinction between the foreground and background of the image, thereby improving the binarization effect. In addition, the present invention removes small-area background interference by reconstructing the image, thereby achieving accurate segmentation of character areas.
[0137] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0138] The above is a detailed introduction to an image preprocessing method, system, readable storage medium and electronic device provided by the embodiments of the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the technical solutions and core ideas of the present invention. Ordinary technicians in this field should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. An image preprocessing method, characterized in that: include: Convert the original image to a grayscale image; Obtaining a first image by performing brightness equalization and contrast enhancement processing on the grayscale image; Obtaining a second image by performing enhancement processing on the first image; determining a connected domain corresponding to the character strokes in the second image, and obtaining a character region based on the connected domain; The step of performing brightness equalization and contrast enhancement processing on the grayscale image to obtain the first image includes: performing a grayscale closing operation on the grayscale image to obtain a template subimage of the same size as the grayscale image; increasing the size of the closing operation structure and calculating the grayscale variance of each pixel in the image; and dividing the grayscale image by the target template subimage to obtain an enhanced first image. Among them, in the step of increasing the size of the closed operation structure and calculating the grayscale variance of each pixel point in the image, it includes: calculating the grayscale variance of each pixel point in the grayscale image and the template subimage to obtain a first variance and a second variance; calculating the quotient of the first variance and the second variance; when the quotient is less than or equal to a preset value, increasing the size of the structural element in the closed operation and recalculating the second variance; when the quotient is greater than the preset value, obtaining the target template subimage.
2. The image preprocessing method according to claim 1, wherein: The step of performing a grayscale closing operation on the grayscale image to obtain a template subimage of the same size as the grayscale image includes: Perform a grayscale closing operation on the grayscale image using the following formula to obtain a template subimage of the same size as the grayscale image; Among them, I orig is a grayscale image, I struct_element is the structural element, I gray_close is the template subgraph, represents grayscale expansion, Represents grayscale erosion.
3. The image preprocessing method according to claim 1, wherein: The step of performing enhancement processing on the first image to obtain the second image includes: performing binarization processing on the first image to obtain a binary image; Performing an erosion operation on the binary image to obtain a seed image; performing a dilation operation on the seed image to obtain a dilated image; An AND operation is performed on the dilated image and the first image to obtain a second image.
4. The image preprocessing method according to claim 1, wherein: The step of determining a connected domain corresponding to character strokes in the second image and acquiring a character region according to the connected domain includes: Extract all the connected domains, and calculate the position and size of the circumscribed rectangle corresponding to each connected domain; Obtaining a first center point of the corresponding connected region according to the position and size of each circumscribed rectangle; Determine a second center point based on all of the first center points; calculating a deviation between the second center point and a third center point of the second image; translating the second image according to the deviation, and recalculating the position and size of the circumscribed rectangle corresponding to each connected region; Determine the initial character area based on the positions and sizes of all recalculated bounding rectangles; Search is performed based on the initial character area to obtain the character area.
5. The image preprocessing method according to claim 4, wherein: The step of searching according to the initial character area to obtain the character area includes: Searching in a preset direction with the initial character area as the center; When the pixel point found is a preset gray value or the search length is greater than a preset length, the search is stopped and the connected domain corresponding to the pixel point is marked as the target character area; Searching in multiple directions with each target character region as the center until the total number of target character regions no longer changes; The character region is obtained according to the set of all the target character regions.
6. An image preprocessing device, characterized in that: include: A conversion module, used to convert the original image into a grayscale image; A first obtaining module is used to obtain a first image by performing brightness equalization and contrast enhancement processing on the grayscale image; A second obtaining module is configured to obtain a second image by performing enhancement processing on the first image; as well as a determination module, configured to determine a connected domain corresponding to the character strokes in the second image, and obtain a character region based on the connected domain; The method of performing brightness equalization and contrast enhancement processing on the grayscale image to obtain the first image includes: performing a grayscale closing operation on the grayscale image to obtain a template subimage of the same size as the grayscale image; increasing the size of the closing operation structure and calculating the grayscale variance of each pixel in the image; and dividing the grayscale image by the target template subimage to obtain an enhanced first image. Among them, increasing the size of the closed operation structure and calculating the grayscale variance of each pixel point in the image includes: calculating the grayscale variance of each pixel point in the grayscale image and the template subimage to obtain a first variance and a second variance; calculating the quotient of the first variance and the second variance; when the quotient is less than or equal to a preset value, increasing the size of the structural element in the closed operation and recalculating the second variance; when the quotient is greater than the preset value, obtaining the target template subimage.
7. An electronic device, characterized in that: The method comprises a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements the steps of the image preprocessing method according to any one of claims 1 to 5.
8. A readable storage medium, characterized in that: The readable storage medium stores a program or instruction, and when the program or instruction is executed by a processor, the image preprocessing method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Railway scene text localization method based on combination of maximum stable extreme value region and stroke width
CN107045634A
Target detection method, device and equipment, computer equipment and storage medium
CN109903272A