Image vectorization method and device, equipment and medium
By generating an SVG list based on the original bitmap and the rendered bitmap during the vectorization process of complex images, and deciding whether to continue to generate a new SVG list based on the image loss, the problem of poor vectorization quality in the prior art is solved. , achieving higher quality vectorization effect.
Patent Information
- Application Number
- CN202411541447.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-30
- Publication Date
- 2025-02-11
AI Technical Summary
The prior art is poor in vectorization of complex images, especially the first strategy is limited by the size and diversity of training data and the ability to generate models, while the second strategy relies on pre-arranged image processing technology. accuracy.
By generating an SVG list based on the original bitmap and the rendered bitmap, the image loss between the rendered bitmap generated by the SVG list and the original bitmap is calculated, and a vector map is generated when the loss meets the preset value. This method does not need to preset the number of SVG commands, and decides whether to continue to generate a new SVG list based on the rendering effect of the current SVG list.
Improve the vectorization quality of complex images, ensure that the vectorized image is as close as possible to the original bitmap, and reduces flaws in the vectorization process.
Smart Images

Figure CN119417948A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image vectorization method, device, equipment and medium. Background Art
[0002] Scalable Vector Graphics (SVG) describes images through multiple sets of parameterized shapes. Compared with bitmap formats, each shape is highly editable and can be scaled to any resolution without blurring. Related technologies There are usually two strategies for converting bitmaps to SVG format for storage. One strategy is to collect data to build and train a generative model, and the trained generative model predicts the SVG path that best matches the input bitmap; the other strategy is to split the image into multiple components through image processing technology, and apply rule-based methods or optimization methods to convert each component into SVG commands.
[0003] However, the first strategy is limited by the size and diversity of training data and the ability to generate models, while the second strategy relies on the accuracy of pre-processed image processing technology. Both strategies produce poor vectorization results when faced with complex graphics. Summary of the invention
[0004] The present application provides an image vectorization method, apparatus, device and medium to solve the technical problem of poor vectorization quality of complex images.
[0005] In a first aspect, an image vectorization method is provided, comprising: generating a first scalable vector image SVG list of step n based on an original bitmap and a first rendered bitmap, wherein the SVG list includes multiple SVG paths and the color filled in a closed figure obtained by rendering each SVG path; wherein, when n=1, the first rendered bitmap is a pure white image; when n is an integer greater than 1, the first rendered bitmap is obtained based on the SVG list generated in step n-1; calculating the image loss between a second rendered bitmap and the original bitmap, the second rendered bitmap being generated based on the first SVG list; when the image loss between the second rendered bitmap and the original bitmap satisfies a first preset value, using the first SVG list as a target SVG list, and generating a vector image based on the target SVG list.
[0006] In a second aspect, an image vectorization device is provided, characterized in that it includes: a processing module, used to generate a first scalable vector image SVG list of step n based on an original bitmap and a first rendering bitmap, the SVG list including multiple SVG paths and the color filled in a closed figure rendered by each SVG path; wherein, when n=1, the first rendering bitmap is a pure white image; when n is an integer greater than 1, the first rendering bitmap is obtained based on the SVG list generated in step n-1; a calculation module, used to calculate the image loss between the second rendering bitmap and the original bitmap, the second rendering bitmap being generated based on the first SVG list; a generation module, used to use the first SVG list as a target SVG list and generate a vector image based on the target SVG list when the image loss between the second rendering bitmap and the original bitmap meets a first preset value.
[0007] In a third aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned image vectorization method when executing the computer program.
[0008] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned image vectorization method are implemented.
[0009] In the scheme implemented by the above-mentioned image vectorization method, device, equipment and medium, the first SVG list of the current step is generated by the original bitmap and the pure white image or the rendering bitmap generated by the current existing SVG list, and the image loss between the second rendering bitmap generated by the first SVG list and the original bitmap is calculated to determine whether the currently generated SVG list can generate an accurate vector map. When the image loss meets the first preset value, it means that the first SVG list is accurate enough, so the vector map generated based on the first SVG is close enough to the original bitmap. This application does not need to pre-set the number of SVG commands, but decides whether a new SVG list needs to be generated based on the difference between the image rendered by the current existing SVG list and the original bitmap. For input images of different complexities, fine image vectorization can be achieved, thereby improving the quality of image vectorization. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application 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 creative labor.
[0011] Figure 1 is a schematic diagram of an application environment of an image vectorization method in an embodiment of the present application;
[0012] Figure 2 is a flow chart of an image vectorization method in one embodiment of the present application;
[0013] Figure 3 is a flow chart of an image vectorization method in another embodiment of the present application;
[0014] Figure 4 yes Figure 1 A schematic flow chart of a specific implementation of step S10;
[0015] Figure 5 is a schematic diagram of components in an embodiment of the present application;
[0016] Figure 6 yes Figure 4 A schematic flow chart of a specific implementation of step S14;
[0017] Figure 7 This is a flowchart of a method for updating an SVG list in an embodiment of the present application;
[0018] Figure 8 yes Figure 7 A schematic flow chart of a specific implementation of step S50;
[0019] Fig. 9 is a flow chart of an image vectorization method in another embodiment of the present application;
[0020] Fig.10 is a structural schematic diagram of an image vectorization device in one embodiment of the present application;
[0021] Fig.11 is a structural schematic diagram of a computer device in one embodiment of the present application;
[0022] Fig.12 It is another structural schematic diagram of a computer device in one embodiment of the present application. DETAILED DESCRIPTION
[0023] 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 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.
[0024] As described in the background technology, Scalable Vector Graphics (SVG) describes images through multiple sets of parameterized shapes. Compared with bitmap formats, each shape is highly editable and can be scaled to any resolution without blur. Related technology The strategies for converting winning bitmaps to SVG format for storage can generally be divided into two types. One strategy is to collect data to build and train a generative model, and the trained generative model predicts the SVG path that best matches the input bitmap; the other strategy is to split the image into multiple components through image processing technology, and apply rule-based methods or optimization methods to convert each component into SVG commands. For example, Potrace converts the input bitmap into a grayscale image, and identifies the contours of the components in the image based on the grayscale changes of the pixels, traces the contours of these components and performs smoothing operations, converts the contours into Bezier curve components (Bezier Paths), and then merges adjacent components; VTracer first splits the image into multiple components based on information such as the color and connected areas of the input image, and then performs the subsequent Bezier Paths conversion process, which increases the ability to vectorize color images. Related tools propose a differentiable renderer that renders SVG parameters into bitmaps, randomly initializes multiple sets of SVG Command parameters, obtains gradients by calculating the mean square error loss between the rendered bitmap and the input bitmap, and uses the gradient descent method to optimize SVG parameters. Some tools optimize each set of SVG parameters on a global scale, and some existing technologies apply advanced semantic segmentation models to split images into components according to semantic information, and optimize the SVG parameters of each component separately, and finally splice the SVG parameters of each component.
[0025] However, the first strategy is limited by the size and diversity of training data and the ability to generate models, while the second strategy relies on the accuracy of pre-processed image processing technology. Both strategies produce poor vectorization results when faced with complex graphics.
[0026] The image vectorization method provided in the embodiment of the present application can be applied in the following aspects: Figure 1In an application environment, the client communicates with the server through a network. After the server receives the original bitmap input by the user, it generates the first SVG list of the nth step based on the original bitmap and the first rendering bitmap, generates the second rendering bitmap based on the first SVG list, and calculates the image loss between the second rendering bitmap and the original bitmap; updates the first SVG list based on the image loss to obtain the second SVG list; when the number of updates meets the first preset value and the image loss meets the second preset value, uses the second SVG as the target list, and generates a vector map based on the target list, which is output to the client, which can effectively improve the vectorization effect of complex images. Among them, the client can be but is not limited to various personal computers, laptops, smart phones, tablet computers and portable wearable devices. The server can be implemented with an independent server or a server cluster consisting of multiple servers. The present application is described in detail below through specific embodiments.
[0027] See also Figure 2 As shown, Figure 2 A flowchart of an image vectorization method provided in an embodiment of the present application includes the following steps:
[0028] S10: Generate a first SVG list of step n based on the original bitmap and the first rendered bitmap.
[0029] Among them, the original bitmap I∈R w×h×3 As the initial input image, w×h represents the number of image pixels, each pixel stores three values representing the colors of the three RGB channels respectively, and the position of each pixel value i∈{1,...,h×w} is represented by a one-dimensional index.
[0030] In some embodiments, an SVG list is automatically constructed based on the original bitmap and the first rendered bitmap, wherein the SVG list includes two lists, P and C. Is a list of N SVG Paths, defining each SVG Path p n It can be rendered as a closed shape, represented by k end-to-end cubic Bezier curves, each of which is defined by four control points, and each control point is represented by a one-dimensional index. n The index of the end control point of the j-th Bezier curve is equal to the index of the start control point of the j+1-th Bezier curve, where j=1,...,k-1. Each SVG Path n Renders a list of the colors c filled in the closed shape, where c is represented by the RGB channels.
[0031] In some embodiments, when n=1, it means that this is the first time that an SVG list is generated and there is no existing SVG list. Therefore, the first rendering bitmap at this time is a pure white image. Since most images have white backgrounds, the pixel values of the first rendering bitmap are set to 255.
[0032] In some other embodiments, when n is an integer greater than 1, the first rendering bitmap is rendered based on the SVG list generated in step n-1. The size of is consistent with the size of the original bitmap I.
[0033] The image vectorization method provided in this application can be applied to various application scenarios where vector graphics need to be generated. For example, in the sales field, some pictures in sales scenarios need vector graphics as elements, such as posters, PPT pictures, etc.
[0034] S20: Calculate the image loss between the second rendering bitmap and the original bitmap.
[0035] In some embodiments, the second rendering bitmap is generated based on the first SVG list. In one implementation, the rendering bitmap is obtained by inputting the first SVG list into a derivable vector graphics rasterization function render(·). The specific implementation method can refer to the relevant technology, and the embodiment of the present application will not be described in detail.
[0036] In some embodiments, the image global mean square error loss (MSE) is determined based on the pixel values of the second rendered bitmap and the original bitmap. in, represents the l2 norm, I represents the original bitmap, Represents the second rendering bitmap.
[0037] S30: When the image loss between the second rendered bitmap and the original bitmap satisfies a first preset value, the first SVG list is used as a target SVG list, and a vector image is generated based on the target SVG list.
[0038] Specifically, when L MSE When the vectorized image is smaller than the first preset value, it is considered that the vectorized image is sufficiently similar to the input original bitmap, so the n+1 step is not performed, and the system converts the current SVG list into the format of an SVG file and outputs it. Optionally, the first preset value is 10.
[0039] In an embodiment of the present application, there is no need to pre-set the number of SVG commands. Instead, a decision is made whether a new SVG list needs to be generated based on the difference between the image rendered by the current SVG list and the original bitmap. This allows fine image vectorization to be achieved for input images of different complexities, thereby improving the quality of image vectorization, ensuring that the vectorized image is as close to the original bitmap as possible, and reducing defects.
[0040] In some embodiments of the present application, when the image loss between the second rendering bitmap and the original bitmap does not satisfy the first preset value, generation of the (n+1)th first SVG list is performed until the image loss satisfies the first preset value. Figure 3 A flowchart of an image vectorization method provided in an embodiment of the present application includes the following steps:
[0041] S10: Generate a first SVG list of step n based on the original bitmap and the first rendered bitmap.
[0042] S20: Calculate the image loss between the second rendering bitmap and the original bitmap.
[0043] The second rendering bitmap is generated based on the first SVG list.
[0044] S30: When the image loss between the second rendered bitmap and the original bitmap satisfies a first preset value, the first SVG list is used as a target SVG list, and a vector image is generated based on the target SVG list.
[0045] S40: When the image loss between the second rendering bitmap and the original bitmap does not satisfy the first preset value, executing the generation of the first SVG list in step (n+1) until the image loss satisfies the first preset value.
[0046] That is, when the loss L between the second rendered bitmap and the original bitmap MSE When it is greater than or equal to the first preset value, a first rendering bitmap is generated based on the first SVG list, a first SVG list of step n+1 is generated based on the original bitmap and the first rendering bitmap, a second rendering bitmap of step n+1 is generated based on the first SVG list, the image loss between the second rendering bitmap and the original bitmap is calculated, and when the image loss between the second rendering bitmap and the original bitmap meets the first preset value, the first SVG list of step n+1 is used as the target SVG list, and a vector image is generated based on the target SVG list. When the image loss between the second rendering bitmap and the original bitmap does not meet the first preset value, the generation of the first SVG list of step n+2 is executed until the image loss meets the first preset value, and the cycle is repeated.
[0047] In an embodiment of the present application, there is no need to pre-set the number of SVG commands. Instead, a decision is made whether a new SVG list needs to be generated based on the difference between the image rendered by the current SVG list and the original bitmap. This allows fine image vectorization to be achieved for input images of different complexities, thereby improving the quality of image vectorization, ensuring that the vectorized image is as close to the original bitmap as possible, and reducing defects.
[0048] In some embodiments of the present application, a method for generating a first SVG list based on the original bitmap and the rendered bitmap in step S10 is provided, such as Figure 4 As shown, steps S11-S14 are included:
[0049] S11: Based on the pixel color difference between the original bitmap and the first rendering bitmap, pixels with the same color difference value are divided into a group.
[0050] In one embodiment, the pixel-by-pixel color difference between the original bitmap and the first rendered bitmap is calculated. i represents the index of the pixel in the image. All pixels are grouped according to their color difference values. Pixels with the same color difference values are grouped into the same group. The number of groups is the number of different color difference values.
[0051] For example, the original bitmap includes 100 pixels. By calculating with the 100 pixels of the first rendering bitmap, the color difference values of the 100 pixels are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9, respectively, which are a total of ten difference values. Then the pixels in the original bitmap with a color difference value of 0 with the first rendering bitmap are divided into a group, such as the 2nd, 6th, 9th, 16th, 30th, 38th, 60th, 66th, and 88th pixels are grouped together, and so on. No specific description is given. That is, the pixels of the original bitmap are divided into 10 groups according to the pixel color difference values.
[0052] S12: Select the target component with the largest number of pixels.
[0053] Among them, the component represents the pixel area with the same color that is connected within each group, and the connected means that there are pixels with the same color as the current pixel among the eight surrounding pixels.
[0054] For example, Figure 5 As shown, a group of pixels with the same color difference value are shown, which include four colors: black, white, red and green. Based on the definition of connectivity, it can be seen that two pixels with white color are connected and form a component; three pixels with black color are connected and form a component.
[0055] Optionally, the target component with the largest number of pixels is the component with the largest area among the components. In one implementation, all components are sorted according to the number of pixels, that is, the size of the component area, and the component with the largest number of pixels or the largest area is selected as the target component. Figure 5 Taking the pixel point shown as an example, the target component is the pixel area where three black pixels are located.
[0056] S13: Copy the original bitmap to obtain a copy bitmap, and set other pixels in the copy bitmap except the target component to a preset color to obtain a target copy bitmap.
[0057] S14: Generate a first SVG list based on the target copy bitmap.
[0058] Specifically, Figure 6 As shown, step S14 can be implemented as steps S141-S143:
[0059] S141: Input the target copy bitmap into the target function to obtain the contour point indexes of different color areas in the target copy bitmap.
[0060] The objective function is a function that can output the contour point index of different color areas based on the input image, for example, the findContours(·) function in OpenCV, or other functions that can achieve this function, which is not limited in the embodiments of the present application.
[0061] S142: Based on the contour point index, construct k Bezier curves.
[0062] Specifically, the index list of all contour points of the target component is obtained through the contour point indexes of different color areas. By selecting four consecutive points in the component contour point index list, the two middle contour points are taken as the indexes of the starting point and the end point of the cubic Bezier curve, and the indexes of the remaining two control points of the cubic Bezier curve are calculated based on the indexes of the four selected contour points, and the four control point indexes of a cubic Bezier curve are obtained. Until all contour points in the list are selected, k Bezier curves are constructed.
[0063] It is worth noting that the value of k is not predefined but is determined according to the number of contour points of the target component.
[0064] S143: Generate a first SVG list based on the k Bezier curves and the pixel colors of the target component.
[0065] Specifically, k Bezier curves are initialized to obtain the SVG Path p of the target component. n , p n The color filled in is the color of the pixel in the target component.
[0066] In some embodiments, if the current step is the generation of the first SVG list in step n, the SVG Path p obtained based on the K Bezier curves and the pixel color of the target component is n The fill color is added to the final SVG list obtained in step n-1.
[0067] In one implementation, the first SVG list of step n is obtained based on the splicing operation:
[0068] P = concat([P; p n ]),
[0069] C = concat([C; c n ]),
[0070] Where concat(·) represents the concatenation operation, and P and C represent the SVG lists finally generated in step n-1.
[0071] In an embodiment of the present application, the number of Bezier curves and the control point index in the SVG Path are initialized according to the size and contour index of each component in the original bitmap, rather than pre-setting the number of curves and randomly initializing the control point index, thereby reducing the optimization steps of the SVG Path parameters and speeding up the image vectorization speed.
[0072] In some embodiments of the present application, in order to reduce the number of optimization steps, after step S20, the first SVG list is updated a preset number of times based on the image loss, and then the image loss and the second preset value are judged. Figure 7 As shown, it also includes steps S50-S70:
[0073] S50: Based on the image loss between the second rendered bitmap and the original bitmap, the first SVG list is updated to obtain a second SVG list.
[0074] Specifically, Figure 8 As shown, step S50 can be implemented as steps S51-S52:
[0075] S51: Determine the global mean square error loss of the image, the distance-based local component loss, and the self-intersection constraint loss of the constrained Bezier curve self-intersection problem.
[0076] The global mean square error loss of the image is calculated based on the formula involved in step S30.
[0077] Distance-guided Local Component Loss (DLC) DLCTaking into account the local information of the target component, first calculate each pixel in the original bitmap I to the second rendering bitmap The distance d between the pixel positions of the nearest contour points of each rendered component i ∈{1,...,h×w}. The size of the distance corresponding to each pixel reflects the correlation between the pixel at that position in the original bitmap and the corresponding SVG list. Therefore, the weight d of each pixel for updating the corresponding SVG list is calculated based on the distance. i ′, the formula is as follows:
[0078]
[0079] Among them, i and j represent the index of the pixel point, d i and d j represents the pixel weight before the SVG list is updated, τ is a predefined distance threshold (10), and ReLU(·) is a nonlinear activation function that sets inputs less than 0 to 0 and keeps inputs greater than or equal to 0 unchanged.
[0080] Furthermore, the distance-based local component loss L DLC The calculation formula is as follows:
[0081]
[0082] Where c represents the index of the RGB channel.
[0083] By using the distance-based local component loss, the parameters in each SVG list are updated only based on the pixel information related to it. The local information of the component is used to make more refined parameter adjustments, and the pixels that are closer to the component outline index rendered by the SVG list provide more guidance information.
[0084] The global mean square error loss of the image and the distance-based local component loss are both calculated by calculating the difference between the rendered bitmap and the original bitmap, and the update of the SVG list is guided by the information of the original bitmap. However, if the optimization is performed only through the above losses, it is possible that the Bezier curves in the SVG Path will have self-intersection problems, resulting in some minor defects in the rendered components, and these defects may have little effect on the numerical value of the image-based loss. Therefore, the embodiment of the present application additionally adds a self-intersection constraint loss L to constrain the self-intersection problem of the Bezier curve. SC For any four control points of a Bezier curve in an existing SVG Path, represented by A, B, C and D, first calculate the vector and vector Whether the angle θ1 is greater than 180°, determines whether the current Bezier curve is drawn counterclockwise or clockwise, and is defined as D1 by the following formula:
[0085]
[0086] Where sign(·) represents the sign function, and × represents the vector cross product. If D1=1, it is considered to be drawn clockwise, and D1=0 is considered to be drawn counterclockwise. Calculate and The sin value of the angle θ2 between them is defined as D2:
[0087]
[0088] When the curve is drawn counterclockwise and θ2 is less than 180°, or when the curve is drawn clockwise and θ2 is greater than 180°, it is considered that the Bezier curve may have a self-intersection problem. According to the values of D1 and D2, the self-intersection constraint loss L SC is defined as follows:
[0089] L SC =D1(ReLU(-D2))+(1-D1)(ReLU(D2))
[0090] The loss L SC The design ensures that when a self-intersection problem occurs, one of the items will have a value greater than 0, thereby ensuring that after updating the SVG Path parameters and minimizing the loss of this item, the self-intersection problem can be avoided as much as possible.
[0091] S52: Based on the global mean square error loss of the image, the distance-based local component loss, and the self-intersection constraint loss of the constrained Bezier curve self-intersection problem, the first SVG list is updated to obtain a second SVG list.
[0092] Combining the above three losses, the overall loss L used to update the parameters in the existing first SVG list {P, C} can be defined as:
[0093] L=λ1L MSE +λ2L DLC +λ3L SC
[0094] Among them, λ1, λ2 and λ3 represent the weights of the loss. For example, λ1, λ2 and λ3 are set to 0.5, 1 and 0.01 respectively, so that L DLC The loss has the greatest impact on parameter updates.
[0095] Furthermore, the overall loss is calculated for the index P of the Bezier curve control point in the SVG list and the gradient of the parameters in the color C. and Update the parameters {P, C} in the SVG list by gradient descent. The formula is as follows:
[0096]
[0097] Wherein, α represents the learning rate when the index P is updated, and β represents the learning rate when the color C is updated. Optionally, α=1, β=0.01.
[0098] In an embodiment of the present application, during the process of updating the SVG list, global and component-based local information of the image are combined, more accurate parameter updates are achieved through multi-scale guidance information, and constraints on the self-intersection problem of Bezier curves are added to ensure that the vectorized image is as close as possible to the original input image and reduce defects.
[0099] S60: When the number of updates is greater than the second preset value, determining whether the image loss between the second rendering bitmap and the original bitmap satisfies the first preset value.
[0100] At this time, if the image loss between the second rendering bitmap and the original bitmap satisfies a first preset value, the second SVG list is used as the target SVG list.
[0101] S70: When the update number is less than or equal to the second preset value, generate a third rendering bitmap based on the second SVG list, and update the second SVG list based on the image loss between the third rendering bitmap and the original bitmap until the update number is greater than the second preset value.
[0102] That is, if Fig. 9 As shown, after the first SVG list of step n is generated based on the original bitmap and the first rendered bitmap, a second rendered bitmap is generated based on the first SVG list, the first SVG list is updated by calculating three losses between the second rendered bitmap and the original bitmap to generate a second SVG list, and whether to end the update of the first SVG list is determined by judging the number of updates of the first SVG list.
[0103] If the number of updates is greater than the second preset value, it is further determined whether the global mean square error loss of the image between the second rendered bitmap and the original bitmap is greater than the first preset value. If the image loss is greater than or equal to the first preset value, the generation of the first SVG list in step n+1 is performed, that is, returning to execute step S10; if the image loss is less than the first preset value, the second SVG list is used as the target SVG list to generate a vector graph.
[0104] If the number of updates is less than or equal to the second preset value, a third rendering bitmap is generated based on the second SVG list, and the second SVG list is updated by calculating the three losses between the third rendering bitmap and the original bitmap to generate a third SVG list. The number of updates of the second SVG list is determined to determine whether to end the update of the second SVG list. This cycle is repeated until the number of updates is greater than the second preset value and the image loss is less than the first preset value, the cycle is stopped, the final SVG list is used as the target SVG list, and a vector image is generated.
[0105] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0106] In one embodiment, an image vectorization device is provided, which corresponds one-to-one to the image vectorization method in the above embodiment. Fig.10 As shown, the image vectorization device includes a processing module 101, a calculation module 102, a generation module 103, and a relationship module 104. The functional modules are described in detail as follows:
[0107] The processing module 101 is used to generate a first scalable vector image SVG list of step n based on the original bitmap and the first rendering bitmap, wherein the SVG list includes multiple SVG paths and the color filled in the closed figure obtained by rendering each SVG path; wherein when n=1, the first rendering bitmap is a pure white image; and when n is an integer greater than 1, the first rendering bitmap is obtained based on the SVG list generated in step n-1;
[0108] A calculation module 102, configured to calculate an image loss between a second rendered bitmap and an original bitmap, wherein the second rendered bitmap is generated based on the first SVG list;
[0109] The generating module 103 is configured to use the first SVG list as a target SVG list and generate a vector image based on the target SVG list when the image loss between the second rendering bitmap and the original bitmap meets a first preset value.
[0110] In some embodiments, the processing module 101 is specifically used to divide pixels with the same color difference value into a group based on the pixel color difference between the original bitmap and the first rendered bitmap; select the target component with the largest number of pixels, the component represents the pixel area with the same color connected within each group, and the connected means that there are pixels with the same color among the eight pixels around the current pixel; copy the original bitmap to obtain a copy bitmap, set the other pixels in the copy bitmap except the target component to a preset color, and obtain a target copy bitmap; generate a first SVG list based on the target copy bitmap.
[0111] In some embodiments, the processing module 101 is specifically used to input the target copy bitmap into the target function to obtain the contour point indexes of different color areas in the target copy bitmap; based on the contour point indexes, construct k Bezier curves; based on the k Bezier curves and the pixel point colors of the target component, generate a first SVG list.
[0112] In some embodiments, an update module 104 is further included. The update module 104 is used to update the first SVG list based on the image loss between the second rendering bitmap and the original bitmap to obtain the second SVG list; when the number of updates is greater than the second preset value, determine whether the image loss between the second rendering bitmap and the original bitmap meets the first preset value; when the number of updates is less than or equal to the second preset value, generate a third rendering bitmap based on the second SVG list, and update the second SVG based on the image loss between the third rendering bitmap and the original bitmap until the number of updates is greater than the second preset value.
[0113] In some embodiments, the processing module 101 is specifically configured to use the second SVG list as a target SVG list.
[0114] In some embodiments, the update module 104 is specifically used to determine the global mean square error loss of the image, the distance-based local component loss, and the self-intersection constraint loss of the constrained Bezier curve self-intersection problem; based on the global mean square error loss of the image, the distance-based local component loss, and the self-intersection constraint loss of the constrained Bezier curve self-intersection problem, the first SVG list is updated.
[0115] In some embodiments, the first SVG list is updated based on the following formula:
[0116]
[0117] Where P′ represents the SVG path in the second SVG list, C′ represents the color in the second SVG list, P represents the SVG path in the first SVG list, C represents the color in the first SVG list, and L = λ1L MSE +λ2L DLC +λ3L SC , λ1, λ2, λ3 represent weights, L MSE Represents the global mean square error loss of the image, L DLC represents the distance-based local component loss, L SC Represents the self-intersection constraint loss for the constrained Bezier curve self-intersection problem.
[0118] The present application provides an image vectorization device, which does not need to pre-set the number of SVG commands. Instead, it decides whether a new SVG list needs to be generated based on the difference between the image rendered by the current existing SVG list and the original bitmap. It can achieve fine image vectorization for input images of different complexities, thereby improving the quality of image vectorization.
[0119] The specific definition of the image vectorization device can be found in the definition of the image vectorization method above, which will not be repeated here. Each module in the above-mentioned image vectorization device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0120] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.11 As shown. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external client via a network connection. When the computer program is executed by the processor, it implements the functions or steps of the server side of an image vectorization method.
[0121] In one embodiment, a computer device is provided. The computer device may be a client, and its internal structure diagram may be as follows: Fig.12 As shown. The computer device includes a processor, a memory, a network interface, a display screen and an input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server via a network connection. When the computer program is executed by the processor, it implements the functions or steps of a client side of an image vectorization method
[0122] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0123] Based on the original bitmap and the first rendered bitmap, a first scalable vector image SVG list of step n is generated, wherein the SVG list includes multiple SVG paths and the color filled in the closed figure obtained by rendering each SVG path; wherein, when n=1, the first rendered bitmap is a pure white image; when n is an integer greater than 1, the first rendered bitmap is obtained based on the SVG list generated in step n-1; the image loss between the second rendered bitmap and the original bitmap is calculated, and the second rendered bitmap is generated based on the first SVG list; when the image loss between the second rendered bitmap and the original bitmap satisfies a first preset value, the first SVG list is used as a target SVG list, and a vector image is generated based on the target SVG list.
[0124] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0125] Based on the original bitmap and the first rendered bitmap, a first scalable vector image SVG list of step n is generated, wherein the SVG list includes multiple SVG paths and the color filled in the closed figure obtained by rendering each SVG path; wherein, when n=1, the first rendered bitmap is a pure white image; when n is an integer greater than 1, the first rendered bitmap is obtained based on the SVG list generated in step n-1; the image loss between the second rendered bitmap and the original bitmap is calculated, and the second rendered bitmap is generated based on the first SVG list; when the image loss between the second rendered bitmap and the original bitmap satisfies a first preset value, the first SVG list is used as a target SVG list, and a vector image is generated based on the target SVG list.
[0126] It should be noted that the above functions or steps that can be implemented by the computer-readable storage medium or computer device can refer to the relevant descriptions on the server side and the client side in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.
[0127] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0128] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0129] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
[0130] The non-Company software tools or components appearing in the embodiments of this application are merely examples and do not represent actual use.
Claims
1. An image vectorization method, characterized in that: include: Based on the original bitmap and the first rendered bitmap, a first scalable vector image SVG list of step n is generated, wherein the SVG list includes multiple SVG paths and the color filled in the closed figure obtained by rendering each SVG path; wherein when n=1, the first rendered bitmap is a pure white image; and when n is an integer greater than 1, the first rendered bitmap is obtained based on the SVG list generated in step n-1; Calculating an image loss between a second rendered bitmap and the original bitmap, the second rendered bitmap being generated based on the first SVG list; When the image loss between the second rendering bitmap and the original bitmap satisfies a first preset value, the first SVG list is used as a target SVG list, and a vector image is generated based on the target SVG list.
2. The method according to claim 1, characterized in that The step of generating the first scalable vector image SVG list in step n based on the original bitmap and the first rendered bitmap includes: Based on the pixel color difference between the original bitmap and the first rendering bitmap, pixels with the same color difference value are divided into a group; Select the target component with the largest number of pixels, where the component represents a pixel area that is connected and has the same color within each group, and the connection means that there are pixels with the same color as the current pixel among the eight surrounding pixels; The original bitmap is copied to obtain a copy bitmap, and other pixels in the copy bitmap except the target component are set to a preset color to obtain a target copy bitmap; The first SVG list is generated based on the target copy bitmap.
3. The method according to claim 2, characterized in that The step of generating the first SVG list based on the target copy bitmap includes: Inputting the target copy bitmap into the target function to obtain the contour point indexes of different color areas in the target copy bitmap; Based on the contour point index, construct k Bezier curves; The first SVG list is generated based on the k Bezier curves and the pixel color of the target component.
4. The method according to claim 1, characterized in that After calculating the image loss between the second rendered bitmap and the original bitmap, the method further includes: Based on the image loss between the second rendering bitmap and the original bitmap, updating the first SVG list to obtain a second SVG list; When the number of updates is greater than a second preset value, determining whether an image loss between the second rendered bitmap and the original bitmap satisfies a first preset value; When the update number is less than or equal to the second preset value, a third rendering bitmap is generated based on the second SVG list, and based on the image loss between the third rendering bitmap and the original bitmap, the second SVG list is updated until the update number is greater than the second preset value.
5. The method according to claim 4, characterized in that When the update number is greater than a second preset value, taking the first SVG list as a target SVG list includes: The second SVG list is used as the target SVG list.
6. The method according to claim 4, characterized in that The updating of the first SVG list based on the image loss between the second rendering bitmap and the original bitmap includes: Determine the image global mean square error loss, distance-based local component loss, and self-intersection constraint loss for constrained Bezier curve self-intersection problem; The first SVG list is updated based on the global mean square error loss of the image, the distance-based local component loss, and the self-intersection constraint loss of the constrained Bezier curve self-intersection problem.
7. The method according to any one of claims 4 to 6, characterized in that The first SVG list is updated based on the following formula: Where P′ represents the SVG path in the second SVG list, C′ represents the color in the second SVG list, P represents the SVG path in the first SVG list, C represents the color in the first SVG list, and L = λ1L MSE +λ2L DLC +λ3L SC , λ1, λ2, λ3 represent weights, L MSE Represents the global mean square error loss of the image, L DLC represents the distance-based local component loss, L SC Represents the self-intersection constraint loss for the constrained Bezier curve self-intersection problem.
8. An image vectorization device, characterized in that: include: A processing module, configured to generate a first scalable vector image SVG list of step n based on the original bitmap and the first rendered bitmap, wherein the SVG list includes a plurality of SVG paths and a color filled in a closed figure obtained by rendering each SVG path; wherein when n=1, the first rendered bitmap is a pure white image; and when n is an integer greater than 1, the first rendered bitmap is obtained based on the SVG list generated in step n-1; a calculation module, configured to calculate an image loss between a second rendered bitmap and the original bitmap, wherein the second rendered bitmap is generated based on the first SVG list; A generating module is used to use the first SVG list as a target SVG list and generate a vector image based on the target SVG list when the image loss between the second rendering bitmap and the original bitmap meets a first preset value.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the image vectorization method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the image vectorization method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
SVG processing method and device, storage medium and electronic equipment
CN116797702A
Method for synthesizing vector image through text guidance
CN118470149A
Superpixel-based sequence path vector graph synthesis method
CN118657855A
Method of encoding and decoding a graphics path sequence into a layered scheme
US20100322527A1