Image vectorization method and device based on adaptive parameter adjustment
By obtaining the original vector path of the target mask of the raster image and optimizing the path using cubic Bezier curves and preset loss functions, the efficiency and accuracy problems in complex image vectorization processing are solved, and efficient and high-precision vector image generation is achieved.
Patent Information
- Application Number
- CN202510548534.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-28
- Publication Date
- 2025-08-15
AI Technical Summary
The prior art is inefficient and insufficient in image vectorization processing of complex images.
By obtaining the original vector paths of multiple target masks of the raster image to be vectorized, M target control points are determined in N control points based on the cubic Bezier curve, the target vector path is optimized using the preset loss function to generate the target vector image.
Improves the efficiency and accuracy of vector image acquisition, and reduces the error between the original and initial vector paths.
Smart Images

Figure CN120492655A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to an image vectorization method and device based on adaptive parameter adjustment. Background Art
[0002] Vector images refer to graphics described using straight lines and curves. The elements that make up a vector image are points, lines, rectangles, polygons, circles, and arcs, which are obtained through mathematical formulas. Because vector images do not retain their original appearance after editing, they have been widely used in technical fields such as digital media and graphic design in recent years.
[0003] Prior art methods for obtaining vector images include traditional image vectorization methods, deep learning-based image vectorization methods, and optimization-based image vectorization methods. Traditional image vectorization methods directly generate vector images by setting fixed geometric parameters. Deep learning-based image vectorization methods learn features from raster images and generate vector graphics. Optimization-based image vectorization methods optimize and generate vector graphics using differentiable rendering technology.
[0004] However, when using existing technologies to perform image vectorization processing on complex images, there are problems of low efficiency and insufficient vectorization accuracy. Summary of the Invention
[0005] Based on this, it is necessary to provide an image vectorization method and device based on adaptive parameter adjustment to address the above technical problems.
[0006] In a first aspect, an embodiment of the present invention provides an image vectorization method based on adaptive parameter adjustment, the method comprising:
[0007] For a plurality of target masks corresponding to the raster image to be vectorized, obtaining an original vector path of each target mask, wherein the original vector path is determined by N control points;
[0008] Based on the cubic Bezier curve, M target control points are determined from the N control points, and an initial vector path of each target mask is determined according to the M target control points, where M≤N;
[0009] Determining a target vector path according to the original vector path, the initial vector path, and a preset loss function;
[0010] A target vector image is generated according to the target vector path and the initial pixel values corresponding to the target mask.
[0011] In one embodiment, for a plurality of target masks corresponding to the raster image to be vectorized, obtaining the original vector path of each target mask includes:
[0012] Segmenting the raster image to be vectorized to obtain a plurality of target masks corresponding to the raster image to be vectorized;
[0013] Vectorization processing is performed on the multiple target masks to obtain an original vector path of each target mask.
[0014] In one embodiment, segmenting the raster image to be vectorized and obtaining a plurality of target masks corresponding to the raster image to be vectorized includes:
[0015] Performing mask processing on the raster image to be vectorized to obtain a plurality of first initial masks;
[0016] Segmenting the raster image to be vectorized according to a superpixel segmentation algorithm to obtain a plurality of superpixel connected regions;
[0017] Performing clustering processing on multiple superpixel connected regions to obtain multiple second initial masks;
[0018] Determining a plurality of first target masks according to an intersection-and-union ratio (IoU) between the plurality of first initial masks and the second initial masks corresponding to the first initial masks and a preset IoU value;
[0019] Sort the multiple first target masks according to their area sizes, and obtain impact factors corresponding to the multiple first target masks;
[0020] According to the influencing factor and the preset influencing factor, a plurality of target masks are determined from the plurality of first target masks.
[0021] In one embodiment, each of the original vector paths includes a plurality of cubic Bezier curves, each of the cubic Bezier curves is determined by four control points, and the method of determining M target control points from the N control points based on the cubic Bezier curves, and determining the initial vector path of each target mask based on the M target control points, includes:
[0022] Among the multiple cubic Bezier curves included in each of the original vector paths, filtering is performed in sequence on eight control points corresponding to two adjacent cubic Bezier curves according to a preset mutation condition and a preset intersection condition, so as to determine M target control points from the N control points;
[0023] According to the M target control points, an initial vector path of each target mask is obtained through a Bessel function.
[0024] In one embodiment, determining the target vector path according to the original vector path, the initial vector path, and a preset loss function includes:
[0025] performing sampling processing on the original vector path and the initial vector path to obtain a first sampling point set corresponding to the original vector path and a second sampling point set corresponding to the initial vector path, wherein the first sampling point set includes a plurality of first sampling points and the second sampling point set includes a plurality of second sampling points;
[0026] The target vector path is determined according to the first sampling point set, the second sampling point set, and the preset loss function, where the preset loss function is determined according to the mutual distance between the first sampling point and the second sampling point.
[0027] In one embodiment, the preset loss function can be defined by the following expression:
[0028]
[0029] Here, b represents each first sampling point included in the first sampling point set, and e represents each second sampling point included in the second sampling point set.
[0030] In one embodiment, before generating the target vector image according to the target vector path and the initial pixel values corresponding to the target mask, the method further includes:
[0031] Obtaining the value of each pixel of the target mask in the corresponding area of the raster image to be vectorized;
[0032] The values of multiple pixels are averaged to obtain the initial pixel value.
[0033] In one embodiment, it further includes:
[0034] The target vector image is optimized according to the raster image to be vectorized, M target control points and a preset structural geometry loss function.
[0035] In one embodiment, the preset structural geometry loss function is determined by a preset structural loss function and a preset geometric loss function, and the optimizing the target vector image according to the raster image to be vectorized, the M target control points, and the preset structural geometry loss function includes:
[0036] Determining the preset structural loss function according to each pixel value of the raster image to be vectorized and each pixel value of the corresponding target vector image;
[0037] Determining the preset geometric loss function according to the M target control points;
[0038] Determining the preset structural geometric loss function according to the preset structural loss function and the preset geometric loss function;
[0039] The target vector image is optimized by minimizing the preset structural geometry loss function.
[0040] In a second aspect, an embodiment of the present invention provides an image vectorization device based on adaptive parameter adjustment, the device comprising:
[0041] An original vector path acquisition module is used to acquire an original vector path of each of the target masks corresponding to the raster image to be vectorized, wherein the original vector path is determined by N control points;
[0042] An initial vector path acquisition module is used to determine M target control points from N control points based on a cubic Bezier curve, and to determine an initial vector path of each target mask according to the M target control points, where M≤N;
[0043] a target vector path acquisition module, configured to determine a target vector path based on the original vector path, the initial vector path, and a preset loss function;
[0044] The target vector image acquisition module is used to generate a target vector image according to the target vector path and the initial pixel value corresponding to the target mask.
[0045] The technical solution provided by the embodiment of the present invention has the following advantages compared with the existing technology:
[0046] An image vectorization method based on adaptive parameter adjustment provided by an embodiment of the present invention utilizes this method to obtain an original vector path for each target mask corresponding to a raster image to be vectorized, wherein the original vector path is determined by N control points; based on a cubic Bezier curve, M target control points are determined from the N control points, and an initial vector path for each target mask is determined based on the M target control points, where M ≤ N; a target vector path is determined based on the original vector path, the initial vector path, and a preset loss function; and a target vector image is generated based on the target vector path and the initial pixel values corresponding to the target mask. In this way, the initial vector path of the target mask is determined based on the M target control points obtained by simplifying the N control points, thereby improving the efficiency of obtaining the initial vector path and, in turn, the efficiency of obtaining the target vector image. Furthermore, the error between the original vector path and the initial vector path is reduced using a preset loss function, thereby improving the accuracy of obtaining the target vector image. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0048] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0049] Figure 1 A schematic diagram of a flow chart of an image vectorization method based on adaptive parameter adjustment provided by an embodiment of the present invention;
[0050] Figure 2 A schematic diagram of a process for generating a target vector image provided by an embodiment of the present invention;
[0051] Figure 3 A schematic diagram of obtaining a target mask provided by an embodiment of the present invention;
[0052] Figure 4 A schematic diagram of obtaining an original vector path provided by an embodiment of the present invention;
[0053] Figure 5 A schematic diagram of an original vector path and an initial vector path sampling process provided by an embodiment of the present invention;
[0054] Figure 6 A schematic diagram of obtaining a preset geometric loss function provided by an embodiment of the present invention;
[0055] Figure 7 A schematic diagram of an experimental comparison result provided by an embodiment of the present invention;
[0056] Figure 8 A schematic structural diagram of an image vectorization device based on adaptive parameter adjustment provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0057] In order to more clearly understand the above-mentioned objectives, features and advantages of the present invention, the scheme of the present invention will be further described below. It should be noted that, in the absence of conflict, the embodiments of the present invention and the features therein can be combined with each other.
[0058] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present invention, rather than all the embodiments.
[0059] In one embodiment, Figure 1-Figure 2 As shown, Figure 1 A flowchart of an image vectorization method based on adaptive parameter adjustment provided by an embodiment of the present invention is shown. Figure 2 A schematic diagram of a process for generating a target vector image provided by an embodiment of the present invention specifically includes the following steps:
[0060] S10: For multiple target masks corresponding to the raster image to be vectorized, obtain the original vector path of each target mask.
[0061] A raster image is an image whose smallest unit is composed of pixels. It contains only point information and will be distorted when scaled. A target mask is a matrix or array corresponding to multiple different target (i.e., foreground) objects included in the raster image to be vectorized. This mask controls image processing by defining the pixel values of these multiple targets. A primitive vector path is defined by N control points. A vector path is a path used to construct a vector image using control points and curves such as Bezier curves.
[0062] Specifically, when a raster image to be vectorized is obtained, the raster image to be vectorized includes multiple different target objects. The raster image to be vectorized includes target masks corresponding to the multiple different target objects, and the original vector path of each target mask is obtained.
[0063] Optionally, based on the above embodiment, in some embodiments of the present invention, one implementation of S10 may be:
[0064] S101: Segment the raster image to be vectorized and obtain multiple target masks corresponding to the raster image to be vectorized.
[0065] Optionally, based on the above embodiment, in some embodiments of the present invention, one implementation of S101 may be:
[0066] S1011: Perform mask processing on the raster image to be vectorized to obtain a plurality of first initial masks.
[0067] Specifically, when a raster image to be vectorized is obtained, mask processing is performed on the raster image to be vectorized to obtain a plurality of first initial masks.
[0068] Exemplary, reference Figure 3 As shown, for a raster image to be vectorized, for example Figure 3 (a) Mask processing can be performed by the automatic mask generator of the existing Segment Anything Model (SAM) to obtain multiple first initial masks corresponding to the raster image to be vectorized. Wherein, w and h represent the width and height of the raster image to be vectorized, respectively, and N1 represents the total number of the first initial masks, such as Figure 3 The multiple first initial masks in (b) are multiple areas with different colors, that is, the area corresponding to each color is a first initial mask, but the present invention is not specifically limited thereto, and those skilled in the art can set it according to actual conditions.
[0069] S1012: Segment the vectorized raster image according to a superpixel segmentation algorithm to obtain a plurality of superpixel connected regions.
[0070] Specifically, when a raster image to be vectorized is obtained, the raster image to be vectorized is segmented according to a superpixel segmentation algorithm to obtain a plurality of superpixel connected regions.
[0071] For example, following the above embodiment, we continue to refer to Figure 3 As shown, multiple superpixel connected regions are Figure 3 (c), but not limited thereto, the present invention is not specifically limited thereto, and those skilled in the art can set it according to actual conditions.
[0072] S1013: Perform clustering processing on multiple superpixel connected regions to obtain multiple second initial masks.
[0073] Specifically, after obtaining a plurality of superpixel connected regions, clustering processing is performed on the plurality of superpixel connected regions to obtain a plurality of second initial masks.
[0074] For example, multiple superpixel connected regions can be clustered using the existing density-based clustering algorithm (Density-Based Spatial Clustering of Applications with Noise, DBSCAN), such as Figure 3 As shown in (d), multiple second initial masks are obtained N2 represents the total number of multiple second initial masks, but is not limited thereto. The present invention is not specifically limited thereto, and those skilled in the art may set it according to actual conditions.
[0075] S1014: Determine a plurality of first target masks according to the intersection-and-union ratios (IoUs) of the plurality of first initial masks, the second initial masks corresponding to the first initial masks, and a preset IoUs value.
[0076] The Intersection over Union (IoU) is a metric used in computer vision to measure the degree of overlap between a predicted result and a true result. The preset IoU value is used to filter out redundant masks in the multiple first initial masks and the multiple second initial masks. The preset IoU value may be, for example, 0.85, but is not limited thereto. The present invention does not specifically limit this, and those skilled in the art may set it based on actual circumstances.
[0077] Specifically, for multiple first initial masks, the intersection-and-union ratio between the first initial mask and the second initial mask corresponding to the first initial mask is calculated, and the intersection-and-union ratio is compared with a preset intersection-and-union ratio value. In this way, redundant masks in the multiple first initial masks and the multiple second initial masks are filtered out to determine multiple first target masks.
[0078] It should be noted that when the intersection-and-union ratio between the first initial mask and the second initial mask corresponding to the first initial mask is high, the first initial mask is preferentially retained due to its smoother edge contour and richer semantic information. Based on this, the intersection-and-union ratio between the first initial mask and the second initial mask corresponding to the first initial mask can be determined by the following formula:
[0079]
[0080] Among them, MaskArea() is the area of the mask, ⊙ and Respectively represent the AND operation and OR operation for each element, represents the i-th second initial mask among multiple second initial masks, represents the jth first initial mask among multiple first initial masks.
[0081] S1015: Sort the multiple first target masks according to their area sizes, and obtain impact factors corresponding to the multiple first target masks.
[0082] The impact factor is used to further filter multiple first target masks. The impact factor can be determined according to the following expression:
[0083]
[0084] in, represents the i-th first target mask among multiple first target masks.
[0085] S1016: Determine multiple target masks from the multiple first target masks according to the impact factor and the preset impact factor.
[0086] The preset impact factor may be, for example, 0.1, but is not limited thereto. The present invention does not specifically limit this, and those skilled in the art may set it according to actual conditions.
[0087] Specifically, the impact factors corresponding to the multiple first target masks are obtained, and the impact factors are compared with the preset impact factors. When the impact factor is smaller than the preset impact factor, the first target mask corresponding to the impact factor is filtered out, thereby obtaining multiple target masks.
[0088] It should be noted that after obtaining the multiple target masks, the multiple target masks are decomposed into multiple levels, and each target mask is filled with an initial pixel value.
[0089] Alternatively, based on the above embodiment, in some embodiments of the present invention, one method for obtaining the initial pixel value may be to obtain the values of each pixel of the target mask corresponding to the region of the raster image to be vectorized, and then average the multiple pixel values to obtain the initial pixel value.
[0090] S102: Perform vectorization processing on multiple target masks to obtain an original vector path of each target mask.
[0091] Specifically, after obtaining multiple target masks from which redundant masks are filtered out, vectorization processing is performed on the multiple target masks to obtain original vector paths of the respective target masks.
[0092] S11: Based on the cubic Bezier curve, determine M target control points from the N control points, and determine the initial vector path of each target mask according to the M target control points.
[0093] Where M≤N. A cubic Bezier curve is a smooth vector curve drawn based on four control points.
[0094] Optionally, based on the above embodiment, in some embodiments of the present invention, each original vector path includes multiple cubic Bezier curves, and each cubic Bezier curve is determined by four control points, that is, it can be understood that each original vector path is determined by N control points. The value of N is determined by the number of multiple cubic Bezier curves that make up each original vector path. However, it should be noted that the N control points for each original vector path are pre-set, and there are redundant control points among the N control points that have little effect on drawing the original vector path. Based on this, in order to efficiently obtain the vector path of each target mask, the N control points of each original vector path are simplified to obtain M target control points, and the initial vector path of each target mask is further determined by the simplified M target control points. Based on this, one implementation method of S11 can be:
[0095] S111: Among the multiple cubic Bezier curves included in each original vector path, filtering processing is performed in sequence on eight control points corresponding to two adjacent cubic Bezier curves according to a preset mutation condition and a preset intersection condition, so as to determine M target control points from N control points.
[0096] The preset mutation condition refers to that any two adjacent cubic Bezier curves among the plurality of cubic Bezier curves cannot have mutations. The preset intersection condition refers to that any two adjacent cubic Bezier curves among the plurality of cubic Bezier curves cannot have intersections.
[0097] It should be noted that the preset mutation condition and the preset intersection condition are used to determine whether there are redundant control points among the eight control points corresponding to two adjacent cubic Bezier curves that have little impact on the drawn target mask. When both the preset mutation condition and the preset intersection condition are met, it indicates that there are redundant control points among the eight control points corresponding to the two adjacent cubic Bezier curves that have little impact on the drawn target mask. In this case, it is necessary to filter out the redundant control points to simplify the N control points and obtain M target control points.
[0098] Specifically, for the multiple cubic Bezier curves included in each original vector path, according to the preset mutation condition and the preset intersection condition, the eight control points of two adjacent cubic Bezier curves in the multiple cubic Bezier curves are iteratively judged in sequence to determine whether there are redundant control points that have little effect on drawing the target mask among the eight control points corresponding to the two adjacent cubic Bezier curves. When the preset mutation condition and the preset intersection condition are both met, it is determined that there are redundant control points among the eight control points corresponding to the two adjacent cubic Bezier curves, and the redundant control points are filtered until all redundant control points in the N control points corresponding to the multiple cubic Bezier curves are filtered, thereby obtaining M target control points.
[0099] Exemplary, reference Figure 4 As shown, the original vector path corresponding to the i-th target mask includes l cubic Bezier curves s i,j Represents the jth cubic Bezier curve among l cubic Bezier curves, cubic Bezier curve s i,j Adjacent cubic Bezier curves s i,j+1 , determine the cubic Bezier curve s i,j The four control points are p1, p2, p3, and p4, which determine the cubic Bezier curve s i,j+1The four control points are p5, p6, p7, and p8, and the preset mutation condition is set to: |180°-∠P3P4P5|<δ, where δ is a parameter used to determine whether a mutation occurs. δ can be 8°, for example. The preset intersection condition is: ∠P4P1P7<∠P2P1P7<90°, and ∠P4P7P1<∠P6P7P1<90°. When both the preset mutation condition and the preset intersection condition are met, it means that P3, P4, and P5 are redundant control points with little influence on drawing the target mask. It is necessary to filter the redundant control points P3, P4, and P5 to obtain the four target control points p1, p2, p7, and p8. Draw the cubic Bezier curve s based on the four target control points p1, p2, p7, and p8, and continue to judge the cubic Bezier curve s and the next adjacent cubic Bezier curve s. i,j+2 Whether there are redundant control points among the corresponding eight control points that have little impact on drawing the target mask, until all redundant control points among the N control points corresponding to the one cubic Bezier curve are filtered out to obtain M target control points. However, this is not limited to this, and the present invention is not specifically limited thereto. Persons skilled in the art can set this according to actual circumstances.
[0100] S112: According to the M target control points, an initial vector path of each target mask is obtained through a Bessel function.
[0101] Specifically, after obtaining M target control points, the Bessel function is used to draw and obtain the initial vector path of each target mask.
[0102] S12: Determine the target vector path according to the original vector path, the initial vector path, and the preset loss function.
[0103] The preset loss function is used to reduce the error between the original vector path and the initial vector path.
[0104] Specifically, after obtaining the initial vector path, in order to minimize the error between the original vector path and the initial vector path, the target vector path is determined according to the original vector path, the initial vector path and a preset loss function.
[0105] Optionally, based on the above embodiment, in some embodiments of the present invention, an implementation of S12 may be:
[0106] S121: Sampling the original vector path and the initial vector path to obtain a first sampling point set corresponding to the original vector path and a second sampling point set corresponding to the initial vector path.
[0107] The first sampling point set includes a plurality of first sampling points, and the second sampling point set includes a plurality of second sampling points.
[0108] Specifically, the original vector path and the initial vector path corresponding to the target mask are sampled respectively to obtain a first sampling point set corresponding to the original vector path and a second sampling point set corresponding to the initial vector path.
[0109] Exemplary, reference Figure 5 As shown, for the original vector path S of the i-th target mask i and the initial vector path S i 'Perform sampling processing to obtain the original vector path S i The corresponding first sampling point set B={b i,j (t)}, the second sampling point set E corresponding to the initial vector path = {e i,j (t)}. Among them, b i,j (t) represents the original vector path S corresponding to the i-th target mask i The sampling point at position t on the j-th cubic Bezier curve among the multiple cubic Bezier curves included, e i,j (t) represents the initial vector path S corresponding to the i-th target mask i The sampling point at position t on the j-th cubic Bezier curve among the multiple cubic Bezier curves is included. However, the present invention is not limited thereto, and those skilled in the art can set it according to actual conditions.
[0110] S122: Determine a target vector path according to the first sampling point set, the second sampling point set, and a preset loss function.
[0111] The preset loss function is determined based on the mutual distance between the first sampling point and the second sampling point. Based on this, the preset loss function can be defined by the following expression:
[0112]
[0113] Here, b represents each first sampling point included in the first sampling point set, and e represents each second sampling point included in the second sampling point set.
[0114] Specifically, after collecting a first sampling point set and a second sampling point set, determining a second sampling point closest to each first sampling point among multiple second sampling points, and determining a first sampling point closest to each second sampling point among multiple first sampling points, the points are substituted into a preset loss function to reduce the error between the original vector path and the initial vector path, thereby obtaining a target vector path.
[0115] For example, following the above embodiment, refer to Figure 5 As shown, for the original vector path S iThe first sampling point b1 on the path is determined, and the second sampling point closest to the first sampling point b1 is determined to be e1 among multiple second sampling points. For the initial vector path S i ', determine the first sampling point b2 closest to the second sampling point e2 among the multiple first sampling points, substitute the first sampling point b1, the second sampling point e1, the second sampling point e2, and the first sampling point b2 into the preset loss function to minimize the preset loss function, thereby reducing the error between the original vector path and the initial vector path, that is, the initial vector path gradually approaches the original vector path, thereby obtaining the target vector path.
[0116] S13: Generate a target vector image according to the target vector path and the initial pixel values corresponding to the target mask.
[0117] Specifically, after obtaining the target vector path corresponding to the target mask, rendering processing is performed according to the obtained target vector path and the initial pixel values corresponding to the target mask to generate a target vector image.
[0118] Thus, the image vectorization method based on adaptive parameter adjustment provided in this embodiment obtains the original vector path of each target mask corresponding to multiple target masks of the raster image to be vectorized, where the original vector path is determined by N control points; based on a cubic Bezier curve, M target control points are determined from the N control points, and the initial vector path of each target mask is determined based on the M target control points, where M ≤ N; the target vector path is determined based on the original vector path, the initial vector path, and a preset loss function; and the target vector image is generated based on the target vector path and the initial pixel values corresponding to the target mask. In this way, the initial vector path of the target mask is determined based on the M target control points obtained by simplifying the N control points, thereby improving the efficiency of obtaining the initial vector path, and thus improving the efficiency of obtaining the target vector image. Furthermore, the error between the original vector path and the initial vector path is reduced by using the preset loss function, thereby improving the accuracy of obtaining the target vector image.
[0119] Optionally, based on the above embodiment, in some embodiments of the present invention, since the initial pixel value is determined by averaging the pixel values of the target mask in the corresponding area of the raster image to be vectorized, the obtained target vector image may have large errors in color. Based on this, in order to obtain a high-quality target vector image, the following method is further included:
[0120] S14: Optimizing the target vector image according to the raster image to be vectorized, the M target control points, and a preset structural geometry loss function.
[0121] Among them, the preset structural geometry loss function is used to further optimize the parameters set for the target vector image in terms of pixel values.
[0122] Optionally, based on the above embodiment, in some embodiments of the present invention, an implementation of S14 may be:
[0123] S141: Determine a preset structural loss function according to each first pixel value of the raster image to be vectorized and each corresponding second pixel value on the target vector image.
[0124] Specifically, each first pixel value of the raster image to be vectorized and the second pixel value corresponding to each first pixel in the target vector image are obtained, and a preset structural loss function is calculated based on each first pixel value and the corresponding second pixel value.
[0125] Optionally, based on the above embodiment, in some embodiments of the present invention, the preset structural loss function may be determined by the following expression:
[0126]
[0127] in, represents a set of first pixel values of the raster image to be vectorized, and I represents a set of corresponding second pixel values on the target vector image.
[0128] S142: Determine a preset geometric loss function based on the M target control points.
[0129] Optionally, based on the above embodiment, in some embodiments of the present invention, the preset geometric loss function may be defined by the following expression:
[0130]
[0131] Among them, f orientation Represents the preset intersection loss function, which is used to determine whether the lines between the four control points do not intersect. intersect Represents the preset opposite direction loss function, which is used to determine whether the lines between the four control points do not have opposite directions. Represents the preset obtuse angle loss function, which is used to determine whether the line between the four control points has an obtuse angle.
[0132] Exemplary, reference Figure 6 As shown, since the cubic Bezier curve is determined by four control points, in order to ensure that a reasonable cubic Bezier curve can be obtained according to the four control points, the preset intersection loss function for the four control points P1, P2, P3, and P4 can be defined by the following expression:
[0133] f intersect (P1,P2,P3,P4)=AND(XOR(O(P1,P2,P3),O(P1,P2,P4)),XOR(O(P3,P4,P1),O(P3,P4,P2)))
[0134] The preset opposite direction function can be defined by the following expression:
[0135] f orientation (P1,P2,P3,P4)=AND(O(P1,P2,P3),O(P2,P3,P4))
[0136] The default obtuse angle loss function can be defined by the following expression:
[0137]
[0138] S143: Determine a preset structural-geometric loss function according to the preset structural loss function and the preset geometric loss function.
[0139] Specifically, a preset structural loss function and a preset geometric loss function are weightedly added to determine the preset structural geometric loss function.
[0140] Optionally, based on the above embodiment, in some embodiments of the present invention, the preset structural geometry loss function may be defined by the following expression:
[0141] L=L2+λ geometric L geometric
[0142] Among them, λ geometric Represents the weight of the preset geometric loss function, λ geometric For example, it can be 0.1, but is not limited thereto. The present invention does not specifically limit this, and those skilled in the art can set it according to actual conditions.
[0143] S144: Optimize the target vector image by minimizing a preset structural geometry loss function.
[0144] Specifically, by minimizing a preset structural geometry loss function, each pixel value of the target vector image is adjusted, thereby optimizing the target vector image.
[0145] In this way, the present invention optimizes the target vector image according to the raster image to be vectorized, M target control points and a preset structural geometry loss function, thereby improving the accuracy of obtaining the target vector image.
[0146] Optionally, based on the above embodiments, in some embodiments of the present invention, in order to verify that the present invention improves the accuracy and efficiency of obtaining the target vector image compared with the prior art, experiments are conducted based on public data sets such as Noto Emoji, FluentEmoji and Iconfont under the condition that the experimental conditions are the same, and the present invention is compared with existing image vectorization algorithms such as O&R, SGLIVE and LIVE, and seven evaluation indicators are selected for quantitative comparison, specifically including: (1) the number of paths, which is used to characterize the ability to adaptively adopt the minimum number of vector paths; (2) the number of control points and color parameters, which is used to characterize the ability to effectively reduce the parameter scale of the vector image; (3) generation time; (4) mean square error (MSE); (5) learning perceptual image block similarity (LPIPS); (6) peak signal-to-noise ratio (PSNR) in pixel distance; (7) structural similarity index (SSIM). The experimental comparison results are shown in Table 1 below.
[0147] Table 1 Comparison of experimental results
[0148]
[0149] As can be seen from Table 1, compared with the prior art, the present invention can obtain a high-quality target vector image using fewer paths and parameters, and improves the efficiency of obtaining the target vector image.
[0150] For further reference, Figure 7 As shown, the fixed vector paths are pre-set to 256 and 64, respectively. Acquiring a target vector image using a fixed vector path results in a large number of redundant shapes for simple graphics, and a loss of detail for complex graphics. In contrast, the present invention dynamically adjusts based on image complexity, improving the efficiency and accuracy of acquiring the target vector image.
[0151] It should be understood that although Figures 1 to 7 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. In addition, Figures 1 to 7 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0152] In one embodiment, Figure 8As shown, an image vectorization device based on adaptive parameter adjustment is provided, which includes: an original vector path acquisition module 10, an initial vector path acquisition module 11, a target vector path acquisition module 12 and a target vector image acquisition module 13.
[0153] The original vector path acquisition module 10 is used to acquire the original vector path of each target mask corresponding to the raster image to be vectorized, wherein the original vector path is determined by N control points.
[0154] The initial vector path acquisition module 11 is configured to determine M target control points from N control points based on a cubic Bezier curve, and determine an initial vector path of each target mask according to the M target control points, wherein M≤N.
[0155] The target vector path acquisition module 12 is configured to determine the target vector path according to the original vector path, the initial vector path and a preset loss function.
[0156] The target vector image acquisition module 13 is configured to generate a target vector image according to the target vector path and the initial pixel values corresponding to the target mask.
[0157] In the above embodiment, the original vector path acquisition module acquires the original vector path for each target mask corresponding to the raster image to be vectorized, where the original vector path is determined by N control points. The initial vector path acquisition module determines M target control points from the N control points based on a cubic Bezier curve, and determines the initial vector path for each target mask based on the M target control points, where M ≤ N. The target vector path acquisition module 12 determines the target vector path based on the original vector path, the initial vector path, and a preset loss function. The target vector image acquisition module generates a target vector image based on the target vector path and the initial pixel values corresponding to the target mask. In this way, the initial vector path of the target mask is determined based on the M target control points obtained by simplifying the N control points, thereby improving the efficiency of acquiring the initial vector path and, in turn, the efficiency of acquiring the target vector image. Furthermore, the error between the original vector path and the initial vector path is reduced using the preset loss function, thereby improving the accuracy of acquiring the target vector image.
[0158] The specific definition of the image vectorization device based on adaptive parameter adjustment can be found in the definition of the image vectorization method based on adaptive parameter adjustment above and will not be repeated here. Each module in the aforementioned server can be implemented in whole or in part through software, hardware, or a combination thereof. Each of the aforementioned modules can be embedded in or independent of a processor in a computer device in hardware form, or stored in a memory in the computer device in software form, so that the processor can call and execute the corresponding operations of each module.
[0159] The embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon. The computer program is used by a processor to implement the image vectorization method based on adaptive parameter adjustment provided by the embodiment of the present invention. For example, when the computer program is executed by the processor, the computer program can be implemented. Figures 1 to 2 The technical solutions of any of the illustrated method embodiments have similar implementation principles and technical effects, which will not be described in detail here.
[0160] Those skilled in the art will appreciate that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program. 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, database or other media used in the embodiments provided by the present invention can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. 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 random access memory (SRAM) and dynamic random access memory (DRAM).
[0161] The technical features of the above embodiments can be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0162] The above-described embodiments merely illustrate several implementations of the present invention, and while their descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent. It should be noted that a person skilled in the art would be able to make numerous variations and improvements without departing from the spirit of the present invention, all of which fall within the scope of protection of the present invention. Therefore, the scope of protection of the patent for this invention shall be determined by the appended claims.
Claims
1. An image vectorization method based on adaptive parameter adjustment, characterized in that: The method comprises: For a plurality of target masks corresponding to the raster image to be vectorized, obtaining an original vector path of each target mask, wherein the original vector path is determined by N control points; Based on the cubic Bezier curve, M target control points are determined from the N control points, and an initial vector path of each target mask is determined according to the M target control points, where M≤N; Determining a target vector path according to the original vector path, the initial vector path, and a preset loss function; A target vector image is generated according to the target vector path and the initial pixel values corresponding to the target mask.
2. The method according to claim 1, characterized in that The step of obtaining the original vector path of each of the plurality of target masks corresponding to the raster image to be vectorized includes: Segmenting the raster image to be vectorized to obtain a plurality of target masks corresponding to the raster image to be vectorized; Vectorization processing is performed on the multiple target masks to obtain an original vector path of each target mask.
3. The method according to claim 2, characterized in that The step of segmenting the raster image to be vectorized and obtaining a plurality of target masks corresponding to the raster image to be vectorized includes: Performing mask processing on the raster image to be vectorized to obtain a plurality of first initial masks; Segmenting the raster image to be vectorized according to a superpixel segmentation algorithm to obtain a plurality of superpixel connected regions; Performing clustering processing on multiple superpixel connected regions to obtain multiple second initial masks; Determining a plurality of first target masks according to an intersection-and-union ratio (IoU) between the plurality of first initial masks and the second initial masks corresponding to the first initial masks and a preset IoU value; Sort the multiple first target masks according to their area sizes, and obtain impact factors corresponding to the multiple first target masks; According to the influencing factor and the preset influencing factor, a plurality of target masks are determined from the plurality of first target masks.
4. The method according to claim 1, wherein Each of the original vector paths includes a plurality of cubic Bezier curves, each of the cubic Bezier curves is determined by four control points. Based on the cubic Bezier curves, M target control points are determined from the N control points, and the initial vector path of each target mask is determined according to the M target control points, including: Among the multiple cubic Bezier curves included in each of the original vector paths, filtering is performed in sequence on eight control points corresponding to two adjacent cubic Bezier curves according to a preset mutation condition and a preset intersection condition, so as to determine M target control points from the N control points; According to the M target control points, an initial vector path of each target mask is obtained through a Bessel function.
5. The method according to claim 1, wherein The determining of the target vector path according to the original vector path, the initial vector path, and a preset loss function includes: performing sampling processing on the original vector path and the initial vector path to obtain a first sampling point set corresponding to the original vector path and a second sampling point set corresponding to the initial vector path, wherein the first sampling point set includes a plurality of first sampling points and the second sampling point set includes a plurality of second sampling points; The target vector path is determined according to the first sampling point set, the second sampling point set, and the preset loss function, where the preset loss function is determined according to the mutual distance between the first sampling point and the second sampling point.
6. The method according to claim 5, characterized in that The preset loss function can be defined by the following expression: Here, b represents each first sampling point included in the first sampling point set, and e represents each second sampling point included in the second sampling point set.
7. The method according to claim 1, characterized in that Before generating the target vector image according to the target vector path and the initial pixel values corresponding to the target mask, the method further includes: Obtaining the value of each pixel of the target mask in the corresponding area of the raster image to be vectorized; The values of multiple pixels are averaged to obtain the initial pixel value.
8. The method according to claim 1, characterized in that Also includes: The target vector image is optimized according to the raster image to be vectorized, M target control points and a preset structural geometry loss function.
9. The method according to claim 8, characterized in that The preset structural geometry loss function is determined by a preset structural loss function and a preset geometric loss function, and the optimizing the target vector image according to the raster image to be vectorized, the M target control points, and the preset structural geometry loss function includes: Determining the preset structural loss function according to each pixel value of the raster image to be vectorized and each pixel value of the corresponding target vector image; Determining the preset geometric loss function according to the M target control points; Determining the preset structural geometric loss function according to the preset structural loss function and the preset geometric loss function; The target vector image is optimized by minimizing the preset structural geometry loss function.
10. An image vectorization device based on adaptive parameter adjustment, characterized in that: The device comprises: An original vector path acquisition module is used to acquire an original vector path of each of the target masks corresponding to the raster image to be vectorized, wherein the original vector path is determined by N control points; An initial vector path acquisition module is used to determine M target control points from N control points based on a cubic Bezier curve, and to determine an initial vector path of each target mask according to the M target control points, where M≤N; a target vector path acquisition module, configured to determine a target vector path based on the original vector path, the initial vector path, and a preset loss function; The target vector image acquisition module is used to generate a target vector image according to the target vector path and the initial pixel value corresponding to the target mask.