Image vectorization method, apparatus, device, and medium

By generating an SVG list and calculating image loss, the problem of poor vectorization of complex images is solved, achieving a refined vectorization effect. The generated vector graphics are close to the original bitmaps, reducing imperfections.

CN119417948BActive Publication Date: 2026-11-27PING AN TECH (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411541447.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-30
Publication Date
2026-11-27
Estimated Expiration
2044-10-30

AI Technical Summary

Technical Problem

Existing techniques produce poor results in the vectorization of complex images, especially complex graphics. Existing methods are limited by the diversity of training data and the capabilities of the generative model, or rely on the accuracy of pre-processing image techniques.

Method used

By generating an SVG list based on the original bitmap and the rendered bitmap, calculating image loss to determine the target SVG list, and iteratively generating accurate vector graphics, the number of SVG commands is avoided by pre-setting and the generation of the SVG list is determined by image differences.

Benefits of technology

It achieves fine vectorization of images with varying degrees of complexity, generating vector graphics that closely resemble the original bitmaps, reducing imperfections and improving vectorization quality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119417948B_ABST
    Figure CN119417948B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of image processing, and discloses an image vectorization method, device, equipment and medium, which comprises the following steps: based on an original bitmap and a first rendering bitmap, a first SVG list of the nth step is generated, the SVG list comprises a plurality of SVG paths and the color filled in a closed figure rendered by each SVG path; 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 the (n-1)th step; image loss between a second rendering bitmap and the original bitmap is calculated, the second rendering bitmap is generated based on the first SVG list; when the image loss between the second rendering bitmap and the original bitmap meets a first preset value, the first SVG list is taken as a target SVG list, and a vector image is generated based on the target SVG list. The vectorization quality of a complex image is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing technology, and in particular to an image vectorization method, apparatus, device and medium. Background Technology

[0002] Scalable Vector Graphics (SVG) describes images using multiple sets of parametric shapes. Compared to bitmap formats, these shapes offer greater editability and can be scaled to any resolution without blurring. Strategies for converting bitmaps to SVG format for storage typically fall into two categories: one involves collecting data to build and train a generative model, which then predicts the SVG path that best matches the input bitmap; the other strategy uses image processing techniques to break down the image into multiple components and applies rule-based or optimization methods to convert each component into SVG commands.

[0003] However, the first strategy is limited by the size and diversity of the training data and the capabilities of the generative model, while the second strategy relies on the accuracy of the preceding image processing techniques. Both strategies produce poor vectorization results when dealing with complex graphics. Summary of the Invention

[0004] This 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 SVG list in step n based on an original bitmap and a first rendered bitmap, wherein the SVG list includes multiple SVG paths and the color used to fill a closed shape rendered by 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, wherein 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, using the first SVG list as a target SVG list, and generating a vector image based on the target SVG list.

[0006] Secondly, an image vectorization apparatus is provided, characterized in that it includes: a processing module, configured to generate a first scalable vector graphic SVG list in 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 shape rendered by 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; a calculation module, configured to calculate the image loss between the second rendered bitmap and the original bitmap, wherein the second rendered bitmap is generated based on the first SVG list; and a generation module, configured to, when the image loss between the second rendered bitmap and the original bitmap satisfies a first preset value, use the first SVG list as a target SVG list and generate a vector graphic based on the target SVG list.

[0007] Thirdly, 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 executes the computer program to implement the steps of the above-described image vectorization method.

[0008] Fourthly, a computer-readable storage medium is provided, which stores a computer program that, when executed by a processor, implements the steps of the above-described image vectorization method.

[0009] In the aforementioned image vectorization methods, apparatuses, devices, and media, a first SVG list for the current step is generated using the original bitmap and a pure white image or a rendered bitmap generated from an existing SVG list. The image loss between the second rendered bitmap generated from the first SVG list and the original bitmap is calculated to determine if the currently generated SVG list can generate an accurate vector image. When the image loss meets a first preset value, it indicates that the first SVG list is sufficiently accurate, and therefore the vector image generated based on the first SVG is sufficiently close to the original bitmap. This application does not require pre-setting the number of SVG commands; instead, it determines whether a new SVG list needs to be generated based on the difference between the image rendered from the existing SVG list and the original bitmap. This allows for fine image vectorization for input images of varying complexity, improving the quality of image vectorization. Attached Figure Description

[0010] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0011] Figure 1 This is a schematic diagram of an application environment for an image vectorization method according to an embodiment of this application;

[0012] Figure 2 This is a flowchart illustrating an image vectorization method in one embodiment of this application;

[0013] Figure 3 This is a flowchart illustrating an image vectorization method in another embodiment of this application;

[0014] Figure 4 yes Figure 1 A schematic diagram of a specific implementation method for step S10;

[0015] Figure 5 This is a schematic diagram of components in one embodiment of this application;

[0016] Figure 6 yes Figure 4 A schematic diagram of a specific implementation method for step S14;

[0017] Figure 7 This is a flowchart illustrating an SVG list update method according to an embodiment of this application;

[0018] Figure 8 yes Figure 7 A schematic diagram of a specific implementation method for step S50;

[0019] Figure 9 This is a flowchart illustrating an image vectorization method in yet another embodiment of this application;

[0020] Figure 10 This is a schematic diagram of the structure of an image vectorization device in one embodiment of this application;

[0021] Figure 11 This is a schematic diagram of the structure of a computer device according to one embodiment of this application;

[0022] Figure 12 This is another structural schematic diagram of a computer device in one embodiment of this application. Detailed Implementation

[0023] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0024] As described in the background section, Scalable Vector Graphics (SVG) describes images using multiple sets of parameterized shapes. Compared to bitmap formats, these shapes offer greater editability and can be scaled to any resolution without blurring. Related technologies typically employ two strategies for converting bitmaps to SVG format for storage. One strategy involves collecting data to build and train a generative model, which then predicts the SVG path that best matches the input bitmap. The other strategy uses image processing techniques to break down the image into multiple components and applies rule-based or optimization methods to convert each component into SVG commands. For example, Potrace converts the input bitmap to grayscale and identifies the contours of components in the image based on pixel grayscale changes. It then traces these contours and performs smoothing operations, converting the contours into Bezier Paths components before merging adjacent components. VTracer, on the other hand, first breaks down the image into multiple components based on information such as the input image's color and connected regions before performing the subsequent Bezier Paths conversion process, increasing its ability to vectorize color images. Among the related tools, a differentiable renderer for SVG parameters to be rendered into a bitmap is proposed. It randomly initializes multiple sets of SVG Command parameters, obtains the gradient by calculating the mean squared error loss between the rendered bitmap and the input bitmap, and optimizes the SVG parameters using gradient descent. Some tools optimize each set of SVG parameters at a global scale. Some existing techniques apply advanced semantic segmentation models to split the image into components according to semantic information, optimize the SVG parameters of each component separately, and finally concatenate the SVG parameters of the components.

[0025] However, the first strategy is limited by the size and diversity of the training data and the capabilities of the generative model, while the second strategy relies on the accuracy of the preceding image processing techniques. Both strategies produce poor vectorization results when dealing with complex graphics.

[0026] The image vectorization method provided in this application embodiment can be applied to, for example, Figure 1In this application environment, the client communicates with the server via a network. After receiving the original bitmap input by the user, the server generates a first SVG list (step n) based on the original bitmap and a first rendered bitmap. It then generates a second rendered bitmap based on the first SVG list and calculates the image loss between the second rendered bitmap and the original bitmap. The server updates the first SVG list based on the image loss to obtain a second SVG list. When the number of updates meets a first preset value and the image loss meets a second preset value, the second SVG is used as the target list, and a vector graphic is generated based on the target list and output to the client. This effectively improves the vectorization effect of complex images. The client can be, but is not limited to, various personal computers, laptops, smartphones, tablets, and portable wearable devices. The server can be implemented using a standalone server or a server cluster consisting of multiple servers. The following detailed description of specific embodiments further illustrates this application.

[0027] Please see Figure 2 As shown, Figure 2 A flowchart illustrating the image vectorization method provided in this application embodiment includes the following steps:

[0028] S10: Based on the original bitmap and the first rendered bitmap, generate the first SVG list for step n.

[0029] Wherein, the original bitmap I∈R w×h×3 As the initial input image, w×h represents the number of pixels in the image. Each pixel stores three values ​​representing the three RGB color channels respectively. 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. The SVG list includes two lists: P and C. It is a list of N SVG Paths, where each SVG Path p is defined. n It can be rendered as a closed shape, represented by k connected cubic Bézier curves, each defined by four control points, each represented by a one-dimensional index. Because they are connected end-to-end, therefore p n The index of the last control point of the j-th Bézier curve is equal to the index of the starting control point of the (j+1)-th Bézier curve, where j = 1, ..., k-1. It is each SVG Pathp n The rendering produces a list of colors c that fill the closed shape, where c is represented by RGB channels.

[0031] In some embodiments, when n=1, it indicates that this is the first time the SVG list is generated and there is no existing SVG list. Therefore, the first rendered bitmap is a pure white image. Since most images have a white background, the pixel value of the first rendered bitmap is set to 255.

[0032] In other embodiments, when n is an integer greater than 1, the first rendered bitmap is rendered based on the SVG list generated in step (n-1). In this case, the first rendered bitmap... Its size is the same as that of the original bitmap I.

[0033] The image vectorization method provided in this application can be applied to various application scenarios that require the generation of vector graphics. For example, in the sales field, images in some sales scenarios require vector graphics as elements, such as posters and PPT images.

[0034] S20: Calculate the image loss between the second rendered bitmap and the original bitmap.

[0035] In some embodiments, the second rendered bitmap is generated based on the first SVG list. In one embodiment, the rendered bitmap is obtained by inputting the first SVG list into the differentiable vector rasterization function render(). For specific implementation details, please refer to related technologies. This application will not provide further details in the embodiments.

[0036] In some embodiments, the global mean square error (MSE) loss is determined based on the pixel values ​​of the second rendered bitmap and the original bitmap. In one embodiment, the global mean square error loss... in, Let l represent the l2 norm, and I represent the original bitmap. This represents the second rendered bitmap.

[0037] S30: When the image loss between the second rendered bitmap and the original bitmap meets the first preset value, the first SVG list is used as the target SVG list, and a vector graphic is generated based on the target SVG list.

[0038] Specifically, when L MSE If the value is less than the first preset value, it is considered that the vectorized image is already sufficiently similar to the original input bitmap, so step n+1 can be discontinued. The system then converts the current SVG list into SVG file format and outputs it. Optionally, the first preset value is 10.

[0039] In this embodiment, there is no need to pre-set the number of SVG commands. Instead, the decision on whether to generate a new SVG list is made based on the difference between the image rendered by the existing SVG list and the original bitmap. Fine image vectorization can be achieved for input images of different complexity, improving the quality of image vectorization and ensuring that the vectorized image is as close as possible to the original bitmap, thus reducing defects.

[0040] In some embodiments of this application, when the image loss between the second rendered bitmap and the original bitmap does not meet a first preset value, the generation of the (n+1)th first SVG list is performed until the image loss meets the first preset value. Figure 3 A flowchart illustrating the image vectorization method provided in this application embodiment includes the following steps:

[0041] S10: Based on the original bitmap and the first rendered bitmap, generate the first SVG list for step n.

[0042] S20: Calculate the image loss between the second rendered bitmap and the original bitmap.

[0043] The second rendered bitmap is generated based on the first SVG list.

[0044] S30: When the image loss between the second rendered bitmap and the original bitmap meets the first preset value, the first SVG list is used as the target SVG list, and a vector graphic is generated based on the target SVG list.

[0045] S40: When the image loss between the second rendered bitmap and the original bitmap does not meet the first preset value, execute the generation of the first SVG list in step n+1 until the image loss meets the first preset value.

[0046] That is, when the loss L between the second rendered bitmap and the original bitmap MSE When the value is greater than or equal to a first preset value, a first rendered bitmap is generated based on the first SVG list. A first SVG list for step n+1 is generated based on the original bitmap and the first rendered bitmap. A second rendered bitmap for step n+1 is generated based on the first SVG list. The image loss between the second rendered bitmap and the original bitmap is calculated. When the image loss between the second rendered bitmap and the original bitmap satisfies the first preset value, the first SVG list for step n+1 is used as the target SVG list, and a vector graphic is generated based on the target SVG list. 。 If the image loss between the second rendered bitmap and the original bitmap does not meet the first preset value, the generation of the first SVG list in step n+2 is performed until the image loss meets the first preset value, and this process is repeated.

[0047] In this embodiment, there is no need to pre-set the number of SVG commands. Instead, the decision on whether to generate a new SVG list is made based on the difference between the image rendered by the existing SVG list and the original bitmap. Fine image vectorization can be achieved for input images of different complexity, improving the quality of image vectorization and ensuring that the vectorized image is as close as possible to the original bitmap, thus reducing defects.

[0048] In some embodiments of this application, a method is provided for generating a first SVG list based on the original bitmap and the rendered bitmap in step S10, 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 rendered bitmap, group pixels with the same color difference value together.

[0050] In one implementation, the pixel-by-pixel color difference between the original bitmap and the first rendered bitmap is calculated. i represents the index of a pixel in the image. All pixels are grouped according to their color difference values. Pixels with the same color difference value are grouped together, and the number of groups is the number of different color difference values.

[0051] For example, if the original bitmap contains 100 pixels, and the color difference values ​​between these pixels and the 100 pixels in the first rendered bitmap are calculated to be 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 (ten different values ​​in total), then the pixels in the original bitmap with a color difference value of 0 are grouped together. For example, pixels 2, 6, 9, 16, 30, 38, 60, 66, and 88 would be grouped together, and so on. In other words, the pixels in the original bitmap are divided into 10 groups based on their color difference values.

[0052] S12: Select the target component with the largest number of pixels.

[0053] Here, a component represents a connected pixel region with the same color within each group, and connected means that there are pixels with the same color among the eight surrounding pixels of the current pixel.

[0054] For example, such as Figure 5 As shown, a set of pixels with the same color difference value is displayed, which includes four colors: black, white, red, and green. Based on the definition of connectivity, two white pixels are connected and form a component; three black pixels 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 their number of pixels, i.e., their area, and the component with the largest number of pixels or the component with the largest area is selected as the target component. Figure 5 Taking the pixel shown as an example, the target component is the pixel area where the three black pixels are located.

[0056] S13: Copy the original bitmap to obtain a copied bitmap, and set the other pixels in the copied bitmap except the target component to the preset color to obtain the target copied bitmap.

[0057] S14: Generate the first SVG list based on the target copied bitmap.

[0058] Specifically, such as 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 outline point indices of different color regions in the target copy bitmap.

[0060] The objective function is a function that can output the contour point indices of different color regions based on the input image. For example, the findContours() function in OpenCV, or other functions that can achieve this function, are also acceptable, and this application does not limit the implementation.

[0061] S142: Construct k Bézier curves based on the contour point index.

[0062] Specifically, by indexing the contour points of different color regions, a list of indices for all contour points of the target component is obtained. Four consecutive points are selected from the component's contour point index list, and the middle two contour points are used as the indices of the start and end points of the cubic Bézier curve, respectively. The indices of the remaining two control points of the cubic Bézier curve are then calculated based on the indices of the four selected contour points, resulting in the four control point indices of a cubic Bézier curve. This process continues until all contour points in the list are selected, constructing k Bézier curves.

[0063] It is worth noting that the value of k is not predefined, but is determined based on the number of contour points of the target component.

[0064] S143: Generate the first SVG list based on k Bézier curves and the pixel colors of the target component.

[0065] Specifically, the SVG Path p of the target component is obtained by initializing k Bézier curves. n p n The color filled in is the same as the color of the pixels in the target component.

[0066] In some embodiments, if the current execution is the first SVG list generation in step n, then the SVG Path p obtained based on K Bézier curves and the pixel colors of the target component will be used. n The fill color is added to the final SVG list obtained in step n-1.

[0067] In one implementation, the first SVG list in the nth step is obtained based on the splicing operation:

[0068] P = concat([P; p) ) n ]),

[0069] C = concat([C; c n ]),

[0070] Here, concat(·) represents the concatenation operation, and P and C represent the final SVG list generated in n-1 steps.

[0071] In this embodiment, the number of Bézier curves and the index of control points in the SVG Path are initialized based on the size and outline index of each component in the original bitmap, instead of presetting the number of curves and randomly initializing the index of control points. This reduces the optimization steps of the SVG Path parameters and speeds up the image vectorization process.

[0072] In some embodiments of this application, to reduce optimization steps, after step S20, the first SVG list is updated a preset number of times based on image loss, and then the image loss is compared with a second preset value. Figure 7 As shown, it also includes steps S50-S70:

[0073] S50: Update the first SVG list based on the image loss between the second rendered bitmap and the original bitmap, and obtain the second SVG list.

[0074] Specifically, such as Figure 8 As shown, step S50 can be implemented as steps S51-S52:

[0075] S51: Determine the global mean square error loss for the image, the distance-based local component loss, and the self-intersection constraint loss for the self-intersection problem of constrained Bézier curves.

[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 (DLC) DLCTaking into account the local information of the target component, the process first calculates the value of each pixel in the original bitmap I to the second rendered bitmap. The distance d between the nearest outline point and the outline points of each rendered component. i ∈{1,...,h×w}. 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 this distance. i ′, its formula is as follows:

[0078]

[0079] Where i and j represent the pixel indices, d i and d j τ represents the pixel weights before the SVG list is updated, τ is a predefined distance threshold (10), and ReLU(·) is a non-linear activation function that sets inputs less than 0 to 0, while inputs greater than or equal to 0 remain unchanged.

[0080] Furthermore, 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 utilizing distance-based local component loss, the parameters in each SVG list are updated only with information from the pixels associated with them. This allows for more refined parameter adjustments using information from the local components, with pixels closer to the component outline index rendered by the SVG list providing more guidance.

[0084] Both the global mean squared error loss and the distance-based local component loss are calculated by comparing the rendered bitmap with the original bitmap, using information from the original bitmap to guide the updating of the SVG list. However, optimization using only these losses may lead to self-intersection issues in the Bézier curves within the SVG path, resulting in minor imperfections in the rendered components. These imperfections may have little impact on the numerical value of the image-based loss. Therefore, this embodiment of the application additionally incorporates a self-intersection constraint loss L to address the self-intersection problem of Bézier curves. SC For any four control points of a Bézier curve in an existing SVG path, denoted as A, B, C, and D, first calculate the vector... sum vector Whether the included angle θ1 is greater than 180° determines whether the current Bézier curve is drawn counterclockwise or clockwise, and is defined by the following formula as D1:

[0085]

[0086] Where sign(·) represents the sign function, and × represents the vector cross product. If D1 = 1, it is considered to be drawn clockwise; if D1 = 0, it is considered to be drawn counterclockwise. Then calculate... and The sine value of the angle θ2 between them is defined as D2:

[0087]

[0088] If the curve is drawn counterclockwise and θ2 is less than 180°, or clockwise and θ2 is greater than 180°, then the Bézier curve is considered to have a potential self-intersection problem. Based on the values ​​of D1 and D2, the self-intersection constraint loss L... SC The definition is 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 terms will have a value greater than 0. This ensures that updating the SVG Path parameters and minimizing this term's loss can minimize the occurrence of self-intersection problems.

[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 constraint Bézier curve self-intersection problem, the first SVG list is updated to obtain the 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] Where λ1, λ2, and λ3 represent the weights of the loss. For example, λ1, λ2, and λ3 can be set to 0.5, 1, and 0.01 respectively, so that L DLC Losses have the greatest impact on parameter updates.

[0095] Furthermore, the gradient of the overall loss with respect to the index P of the control point of the Bézier curve in the corresponding SVG list and the parameters in the color C is calculated. and The parameters {P, C} in the SVG list are updated using gradient descent, as shown in the following formula:

[0096]

[0097] Where α represents the learning rate when index P is updated, and β represents the learning rate when color C is updated. Optionally, α = 1, β = 0.01.

[0098] In this embodiment, during the SVG list update process, both global image information and component-based local information are combined. More accurate parameter updates are achieved through multi-scale guidance information, and constraints on the self-intersection problem of Bézier curves are added to ensure that the vectorized image is as close as possible to the original input image, thereby reducing imperfections.

[0099] S60: When the number of updates is greater than the second preset value, determine whether the image loss between the second rendered bitmap and the original bitmap meets the first preset value.

[0100] At this point, if the image loss between the second rendered bitmap and the original bitmap meets the first preset value, then the second SVG list is used as the target SVG list.

[0101] S70: When the number of updates is less than or equal to the second preset value, generate a third rendered bitmap based on the second SVG list, and update the second SVG list based on the image loss between the third rendered bitmap and the original bitmap, until the number of updates is greater than the second preset value.

[0102] That is, such as Figure 9 As shown, after generating the first SVG list in step n 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, and a second SVG list is generated. The update of the first SVG list is determined by judging the number of times the first SVG list has been updated.

[0103] If the number of updates is greater than the second preset value, then it is further determined whether the global mean square error loss 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, then the generation of the first SVG list in step n+1 is performed, that is, the execution of step S10 is returned again. If the image loss is less than the first preset value, then the second SVG list is used as the target SVG list to generate a vector graphic.

[0104] If the number of updates is less than or equal to the second preset value, a third rendered bitmap is generated based on the second SVG list. The second SVG list is updated by calculating three losses between the third rendered bitmap and the original bitmap, generating the third SVG list. The number of updates to the second SVG list is used to determine whether to end the update process. This process is repeated until the number of updates exceeds the second preset value and the image loss is less than the first preset value. At this point, the loop stops, and the final SVG list is used as the target SVG list to generate a vector graphic.

[0105] It should be understood that the sequence number of each step in the above embodiments does not imply 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 this application.

[0106] In one embodiment, an image vectorization apparatus is provided, which corresponds one-to-one with the image vectorization methods described in the above embodiments. For example... Figure 10 As shown, the image vectorization device includes a processing module 101, a calculation module 102, a generation module 103, and a relation module 104. Detailed descriptions of each functional module are as follows:

[0107] Processing module 101 is used to generate a first scalable vector SVG list in step n based on the original bitmap and the first rendered bitmap. The SVG list includes multiple SVG paths and the color used to fill the closed shape rendered by each SVG path. 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.

[0108] Calculation module 102 is used to calculate the image loss between the second rendered bitmap and the original bitmap, the second rendered bitmap being generated based on the first SVG list;

[0109] The generation module 103 is used to take the first SVG list as the target SVG list and generate a vector graphic based on the target SVG list when the image loss between the second rendered bitmap and the original bitmap meets a first preset value.

[0110] In some embodiments, the processing module 101 is specifically used to: group 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, where the component represents a connected pixel region with the same color within each group, and connected means that there are pixels with the same color among the eight surrounding pixels of the current pixel; copy the original bitmap to obtain a copied bitmap, set the other pixels in the copied bitmap except the target component to a preset color, and obtain a target copied bitmap; and generate a first SVG list based on the target copied 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 regions in the target copy bitmap; construct k Bézier curves based on the contour point indexes; and generate a first SVG list based on the k Bézier curves and the pixel colors of the target component.

[0112] In some embodiments, an update module 104 is further included. The update module 104 is configured to update the first SVG list based on the image loss between the second rendered bitmap and the original bitmap to obtain a second SVG list; when the number of updates is greater than a second preset value, determine whether the image loss between the second rendered bitmap and the original bitmap meets a first preset value; when the number of updates is less than or equal to the second preset value, generate a third rendered bitmap based on the second SVG list, and update the second SVG based on the image loss between the third rendered 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 used to use the second SVG list as the target SVG list.

[0114] In some embodiments, the updating 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 Bézier curve self-intersection problem; and to update the first SVG list 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 Bézier curve self-intersection problem.

[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, and λ3 represent weights, and L MSE L represents the global mean square error loss of the image. DLC L represents the distance-based local component loss. SC This represents the self-intersection constraint loss for the self-intersection problem of constrained Bézier curves.

[0118] This application provides an image vectorization device that does not require pre-setting the number of SVG commands. Instead, it determines whether a new SVG list needs to be generated based on the difference between the image rendered by the existing SVG list and the original bitmap. This allows for fine image vectorization for input images of varying complexity, improving the quality of image vectorization.

[0119] Specific limitations regarding the image vectorization device can be found in the limitations of the image vectorization method above, and will not be repeated here. Each module in the aforementioned image vectorization device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in hardware or independently of the processor in a computer device, or stored in software in the memory of a computer device, so that the processor can call and execute the operations corresponding to each module.

[0120] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 11 As shown, the computer device includes a processor, memory, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile and / or volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The network interface is used to communicate with external clients via a network connection. When executed by the processor, the computer program implements the functions or steps of an image vectorization method on the server side.

[0121] In one embodiment, a computer device is provided, which may be a client, and its internal structure diagram may be as follows: Figure 12 As shown, the computer device includes a processor, memory, network interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface is used to communicate with an external server via a network connection. When executed by the processor, the computer program implements the functions or steps of a client-side 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 executes the computer program to perform the following steps:

[0123] Based on the original bitmap and the first rendered bitmap, a first scalable vector SVG list is generated in step n. The SVG list includes multiple SVG paths and the color used to fill the closed shape rendered by each SVG path. 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. 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 meets a first preset value, the first SVG list is used as the target SVG list, and a vector graphic is generated based on the target SVG list.

[0124] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor:

[0125] Based on the original bitmap and the first rendered bitmap, a first scalable vector SVG list is generated in step n. The SVG list includes multiple SVG paths and the color used to fill the closed shape rendered by each SVG path. 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. 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 meets a first preset value, the first SVG list is used as the target SVG list, and a vector graphic is generated based on the target SVG list.

[0126] It should be noted that the functions or steps that can be implemented by the computer-readable storage medium or computer device described above can be referred to the relevant descriptions on the server side and client side in the foregoing method embodiments. To avoid repetition, they will not be described one by one here.

[0127] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, 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. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0128] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to 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 above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

[0130] The software tools or components not belonging to our company that appear 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, the first scalable vector SVG list for step n is generated, including: grouping 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; selecting the target component with the largest number of pixels, where the component represents a connected pixel region with the same color within each group, and the connected region means that there are pixels with the same color among the eight surrounding pixels of the current pixel; copying the original bitmap to obtain a copied bitmap, setting the other pixels in the copied bitmap except for the target component to a preset color to obtain a target copied bitmap; generating the first SVG list based on the target copied bitmap; the SVG list includes multiple SVG paths and the color used to fill the closed shape rendered by 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; Calculate the image loss between the second rendered bitmap and the original bitmap, wherein 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 meets a first preset value, the first SVG list is used as the target SVG list, and a vector graphic is generated based on the target SVG list.

2. The method according to claim 1, characterized in that, The step of generating the first SVG list based on the target copied bitmap includes: The target bitmap is input into the target function to obtain the outline point indices of different color regions in the target bitmap; Based on the contour point index, construct k Bézier curves; The first SVG list is generated based on the k Bézier curves and the pixel colors of the target component.

3. 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 rendered bitmap and the original bitmap, the first SVG list is updated to obtain the second SVG list; When the number of updates exceeds the second preset value, determine whether the image loss between the second rendered 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, a third rendered bitmap is generated based on the second SVG list, and the second SVG list is updated based on the image loss between the third rendered bitmap and the original bitmap, until the number of updates is greater than the second preset value.

4. The method according to claim 3, characterized in that, When the number of updates exceeds a second preset value, the step of using the first SVG list as the target SVG list includes: Use the second SVG list as the target SVG list.

5. The method according to claim 3, characterized in that, The step of updating the first SVG list based on the image loss between the second rendered bitmap and the original bitmap includes: Determine the global mean square error loss for images, the distance-based local component loss, and the self-intersection constraint loss for the constrained Bézier 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 Bézier curve self-intersection problem.

6. The method according to any one of claims 3 to 5, characterized in that, The first SVG list is updated based on the following formula: in, This indicates the SVG path in the second SVG list. Represents the colors in the second SVG list. This indicates the path of the SVG in the first SVG list. Represents the colors in the first SVG list. , , , Indicates weight, This represents the global mean square error loss of the image. This represents the distance-based local component loss. This represents the self-intersection constraint loss for the self-intersection problem of constrained Bézier curves.

7. An image vectorization device, characterized in that, include: The processing module is used to generate a first scalable vector SVG list in step n based on the original bitmap and the first rendered bitmap, including: grouping 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; selecting the target component with the largest number of pixels, wherein the component represents a connected pixel region with the same color within each group, and the connected means that there are pixels with the same color among the eight surrounding pixels of the current pixel; copying the original bitmap to obtain a copy bitmap, setting the other pixels in the copy bitmap except the target component to a preset color to obtain a target copy bitmap; generating the first SVG list based on the target copy bitmap; the SVG list includes multiple SVG paths and the color filled in the closed shape rendered by 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 calculation module is used to calculate the image loss between the second rendered bitmap and the original bitmap, wherein the second rendered bitmap is generated based on the first SVG list; The generation module is used to take the first SVG list as the target SVG list and generate a vector graphic based on the target SVG list when the image loss between the second rendered bitmap and the original bitmap meets a first preset value.

8. 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, it implements the steps of the image vectorization method as described in any one of claims 1 to 6.

9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the image vectorization method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Superpixel-based sequence path vector graph synthesis method

    CN118657855A