A method and device for analyzing wired table images based on semantic segmentation
Through the method based on semantic segmentation, the problem of difficulty in processing interference items and non-straight tables in table image parsing in the existing technology is solved, efficient and accurate table information extraction and text recognition are achieved, editable text tables are generated, and the parsing effect is improved. and anti-interference ability.
Patent Information
- Application Number
- CN202011439017.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-07
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2040-12-07
AI Technical Summary
When parsing table images, the existing technology is difficult to effectively handle interfering items such as folds, optical fibers, and seals. It also has poor parsing effect on non-straight table images and dense table images taken by mobile phones, and cannot effectively extract row and column information and merged cell information. .
A wired table image parsing method based on semantic segmentation is used to process the table image through semantic segmentation, obtain connected domains, calculate cell coordinate information, redraw the table, extract row and column information and merge cell information, and use OCR for text recognition to generate a visible Editable text form.
This method can accurately and efficiently parse table images, enhance anti-interference, reduce the need for manual analysis, reduce labor costs, and is suitable for general table images.
Smart Images

Figure CN112507876B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer processing technology, in particular to the field of image processing and natural language processing, and specifically to a method and device for analyzing wired table images based on semantic segmentation. Background Art
[0002] At present, deep learning is developing rapidly in the field of computer vision. It has completely surpassed the accuracy and efficiency of traditional methods, and has attracted widespread attention from the industry. Deep learning is a branch in the field of machine learning. It combines low-level features to form more abstract high-level representation attribute categories or features to discover distributed feature representations of data. The purpose of studying deep learning is to establish a neural network that simulates the human brain for analysis and learning. It imitates the mechanism of the human brain to interpret data such as images, sounds, and text. However, parsing table images refers to converting table images in table images into editable table text, and retaining the cell position information, row and column information, and merged cell information of the original table image. This process requires the use of table parsing technology.
[0003] In the existing technology, there are various methods for parsing table images, which are mainly divided into two categories: parsing table images based on projection algorithms and parsing table images based on text positioning. In the parsing of table images based on projection algorithms, it is found that the errors caused by interference items (folds, light, seals, etc.) are large, and the interference items cannot be removed well. In addition, for table images taken by mobile phones, since the table lines are not straight, the projection algorithm cannot be well applied to such table images. In the parsing of table images based on text positioning, effective table extraction cannot be performed for dense table images and images containing merged cells.
[0004] Therefore, a general, efficient, and accurate method for parsing table images is needed. Summary of the invention
[0005] The purpose of the present invention is to overcome the defects of the prior art and to solve the problem that the prior art methods cannot effectively parse general table images. A wired table image parsing method and device based on semantic segmentation are proposed.
[0006] The technical solution adopted by the present invention is as follows:
[0007] A method for parsing a wired table image based on semantic segmentation includes the following steps:
[0008] Perform semantic segmentation on table images;
[0009] Process the semantic segmentation result graph to obtain the connected domain;
[0010] Calculate cell coordinate information through connected domains;
[0011] Redraw the table image based on table line clustering using cell coordinate information;
[0012] Parse the redrawn table image to obtain row and column information as well as merged cell information;
[0013] Cut the cells of the original table image for text recognition;
[0014] Combine the text recognition results, row and column information, and merged cell information to generate an editable text table.
[0015] Furthermore, before the semantic segmentation process, the table image is preprocessed; the preprocessing includes gray-scaling the table image to generate a grayscale image of the table image.
[0016] Furthermore, the semantic segmentation process is performed using a U-Net network model to assign a label to each pixel in the image, that is, each pixel belongs to a table line or does not belong to a table line. The semantic segmentation process includes:
[0017] Perform Conv+Pooling downsampling and learn deep features through different degrees of convolution;
[0018] Use Deconv deconvolution upsampling to fuse with the previous low-level feature map.
[0019] Furthermore, the processing of the semantic segmentation result graph includes:
[0020] Binarize the semantic segmentation result map to obtain a binary image;
[0021] Perform image filtering on the binary image;
[0022] Perform morphological operations on the filtered image, including corrosion, expansion, opening, and closing operations;
[0023] Perform contour search and detection on the image after morphological operation to obtain the connected domain.
[0024] Furthermore, the calculating of the cell coordinate information through the connected domain includes:
[0025] Filter the connected areas and discard those with too small area and too short length;
[0026] For each remaining valid connected area, get the fitted minimum enclosing rectangle information and return the coordinate information of its four points ((x1, y1), (x2, y2), (x3, y3), (x4, y4)), which represent the upper left corner, upper right corner, lower right corner, and lower left corner respectively.
[0027] Furthermore, the redrawing of the table image based on table line clustering includes:
[0028] Create a white canvas the same size as the original image;
[0029] The cell coordinate points obtained by connected domain calculation are formed into two cell boundary lines, including an upper boundary line and a left boundary line, and two hash tables are created, one of which is a bidirectional dictionary of the upper boundary line and the cell, and the other is a bidirectional dictionary of the left boundary line and the cell;
[0030] Line clustering based on upper boundary line;
[0031] Cluster lines based on the right boundary line.
[0032] Furthermore, the parsing of the redrawn table includes:
[0033] Get the projection points of the table line on the x-axis and y-axis;
[0034] Project the table line on the x-axis and y-axis at points v1,…v m and h1…h n Generate two lists v_list: [1-1,v1+1,v2-1,v2+1…v m -1,v m +1] and h_list[h1-1,h1+1,h2-1,h2+1…h n -1,h n +1];
[0035] Loop through v_list and h_list, and judge ( i -1,h j -1),(v i +1,h j -1),(v i -1,h j +1),(v i +1,h j +1) Whether the small rectangle formed by these four points has horizontal and vertical lines, and based on this method, the row and column information and merged cell information are determined.
[0036] Furthermore, the text recognition of the cells of the cut original table image is performed by using an OCR recognition tool to recognize the cell image, thereby performing text recognition in the cell.
[0037] A wired table image parsing device based on semantic segmentation is an electronic device comprising a memory and a processor, wherein the memory stores a computer program, the computer program is configured to be executed by the processor, and the computer program includes instructions for executing the above method of the present invention.
[0038] Compared with the existing technology, the method of the present invention overcomes the defects of errors caused by interference items such as folds, optical fibers, and seals, enhances the versatility and anti-interference of parsing wired table images, can accurately and efficiently parse table images, has good results, does not require manual analysis, and reduces labor costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 A flow chart of a method for parsing a table image based on semantic segmentation in one embodiment;
[0040] Figure 2 is an original image in one embodiment;
[0041] Figure 3 A semantic segmentation map generated in one embodiment;
[0042] Figure 4 A connection graph generated based on a connected domain in one embodiment;
[0043] Figure 5 A layout diagram generated based on table line redrawing in one embodiment;
[0044] Figure 6 FIG. 4 is a diagram of a semantic segmentation network structure in one embodiment. DETAILED DESCRIPTION
[0045] In some of the processes described in the specification and claims of the present invention and the above figures, multiple operations appearing in a specific order are included, but it should be clearly understood that these operations may not be executed in the order in which they appear in this document or may be executed concurrently. The sequence numbers of the operations, such as S50, S60, etc., are only used to distinguish different operations, and the sequence numbers themselves do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed sequentially or in parallel.
[0046] In addition, if there are descriptions involving "first", "second", etc. in the embodiments of the present invention, the descriptions of "first", "second", etc. are only used for descriptive purposes and cannot be understood as indicating or suggesting their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.
[0047] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention is clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work belong to the protection content of the present invention.
[0048] See also Figure 1 , an embodiment of the present invention provides a method for parsing table images based on semantic segmentation, such as Figure 1 As shown, the specific steps include:
[0049] S00, input a table image, and preprocess the table image.
[0050] In an embodiment of the present invention, the table image may be a table photo collected by a camera device or a table image captured by screenshot, such as a table image captured in a PDF document, etc. The table image of the present invention is preprocessed to obtain a grayscale image.
[0051] The table image is grayed to generate a grayscale image. Figure 2 , Figure 2 A grayscale image generated in one embodiment.
[0052] S10, performing semantic segmentation processing on the preprocessed table image.
[0053] In the embodiment of the present invention, semantic segmentation training is performed by inputting multiple target table samples in advance to train a network capable of performing table semantic segmentation. Specifically, feature point extraction and feature point fusion are performed on the sample image, and finally a semantic segmentation network is output. The target sample includes at least a picture sample and the coordinates of the table lines marked.
[0054] Semantic segmentation is to understand images at the pixel level. Semantic segmentation is classification at the pixel level, and pixels belonging to the same category are classified into one category.
[0055] For table-type images, the present invention uses image segmentation technology to identify table frame line pixels, that is, uses deep learning methods to perform semantic segmentation on the table. The purpose of segmentation is to mark the table line part, and the marked categories are divided into two categories (two categories): table line and not table line. Image segmentation aims to assign a label to each pixel in the image, that is, each pixel belongs to the table line or does not belong to the table line.
[0056] The overall idea of the present invention is a semantic segmentation process based on deep network training, specifically, classifying pixels in the image through a U-Net convolutional neural network.
[0057] See also Figure 6 , Figure 6 It is based on the U-Net convolutional neural network. The semantic segmentation network used in the present invention is improved based on the U-Net convolutional neural network. Specifically, downsampling is performed first, and after different degrees of convolution, deep-level features are learned, and then upsampling (deconvolution) is performed to restore the original image size, and finally the feature map of the number of categories is output, such as our image segmentation task is two categories (yes or no). The entire U-Net network structure is similar to a big U letter: first, Conv+Pooling downsampling is performed; then Deconv deconvolution is used for upsampling, and it is fused with the previous low-level feature map; then upsampling again. U-Net performed a total of 4 upsamplings, and used skip connections in the same stage (stage), instead of directly performing supervision and loss back propagation on high-level semantic features, so that the feature map finally restored is guaranteed to integrate more low-level features, and feature maps of different sizes are also integrated, so that multi-scale prediction can be performed. At the same time, the 4 upsamplings also make the segmentation map restore edge information more refined, thereby obtaining the result map after segmenting the table line. Figure 3 The generated semantic segmentation map.
[0058] S20, inputting a semantic segmentation result graph, and processing the semantic segmentation result graph to obtain a connected domain. The processing of the semantic segmentation result graph in the present invention specifically includes the following steps:
[0059] Step 1: binarize the semantic segmentation result map to obtain a binary image.
[0060] Step 2: Perform image filtering on the binary image.
[0061] Image filtering is to suppress the noise of the target image while retaining the image details as much as possible. It is an indispensable operation in image preprocessing. The quality of its processing will directly affect the effectiveness and reliability of subsequent image processing and analysis.
[0062] Mean filtering is also a low-pass filter. The principle of mean filtering is to assign the average value in the field to the central element. A linear method is used to average the pixel values in the entire window range to achieve the effect of blurring and denoising the image.
[0063] The main application of the mean filter is to remove irrelevant details in the image. Irrelevant refers to the pixel area that is smaller than the filter template. Blur the picture to get a rough description of the object of interest, so the grayscale of smaller objects will be mixed with the background, and larger objects will become like spots and easy to detect. Therefore, the mean filter has the function of smoothing the image and filtering out noise.
[0064] Step 3: Perform morphological operations on the filtered image.
[0065] In image processing technology, some operations will change the morphology of the image, which are generally called morphological operations. Mathematical morphology is an image processing method based on set theory. It first appeared in the morphology and structure of biology. Morphological operations in image processing are used in image and processing operations (denoising, shape simplification), image enhancement (skeleton extraction, refinement, convex hull and object labeling), object background segmentation and object morphology quantification. Connect adjacent elements or separate independent elements to complete the reconnection of broken lines and the elimination of isolated noise points in the table segmentation diagram.
[0066] This step specifically includes the following 4 sub-steps:
[0067] B1. Perform corrosion operation on the image.
[0068] The erosion operation is to erode the edge of an object. The specific operation method is to take a rectangle with a width of m and a height of n as a template, and do the following processing for each pixel x in the image: pixel x is at the center of the template, and according to the size of the template, all other pixels covered by the template are traversed, and the value of pixel x is modified to the minimum value of all pixels. The result of this operation is that the protruding points on the periphery of the image will be eroded.
[0069] B2. Perform dilation operation on the image.
[0070] The dilation operation is to expand the outline of the image. The operation method is similar to the erosion operation, which is to use a rectangular template to traverse each pixel of the image. The difference is that the value of the modified pixel is not the smallest value among all pixels, but the largest value. The result of this operation will connect the protruding points on the periphery of the image and extend them outward.
[0071] B3. Open the picture.
[0072] The opening operation is to erode the image first and then dilate it. The templates used for erosion and dilation are the same size.
[0073] B4. Perform a closing operation on the image.
[0074] The closing operation is to dilate the image first and then erode it. The result of the closing operation is generally that many nearby blocks can be connected to form a connected domain without protrusions.
[0075] Step 4: Perform contour search and detection on the morphological operation image to obtain the connected domain, that is, each small table unit. Figure 4 A connected graph generated based on a connected domain in an embodiment. A connected graph refers to a cell surrounded by a complete border line to form a closed cell, thereby forming a complete wired table graph.
[0076] S30, calculating cell coordinate information through connected domain
[0077] The embodiment of the present invention provides a method for calculating the coordinate information of cells based on a connected domain. The contour of the table line is searched and detected to obtain the connected area, that is, each small table cell. The connected area is then filtered, and the areas that are too small or too short are discarded. For each remaining valid connected area, the fitted minimum enclosing rectangle information is obtained, and the coordinate information of its four points ((x1, y1), (x2, y2), (x3, y3), (x4, y4)) is returned. They represent the upper left corner, upper right corner, lower right corner, and lower left corner respectively.
[0078] S40. Redraw the table layout based on table line clustering. Figure 5 The layout diagram is generated based on the table line redrawing. The redrawing table layout has the following steps:
[0079] Step 1. Create a white canvas of the same size as the original image.
[0080] Step 2: Form two cell boundary lines (upper boundary line and left boundary line) through the cell coordinate points obtained in S30, and create two hash tables. One hash table is a two-way dictionary of the upper boundary line and the cell, called the upper boundary list; the other hash table is a two-way dictionary of the left boundary line and the cell, called the left boundary list.
[0081] Step 3: Cluster lines based on the upper boundary line.
[0082] This step specifically includes the following 8 sub-steps:
[0083] C1. Randomly select an upper boundary in the upper boundary list, delete the upper boundary from the upper boundary list, and record it as pos_line.
[0084] C2. Find the upper boundary adjacent to the right of the upper boundary pos_line.
[0085] C3, if C2 finds a right adjacent upper boundary, record it as cur_line, and search for a right adjacent upper boundary from cur_line to the right until no right adjacent upper boundary is found. Whenever a right adjacent upper boundary is found, cur_line is deleted from the upper boundary list.
[0086] C4. Find the upper boundary adjacent to the left of the upper boundary pos_line.
[0087] C5. If C4 finds a left-adjacent upper boundary, record it as cur_line, and search for a left-adjacent upper boundary from cur_line to the left until no left-adjacent upper boundary is found. Whenever a left-adjacent upper boundary is found, cur_line is deleted from the upper boundary list.
[0088] C6. Put the boundary lines clustered to the right and to the left by pos_line into the list lst.
[0089] C7. Put the list lst into the list lsts. If the upper boundary list is not empty, return to step C1; if the upper boundary is empty, return to step C8.
[0090] C8. Sort the lst list of the clustered upper boundary lsts list by x coordinate to obtain the first upper boundary S and the last upper boundary E. The first and last endpoints of the upper boundary S are ((sx0,sy0),(sx1,sy1)) and ((ex0,ey0),(ex1,ey1)) respectively. Draw a black straight line with endpoints (sx0,sy0) and (ex1,sy0) on the white canvas, and obtain the horizontal projection position sy0. Among them, sx0 represents the x-coordinate of the left endpoint of the upper boundary line of the leftmost cell in a row in the table, sy0 represents the y-coordinate of the left endpoint of the upper boundary line of the leftmost cell in a row in the table, sx1 represents the x-coordinate of the right endpoint of the upper boundary line of the leftmost cell in a row in the table, sy1 represents the y-coordinate of the right endpoint of the upper boundary line of the leftmost cell in a row in the table, ex0 represents the x-coordinate of the left endpoint of the upper boundary line of the rightmost cell in a row in the table, ey0 represents the y-coordinate of the left endpoint of the upper boundary line of the rightmost cell in a row in the table, ex1 represents the x-coordinate of the right endpoint of the upper boundary line of the rightmost cell in a row in the table, and ey1 represents the y-coordinate of the right endpoint of the upper boundary line of the rightmost cell in a row in the table.
[0091] Step 4: Cluster lines based on the right boundary line. The specific method is similar to step 3, and includes the following steps:
[0092] D1. Randomly select a left boundary in the left boundary list, delete the left boundary from the left boundary list, and record it as pos_line.
[0093] D2. Find the adjacent left boundary on the left boundary pos_line.
[0094] D3: If D2 finds an upper adjacent left boundary, record it as cur_line, and search upwards for an upper adjacent left boundary with cur_line until no upper adjacent left boundary is found. Whenever an upper adjacent left boundary is found, cur_line is deleted from the left boundary list.
[0095] D4. Find the left boundary adjacent to the left boundary pos_line.
[0096] D5. If D4 finds the lower adjacent left boundary, record it as cur_line, and search for the lower adjacent left boundary downward with cur_line until the lower adjacent left boundary is not found. Whenever a lower adjacent left boundary is found, cur_line is deleted from the left boundary list.
[0097] D6. Put the boundary lines obtained by clustering pos_line upward and downward into the list lst.
[0098] D7. Put the list lst into the list lsts. If the left boundary list is not empty, return to step D1; if the left boundary is empty, return to step D8.
[0099] D8. Sort the lst list of the clustered upper boundary lsts list by y coordinates to obtain the first left boundary S and the last left boundary E. The first and last endpoints of the left boundary S are ((sx0,sy0), (sx1,sy1)) and ((ex0,ey0), (ex1,ey1)) respectively. Draw a black straight line with endpoints (sx0,sy0) and (sx0,ey1) on the white canvas, and obtain the vertical projection position sx0. S50. Analyze the redrawn table image to obtain row and column information and merged cell information.
[0100] The redrawn table only has table lines without any interference items, and the table lines are all straight. Based on step three and step four in S40, the method obtains the projection points of the table lines on the x-axis and y-axis. A network block diagram is made based on the projection points, and the row and column information of the cells and the merged cell information are obtained by projection. The present invention has the following steps to parse the redrawn table:
[0101] Step 1: Project the table line on the x-axis and y-axis at points v1,…v m and h1…h n Generate two lists v_list: [c1-1,v1+1,v2-1,v2+1…v m -1,v m +1] and h_list[h1-1,h1+1,h2-1,h2+1…h n -1,h n +1]
[0102] Step 2: Loop through v_list and h_list to determine (v i -1,h j -1),(v i +1,h j -1),(v i -1,h j +1),(v i +1,h j +1) Whether the small rectangle formed by these four points has horizontal and vertical lines, and based on this method, the row and column information and merged cell information are determined.
[0103] S60, cutting cells of the original table for text recognition.
[0104] In the embodiment of the present invention, an OCR recognition tool is used to recognize the cut cell image, thereby performing text recognition.
[0105] S70, generating an editable text table by combining the text recognition result with the row and column information of the table analysis and the merged cell information.
[0106] Since then, a method for parsing tables based on semantic segmentation has been implemented.
[0107] Based on the same inventive concept, another embodiment of the present invention provides a wired table image parsing device based on semantic segmentation, which is an electronic device (computer, server, smart phone, etc.), which includes a memory and a processor, the memory stores a computer program, the computer program is configured to be executed by the processor, and the computer program includes instructions for executing each step in the method of the present invention.
[0108] Based on the same inventive concept, another embodiment of the present invention provides a computer-readable storage medium (such as ROM / RAM, disk, CD), which stores a computer program. When the computer program is executed by a computer, it implements the various steps of the method of the present invention.
[0109] Although the embodiments of the present invention are described in conjunction with the accompanying drawings, it is apparent to those skilled in the art that several improvements may be made without departing from the principles of the present invention, and these improvements should also be considered to fall within the protection scope of the present invention.
Claims
1. A wired table image parsing method based on semantic segmentation, characterized in that: The steps include: Perform semantic segmentation on table images; Process the semantic segmentation result graph to obtain the connected domain; Calculate cell coordinate information through connected domains; Redraw the table image based on table line clustering using cell coordinate information; Parse the redrawn table image to obtain row and column information as well as merged cell information; Cut the cells of the original table image for text recognition; Combine the text recognition results, row and column information, and merged cell information to generate an editable text table; The semantic segmentation process is performed using a U-Net network model to assign a label to each pixel in the image, that is, each pixel belongs to a table line or does not belong to a table line. The semantic segmentation process includes: performing Conv+Pooling downsampling, and learning deep features through different degrees of convolution; using Deconv deconvolution upsampling to fuse with the previous low-level feature map; the table image is redrawn based on table line clustering, including: creating a white canvas with the same size as the original image; forming two cell boundary lines, including an upper boundary line and a left boundary line, by calculating the cell coordinate points obtained through the connected domain, and creating two hash tables, one of which is a bidirectional dictionary of the upper boundary line and the cell, and the other is a bidirectional dictionary of the left boundary line and the cell; performing line clustering based on the upper boundary line; performing line clustering based on the right boundary line; obtaining the first and last endpoints of each boundary based on clustering, and drawing black straight lines with the endpoints on the white canvas.
2. The method according to claim 1, characterized in that: Before the semantic segmentation process, the table image is preprocessed; the preprocessing includes grayscale processing of the table image to generate a grayscale image of the table image.
3. The method according to claim 1, characterized in that The processing of the semantic segmentation result graph includes: Binarize the semantic segmentation result map to obtain a binary image; Perform image filtering on the binary image; Perform morphological operations on the filtered image, including corrosion, expansion, opening, and closing operations; Perform contour search and detection on the image after morphological operation to obtain the connected domain.
4. The method according to claim 1, characterized in that: The calculating of the cell coordinate information through the connected domain includes: Filter the connected areas and discard those with too small area and too short length; For each remaining valid connected area, get the fitted minimum enclosing rectangle information and return the coordinate information of its four points ((x1, y1), (x2, y2), (x3, y3), (x4, y4)), which represent the upper left corner, upper right corner, lower right corner, and lower left corner respectively.
5. The method according to claim 1, characterized in that The parsing of the redrawn table includes: Get the projection points of the table line on the x-axis and y-axis; Project the table line on the x-axis and y-axis at points v1,…v m and h1…h n Generate two lists v_list: [v1-1,v1+1,v2-1,v2+1…v m -1,v m +1] and h_list[h1-1,h1+1,h2-1,h2+1…h n -1,h n +1]; Loop through v_list and h_list, and judge (v i -1,h j -1),(v i +1,h j -1),(v i -1,h j +1),(v i +1,h j +1) Whether the small rectangle formed by these four points has horizontal and vertical lines, and based on this method, the row and column information and merged cell information are determined.
6. The method according to claim 1, characterized in that The text recognition of the cells of the cut original table image is to use an OCR recognition tool to recognize the cell image, thereby performing text recognition in the cell.
7. A wired table image parsing device based on semantic segmentation, characterized in that: The invention comprises a memory and a processor, wherein the memory stores a computer program, the computer program is configured to be executed by the processor, and the computer program comprises instructions for executing the method according to any one of claims 1 to 6.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a computer, the method according to any one of claims 1 to 6 is implemented.
