Vectorization method of raster pattern, mobile terminal, electronic device and medium
By using the water immersion filling method to determine the node and edge information at the branches during the vectorization process of the raster pattern, the ambiguity problem caused by multiple branches is solved, and the synonymity and efficiency of the vectorization results are improved.
Patent Information
- Application Number
- CN202210639833.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-06
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2042-06-06
AI Technical Summary
In the vectorization process of raster patterns, multiple branches cause the inner and outer contours to share the same point, causing ambiguity, which in turn makes subsequent algorithms confusing, and each vector edge cannot be restored losslessly, resulting in large memory and time overhead.
By accessing the raster cells to be accessed, use the water immersion filling method to determine the unique nodes and edge information at multiple branches, extract the contour map of the connected domain, and separate and combine the contour maps until all raster cells are traversed to obtain the raster Checkered pattern vector illustration.
Automatically select unique nodes and edge information at multiple branches to ensure the synonymity of vectorized results, reduce memory and time overhead, and improve the accuracy and efficiency of results.
Smart Images

Figure CN115147442B
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a raster pattern vectorization method, a mobile terminal, an electronic device and a medium. Background Art
[0002] Generally, in the field of image processing technology, raster patterns are often used in various industries to directly record the attributes of image data, such as geographic reference, land survey, map download, etc.
[0003] At present, in the process of vectorizing raster patterns, multiple branches are often encountered when traversing the contour map, causing the vector polygon to have the inner and outer contours share the same point, making it impossible to make a deterministic selection at multiple branches, resulting in two descriptions existing in the appropriate results at the same time, that is, ambiguity, which leads to confusion in subsequent algorithms.
[0004] Furthermore, since the ambiguity makes it impossible to restore each vector edge of the raster image without loss, such additional judgment will also result in a large amount of memory and time overhead when matching the inner and outer contours with the pre-saved results. Summary of the invention
[0005] In order to solve the above technical problems, the technical solution adopted in the first aspect of the present application is to provide a vectorization method for a raster pattern, which vectorization method includes: accessing the raster pixels to be accessed, and multiple raster pixels constitute a raster pattern; performing water filling according to the category of the pixels to determine the access information of the unique nodes and edge information at multiple branches between multiple raster pixels in the raster pattern; extracting the connected domain through the access information, and constructing a contour map of the connected domain; until all raster pixels are accessed and traversed, the contour map is separated and multiple contour maps are combined to obtain a vector map of the raster pattern.
[0006] In order to solve the above technical problems, the technical solution adopted in the second aspect of the present application is to provide a mobile terminal, the mobile terminal comprising: an access module, used to access a grid pixel to be accessed, a plurality of grid pixels forming a grid pattern;
[0007] A filling module, used for performing water filling according to the category of the grid pixels, so as to determine access information of unique nodes and edge information at multiple branches between multiple grid pixels in the grid pattern;
[0008] A construction module, used for extracting a connected domain by accessing information and constructing a contour map of the connected domain;
[0009] The separation module is used to separate the contour map and combine multiple contour maps until all grid pixels are visited and traversed to obtain a vector map of the grid pattern.
[0010] In order to solve the above technical problems, the technical solution adopted in the third aspect of the present application is to provide an electronic device, which includes: a processor and a memory, the memory stores a computer program, and the processor is used to execute the computer program to implement the vectorization method as in the first aspect of the present application.
[0011] In order to solve the above technical problems, the technical solution adopted in the fourth aspect of the present application is to provide a computer-readable storage medium, which stores a computer program, and the computer program can implement the vectorization method of the first aspect of the present application when executed by a processor.
[0012] The beneficial effect of the present application is as follows: by proposing a method for vectorizing a raster pattern, when contour points are shared at multiple branches, the present application can control and automatically select unique node and edge information by using a water filling method, thereby maintaining synonymy of the vectorization result of the raster pattern. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0014] Figure 1 It is a schematic diagram of the structure of abstract concepts such as raster pixels, branches, connected domains, and contour maps;
[0015] Figure 2 It is a flowchart of an embodiment of a method for vectorizing a raster pattern of the present application;
[0016] Figure 3 This application Figure 1 A flow chart of a specific embodiment of step S12;
[0017] Figure 4 This application Figure 3 A flowchart of a specific embodiment of step S21;
[0018] Figure 5 This application Figure 4 A schematic diagram of a structure of a specific embodiment of a branchless traversal, wherein Figure 5 (1) is a grid diagram. Figure 5 (2) is the outline diagram of pixel A filled with water. Figure 5 (3) is a schematic diagram of the contour obtained by filling the connected domain where A is located with flood water;
[0019] Figure 6 This application Figure 4 There is a branch traversal schematic diagram of a specific embodiment, wherein Figure 6 (1) is a schematic diagram of the category and edge information grid of each pixel in the branch. Figure 6 (2) is a schematic diagram of the contour obtained by filling the connected domain where A is located with flood water;
[0020] Figure 7 This application Figure 2 A flow chart of a specific embodiment of step S13;
[0021] Figure 8 This application Figure 4 A schematic diagram of a specific embodiment of step S32;
[0022] Fig. 9 It is a schematic diagram of several coordinate expressions of the vector product of the front and back paths of the common nodes of this application, among which Fig. 9 (1) is the coordinate diagram of the first counterclockwise vector product. Fig. 9 (2) is the coordinate diagram of the second counterclockwise vector product. Fig. 9 (3) is the coordinate diagram of the first clockwise vector product. Fig. 9 (4) is a coordinate diagram of the second clockwise vector product;
[0023] Fig.10 This application Figure 6 A flowchart of a specific embodiment of step S53;
[0024] Fig.11 It is a flowchart of a detailed embodiment of raster vectorization of the present application;
[0025] Fig.12 It is a schematic diagram of the process of extracting connected domains and constructing contour maps in this application;
[0026] Fig.13 It is a schematic diagram of the effect before and after vectorization of this application, where Fig.13 (1) is the corresponding grid diagram before vectorization. Fig.13 (2) The corresponding vector diagram after vectorization;
[0027] Fig.14 is a schematic block diagram of the structure of an embodiment of a mobile terminal of the present application;
[0028] Fig.15 is a schematic structural block diagram of an embodiment of an electronic device of the present application;
[0029] Fig.16 It is a circuit schematic block diagram of an embodiment of a computer-readable storage medium of the present application. DETAILED DESCRIPTION
[0030] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0031] It should be understood that when used in this specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0032] It should also be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0033] It should be further understood that the term “and / or” used in the specification and appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0034] As used in this specification and the appended claims, the term "if" may be interpreted as "when" or "upon" or "in response to determining" or "in response to detecting," depending on the context. Similarly, the phrases "if it is determined" or "if [described condition or event] is detected" may be interpreted as meaning "upon determination" or "in response to determining" or "upon detection of [described condition or event]" or "in response to detecting [described condition or event]," depending on the context.
[0035] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0036] In order to illustrate the technical solution of the present application, the following is a specific embodiment to illustrate that the present application provides a method for vectorizing a raster pattern. Figure 1 and Figure 2 , Figure 1 It is a structural diagram of abstract concepts such as raster pixels, branches, connected domains, and contour maps. Figure 2 1 is a flow chart of an embodiment of a method for vectorizing a raster pattern of the present invention, and the method for vectorizing a raster pattern specifically comprises the following steps:
[0037] S11: access the grid pixel to be accessed;
[0038] Generally speaking, the smallest unit of a remote sensing image or grid pattern expressed in grid form can be called a grid pixel. Figure 1 As shown, a plurality of grid pixels M of different area degrees form a grid pattern. In order to vectorize the grid pattern, the grid pixels to be accessed can be accessed sequentially to implement the vectorization process of the grid pattern.
[0039] Specifically, for example, the raster pixels can be accessed sequentially from left to right, or from top to bottom. Of course, relevant technical personnel in this field can also use other traversal methods to access the raster pixels, thereby realizing the vectorization of the raster pattern. The specific selection can be made according to the actual situation and is not limited here.
[0040] S12: performing water filling according to the category of the grid pixels to determine access information of unique nodes and edge information at multiple branches between multiple grid pixels in the grid pattern;
[0041] For more detailed information about the branches, please refer to Figure 1 At N in , the branches can be 2 or 3. The specific number depends on the number of divisions between grid pixels, such as Figure 1 As shown, there are surrounding nodes at branch N that divide the grid pixels into four parts.
[0042] The flood filling method is actually a breadth-first search. When encountering objects of other categories or image boundaries in the search direction, a directed edge with a counterclockwise point order is constructed between the two grid corner points on the boundary.
[0043] Generally, if multiple pixels visited in sequence are of the same category, it can be considered that there is no branch between the access points experienced by the grid patterns corresponding to the multiple pixels, and the only branch can be directly determined to continue visiting the pixels in sequence.
[0044] In addition, there can be multiple categories for pixels. For different categories, the surrounding pixels of the current pixel can be supplemented by water filling. If the current pixel and the supplementary pixel and other pixels are of different categories, it can be determined that the access points between the grid patterns corresponding to multiple pixels have at least two branches.
[0045] Because there are at least two branches, it is necessary to confirm and select the node and edge information corresponding to the next pixel to be visited. Specifically, through the flood filling method, the nodes and edge information that need to be searched first can be selected, thereby determining the access information of the unique nodes and edge information at multiple branches.
[0046] S13: extracting connected domains through access information and constructing a contour map of the connected domains;
[0047] like Figure 1 As shown, the specific connected domain O is a connected component, which generally refers to an image region (Region, Blob) composed of foreground pixels with the same pixel value and adjacent positions in the image, that is, the same area with similar pixel values.
[0048] Therefore, through the access confirmation method in step S12, the access status of each node and edge information can be uniquely determined, thereby realizing the unique connection method of the connected domain, and then by constructing the contour graph composed of the connected domain, the contour graph construction after each access can be realized, wherein the contour graph is a measure of the clustering effect, which is used to represent the contour of the image and depict the line graph, such as Figure 1 A circle of lines surrounding the connected domain O in .
[0049] S14: until all grid pixels are visited and traversed, the contour map is separated and multiple contour maps are combined to obtain a vector map of the grid pattern.
[0050] Continuing step S11 to step S13, multiple partial contour maps can be obtained. By merging and splicing each contour map, all contour maps corresponding to the raster pattern can be obtained. The vectorization result can be obtained while maintaining synonymy, and then the contour maps are separated and multiple contour maps are combined to obtain a unique vector map of the raster pattern.
[0051] Specifically, the contour map obtained by visiting the grid pixels is kept until any node of any remaining edge is used as the starting point to visit and traverse all the grid pixels until returning to the starting point. During the traversal, the closed path as the inner contour is saved in sequence, uniquely determined by immersion filling, unnecessary edge information is deleted, and the outer contour is traversed continuously until returning to the starting point, thereby obtaining all the contour maps.
[0052] Therefore, the present application proposes a raster pattern vectorization method. Based on the visit and traversal of the raster pattern composed of multiple raster pixels to be visited, when the contour points are shared at multiple branches, the water filling method is used to control and automatically select unique node and edge information to construct the contour map, so that the vectorization result of the raster pattern remains synonymous, and then the contour map is separated to obtain a unique vector map.
[0053] Further, the steps of performing water filling according to the category of the grid pixels to determine the access information of the unique node and edge information at multiple branches between multiple grid pixels in the grid pattern are shown in Figure 3 , Figure 3 This application Figure 2 The flowchart of step S12 in a specific embodiment specifically includes the following steps:
[0054] S21: in the forward direction of accessing the grid pixel, at multiple branches, with the current pixel as the center, determine the category between other pixels and the current pixel by means of immersion filling;
[0055] Specifically, the flood filling method is actually a breadth-first search. When encountering objects of other categories or image boundaries in the search direction, a directed edge with a counterclockwise point order is constructed for the two grid corner points on the boundary.
[0056] Therefore, in the forward direction of visiting the grid pixels, the categories between other pixels and the current pixel are determined by flood filling at multiple branches with the current pixel as the center. Specifically, Figure 5 As shown in , around pixel E, other pixels belong to the same category, but they are two categories with pixel E, such as Figure 6 As shown, around pixel E, pixel G belongs to the same category as pixel E, and other pixels belong to the same category and are in two categories with pixel E.
[0057] S22: Based on the category, determine the direction of the contour point sequence between other pixels and the current pixel.
[0058] By determining the category, when encountering objects or image boundaries of other categories in the search direction, a directed edge with a counterclockwise point order is constructed between the two grid corner points on the boundary; when encountering objects or image boundaries of the same category in the search direction, a directed edge with a clockwise point order is constructed between the two grid corner points on the boundary, thus determining the direction of the contour point order between other pixels and the current pixel.
[0059] Among them, in the forward direction of accessing the raster pixel, at multiple branches, with the current pixel as the center, the steps of determining the category between other pixels and the current pixel by flood filling are shown in Figure 7 , Figure 7 This application Figure 3 The flowchart of step S21 in a specific embodiment specifically includes the following steps:
[0060] S31: in the forward direction of accessing the grid pixel, at multiple branches, with the current pixel as the center, determine whether other pixels are consistent with the category of the current pixel by flood filling;
[0061] If they are consistent, the process proceeds to step S32, i.e. no processing is performed; if they are inconsistent, the process proceeds to step S33, i.e. a directed edge with a point sequence in the first direction is constructed for any two grid corner points of the image boundary of the current pixel to form a closed contour, where the first direction is represented as the counterclockwise direction and the second direction is represented as the clockwise direction.
[0062] Specifically, see Figure 5 and Figure 6 , Figure 5 This application Figure 3 A schematic diagram of a structure of a specific embodiment of a branchless traversal, wherein Figure 5 (1) is a grid diagram. Figure 5 (2) is the outline diagram of pixel A filled with water. Figure 5 (3) is a schematic diagram of the contour obtained by filling the connected domain where A is located with flood water; Figure 6 This application Figure 4 There is a branch traversal schematic diagram of a specific embodiment, wherein Figure 6 (1) is a schematic diagram of the category and edge information grid of each pixel in the branch. Figure 6 (2) is a schematic diagram of the contour obtained by filling the connected domain where A is located with flood water.
[0063] like Figure 5 As shown, for example, if pixel D is the center, the same pixel colors (such as A4-5, G9-8) indicate the same type, and no edge can be constructed. Different pixel colors (such as E9-5, the space 4-8 on the left of D (filled with water)) indicate different types, and a counterclockwise directed edge can be constructed. Figure 5 As shown, for example, with pixel D as the center, the same pixel color (such as A4-5) indicates the same type, so no edge can be constructed. Different pixel colors (such as E9-5, the space 4-8 on the left of D (filled with water), D8-9) indicate different types, so a counterclockwise directed edge can be constructed. Of course, the specific grid contour map also needs to be extracted through the node out-degree and in-degree.
[0064] Furthermore, after the step of determining the category between other pixels and the current pixel, the vectorization method further includes step S34:
[0065] S34: Storing the node and edge information of the directed edges and the outline graph of the connected domain in the hash table and the adjacency list.
[0066] Further, the steps to extract the connected domains through access conditions and construct the contour map are as follows: Figure 7 , Figure 7 This application Figure 2 The flowchart of step S13 in the specific embodiment specifically includes the following steps:
[0067] S41: judging whether the accessed closed connected domain path is a first direction polygon or a second direction polygon according to a preset rule of the contour point sequence in the vector file;
[0068] According to the preset rules of the vector file for the order of contour points, specifically, since the vector file in the shp format has requirements for the order of contour points, for the generated vector result, the order of the outer contour points must be counterclockwise, then it constitutes a closed connected domain path of the polygon in the first direction, and the order of the inner contour points must be clockwise, then it constitutes a closed connected domain path of the polygon in the first direction.
[0069] If the contour extracted from the point sequence connection graph is counterclockwise, it is taken as the outer contour; if the contour extracted from the point sequence connection graph is clockwise, it is taken as the inner contour. Therefore, specifically, by judging whether the closed connected domain path obtained by traversal is a first direction polygon or a second direction polygon, it can be determined whether it is an outer contour or an inner contour.
[0070] S42: If it is a first direction polygon, construct the first direction polygon as an outer contour and save it in a preset file;
[0071] Specifically, if it is a first direction polygon, it is represented as a counterclockwise polygon, so that the first direction polygon can be constructed as an outer contour, that is, an outer contour in the counterclockwise direction is constructed, as shown in the following example. Figure 5 As shown, with 0 as the starting point, the closed contour 0-4-8-12-13-14-15-11-7-3-2-1-0 can be constructed as the outer contour, such as Figure 6 As shown, with 0 as the starting point, a closed contour 0-4-8-9-13-14-15-11-7-3-2-1-0 can be constructed as the outer contour. In addition, in order to facilitate later calls, the counterclockwise outer contour can be saved in a preset file.
[0072] S43: If it is a second direction polygon, construct the second direction polygon as an inner contour and save it in a preset file.
[0073] Similarly, specifically, if it is a second direction polygon, it is represented as a clockwise polygon, so that the second direction polygon can be constructed as an outer contour, that is, a clockwise outer contour is constructed, as shown in the following example. Figure 5 As shown, with 0 as the starting point, the closed contour 5-9-10-6-5 can be constructed as the inner contour, as shown in Figure 6 As shown, with 0 as the starting point, a closed contour 9-5-6-10-9 is constructed as the inner contour. In addition, in order to facilitate later calls, the clockwise outer contour can be saved in a preset file.
[0074] In addition, for the steps to construct a directed edge with the first direction point order for any two grid corner points of the image boundary of the current pixel, see Figure 8 , Figure 8 This application Figure 4 The flowchart of step S32 in a specific embodiment specifically includes the following steps:
[0075] S51: In the forward direction of accessing the grid pixel, taking any point of the current pixel as the starting point, determine whether the out-degree and in-degree of each node in the contour map are not 1;
[0076] In general, the out-degree and in-degree of each node in the contour graph are both 1, and the traversal process will not encounter branches. In special cases, that is, when the inner and outer contours share nodes, the node out-degree may be higher than 1. Figure 6 As shown, when the outer contour is traversed to 8-9, there are two branches 9-5 and 9-13. The traversal strategy at this time determines the generated vector map. Usually, the same contour will not pass through the same point twice, and the polygon will be represented with the least contour possible.
[0077] If both are 1, then the process goes to step S52, that is, it is determined that the access process will not encounter a branch, and the access direction continues to move forward to form a closed contour;
[0078] If it is not 1, the process goes to step S53, that is, it is determined whether there are common nodes between the inner and outer contours during the access process.
[0079] In this way, when common nodes between inner and outer contours appear during the traversal, refer to Fig. 9 and Fig.10 , Fig. 9 It is a schematic diagram of several coordinate expressions of the vector product of the front and back paths of the common nodes in this application. Fig.10 This application Figure 6 The flowchart of step S53 in a specific embodiment specifically includes the following steps:
[0080] S61: Calculate the vector product of the path vectors before and after the common node;
[0081] like Fig. 9 As shown, Fig. 9 (1) is the coordinate diagram of the first counterclockwise vector product. Fig. 9(2) is the coordinate diagram of the second counterclockwise vector product. Fig. 9 (3) is the coordinate diagram of the first clockwise vector product. Fig. 9 (4) is a coordinate diagram of the second clockwise vector product.
[0082] Take x-0-y as the coordinate system, where ax and bx represent the projections of vector a and vector b on the x coordinate, and ay and by represent the projections of vector a and vector b on the y coordinate. Figure 6 As can be seen from the embodiment in FIG. , the common node is closer to Fig. 9 (3), vector a(1,0), b1(0,-1), b2(0,1), therefore, we can calculate that the difference between the path 8-9 corresponding to vector a(1,0) and the path 9-13 corresponding to b2(0,1) is 1, and we can also calculate that the difference between the path 8-9 corresponding to vector a(1,0) and the path 9-5 corresponding to b1(0,-1) is -1.
[0083] S62: Determine whether the vector product is greater than 0;
[0084] When it is determined that the vector product is greater than 0, the process proceeds to step S63, that is, the traversal direction of the branch path corresponding to the vector product greater than 0 is selected to continue to move forward to form a closed contour; specifically, combined with Figure 6 From the embodiment in, it can be seen that the difference between the vector a(1,0) corresponding to 8-9 and the vector b2(0,1) corresponding to the path 9-13 is 1, which is greater than 0. Therefore, it can be determined that the vector product is greater than 0, and the path 9-13 is selected as the traversal direction to continue moving forward.
[0085] When it is determined that the vector product is less than or equal to 0, the process proceeds to step S64, that is, the branch path corresponding to the vector product being less than or equal to 0 is abandoned.
[0086] In order to further describe the technical solution of the present application in detail, a detailed embodiment is specifically provided here for description. Fig.11 , Fig.11 A flowchart of a detailed embodiment of applying for raster vectorization is provided. The raster pattern vectorization method specifically includes the following steps:
[0087] S71: traverse the pixels;
[0088] This step is the same as Figure 2 The step S11 is similar and will not be described again here.
[0089] S72: whether the pixel has been visited;
[0090] If the current pixel has been visited, return to step S71 to continue traversal. Otherwise, perform flood filling (breadth-first search) according to the category of the pixel. When encountering objects of other categories or image boundaries in the forward direction, construct a directed edge with counterclockwise point order for the two grid corner points on the boundary (the information of the constructed points and edges is stored in the hash table and adjacency table). At the same time, set each filled pixel as visited.
[0091] It is worth noting that after completing step S72, all pixels in the connected domain where the current pixel is located are also traversed and set as visited. At the same time, the inner and outer contours of the connected domain are also constructed and placed in the hash table and the adjacency table.
[0092] S73: extracting connected domains and constructing contour maps;
[0093] Starting from the node at the upper left corner of the contour map, traverse the contour map until you return to the starting point. If you encounter multiple branches during the traversal, give priority to the branch whose vector product of the front and back paths is greater than 0. Save the closed path obtained by this traversal as the outer contour of the polygon. And delete all the edges passed from the current contour map.
[0094] S74: Separation contour;
[0095] If there are still edges in the current contour graph, take any node of any remaining edge as the starting point and traverse the contour graph until you return to the starting point. If multiple branches are encountered during the traversal, the branch with the vector product of the front and back paths greater than 0 is preferred. The closed path obtained by this traversal is saved as the inner contour of the polygon. And delete all the edges passed from the current contour graph.
[0096] Specifically, starting from the node at the upper left corner of the contour graph, traverse the contour graph until you return to the starting point. Save the closed path obtained by this traversal as the outer contour of the polygon. Delete all the paths (directed edges) passed from the current contour graph. When a path is deleted and the out-degree of the starting point of the path becomes 0, delete the point from the contour graph.
[0097] If there are still nodes in the current contour map, take any existing node as the starting point and traverse the contour map until you return to the starting point. Save the closed path obtained by this traversal as the inner contour of the polygon. And delete all the edges passed from the current contour map.
[0098] S75: Determine whether the traversal is completed;
[0099] Repeat step S74 until there are no directed edges left in the current contour graph. Save the outer contour and inner contour (if any) obtained this time into the shp file.
[0100] S76: Output vector file.
[0101] See also Fig.13 , Fig.13 It is a schematic diagram of the effect before and after vectorization of this application, where Fig.13 (1) is the corresponding grid diagram before vectorization. Fig.13 (2) The corresponding vector diagram after vectorization. Fig.13 As shown, through the vectorization method, we can Fig.13 The raster pattern in (1) is vectorized to obtain Fig.13 The vector result in (2).
[0102] Therefore, on the one hand, the present application can efficiently and losslessly perform raster-to-vector conversion, ensuring that the generated vector file accurately describes the contours of the raster image, and the generated vector results maintain synonymy. In addition, it can also support direct vectorization of the entire image, and also support specifying any multiple points (floating point coordinates) in the raster image and performing independent vectorization operations on the polygons at these locations.
[0103] For details on extracting connected domains and constructing contour maps, please refer to Fig.12 , Fig.12 This is a schematic diagram of the process of extracting connected domains and constructing contour maps in this application, which may specifically include the following steps:
[0104] S81: The current pixel is added to the search queue;
[0105] In order to traverse the object elements in an orderly manner, the current pixel can be added to the search queue, and the object elements in the search queue are arranged to facilitate the traversal of the pixels.
[0106] S82: traverse the pixels that have not been visited in the four fields for the first element of the team;
[0107] Specifically, Figure 5 As shown, when the flood fills the connected domain where A is located ( Figure 5 (1)), A will encounter the image boundary when it moves upward and leftward, so two directed edges with counterclockwise order are constructed ( Figure 5 (2)), after completely filling the entire connected domain, we get the contour map of the connected domain where A is located ( Figure 5 (3)).
[0108] S83: whether other categories or image boundaries are encountered in the traversal direction;
[0109] If yes, then go to step S84, i.e. construct a counterclockwise directed edge and store the relevant information in the hash table and adjacency table; if no, then go to step S85, i.e. construct a clockwise directed edge and store the relevant information in the hash table and adjacency table;
[0110] S86: The current pixel is set as visited and removed from the search queue;
[0111] Specifically, Figure 5 As shown, starting from 0, the closed contour 0-4-8-12-13-14-15-11-7-3-2-1-0 is traversed as the outer contour. After deleting the contour, the contour map still has 5-6-9-10-5. Starting from any point, the contour is traversed to obtain the inner contour. After deleting the contour, the contour map is empty, and the contour separation operation is completed.
[0112] Enter Figure 6 As shown, when traversing the outer contour to 8-9, there are two branches 9-5 and 9-13. If the algorithm gives priority to the branch that makes the vector product of the front and back path vectors greater than 0, it can be guaranteed that the same contour of the generated vector map will not pass through the same point twice. On the contrary, if the algorithm gives priority to the branch that makes the vector product of the front and back path vectors less than 0, it can be guaranteed that the generated vector map uses the least contours to represent the polygon as much as possible.
[0113] Specifically, Figure 6 As shown in the figure, under the strategy of giving priority to ensuring that the same contour does not pass through the same point twice, when traversing the outer contour to 8-9, since the vector product of the two directed edges 9-13 and 8-9 is greater than 0, the path 9-13 will be selected at this time, and the closed contour 0-4-8-9-13-14-15-11-7-3-2-1-0 will be obtained as the outer contour. After deleting this contour from the contour graph, the inner contour 9-5-6-10-9 will be traversed again.
[0114] S87: Search whether the queue is empty;
[0115] Continue the above steps and determine whether the search queue is empty. If it is not empty, it means that there are still pixels in the search queue that need to be traversed. If it is empty, it means that the pixels in the search queue have been completely traversed, and you can go to step S88 to end the traversal process.
[0116] S88: End.
[0117] Therefore, the present application proposes a novel and efficient raster vectorization method that can consume less time, mainly due to the algorithm's ability to preferentially find the outer contour and automatically match it with the inner contour without the need for additional matching operations. At the same time, the traversed contour result naturally meets the requirements of the shp file for the contour point order, that is, the outer contour is counterclockwise and the inner contour is clockwise, without the need to check the point order additionally. It is also possible to control the vectorization results to maintain synonymy when the inner and outer contours share contour points. In addition, the present application can not only vectorize the entire map, but also support independent vectorization of one or more polygons at any specified position.
[0118] In order to illustrate the technical solution of the present application, the present application also provides a mobile terminal, see Fig.14 , Fig.14: is a schematic block diagram of the structure of an embodiment of a mobile terminal of the present application, wherein the mobile terminal 90 includes:
[0119] An access module 91, used for accessing a grid pixel to be accessed, wherein a plurality of grid pixels form a grid pattern;
[0120] A filling module 92, for performing water filling according to the category of the pixel, so as to determine access information of unique nodes and edge information at multiple branches between multiple grid pixels in the grid pattern;
[0121] A construction module 93, used for extracting a connected domain by accessing information and constructing a contour map of the connected domain;
[0122] The separation module 94 is used to separate the contour map and combine multiple contour maps until all grid pixels are visited and traversed to obtain a vector map of the grid pattern.
[0123] Therefore, the present application proposes a method for vectorizing a raster pattern. Based on the traversal module 91, on the basis of visiting and traversing the raster pattern composed of multiple raster pixels, when contour points are shared at multiple branches, the filling module 92 uses the immersion filling method to control and automatically select unique node and edge information, and implement the construction module 93 to construct the contour map, so that the vectorization result of the raster pattern remains synonymous, and the separation module 94 separates the contour map to obtain a unique vector map.
[0124] In order to illustrate the technical solution of the present application, the present application also provides an electronic device, which can be a computer or a mobile phone, etc., without specific limitation. Fig.15 , Fig.15 It is a schematic block diagram of the structure of an electronic device embodiment of the present application. The electronic device 100 includes: a processor 110 and a memory 120. The memory 120 stores a computer program 121. The processor 110 is used to execute the computer program 121 to implement a vectorization method as in the embodiment of the present application, which will not be repeated here.
[0125] In addition, this application also provides a computer-readable storage medium, see Fig.16 , Fig.16 It is a circuit schematic block diagram of an embodiment of a computer-readable storage medium of the present application. The computer-readable storage medium 200 stores a computer program 201. When the computer program 201 is executed by a processor, it can implement the vectorization method of the embodiment of the present application, which will not be described in detail here.
[0126] If it is implemented in the form of a software functional unit and sold or used as an independent product, it can also be stored in a device with a storage function. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage device, including a number of instructions (program data) to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to perform all or part of the steps of each implementation method of the present invention. The aforementioned storage device includes: various media such as USB flash drive, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disk, and electronic devices such as computers, mobile phones, laptops, tablet computers, cameras, etc. with the above storage media.
[0127] The description of the execution process of the program data in the device with storage function can refer to the description in the method embodiment of the present application mentioned above, which will not be repeated here.
[0128] The above descriptions are merely embodiments of the present application and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A method for vectorizing a raster pattern, characterized in that: The vectorization method comprises: Accessing a grid pixel to be accessed, a plurality of the grid pixels forming the grid pattern; Performing water filling according to the category of the grid pixels to determine access information of unique nodes and edge information at multiple branches between multiple grid pixels in the grid pattern; Extracting a connected domain through the access information, and constructing a contour map of the connected domain; Until all the grid pixels are visited and traversed, the contour map is separated and a plurality of the contour maps are combined to obtain a vector map of the grid pattern; The step of performing water filling according to the category of the grid pixels to determine access information of unique nodes and edge information at multiple branches between multiple grid pixels in the grid pattern includes: In the forward direction of accessing the grid pixel, at multiple branches, with the current pixel as the center, determining whether other pixels are consistent with the category of the current pixel by flood filling; When an object or image boundary whose category is inconsistent with the current pixel is encountered in the search direction, a directed edge of a first direction point sequence is constructed for two grid corner points on the boundary, and the directed edge of the first direction point sequence is used to form an outer contour; When an object of the same category as the current pixel is encountered in the search direction, a directed edge of the second direction point sequence is constructed for two grid corner points on the boundary, and the directed edge of the second direction point sequence is used to form an inner contour.
2. The vectorization method according to claim 1, characterized in that: After the step of determining the category between other pixels and the current pixel, the vectorization method further comprises: The nodes and edge information of the directed edges and the outline graph of the connected domain are stored in a hash table and an adjacency table.
3. The vectorization method according to claim 2, characterized in that: The step of extracting a connected domain through the access information and constructing a contour map of the connected domain comprises: According to the preset rule of the vector file for the sequence of contour points, it is determined whether the accessed closed connected domain path is a first direction polygon or a second direction polygon; If it is a first direction polygon, construct the first direction polygon as an outer contour and save it in a preset file; If it is a second direction polygon, the second direction polygon is constructed as an inner contour and saved in a preset file.
4. The vectorization method according to claim 3, characterized in that: The step of constructing a directed edge of a first direction point sequence for two grid corner points on the boundary includes: In the forward direction of accessing the grid pixel, starting from any point of the current pixel, determine that the out-degree and in-degree of each node in the contour map are not 1, then Determine if there are common nodes between inner and outer contours during the access process; Calculating the vector product of the path vectors before and after the common node; When it is determined that the vector product is greater than 0, the access direction of the branch path corresponding to the vector product greater than 0 is selected to continue to move forward to form a closed contour.
5. The vectorization method according to claim 3, characterized in that: The step of constructing a directed edge of a first direction point sequence for two grid corner points on the boundary includes: Determine that the out-degree and in-degree of each node in the contour graph are 1, then the visit process will not encounter branches; Continue in the access direction to form a closed contour.
6. A mobile terminal, characterized in that: The mobile terminal comprises: An access module, used for accessing a grid pixel to be accessed, wherein a plurality of the grid pixels form a grid pattern; A filling module, used for performing water-filling according to the category of the grid pixel to determine access information of unique nodes and edge information at multiple branches between multiple grid pixels in the grid pattern; in the forward direction of accessing the grid pixel, taking the current pixel as the center at multiple branches, judging whether other pixels are consistent with the category of the current pixel by water-filling; when encountering an object or image boundary whose category is inconsistent with that of the current pixel in the search direction, constructing a directed edge of a first direction point sequence for two grid corner points on the boundary, and the directed edge of the first direction point sequence is used to form an outer contour; when encountering an object of the same category as that of the current pixel in the search direction, constructing a directed edge of a second direction point sequence for two grid corner points on the boundary, and the directed edge of the second direction point sequence is used to form an inner contour; A construction module, used for extracting a connected domain through the access information and constructing a contour map of the connected domain; The separation module is used to separate the contour map and combine multiple contour maps until all the grid pixels are visited and traversed to obtain the vector map of the grid pattern.
7. An electronic device, characterized in that: include: A processor and a memory, wherein the memory stores a computer program, and the processor is used to execute the computer program to implement the vectorization method according to any one of claims 1 to 5.
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 processor, the vectorization method according to any one of claims 1 to 5 is implemented.
