Image recognition-based data extraction method, system and device
By digitally processing the spatial distribution map of rainfall using image recognition technology, the color values and numerical relationships of the legend strips are extracted, solving the problems of scattered rainfall data storage and difficulty in acquisition, and realizing convenient and accurate data extraction and hydrological modeling applications.
Patent Information
- Application Number
- CN202311853303.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-28
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2043-12-28
AI Technical Summary
In existing technologies, the spatial distribution of rainfall data is characterized by scattered storage media, making it difficult to obtain. Historical rainfall data is also difficult to obtain accurately, which affects hydrological analysis and forecasting.
An image recognition-based method is used to digitize the spatial distribution map of rainfall, extract the color values of the legend strips and their corresponding values, establish a functional relationship between the color values and the rainfall values, calculate the rainfall value for each pixel and grid, and obtain the distribution data.
It enables convenient and accurate extraction of rainfall data from literature or reports, avoids the tedious work of collecting and entering station data, increases the amount of usable data, and improves the practicality of hydrological modeling data applications.
Smart Images

Figure CN117854093B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of hydrological analysis technology, and in particular to a data extraction method, system, and apparatus based on image recognition. Background Technology
[0002] Rainfall data and its spatial distribution form the basis for watershed runoff simulation and water resource assessment. Typically, this data can be obtained from observational datasets released by meteorological or water resources departments at rainfall monitoring stations.
[0003] However, currently available rainfall measurement datasets are limited, mainly consisting of data from recent days or months, making historical rainfall observation data difficult to obtain. Historical rainfall data is typically stored in various research reports and literature as spatial distribution maps, showing the spatial distribution characteristics of rainfall at a certain moment, but not providing numerical values at specific locations, resulting in a waste of rainfall information in the literature reports. Users also find it difficult to directly obtain intuitive and effective data from rainfall data for analysis and prediction. Summary of the Invention
[0004] The present invention provides a data extraction method, system, and apparatus based on image recognition, which solves the problems of scattered storage media and difficulty in obtaining data on the spatial distribution of rainfall in the background art. It can conveniently extract data directly from spatial distribution images in literature or reports with high accuracy.
[0005] In a first aspect, the present invention discloses a data extraction method based on image recognition, the method comprising the following steps:
[0006] Obtain a spatial distribution map of rainfall, divide the spatial distribution map of rainfall into map images and legend images, and preprocess the map images and legend images;
[0007] The map image is then processed to remove the background.
[0008] Extract the color values of the legend stripes in the legend image and their corresponding rainfall values, and establish a functional relationship between the color values and the rainfall values;
[0009] Calculate the rainfall value for each pixel and grid in the spatial distribution map of rainfall, and integrate them to obtain the rainfall distribution data.
[0010] In some implementations, the color values of the legend bars in the legend image and their corresponding rainfall values are extracted, and a functional relationship between the color values and rainfall values is established, including:
[0011] Calculate the grayscale value of the starting point, the starting point rainfall value, the ending point grayscale value, and the ending point rainfall in the legend strip in the legend image;
[0012] Determine the sampling points for grayscale values in the legend strips. Use linear interpolation to calculate the rainfall values at the sampling points based on their positions in the legend strips and the rainfall values at the start and end points of the legend.
[0013] By fitting a linear function to the grayscale values and rainfall values, the functional relationship between the grayscale values and rainfall values in the legend image is obtained.
[0014] In some embodiments, after preprocessing the map image and legend image, the method further includes:
[0015] The map image is converted into a grayscale image to generate a first digital matrix; the first digital matrix is used for background removal processing.
[0016] The legend image is converted into a grayscale image to generate a second digital matrix; the second digital matrix is used to extract color values and rainfall values.
[0017] The numerical values of the elements in the first and second digital matrices are equal to the grayscale values of each pixel in the grayscale image.
[0018] In some implementations, background removal processing of the map image includes:
[0019] Randomly select several reference points in the background of the map image, and obtain the average gray value of the reference points as the background gray value reference.
[0020] Identify the first and second mutation points in each row of the first digital matrix to obtain the start and end points of the map boundary; the first and second mutation points are points in the map image where the change in the average value of all pixels after that point and the background grayscale reference value is greater than a threshold.
[0021] The gray values of all elements before the first mutation point and all elements after the second mutation point in each row of the first digital matrix are assigned to -1 to generate the first digital submatrix.
[0022] Restore the first digital submatrix to a grayscale image to complete the background removal process.
[0023] In some implementations, calculating the rainfall value for each pixel and grid in the spatial distribution map of rainfall includes:
[0024] Iterate through each element of the first digital submatrix, and calculate the rainfall matrix based on the functional relationship between the grayscale value and the rainfall value to obtain the rainfall value for each pixel.
[0025] The rainfall values in the rainfall matrix are statistically analyzed according to a grid of a certain spatial size to obtain the rainfall value for each grid.
[0026] In some implementations, rainfall values in the rainfall matrix are statistically analyzed according to a grid of a certain spatial size to obtain the rainfall value for each grid, including:
[0027] Determine the spatial grid and calculate the number of rows and columns of pixels contained within the spatial grid;
[0028] A rectangular sliding window is constructed, which slides on the rainfall matrix in a preset direction. The average rainfall value within the rectangular sliding window is calculated to obtain the rainfall value for each grid.
[0029] In some implementations, rainfall distribution data is integrated, including
[0030] Obtain the coordinates of preset points in the map image and calculate the longitude and latitude span of the rainfall map;
[0031] Rainfall distribution data is constructed by matching the rainfall values of each grid with the corresponding longitude and latitude coordinates; the rainfall distribution data includes the rainfall matrix of the grid, the longitude and latitude of the grid.
[0032] In some implementations, the preprocessing includes segmenting the spatial distribution map of rainfall, determining map boundaries, and control points.
[0033] Secondly, the present invention provides a data extraction system, comprising:
[0034] The image processing module is used to acquire a spatial distribution map of rainfall, divide the spatial distribution map of rainfall into a map image and a legend image, preprocess the map image and the legend image, and remove the background from the map image.
[0035] The module for establishing functional relationships extracts the color values of the legend stripes in the legend image and their corresponding rainfall values, and establishes a functional relationship between the color values and the rainfall values.
[0036] The calculation module calculates the rainfall value for each pixel and grid in the spatial distribution map of rainfall, and integrates them to obtain the rainfall distribution data.
[0037] Thirdly, a data extraction apparatus is disclosed, the apparatus comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement a data extraction method based on image recognition as described above.
[0038] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0039] This application provides a data extraction method, system, and apparatus based on image recognition. It employs image recognition to digitize spatial distribution images, extracting color values and their corresponding numerical values from the legend bars of the spatial distribution map. A functional relationship between color values and numerical values is established, thereby calculating the value of each pixel and grid in the spatial distribution map to obtain distribution data. This avoids the tedious work of collecting, reviewing, and entering site data, and fully utilizes images in documents and literature to increase the amount of usable data, making it easily applicable in hydrological modeling. Furthermore, this method operates on image pixels, allowing for convenient and batch data extraction via computer programs, thus enhancing its practicality. Attached Figure Description
[0040] Figure 1 A schematic flowchart illustrating a data extraction method based on image recognition provided by the present invention;
[0041] Figure 2 This is a schematic diagram of step S2 of the data extraction method based on image recognition provided by the present invention;
[0042] Figure 3 This is a schematic diagram of step S3 of the data extraction method based on image recognition provided by the present invention;
[0043] Figure 4 This is a schematic diagram of step S4 of the data extraction method based on image recognition provided by the present invention;
[0044] Figure 5 This is a schematic diagram of step S42 of the data extraction method based on image recognition provided by the present invention;
[0045] Figure 6 This is a schematic diagram of the spatial distribution of rainfall, which is provided by the image recognition-based data extraction method of the present invention.
[0046] Figure 7 This is a schematic diagram illustrating the extraction of monthly rainfall data using an image recognition-based data extraction method provided by the present invention.
[0047] Figure 8 This is a schematic diagram of longitude data for a data extraction method based on image recognition provided by the present invention. Detailed Implementation
[0048] To better understand and implement this invention, the technical solutions in the embodiments of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this invention, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0049] The terms “comprising” and “having” and any variations thereof in this invention are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device that includes a series of steps or modules is not necessarily limited to those steps or modules that are explicitly listed, but may include other steps or modules that are not explicitly listed or that are inherent to such process, method, product or device.
[0050] like Figure 1 As shown, this application provides a data extraction method based on image recognition, which solves the problems of scattered storage media and difficulty in obtaining spatially distributed data in the background technology. It can directly extract data from spatially distributed images in literature or reports with high accuracy.
[0051] Step S1: Obtain a spatial distribution map, divide the spatial distribution map into map images and legend images, and preprocess the map images and legend images;
[0052] Step S2: Remove the background from the map image;
[0053] Step S3: Extract the color values of the legend stripes in the legend image and their corresponding numerical values, and establish a functional relationship between the color values and the numerical values;
[0054] Step S4: Calculate the value of each pixel and grid in the spatial distribution map of rainfall, and integrate them to obtain the distribution data.
[0055] This application provides a data extraction method, system, and apparatus based on image recognition. It employs image recognition to digitize spatial distribution images, extracting color values and their corresponding numerical values from the legend bars of the spatial distribution map. A functional relationship between color values and numerical values is established, thereby calculating the value of each pixel and grid in the spatial distribution map to obtain distribution data. This avoids the tedious work of collecting, reviewing, and entering site data, and fully utilizes images in documents and literature to increase the amount of usable data, making it easily applicable in hydrological modeling. Furthermore, this method operates on image pixels, allowing for convenient and batch data extraction via computer programs, thus enhancing its practicality.
[0056] The following section uses rainfall data to illustrate this method, which includes the following steps:
[0057] Step S1: Obtain a spatial distribution map of rainfall, divide the spatial distribution map of rainfall into map images and legend images, and preprocess the map images and legend images;
[0058] The preprocessing includes segmenting the spatial distribution map of rainfall, determining map boundaries, and establishing control points. Specifically, the spatial distribution map of rainfall to be digitized is collected, and the image is converted into a processable format. An image processing tool is used to segment the rainfall distribution map into two parts: a map image and a legend image. The map image is a regional map containing the spatial distribution of rainfall; the legend image is a legend containing rainfall amounts and their corresponding color changes.
[0059] Select the top, bottom, left, and rightmost points of the map boundary contained in the map image as coordinate control points, denoted as U1, U2, S1, and S2. Based on the place names, locations, and shapes of the map, determine the corresponding areas using existing maps, such as map software on a smart terminal or a paper map. Locate the four control points on the map visually and extract their latitude and longitude coordinates (U1, U2, S1, S2). Crop the map image into a rectangle using these four points as boundaries to create a new map image.
[0060] Select the four vertices of the legend stripe rectangle in the legend image as control points, and crop the legend file to create a new legend image.
[0061] After preprocessing the map image and legend image, the process also includes:
[0062] Step S11: Convert the map image into a grayscale image to generate a first digital matrix; the first digital matrix is used for background removal processing.
[0063] This program uses Python OpenCV to read a cropped map image into a Python program, converts the color image into a grayscale image, and then converts the grayscale image into a larger size. The first numerical matrix F1; where, The total number of rows in the first numerical matrix F1 is equal to the total number of rows of all pixels in the imported map image; The total number of columns in the first number matrix F1 is equal to the total number of columns of all pixels in the imported map image; the value of each element in the first number matrix F1 is equal to the grayscale value of each pixel in the imported image.
[0064] Step S12: Convert the legend image into a grayscale image to generate a second digital matrix; the second digital matrix is used to extract color values and rainfall values;
[0065] Similar to step S11, the processing of the legend image is as follows: Based on Python OpenCV programming, the cropped legend image is read into the Python program, and the read-in color image is converted into a grayscale image; then the grayscale image is converted into a size of The second digital matrix F2 ;middle, This is the total number of rows in the second number matrix F2, which is equal to the total number of rows of all pixels in the imported legend image; The total number of columns in the second number matrix F2 is equal to the total number of columns of all pixels in the imported legend image; the value of each element in the second number matrix F2 is equal to the grayscale value of each pixel in the legend image.
[0066] Step S2: Remove the background from the map image.
[0067] The software iterates through all pixels in the map image, identifies map boundaries and background, and removes the background to extract more accurate rainfall data.
[0068] Specifically, such as Figure 1 As shown, it includes the following steps:
[0069] Step S21: Randomly select several reference points in the background of the map image, and obtain the average gray value of the reference points as the background gray value reference.
[0070] Using a visual inspection method, 10 points were randomly selected in the background outside the map area of the map image. Their grayscale values were obtained, and the average value of these values was calculated. This average value is denoted as: , as a reference value for background grayscale.
[0071] Step S22: Identify the first and second mutation points in each row of the first digital matrix to obtain the start and end points of the map boundary; the first and second mutation points are points in the map image where the average value of the pixels following that point changes more than a threshold compared to the background grayscale reference value.
[0072] From the first digital matrix Starting with the first row and first column, loop through the first row of the first number matrix element by element. When the first abrupt change in the value of an element in the first number matrix is identified... The point is recorded as the row number it belongs to in the first numerical matrix. Column Number The first mutation point refers to the point preceding this mutation. indivual( The average grayscale value of the 100 pixels is equal to or approximately equal to However, the grayscale value changes abruptly after that point, that is, after that... indivual( The average grayscale value of the (=100) pixels is significantly greater than or less than This mutation indicates that the map boundary has been scanned. The point represents the starting point of the map boundary in the first row of elements. Identify the first mutation point. After that, continue traversing the first row of elements until the second mutation point of the first numerical matrix element is identified. A point is recorded, indicating the row number of that point in the numerical matrix. Column Number The second mutation point refers to the point preceding this mutation point. indivual( The average grayscale value of the (=100) pixels is significantly greater than or less than However, the grayscale value changes abruptly after that point, that is, after that... indivual( The average grayscale value of the 100 pixels is equal to or approximately equal to This mutation indicates that the map boundary has been scanned. The point represents the endpoint of the map's boundary in the first row of elements. Repeat this process for the other rows, identifying the starting point of the map's boundary. and the end point .
[0073] Step S23: Assign -1 to the gray values of all elements before the first mutation point and all elements after the second mutation point in each row of the first digital matrix to generate the first digital submatrix.
[0074] By assigning -1 to the values before each row point in the first numerical matrix and -1 to the values after each row point, the background of the image is removed. The resulting numerical matrix after background removal is denoted as... That is, the first digital submatrix.
[0075] Step S24: Restore the first digital submatrix to a grayscale image to complete the background removal process.
[0076] Using Python OpenCV programming, the first digital submatrix after removing the background is obtained. Restore the image to grayscale and compare it with the map image from step S1 to visually assess the background removal effect. If the removal effect is unsatisfactory, adjustments can be made in step S22. Repeat the above steps until a satisfactory result is achieved.
[0077] Step S3: Extract the color values of the legend stripes in the legend image and their corresponding rainfall values, and establish a functional relationship between the color values and the rainfall values.
[0078] The legend image includes legend bars. Color values and their corresponding rainfall values are extracted from these bars, thus establishing a functional relationship between them. When users obtain literature or images, they can directly calculate specific rainfall values using this functional relationship.
[0079] Specifically, such as Figure 3 As shown, it includes the following steps:
[0080] Step S31: Calculate the grayscale value of the starting point, the starting point rainfall value, the ending point grayscale value, and the ending point rainfall in the legend image.
[0081] The starting grayscale values and starting rainfall amounts for the legend strips are calculated as follows:
[0082] From the second numerical matrix F2, extract a submatrix containing columns 1-5 and all rows, denoted as matrix F2s. Calculate the average grayscale value of all elements in matrix F2s, denoted as... .Will This represents the grayscale value of the starting point of the legend strip. To reduce errors during image cropping, the average grayscale value of the first five pixel columns of the legend strip is used as the starting grayscale value. The rainfall value at the starting point of the legend is found in the rainfall spatial distribution map and denoted as... .
[0083] The mathematical formula for the above process is:
[0084] F2e = F2 (: ; -5:)
[0085] mean(F2e)
[0086] The process of calculating the grayscale value of the endpoint of the legend strip and the endpoint rainfall is as follows:
[0087] From the numerical matrix F2, extract a submatrix containing the last 5 columns and all rows, denoted as the second mathematical submatrix F2e. Calculate the average grayscale value of all elements in the second mathematical submatrix F2e, denoted as... .Will This represents the grayscale value at the endpoint of the legend strip. To reduce errors during image cropping, the average grayscale value of the last five pixel columns of the legend strip is taken as the endpoint grayscale value. The rainfall value at the endpoint of the legend is found in the rainfall spatial distribution map and denoted as... .
[0088] The mathematical formula for the above process is:
[0089] F2e = F2 (: ; -5:)
[0090] mean(F2e)
[0091] Step S32: Determine the sampling points of grayscale values in the legend strips. Using linear interpolation, calculate the rainfall values of the sampling points based on their positions in the legend strips and the rainfall values at the start and end points of the legend.
[0092] From the second numerical matrix F2, every... Column, extract the submatrix containing 1 column and all rows, denoted as matrix. .in, v This indicates interval counting. Starting from the first column of the second number matrix F2, each interval is one... The submatrix extracted from the column is ; 2 columns away from the first column of the second numerical matrix F2 The submatrix extracted from the column is ; distance from the first column of the second numerical matrix F2 v indivual The submatrix extracted from the column is .in, , This represents the total number of columns in the second numerical matrix, F2. Calculate the matrix. The average grayscale value of all elements in the image is denoted as . .
[0093]
[0094] mean( )
[0095] Using linear interpolation, the rainfall values at the sampling points are calculated based on their positions within the legend strips and the rainfall values at the start and end points of the legend. .
[0096]
[0097] Step S33: Fit the grayscale values and rainfall values using a linear function to obtain the functional relationship between the grayscale values and rainfall values in the legend image.
[0098] Using a linear function to process grayscale values and rainfall values By performing fitting calculations, the functional relationship between grayscale and rainfall values in the legend can be obtained. ,Right now:
[0099]
[0100] These are grayscale values. This represents rainfall data. The fitting coefficients are denoted as .
[0101] Step S4: Calculate the rainfall value for each pixel and grid in the spatial distribution map of rainfall, and integrate them to obtain the rainfall distribution data.
[0102] like Figure 4 As shown, the rainfall value for each pixel and grid in the spatial distribution map of rainfall is calculated, including:
[0103] Step S41: Traverse each element of the first digital submatrix, calculate the rainfall matrix according to the functional relationship between the gray value and the rainfall value, and obtain the rainfall value of each pixel.
[0104] The computer program iterates through each element of the digital matrix F11 using loop calculations. Each element of F11 represents a grayscale value in the rainfall image. The grayscale value of each element is then input into a function. In the middle, the rainfall matrix is calculated and denoted as R11.
[0105] if >0
[0106] if
[0107] in, , These are the elements of matrices R11 and F11, respectively. If the grayscale value of an element in the first digital submatrix F11 is -1, it indicates that the element is located in the background of the image and there is no rainfall value.
[0108] Step S42: Calculate the rainfall values in the rainfall matrix according to the grid of the preset spatial size to obtain the rainfall value of each grid.
[0109] In step S41, the rainfall matrix R11 uses the pixels of the corresponding map image as its base resolution, and each element in the matrix represents the rainfall value for each pixel. Therefore, the matrix has a large number of rows and columns, resulting in a large data size, which is inconvenient for practical use. Therefore, it is necessary to statistically analyze the rainfall values in the matrix according to a grid of a certain spatial size, calculating the rainfall amount for each grid cell. For example... Figure 5 As shown, this step includes:
[0110] Step S421: Determine the spatial grid and calculate the number of rows and columns of pixels contained in the spatial grid; in this application, the size of the statistical spatial grid is determined to be 1 km * 1 km.
[0111] Step S422: Construct a rectangular sliding window. The rectangular sliding window slides on the rainfall matrix in a preset direction. Calculate the average rainfall value within the rectangular sliding window to obtain the rainfall value for each grid.
[0112] The longitude and latitude coordinates of the top, bottom, left and rightmost points of the map boundary in step S1 are labeled as Long(U1), Lati(U1), Long(U2), Lati(U2); Long(S1), Lati(S1), Long(S2), Lati(S2), where Long() and Lati() represent longitude and latitude, respectively.
[0113] Calculate the latitudinal span of the uppermost and lowermost control points on the rainfall map:
[0114] Latitude span = | Lati(U1) - Lati(U2)|
[0115] Calculate the longitude span of the leftmost and rightmost control points on the rainfall map:
[0116] Longitude span = | Long(S1) - Long(S2)|
[0117] Based on the latitudinal span of the rainfall map, calculate the vertical spherical distance between the uppermost and lowermost boundaries of the region. The Haversine formula, a spherical trigonometry formula, is used for the calculation.
[0118] Vertical Great Circle Distance = Haversine(Latitude span)
[0119] The calculated Earth surface distance is converted into a straight-line distance using the Lambert projection, which has higher accuracy and is more suitable for the mid-latitude characteristics of my country:
[0120] Vertical Distance = Lambert (Vertical Great Circle Distance)
[0121] Based on the total number of rows in data matrix F1, calculate the spatial distance occupied by each pixel in the vertical direction:
[0122] Dv = Vertical Distance /
[0123] The number of rows of pixels within a vertical 1km range is:
[0124] V1 = 1 / Dv
[0125] Similarly, calculate the number of pixel columns within a 1km horizontal range. Based on the longitude span of the rainfall map, calculate the horizontal spherical distance from the leftmost to the rightmost boundary of the region. The Haversine formula, a spherical trigonometry formula, is used for the calculation.
[0126] Horizontal Great Circle Distance = Haversine(Longitude span)
[0127] The calculated distances on the Earth's surface are converted into straight-line distances using the Lambert projection:
[0128] Horizontal Distance = Lambert (Horizontal Great Circle Distance)
[0129] Based on the total number of columns in the data matrix F1, calculate the spatial distance occupied by each pixel in the horizontal direction:
[0130] Dh = Horizontal Distance / N
[0131] Therefore, the number of pixel columns within a horizontal range of 1km is:
[0132] H1 = 1 / Dh
[0133] A rectangular sliding window is constructed with V1 as the number of rows and H1 as the number of columns. This window is used to slide across the rainfall R11 matrix from top to bottom and from left to right, averaging the rainfall values within the window. Each downward slide has a step size of V1 rows, and each left-to-right slide has a step size of H1 columns. When the sliding window contains an element with a value of -1, -1 is subtracted, and only the average of the remaining non--1 values is calculated to eliminate the influence of the rainfall image background. The average rainfall value calculated after each slide is denoted as... , where i is the number of times to slide from top to bottom each time, and j is the number of times to slide from left to right each time. , , where M is the total number of rows in matrix R11 and N is the total number of columns in R11.
[0134] After obtaining the rainfall values within the grid, the data from each grid is integrated to obtain rainfall distribution data, such as... Figure 6 , 7 As shown in Figure 8, it includes:
[0135] Step S43: Obtain the coordinates of preset points in the map image, calculate the longitude and latitude span of the rainfall map; match the rainfall value of each grid with the corresponding longitude and latitude coordinates to form rainfall distribution data; the rainfall distribution data includes the rainfall matrix of the grid, the longitude and latitude of the grid.
[0136] Specifically, the longitude and latitude coordinates of the top, bottom, left and rightmost points of the map boundary in step S1 are labeled as Long(U1), Lati(U1); Long(U2), Lati(U2); Long(S1), Lati(S1); Long(S2), Lati(S2), where Long() and Lati() represent longitude and latitude respectively.
[0137] Calculate the latitudinal span of the uppermost and lowermost control points on the rainfall map:
[0138] Latitude span = | Lati(U1) - Lati(U2)|
[0139] Calculate the longitude span of the leftmost and rightmost control points on the rainfall map:
[0140] Longitude span = | Long(S1) - Long(S2)|
[0141] Rainfall value for each grid Corresponding latitude coordinates:
[0142]
[0143] Rainfall value for each grid Corresponding longitude coordinates:
[0144]
[0145] The rainfall distribution data includes a grid-based rainfall matrix, the grid's longitude, and latitude—that is, three matrices. The first matrix is the grid's rainfall matrix, with a total of [number missing] rows. The total number of columns is The value of each element in the matrix is The second matrix represents the grid dimensions, with a total of [number] rows. The total number of columns is The value of each element in the matrix is The third matrix represents the longitude of the grid, with a total of [number] rows. The total number of columns is The value of each element in the matrix is .
[0146] Based on the same inventive concept, this application also provides a data extraction system, comprising:
[0147] The image processing module is used to acquire a spatial distribution map of rainfall, divide the spatial distribution map of rainfall into a map image and a legend image, preprocess the map image and the legend image, and perform background removal processing on the map image.
[0148] The module for establishing functional relationships extracts the color values of the legend stripes in the legend image and their corresponding rainfall values, and establishes a functional relationship between the color values and the rainfall values.
[0149] The calculation module calculates the rainfall value for each pixel and grid in the spatial distribution map of rainfall, and integrates them to obtain the rainfall distribution data.
[0150] This application provides a data extraction method, system, and apparatus based on image recognition. It employs image recognition to digitize images of spatial distribution of rainfall. By extracting the color values and corresponding rainfall values from the legend bars of the rainfall spatial distribution map, a functional relationship between color values and rainfall values is established. This allows for the calculation of rainfall values for each pixel and grid in the rainfall spatial distribution map, thereby obtaining rainfall distribution data. This avoids the tedious work of collecting, reviewing, and entering rainfall station data, and fully utilizes rainfall images in documents and literature, increasing the amount of usable rainfall data and making it easily applicable in hydrological modeling. Furthermore, this method operates on image pixels, enabling convenient and batch data extraction via computer programs, thus enhancing its practicality.
[0151] Although this application only lists methods for extracting rainfall data, it is understood that other data, such as altitude data and temperature data, can also be extracted using this method based on image recognition.
[0152] This application also provides an apparatus or electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement a data extraction method based on image recognition as described above.
[0153] This application also provides a non-transitory machine-readable storage medium storing an executable program. When the executable program is run by a processor, it causes the processor to perform the method provided in the above embodiments. A memory storing executable program code is also provided.
[0154] A processor coupled to memory;
[0155] The processor calls the executable program code stored in memory to execute a described image recognition-based data extraction method.
[0156] This invention discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to perform a described image recognition-based data extraction method.
[0157] The embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical modules. They may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0158] Through the detailed description of the above embodiments, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, including read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-Erasable Programmable Read-Only Memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0159] Finally, it should be noted that the embodiments disclosed in this invention are merely preferred embodiments of the invention and are only used to illustrate the technical solutions of the invention, not to limit it. Although the invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this invention.
Claims
1. A data extraction method based on image recognition, characterized in that, This method includes the following steps: A spatial distribution map is obtained and divided into a map image and a legend image. Both the map image and the legend image are preprocessed. The map image is a regional map containing the spatial distribution; the legend image is a legend containing target physical quantities and their corresponding color changes. The top, bottom, left, and rightmost points of the map boundary in the map image are selected as coordinate control points. Based on the place names, locations, and shapes of the map, the corresponding areas are determined, and the map image is cropped into a rectangle using the coordinate control points as boundaries to form a new map image. Similarly, the four vertices of the legend stripe rectangle in the legend image are selected as control points and cropped to form a new legend image. The map image is then processed to remove the background. Extract the color values of the legend stripes in the legend image and their corresponding numerical values, and establish a functional relationship between the color values and numerical values; Calculate the values of all pixels in each grid of the spatial distribution map and integrate them to obtain the distribution data.
2. The data extraction method based on image recognition according to claim 1, characterized in that, The data includes rainfall data. The color values and corresponding numerical values of the legend bars in the legend image are extracted, and a functional relationship between the color values and numerical values is established, including: Calculate the grayscale value of the starting point, the starting rainfall, the ending grayscale value, and the ending rainfall of the legend strips in the legend image; Determine the sampling points for grayscale values in the legend strips. Use linear interpolation to calculate the rainfall values at the sampling points based on their positions in the legend strips and the rainfall values at the start and end points of the legend. By fitting a linear function to the grayscale values and rainfall values, the functional relationship between the grayscale values and rainfall values in the legend image is obtained.
3. A data extraction method based on image recognition according to claim 1 or 2, characterized in that, After preprocessing the map image and legend image, the process also includes: The map image is converted into a grayscale image to generate a first digital matrix; the first digital matrix is used for background removal processing. The legend image is converted into a grayscale image to generate a second digital matrix; the second digital matrix is used to extract color values and rainfall values. The numerical values of the elements in the first and second digital matrices are equal to the grayscale values of each pixel in the grayscale image.
4. The data extraction method based on image recognition according to claim 3, characterized in that, The map image is subjected to background removal processing, including: Randomly select several reference points in the background of the map image, and obtain the average gray value of the reference points as the background gray value reference. Identify the first and second mutation points in each row of the first digital matrix to obtain the start and end points of the map boundary; the first and second mutation points are points in the map image where the average value of all pixels after that point changes more than a threshold from the background grayscale reference value. The gray values of all elements before the first mutation point and all elements after the second mutation point in each row of the first digital matrix are assigned to -1 to generate the first digital submatrix. Restore the first digital submatrix to a grayscale image to complete the background removal process.
5. The data extraction method based on image recognition according to claim 4, characterized in that, Calculate the values of all pixels in each grid of the rainfall spatial distribution map, including: Iterate through each element of the first digital submatrix, and calculate the rainfall matrix based on the functional relationship between the grayscale value and the rainfall value to obtain the rainfall value for each pixel. The rainfall values in the rainfall matrix are statistically analyzed according to a grid of preset spatial size to obtain the rainfall value for each grid.
6. The data extraction method based on image recognition according to claim 5, characterized in that, The rainfall values in the rainfall matrix are statistically analyzed according to a grid of preset spatial size to obtain the rainfall value for each grid, including: Determine the spatial grid and calculate the number of rows and columns of pixels contained within the spatial grid; A rectangular sliding window is constructed, which slides on the rainfall matrix in a preset direction. The average rainfall value within the rectangular sliding window is calculated to obtain the rainfall value for each grid.
7. The data extraction method based on image recognition according to claim 2, characterized in that, The integrated distributed data includes Obtain the coordinates of preset points in the map image and calculate the longitude and latitude span of the rainfall map; Rainfall distribution data is constructed by matching the rainfall values of each grid with the corresponding longitude and latitude coordinates; the rainfall distribution data includes the rainfall matrix of the grid, the longitude and latitude of the grid.
8. The data extraction method based on image recognition according to claim 1, characterized in that, The preprocessing includes segmenting the spatial distribution map, determining map boundaries, and setting control points.
9. A data extraction system, characterized in that, include: An image processing module is used to acquire a spatial distribution map, divide the spatial distribution map into a map image and a legend image, and preprocess the map image and the legend image. The map image is a regional map containing the spatial distribution; the legend image is a legend containing target physical quantities and their corresponding color changes. The top, bottom, left, and rightmost points of the map boundary contained in the map image are selected as coordinate control points. The corresponding area is determined according to the place name, location, and shape of the map, and the map image is cropped into a rectangle with the coordinate control points as the boundary to form a new map image. The four vertices of the legend color strip rectangle in the legend image are selected as control points and cropped to form a new legend image. The map image is then processed to remove the background. The function relationship establishment module extracts the color values and corresponding numerical values of the legend stripes in the legend image and establishes the function relationship between the color values and the numerical values. The calculation module calculates the values of all pixels in each grid of the spatial distribution map and integrates them to obtain the distribution data.
10. A data extraction device, characterized in that, include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements a data extraction method based on image recognition as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Hydrological long sequence data extraction method based on image recognition
CN113436117A
Regional waterlogging risk prediction method and system based on catchment partition
CN117196302A