A method for automatically extracting spatial elements based on character recognition and image processing
Through the method based on character recognition and image processing, spatial elements are automatically extracted, which solves the problems of high time and labor costs and low accuracy in traditional methods, and achieves efficient and accurate spatial element extraction.
Patent Information
- Application Number
- CN202310983197.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-07
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2043-08-07
AI Technical Summary
The prior art has problems such as high time and labor costs, low accuracy and poor model universality in spatial factor extraction, especially when processing maps on a large scale.
Using a method based on character recognition and image processing, vector skeleton lines are extracted through Kalman filtering, edge detection, refinement and binarization, combining character recognition and nearest neighbor coordinate matching of machine learning to achieve automated geo-registration and spatial reference information assignment.
It realizes efficient and automated spatial factor extraction, reduces manual intervention errors, improves accuracy and adaptability, and reduces time and labor costs.
Smart Images

Figure FDA0005461143200000011 
Figure FDA0005461143200000012 
Figure FDA0005461143200000013
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of map data processing, and more specifically, to an automatic extraction method for spatial elements based on character recognition and image processing. Background Art
[0002] Spatial element extraction is to convert the spatial elements represented in the form of raster data in a map into vector data and assign spatial reference information, so as to be easier to process and analyze, make the elements on the map more accurate and clear, and at the same time reduce the storage space, and has extremely wide applications.
[0003] The traditional method of spatial element extraction is to first load the map data to be processed in GIS, define its geographic reference coordinate system, use the georeferencing tool to add control points to perform correction, and then use the vectorization tool to convert the geographic elements such as lines, polygons, and points in the map into vector data by manually drawing vector elements or using auxiliary tools. Finally, necessary editing and cleaning of the vector data are performed through operations such as fixing incorrect topological errors, deleting overlapping elements, and trimming and merging lines to ensure the quality and accuracy of the data. In recent years, there have been supervised classification methods based on machine learning, such as SVM, RF, etc., which achieve automatic extraction of spatial data element vectorization by training a sample set to invert the model.
[0004] The traditional spatial element extraction has the following problems: For the GIS method, first, the time and labor costs are high. Manual georeferencing and data vectorization consume a large amount of time and labor costs because a large number of control point identifications and element break point drawings are required, especially when dealing with large-scale maps. Secondly, due to possible deviations in manual matching during georeferencing and the occurrence of omissions or errors during the vectorization process, it will cause a reduction in the accuracy of spatial reference information assignment and data vector conversion. For the method based on machine learning supervised classification, a large number of training samples are required to ensure the accuracy of the model, and a large amount of time is also required during the training sample process, and the automation of spatial reference information assignment cannot be achieved, and the universality of the model will also decrease due to the large differences in different styles between the original maps. Summary of the Invention
[0005] The object of the present invention is to overcome the deficiencies of the above-mentioned existing technologies, and provide an automatic extraction method for spatial elements based on character recognition and image processing; mainly solve the problem that the existing spatial elements cannot be automatically extracted.
[0006] The technical solution provided by the present invention is: an automatic extraction method for spatial elements based on character recognition and image processing, which is characterized in that it includes the following steps:
[0007] S1: Read the initial map image and perform Kalman filtering on it;
[0008] S2: Solve the gradient of the new image after Kalman filtering, perform edge detection on it using the Roberts operator, and obtain the edge image;
[0009] S3: Obtain the between-class variance g through Equations 1 - 3, take its maximum value as the adaptive threshold T, reassign the pixels in the edge image with values higher than T to 1, and reassign the pixels lower than T to 0 to obtain the binary image;
[0010] Equation 1:
[0011] Equation 2:
[0012] Equation 3: g = ω0ω1(μ0 - μ1) 2 ,
[0013] where M is the number of rows of the edge image, N is the number of columns of the edge image, N0 and N1 are the numbers of pixels less than or equal to and greater than the traversal parameter in the edge image respectively, ω0 and ω1 are the proportions of N0 and N1 in the total number of pixels respectively, μ0 and μ1 are the average values of pixels less than or equal to and greater than the traversal parameter respectively, and g is the between-class variance;
[0014] S4: Thin the binary image and extract the vector skeleton line;
[0015] S5: Identify and extract the pixel coordinate values of the marked grid lines in the initial map image, and record them as v1, v2,..., v n , calculate the center point coordinates (X n , Y n ) in the image space where the extracted value is located through Equation 4, and represent the pixel coordinate values of the marked grid lines and their corresponding center point coordinates by C n = {v n , (x n , y n )};
[0016] Equation 4:
[0017] where x n , y n are the horizontal and vertical image space coordinate values of the center point, x max , y max are the maximum horizontal and vertical coordinates of the image space range where this value is located, and x min , y min are the minimum horizontal and vertical coordinates of the image space range where this value is located;
[0018] S6: Traverse the binary image in the order from left to right and top to bottom with a 5*5 window matrix. When encountering a pixel with a value of 1, record its position X i m =(x i m ,y i m ), until the entire traversal is completed. Represent all the recorded horizontal grid line pixels as X = [X1, X2, … X m ; Similarly, represent all the obtained vertical grid line pixels as Y = [Y1, Y2, … Y n ;
[0019] S7: Take the first coordinate point X m 、Y n of each grid line X 1 m (Y 1 n ) and the last coordinate point X i m [[ID=:29]]、Y i n as the starting point and the ending point. Take the starting point or the ending point as point A, and cyclically take all the coordinate center points as point B. Calculate the distance between the two points, and use the coordinate value corresponding to the coordinate center point with the closest distance as the scale value of this grid line. Add the attribute value C m 、Y n representing the scale value to the grid lines X m 、C n ;
[0020] S8: Take all the horizontal grid lines X n as the input layer, and all the vertical grid lines Y n as the overlay layer. Import them into the geospatial analysis software for intersection overlay analysis to obtain the grid node pixels as control points, and assign the scale values of the horizontal and vertical grid lines as the georeference coordinate attributes;
[0021] S9: Substitute the image space coordinates and georeference coordinate attributes of the control points into Equation 5-6 to fit the georegistration model by trend surface, and at the same time substitute all the pixels without spatial reference information into this model to achieve the georegistration of the entire image;
[0022] Equation 5: x′ = Ax 2 +By 2 +Cx+Dy+E,
[0023] Equation 6: y′ = Fy 2 +Gx 2 +Hy+Ix+J,
[0024] Among them, x and y are the horizontal and vertical coordinates of the initial image space respectively, x' and y' are the horizontal and vertical coordinates of the transformation respectively, and A, B, C, D, E, F, G, H, I, and J are transformation coefficients;
[0025] S10: In the binary image, reassign the grid line pixels to 0, and keep the other pixels unchanged to obtain a re-assigned image;
[0026] S11: Traverse the re-assigned image with a 5*5 window matrix from left to right and from top to bottom, record the pixels with a value of 1, pause when there are no pixels with a value of 1 in the window matrix, pack all the recorded pixels into a feature pixel group, and then repeat this process until the traversal ends;
[0027] S12: Calculate the total number of pixels in the feature pixel group. If it is 1, its geometric type is a point. If it is not 1, solve the discrimination threshold S according to Equation 7-8. Those less than S are lines, and those greater than S are surfaces;
[0028] Equation 7:
[0029] Equation 8:
[0030] Where D mht is the average Manhattan distance, k is the total number of elements in the feature pixel group, S is the discrimination threshold, e is the natural logarithm base, and μ and σ are the average and standard deviation of the distances between the inflection points in the feature pixel group respectively;
[0031] S13: According to the GeoJSON data format standard, create data files and write the geographic reference coordinates representing the feature inflection points into them respectively according to the geometric types of points, lines, and surfaces, and finally obtain a data file in GeoJSON format containing the elements in the initial map image space.
[0032] Furthermore, the Kalman filtering process in the S1 step includes the following specific steps:
[0033] 1) Determine the noise state equation and the observation equation;
[0034] 2) Input each parameter: horizontal coordinate, vertical coordinate, process noise variance, observation noise variance, initial value of the filtering vector, observation state variance at any time;
[0035] 3) Calculate the coefficients of the prediction equation, and finally implement the filtering through the difference equation.
[0036] Furthermore, the extraction of the vector skeleton line in the S4 step includes the following specific steps:
[0037] 1) Set a 3*3 traversal matrix and perform iterative operations on each pixel starting from the upper left corner of the binary image from left to right and from top to bottom;
[0038] 2) In each iteration operation, following the principle that internal points cannot be deleted and the start and end points cannot be deleted, the outermost layer of pixels of the binary image is peeled off layer by layer to obtain the final vector skeleton line.
[0039] Advantages of the present invention:
[0040] 1. Because a batch of efficient image processing methods (including filtering, edge detection, thinning, and binarization) are adopted, the noise brought by external problems such as ambient light and clutter interference to the scanned map can be filtered out, and the optimal global edge detection threshold with the best accuracy is determined through a large number of experiments to reduce invalid edges. Compared with the traditional supervised classification method based on machine learning, the consistency of color space attributes among different original maps is achieved, and thus it has a wider adaptability without being limited to a specific model;
[0041] 2. By intelligent character recognition and nearest neighbor coordinate matching, the control points are selected and the target coordinates are assigned, avoiding the wrong processing caused by manual intervention. At the same time, using the second-order polynomial as the permanent transformation model of the spatial reference information can take into account the random errors that are prone to occur in the low-order polynomial and the extrapolation errors that are prone to occur in the higher-order polynomial, thus avoiding the errors brought by the traditional method due to manual intervention;
[0042] 3. By adopting the image processing method based on machine learning character recognition, a large number of control points can be obtained according to the intersection points of all grid lines and the coordinate value characters of the nearest neighbors in the scanned map to add the geographic reference information of the original image and extract the element data of point, line, and surface geometries, avoiding a large amount of repetitive labor, and thus achieving a great saving in human cost and time cost compared with the traditional method. Specific implementation mode
[0043] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below. It should be understood that the specific implementation modes described here are only used to explain the present invention and are not used to limit the present invention.
[0044] A method for automatically extracting spatial elements based on character recognition and image processing, comprising the following steps:
[0045] S1: Read the initial map image. Since the initial map image is generally a scanned map and is affected by the scanner, scanning visit, and scanning light conditions to form noise in the scanned image, in order to weaken the interference of the noise on the accuracy, it can be completed through Kalman filtering; Read the initial map image into Matlab and perform Kalman filtering to reduce the image noise and improve the steepness of the image edge;
[0046] The specific steps of the Kalman filtering process are:
[0047] 1) Determine the noise state equation and the observation equation;
[0048] 2) Input each parameter: abscissa, ordinate, process noise variance, observation noise variance, initial value of the filtering vector, observation state variance at any moment;
[0049] 3) Obtain the coefficients of the prediction equation, and finally realize filtering through the difference equation;
[0050] S2: Edge detection of the initial map image can strengthen its grid lines representing map coordinate information and the break points constituting spatial elements; The Roberts operator is sensitive to noise and cannot suppress noise, while this drawback can be overcome through Kalman filtering processing; Solve the gradient of the new image after Kalman filtering processing, determine the two diagonal templates of the Roberts operator, and then perform convolution operations pixel by pixel in the entire image to obtain the edge image;
[0051] S3: Binarization of the edge image can significantly improve the efficiency of image processing; Since the steepness of the edges of different images is different, it is necessary to adaptively adjust the threshold according to the characteristics of the image itself; Obtain the resolution of the edge image and the total number of statistical pixels and calculate the average value. Substitute the above parameters into Equation 1 - 3 with the traversal parameter within the range of 0 - 255 to obtain the between-class variance g. Sort the between-class variances g under different traversal parameters, and use its maximum value as the adaptive threshold T. Reclassify the pixels in the edge image. Pixels with values higher than T are reassigned to 1, and pixels lower than T are reassigned to 0 to obtain the binary image;
[0052] Equation 1:
[0053] Equation 2:
[0054] Equation 3: g = ω0ω1(μ0 - μ1) 2
[0055] Among them, M is the number of rows of the edge image, N is the number of columns of the edge image, N0 and N1 are the numbers of pixels less than or equal to and greater than the traversal parameter in the edge image respectively, ω0 and ω1 are the proportions of N0 and N1 in the total number of pixels respectively, μ0 and μ1 are the average values of pixels less than or equal to and greater than the traversal parameter respectively, and g is the between-class variance;
[0056] S4: In the unthinned binary image, there are problems such as multiple pixels corresponding to a single point and overly thick line pixels, and vector data format conversion cannot be performed. Thinning can solve this problem; Thin the binary image and extract the vector skeleton line as the basis for subsequent georegistration and feature extraction. The specific steps are as follows:
[0057] 1) Set up a 3*3 traversal matrix and perform iterative operations on each pixel from left to right and top to bottom starting from the upper left corner of the binary image;
[0058] 2) Each iterative operation follows the principle that internal points cannot be deleted and the head and tail endpoints cannot be deleted, and gradually strip the outermost layer of pixels of the binary image to obtain the final vector skeleton line;
[0059] S5: The following operations are performed in the Python environment. Extract the numerical values of the marked grid line coordinates in the initial map image through the character recognition function in the Python site package and record them as v1, v2,..., v n ; Extract the maximum and minimum values in the horizontal and vertical directions of the image space where the values are located, and calculate the center point coordinates (X n , Y n ) of the extracted value through Equation 4. Represent the pixel coordinate values of the marked grid line and their corresponding center point coordinates through C n = {v n , (x n , y n )}:
[0060] Equation 4:
[0061] where x n , y n are the horizontal and vertical image space coordinate values of the center point, x max , y max are the maximum horizontal and vertical coordinates of the image space range where the value is located, and x min , y min are the minimum horizontal and vertical coordinates of the image space range where the value is located;
[0062] S6: Traverse the binary image in the order from left to right and top to bottom with a 5*5 window matrix. When encountering a pixel with a value of 1, record its position X i m = (x i m , y i m ), until the values of all pixels in the window matrix are 0. Combine all the recorded pixels into X m = [X1, X2,..., X m ; Repeat this process until the traversal ends; Calculate the length of each horizontal grid line, generate a histogram based on the length, delete the horizontal grid lines in the top 20%, and combine the remaining horizontal grid lines into the horizontal grid X = [X1, X2,...X m ; Similarly, obtain the vertical grid Y = [Y1, Y2,..., Y n ;
[0063] S7: The grid line values extracted by combining the grid lines and characters are given the true geospatial reference information of the grid lines. Taking the first coordinate points X m and Y n of each grid line as the starting point and the last coordinate points X 1 m (Y 1 n ) as the ending point, taking the starting point or the ending point as point A, and cyclically taking all the coordinate center points as point B, calculate the distance between the two points. Take the coordinate value corresponding to the coordinate center point with the closest distance as the scale value of this grid line. Add the attribute values C i m and Y i n representing the scale value for the grid lines X m and Y n ; m and C n ;
[0064] S8: The intersection points of the horizontal and vertical grid lines are the pixel points with geospatial reference information in the initial map image. Its longitude is the value of the horizontal grid line, and its latitude is the value of the vertical grid line. Taking all the horizontal grid lines X n as the input layer and all the vertical grid lines Y n as the overlay layer, import them into the geospatial analysis software for intersection overlay analysis to obtain the grid node pixels as control points, and assign the scale values of the horizontal and vertical grid lines as the georeference coordinate attributes;
[0065] S9: Substitute the image space coordinates and georeference coordinate attributes of the control points into Equation 5-6 for trend surface fitting to obtain the georegistration model. At the same time, substitute all the pixels without spatial reference information into this model to assign spatial reference information to each pixel, realizing the georegistration of the initial map image;
[0066] Equation 5: x′ = Ax 2 + By 2 + Cx + Dy + E
[0067] Equation 6: y′ = Fy 2 + Gx 2 + Hy + Ix + J
[0068] where x and y are the horizontal and vertical coordinates of the initial image space respectively, x′ and y′ are the transformed horizontal and vertical coordinates respectively, and A, B, C, D, E, F, G, H, I, J are transformation coefficients;
[0069] S10: Delete the grid lines in the binary image, and the remaining pixels represent the break points of the spatial features. Reassign the grid line pixels to 0, and keep the other pixels unchanged to obtain the re-assigned image;
[0070] S11: Traverse the re-assigned image from left to right and top to bottom with a 5*5 window matrix, record the pixels with a value of 1, and pause when there are no pixels with a value of 1 in the window matrix. At this time, a spatial feature is obtained, and then repeat this process until the traversal ends to obtain spatial features of three types: points, lines, and polygons.
[0071] S12: Classify the obtained spatial features, calculate the total number of pixels in the feature pixel group. Since it has been thinned, for the feature pixel group with a total number of pixels of 1, determine its geometric type as a point, and the rest are spatial features of line geometric type or polygon geometric type. Due to the different spatial aggregations of lines and polygons, the points between the line breakpoints show the characteristics of looseness and a large aspect ratio, so the Manhattan distance between each breakpoint is small, while the breakpoints of the polygon form a closed loop and are relatively uniform, so the Manhattan distance is large. It can be segmented by the Manhattan distance between each breakpoint, and the discrimination threshold S is solved according to Equation 7-8. Those less than S are line spatial features, and those greater than S are polygon spatial features.
[0072] Equation 7:
[0073] Equation 8:
[0074] where D mht is the average Manhattan distance, k is the total number of elements in the feature pixel group, S is the discrimination threshold, e is the natural logarithm base, and μ and σ are the average and standard deviation of the distances between each breakpoint in the feature pixel group, respectively.
[0075] where D mht is the average Manhattan distance, k is the total number of elements in the feature pixel group, S is the discrimination threshold, e is the natural logarithm base, and μ and σ are the average and standard deviation of the distances between each breakpoint in the feature pixel group, respectively.
[0076] S13: Create a new json file and open it with the VisualStudioCode editor. According to the GeoJSON data format standard, write the geographical reference coordinates representing the feature breakpoints into it according to the point, line, and polygon geometric types respectively. The coordinate attributes are two-dimensional array, three-dimensional array, and four-dimensional array respectively, and save it as a geojson format. Finally, obtain the data files of the spatial features of the point, line, and polygon geometric types in the initial map image.
[0077] It should be understood that the technical features not elaborated in detail in this specification all belong to the prior art. Although the embodiments of the present invention have been described above in conjunction with the accompanying drawings, the present invention is not limited to the above specific embodiments. The above specific embodiments are merely illustrative and not restrictive. Those of ordinary skill in the art can, under the inspiration of the present invention and without departing from the spirit of the present invention and the scope protected by the claims, make more forms, and all of these fall within the protection scope of the present invention.
Claims
1. An automatic extraction method for spatial elements based on character recognition and image processing, characterized in that, It includes the following steps: S1: Read the initial map image and perform Kalman filtering on it; S2: Solve the gradient of the new image after Kalman filtering, and use the Roberts operator to perform edge detection on it to obtain an edge image; S3: Obtain the between-class variance g through Equation 1-3, take its maximum value as the adaptive threshold T, reassign the pixels with values higher than T in the edge image to 1, and reassign the pixels with values lower than T to 0 to obtain a binary image; Formula 1: Formula 2: Equation 3: g = ω0ω1(μ0 - μ1) 2 , Among them, M is the number of rows of the edge image, N is the number of columns of the edge image, N0 and N1 are the numbers of pixels less than or equal to and greater than the traversal parameter in the edge image respectively, ω0 and ω1 are the proportions of N0 and N1 in the total number of pixels respectively, μ0 and μ1 are the average values of the pixels less than or equal to and greater than the traversal parameter respectively, and g is the between-class variance; S4: Thin the binary image and extract the vector skeleton line; S5: Identify and extract the pixel coordinate values of the marked grid lines in the initial map image, and record them as v1, v2, …, v n , and calculate the center point coordinates (X n , Y n ) in the image space of the extracted value through Equation 4. Represent the pixel coordinate values of the marked grid lines and their corresponding center point coordinates by C n = {v n , (x n , y n )}: Formula 4: where x n and y n are the horizontal and vertical image space coordinate values of the center point, x max and y max are the maximum horizontal and vertical coordinate values of the image space range where the value is located, x min and y min are the minimum horizontal and vertical coordinate values of the image space range where the value is located; S6: Traverse the binary image in the order from left to right and from top to bottom with a 5*5 window matrix. When encountering a pixel with a value of 1, record its position X i m =(x i m ,y i m ), until the entire traversal is completed. Represent all the recorded horizontal grid line pixels as X = [X1, X2, … X m ; Similarly, represent all the obtained vertical grid line pixels as Y = [Y1, Y2, … Y n ; S7: Using the first coordinate points X m and Y n of each grid line, with the starting point being the first coordinate point X 1 m (Y 1 n ) and the ending point being the last coordinate point X i m and Y i n , taking the starting point or the ending point as point A, and cyclically taking all the coordinate center points as point B, calculate the distance between the two points. Use the coordinate value corresponding to the coordinate center point with the shortest distance as the marking value of this grid line. Add the attribute values C m and C n representing the marking values to the grid lines X m and Y n ; S8: Using all the horizontal grid lines X m as the input layer, and all the vertical grid lines Y n as the overlay layer, import them together into the geospatial analysis software for intersection overlay analysis to obtain the grid node pixels as control points, and assign the scale values of the horizontal and vertical grid lines to them as the georeference coordinate attributes; S9: Substitute the image space coordinates and georeference coordinate attributes of the control points into Equation 5-6 to fit the georegistration model by trend surface, and at the same time substitute all pixels without spatial reference information into this model to achieve the georegistration of the entire image; Formula 5: x ′ = Ax 2 + By 2 + Cx + Dy + E, Equation 6: y ′ = Fy 2 + Gx 2 + Hy + Ix + J, Among them, x and y are the horizontal and vertical coordinates of the initial image space respectively, x' and y' are the transformed horizontal and vertical coordinates respectively, and A, B, C, D, E, F, G, H, I, J are transformation coefficients; S10: In the binary image, reassign the grid line pixels to 0, and keep the other pixels unchanged to obtain a re-assigned image; S11: Traverse the re-assigned image with a 5*5 window matrix from left to right and from top to bottom, record the pixels with a value of 1, pause when there are no pixels with a value of 1 in the window matrix, pack all the recorded pixels into a feature pixel group, and then repeat this process until the traversal ends; S12: Calculate the total number of pixels in the feature pixel group. If it is 1, its geometric type is a point. If it is not 1, solve the discrimination threshold S according to Equation 7-8. Those less than S are lines, and those greater than S are surfaces; Formula 7: Formula 8: where D mht is the average Manhattan distance, k is the total number of elements in the feature image group, S is the discrimination threshold, e is the natural base, and μ and σ are the average value and standard deviation of the distances between the inflection points within the feature image group, respectively; S13: According to the GeoJSON data format standard, create data files respectively according to the geometric types of points, lines, and surfaces, and write the georeference coordinates representing the feature breakpoints into them. Finally, obtain a data file in GeoJSON format containing the spatial features of the initial map image.
2. The automatic extraction method of spatial elements based on character recognition and image processing according to claim 1, characterized in that The Kalman filtering process in step S1 includes the following specific steps: 1) Determine the noise state equation and observation equation; 2) Input each parameter: horizontal coordinate, vertical coordinate, process noise variance, observation noise variance, initial value of the filtering vector, observation state variance at any time; 3) Calculate the coefficients of the prediction equation, and finally implement filtering through the difference equation.
3. A method for automatically extracting spatial elements based on character recognition and image processing according to claim 1, characterized in that, The extraction of the vector skeleton line in step S4 includes the following specific steps: 1) Set a 3*3 traversal matrix and perform iterative operations on each pixel from the upper left corner of the binary image from left to right and from top to bottom; 2) Each iterative operation follows the principle that internal points cannot be deleted and the head and tail endpoints cannot be deleted, and gradually strip the outermost layer of pixels of the binary image to obtain the final vector skeleton line.
Citation Information
Patent Citations
Map image thinning and linear tracking method based on bit arithmetic
CN101520898A
Method and system for vector-raster overlay analysis of ground surface image area based on edge clipping
US20200342655A1