Irregular image tracing method, device, equipment and storage medium

By using adaptive threshold algorithm and parameterized curve algorithm in image processing, the problem of poor accuracy of complex images is solved, and a higher quality image stroke effect is achieved.

CN119228826BActive Publication Date: 2025-05-23乐麦信息技术(杭州)有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411745566.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-29
Publication Date
2025-05-23
Estimated Expiration
2044-11-29

AI Technical Summary

Technical Problem

In the prior art, it is difficult to achieve accurate strokes when processing complex images, especially for raster images with rich details and textures. The SVG format cannot be processed directly, resulting in jagged or distorted stroke curves.

Method used

By determining whether the image to be stroked has an alpha channel, the grayscale image is determined, and the adaptive threshold algorithm is used to binarize it. Then, based on the preset contour search algorithm, search and sample, optimize the sampling points, build a linked list, delete redundant points, increase the curvature change points, and finally use the parameterized curve algorithm to fit the target sampling points to generate the target stroke image.

Benefits of technology

It improves the accuracy of complex image strokes, can better process the detailed information of the image, generate stroke effects with rich details, and improves the smoothness and nature of image strokes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119228826B_ABST
    Figure CN119228826B_ABST
Patent Text Reader

Abstract

The present application discloses an irregular image stroking method, device, equipment and storage medium, which relates to the field of image processing technology, including: judging whether the image to be stroked has an alpha channel, determining a grayscale image based on the judgment result, and binarizing the grayscale image using an adaptive threshold algorithm; searching for image contours in the binary image based on a preset contour search algorithm, and screening the obtained closed contours; sampling the screened contours and optimizing each sampling point, and obtaining a linked list based on the optimized sampling points less than a preset distance threshold; performing vector unitization and dot product operations on the target vector constructed based on the optimized sampling points in the linked list, and deleting the optimized sampling points through the dot product value; adding the remaining sampling points of the local contour in the screened contour, and fitting the target sampling points using a preset parameterized curve algorithm to obtain a target stroked image. The smoothness and accuracy of image stroking can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing technology, and in particular to an irregular image tracing method, device, equipment and storage medium. Background Art

[0002] Currently, images are stroked based on SVG (Scalable Vector Graphics). However, the SVG format has difficulties in edge detection and contour extraction of raster images and cannot directly process raster images with rich details and textures, which limits the scope of application. It may not be able to accurately fit complex contours, resulting in jagged or distorted stroke curves.

[0003] As can be seen from the above, how to improve the accuracy of complex image strokes is a problem that needs to be solved urgently. Summary of the invention

[0004] In view of this, the purpose of the present invention is to provide an irregular image tracing method, device, equipment and storage medium, which can improve the accuracy of complex image tracing. The specific scheme is as follows:

[0005] In a first aspect, the present application provides an irregular image stroke method, comprising:

[0006] Determine whether the image to be stroked has an alpha channel, determine a grayscale image of the image to be stroked based on the determination result, and binarize the grayscale image using an adaptive threshold algorithm to obtain a binary image;

[0007] Searching for an image contour in the binary image based on a preset contour search algorithm to obtain a closed contour, and screening the closed contour to obtain a screened contour;

[0008] The filtered contour is sampled using a preset sampling rule to obtain sampling points, and each sampling point is optimized to obtain an optimized sampling point, and a linked list is constructed for the optimized sampling points that are less than a preset distance threshold to obtain a corresponding linked list;

[0009] Performing vector normalization and dot product operation on the target vector constructed based on the optimized sampling points in the linked list, so as to delete the optimized sampling points according to the obtained dot product values ​​to obtain the remaining sampling points;

[0010] The remaining sampling points corresponding to the local contours satisfying the preset curvature change condition in the filtered contours are added to obtain target sampling points, and the target sampling points are fitted using a preset parameterized curve algorithm to obtain a target stroke image.

[0011] Optionally, the determining whether the image to be stroked has an alpha channel and determining a grayscale image of the image to be stroked based on the determination result includes:

[0012] Determine whether the image to be stroked has an alpha channel;

[0013] If the image to be stroked has an alpha channel, extracting the alpha channel to obtain a grayscale image of the image to be stroked;

[0014] If the image to be stroked has no alpha channel, any RGB channel of the image to be stroked is used as the alpha channel, and the alpha channel is extracted to obtain a grayscale image of the image to be stroked.

[0015] Optionally, binarizing the grayscale image using an adaptive threshold algorithm to obtain a binary image includes:

[0016] Determining whether the grayscale image meets a preset brightness change condition;

[0017] If the grayscale image meets the preset brightness change condition, binarizing the grayscale image using a local adaptive threshold algorithm to obtain a binary image;

[0018] If the grayscale image does not meet the preset brightness change condition, the grayscale image is binarized using the maximum inter-class variance method to obtain a binary image.

[0019] Optionally, screening the closed contour to obtain a screened contour includes:

[0020] The closed contour is screened by a preset contour screening rule to obtain a screened contour;

[0021] The preset contour screening rule is to filter the contours whose contour areas do not satisfy the preset area conditions in the closed contours and to filter the contours whose contour perimeters do not satisfy the preset perimeter conditions in the closed contours.

[0022] Optionally, constructing a linked list for the optimized sampling points that are less than a preset distance threshold to obtain a corresponding linked list includes:

[0023] Calculating two adjacent optimized sampling points using a distance formula between two points to obtain a distance value;

[0024] If the distance value is less than a preset distance threshold, one of the two adjacent optimized sampling points is deleted, and a linked list is constructed using the remaining optimized sampling points to obtain a corresponding linked list.

[0025] Optionally, performing vector normalization and dot product operation on a target vector constructed based on the optimized sampling points in the linked list, and deleting the optimized sampling points according to the obtained dot product values ​​to obtain remaining sampling points, includes:

[0026] Obtain a first vector based on the first optimized sampling point and the second optimized sampling point of the linked list, and obtain a second vector using the second optimized sampling point and the third optimized sampling point;

[0027] Normalizing the first vector and the second vector and performing a dot product operation, and determining whether the obtained dot product value satisfies a preset dot product condition;

[0028] If the dot product value satisfies a preset dot product condition, the second optimized sampling points are deleted to obtain remaining sampling points.

[0029] Optionally, the step of adding remaining sampling points corresponding to the local contours satisfying a preset curvature change condition in the filtered contour to obtain target sampling points, and fitting the target sampling points using a preset parameterized curve algorithm to obtain a target stroked image includes:

[0030] Using the curvature formula, the remaining sampling points corresponding to the local contours satisfying the preset curvature change condition in the screened contour are subjected to curvature calculation to obtain a curvature value, and determining whether the curvature value is greater than a preset curvature threshold;

[0031] If the curvature value is greater than a preset curvature threshold, the remaining sampling points on the local contour are added to obtain target sampling points, and the target sampling points are fitted using a B-spline curve algorithm or a Bezier curve algorithm to obtain a target stroke image.

[0032] In a second aspect, the present application provides an irregular image tracing device, comprising:

[0033] An image binarization module is used to determine whether the image to be stroked has an alpha channel, determine a grayscale image of the image to be stroked based on the determination result, and binarize the grayscale image using an adaptive threshold algorithm to obtain a binary image;

[0034] A contour screening module, used for searching the image contour in the binary image based on a preset contour search algorithm to obtain a closed contour, and screening the closed contour to obtain a screened contour;

[0035] A linked list construction module, used to sample the filtered contour using a preset sampling rule to obtain each sampling point, and optimize each sampling point to obtain an optimized sampling point, and to construct a linked list for the optimized sampling points that are less than a preset distance threshold to obtain a corresponding linked list;

[0036] A sampling point deletion module, used for performing vector normalization and dot product operation on a target vector constructed based on the optimized sampling points in the linked list, so as to delete the optimized sampling points according to the obtained dot product values ​​to obtain remaining sampling points;

[0037] The curve fitting module is used to increase the remaining sampling points corresponding to the local contours that meet the preset curvature change conditions in the filtered contour to obtain target sampling points, and use a preset parameterized curve algorithm to fit the target sampling points to obtain a target stroke image.

[0038] In a third aspect, the present application provides an electronic device, including:

[0039] Memory, used to store computer programs;

[0040] The processor is used to execute the computer program to implement the aforementioned irregular image stroking method.

[0041] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program, wherein the computer program implements the aforementioned irregular image stroking method when executed by a processor.

[0042] The present application determines whether an image to be stroked has an alpha channel, determines a grayscale image of the image to be stroked based on the determination result, and uses an adaptive threshold algorithm to binarize the grayscale image to obtain a binary image; searches for image contours in the binary image based on a preset contour search algorithm to obtain a closed contour, and filters the closed contour to obtain a filtered contour; samples the filtered contour using a preset sampling rule to obtain each sampling point, and optimizes each sampling point to obtain an optimized sampling point, and constructs a linked list of the optimized sampling points that are less than a preset distance threshold to obtain a corresponding linked list; performs vector unitization and dot product operations on a target vector constructed based on the optimized sampling points in the linked list, and deletes the optimized sampling points through the obtained dot product values ​​to obtain the remaining sampling points; adds the remaining sampling points corresponding to the local contours that meet the preset curvature change conditions in the filtered contour to obtain target sampling points, and fits the target sampling points using a preset parameterized curve algorithm to obtain a target stroked image.

[0043] As can be seen from the above, the present application searches for the image contour in the binary image through a preset contour search algorithm to obtain a closed contour, and filters the closed contour to obtain a filtered contour, which can avoid the situation where noise, blur, complex texture, etc. affect the image stroke, and then optimizes each sampling point on the filtered contour, and constructs a linked list for the optimized sampling points that are less than the preset distance threshold, and performs a vector dot product operation on the optimized sampling points in the linked list, and deletes the corresponding optimized sampling points based on the operation result to obtain the remaining sampling points, and then adds the remaining sampling points corresponding to the local contour that meets the preset curvature change condition in the filtered contour to obtain the target sampling points. In this way, the target stroke image obtained by curve fitting using the preset parameterized curve algorithm target sampling points is more accurate, can better process the detail information of complex images, generate a stroke effect with rich details, and the smoothness and naturalness of the image stroke will also be significantly improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0044] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0045] Figure 1 A flow chart of an irregular image stroke method disclosed in this application;

[0046] Figure 2 A schematic diagram of a target sampling point provided for this application;

[0047] Figure 3 A schematic diagram of an image stroke provided for this application;

[0048] Figure 4 A schematic diagram of a contour curve provided for this application;

[0049] Figure 5 A schematic diagram of deleting sampling points provided for this application;

[0050] Figure 6 A schematic diagram of adding sampling points provided for this application;

[0051] Figure 7 A specific irregular image stroke schematic diagram provided for this application;

[0052] Figure 8 This is a schematic diagram of the structure of an irregular image tracing device disclosed in this application;

[0053] Fig. 9This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION

[0054] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0055] At present, the SVG format cannot directly process raster images with rich details and textures, which limits its application scope; it cannot accurately fit complex contours, which causes jagged or distorted stroke curves. To this end, this application provides an irregular image stroke method, which uses a preset parameterized curve algorithm target sampling point to perform curve fitting to obtain a target stroke image that is more accurate, can better process the detail information of complex images, and generate a stroke effect with rich details. The smoothness and naturalness of the image stroke will also be significantly improved.

[0056] See also Figure 1 As shown, an embodiment of the present invention discloses an irregular image stroke method, comprising:

[0057] Step S11, judging whether the image to be stroked has an alpha channel, determining a grayscale image of the image to be stroked based on the judgment result, and binarizing the grayscale image using an adaptive threshold algorithm to obtain a binary image.

[0058] After acquiring the image to be stroked, this embodiment determines whether the image to be stroked has an alpha channel. If the image to be stroked has an alpha channel, the alpha channel of the image to be stroked is extracted to obtain a grayscale image. If the image to be stroked does not have an alpha channel, the RGB (a color standard) channel of the image to be stroked is selected as the alpha channel of the image to be stroked, and then the alpha channel is extracted to obtain the grayscale image of the image to be stroked. Specifically, the determination of whether the image to be stroked has an alpha channel and the determination of the grayscale image of the image to be stroked based on the determination result include: determining whether the image to be stroked has an alpha channel; if the image to be stroked has an alpha channel, the alpha channel is extracted to obtain the grayscale image of the image to be stroked; if the image to be stroked does not have an alpha channel, any RGB channel of the image to be stroked is used as the alpha channel, and the alpha channel is extracted to obtain the grayscale image of the image to be stroked.

[0059] Correspondingly, if the image to be stroked has corresponding transparency information, the grayscale image of the image to be stroked is obtained based on the transparency information; if the image to be stroked does not have corresponding transparency information, an approximate alpha value can be estimated by the values ​​of the RGB channels corresponding to the image to be stroked. Specifically, the values ​​of the RGB channels corresponding to the image to be stroked can be normalized, and R, G, and B can be converted to values ​​between 0 and 1, and then these three values ​​can be added to obtain the alpha value. It should be pointed out that if the background in the image to be stroked is a solid color background, the alpha value of the image to be stroked can be calculated based on the difference between the background color and the foreground color, and the grayscale image of the image to be stroked can be obtained by the alpha value.

[0060] It is understandable that after obtaining the grayscale image, different adaptive threshold algorithms are selected for binarization according to the brightness change of the grayscale image. Specifically, the use of the adaptive threshold algorithm to binarize the grayscale image to obtain a binary image includes: judging whether the grayscale image meets the preset brightness change condition; if the grayscale image meets the preset brightness change condition, the local adaptive threshold algorithm is used to binarize the grayscale image to obtain a binary image; if the grayscale image does not meet the preset brightness change condition, the maximum inter-class variance method is used to binarize the grayscale image to obtain a binary image. That is, for areas where the image brightness changes greatly, the local adaptive threshold algorithm can be used to binarize the grayscale image. It is worth mentioning that the preset brightness change condition can be adjusted accordingly according to the actual situation, and is not specifically limited here.

[0061] Step S12: searching for image contours in the binary image based on a preset contour search algorithm to obtain closed contours, and screening the closed contours to obtain screened contours.

[0062] In this embodiment, the findContours function of OpenCV (Open Source Computer Vision Library) can be used to search for all image contours in the binary image to obtain closed contours, and the closed contours are screened by area, perimeter, and morphological features to obtain filtered contours. Specifically, the filtering of the closed contours to obtain filtered contours includes: filtering the closed contours by preset contour filtering rules to obtain filtered contours; wherein the preset contour filtering rules are filtering contours in the closed contours whose contour areas do not meet the preset area conditions and filtering contours in the closed contours whose contour perimeters do not meet the preset perimeter conditions. It should be noted that for some specific scenarios, other contour search algorithms can be considered, such as boundary tracking algorithms.

[0063] It is understandable that the contours with small area and too short perimeter in the closed contour can be filtered because these contours may represent noise, and can also be filtered according to the shape characteristics of the contour (such as circularity and rectangularity). Further, the closed contour can be opened or closed accordingly to remove some small noise points or fill small holes. After the operation, the contour can be refined to a single pixel width, making the image processing more refined.

[0064] Step S13: sampling the filtered contour using a preset sampling rule to obtain each sampling point, optimizing each sampling point to obtain an optimized sampling point, and constructing a linked list of the optimized sampling points that are less than a preset distance threshold to obtain a corresponding linked list.

[0065] In this embodiment, the filtered contour is sampled at equal intervals based on a fixed interval to obtain each sampling point, and each sampling point is optimized using the least square method to obtain an optimized sampling point, and then the distance between two adjacent optimized sampling points is calculated using the distance formula between two points to obtain a corresponding distance value, and the distance value is compared with a preset distance threshold to delete the corresponding optimized sampling point based on the comparison result, and a linked list is constructed by the remaining optimized sampling points to obtain a linked list. Specifically, the linked list is constructed by constructing a linked list for the optimized sampling points that are less than the preset distance threshold to obtain a corresponding linked list, including: calculating the distance value for two adjacent optimized sampling points using the distance formula between two points; if the distance value is less than the preset distance threshold, deleting one of the two adjacent optimized sampling points, and constructing a linked list using the remaining optimized sampling points to obtain a corresponding linked list.

[0066] It can be understood that the distance between two adjacent optimized sampling points is calculated using the distance formula between two points to obtain a distance value, wherein the distance formula between two points is as follows:

[0067] ;

[0068] Among them, A and B are two adjacent optimized sampling points, and the coordinates corresponding to A are , the coordinates corresponding to B are If the preset distance threshold is 1, then If it is less than 1, then delete any one of the two optimized sampling points A and B. Then, the remaining optimized sampling points are used to construct a linked list in the order of paths to obtain a linked list.

[0069] Step S14: Perform vector normalization and dot product operation on the target vector constructed based on the optimized sampling points in the linked list, and delete the optimized sampling points through the obtained dot product value to obtain the remaining sampling points.

[0070] In this embodiment, after obtaining the linked list, a target vector is obtained based on the optimized sampling points in the linked list, and vector normalization and dot product operation are performed on the target vector to obtain the corresponding dot product value. If the dot product value is close to the preset dot product threshold, the optimized sampling point corresponding to the dot product value is deleted to obtain the remaining sampling points. Specifically, the step of performing vector normalization and dot product operation on the target vector constructed based on the optimized sampling points in the linked list, and deleting the optimized sampling points through the obtained dot product value to obtain the remaining sampling points includes: obtaining a first vector based on the first optimized sampling point and the second optimized sampling point in the linked list, and obtaining a second vector by using the second optimized sampling point and the third optimized sampling point; performing unit normalization and dot product operation on the first vector and the second vector, and determining whether the obtained dot product value meets the preset dot product condition; if the dot product value meets the preset dot product condition, delete the second optimized sampling point to obtain the remaining sampling points.

[0071] It can be understood that the first optimized sampling point A, the second optimized sampling point B, and the third optimized sampling point C in the linked list can be selected. The vector AB is obtained through the first optimized sampling point and the second optimized sampling point, and the vector BC is obtained through the second optimized sampling point and the third optimized sampling point. Then, the vector AB and the vector BC are normalized, and the dot product (i.e., the cosine value of the included angle between the two vectors) of the normalized vector AB and vector BC is taken. The obtained dot product value ranges from -1 to 1. If the dot product value is close to 1, it indicates that the included angle between the vector AB and the vector BC is very small, meaning that these two vectors are almost in the same direction. Therefore, for the first optimized sampling point A, the second optimized sampling point B, and the third optimized sampling point C corresponding to the dot product value close to 1, the second optimized sampling point B is selected for deletion, which will not affect the curvature change points and still maintain the overall curve shape. Then, the next item D in the linked list is taken to construct the vector AC and the vector CD, and the steps of performing vector normalization and dot product operation on the constructed target vector are repeated.

[0072] Step S15: Add the remaining sampling points corresponding to the local contours that meet the preset curvature change condition in the filtered contour to obtain the target sampling points, and use the preset parametric curve algorithm to fit the target sampling points to obtain the target stroke image.

[0073] In this embodiment, it is determined whether the contour in the filtered contour satisfies the preset curvature change condition. If the contour in the filtered contour satisfies the preset curvature change condition, the sampling points corresponding to the local contour that satisfies the preset curvature change condition are increased to obtain the target sampling points. If the contour in the filtered contour does not satisfy the preset curvature change condition, the sampling points corresponding to the local contour that satisfies the preset curvature change condition are reduced to obtain the target sampling points, and then the target sampling points are fitted using a B-spline curve algorithm or a Bezier curve algorithm to obtain a target stroked image. Specifically, the remaining sampling points corresponding to the local contours that meet the preset curvature change conditions in the filtered contour are added to obtain target sampling points, and the target sampling points are fitted using a preset parameterized curve algorithm to obtain a target stroked image, including: using a curvature formula to calculate the curvature of the remaining sampling points corresponding to the local contours that meet the preset curvature change conditions in the filtered contour to obtain a curvature value, and judging whether the curvature value is greater than a preset curvature threshold; if the curvature value is greater than the preset curvature threshold, the remaining sampling points on the local contour are added to obtain target sampling points, and a B-spline curve algorithm or a Bezier curve algorithm is used to fit the target sampling points to obtain a target stroked image.

[0074] It can be understood that the curvature formula is used to determine whether the contour in the screened contour meets the preset curvature change condition. The curvature formula is:

[0075] ;

[0076] Wherein, t is a parameter, and x(t) and y(t) are functions of the curve on the x-axis and y-axis. If the preset curvature threshold is 0.01, and if the obtained curvature value k is greater than 0.01, it indicates that the contour in the screened contour meets the preset curvature change condition, and the sampling points corresponding to the local contour meeting the preset curvature change condition are increased to obtain the target sampling point; if the curvature value k is less than 0.01, it indicates that the contour in the screened contour does not meet the preset curvature change condition, and the sampling points corresponding to the local contour meeting the preset curvature change condition are reduced to obtain the target sampling point.

[0077] Figure 2 A schematic diagram of target sampling points provided in this embodiment, in an area with a small curvature change, the target sampling points are relatively small, and in an area with a large curvature change, the target sampling points are relatively large. Figure 3 A schematic diagram of image stroke provided by this embodiment, after obtaining the target sampling points, curve fitting is performed on the target sampling points using a B-spline curve algorithm or a Bezier curve algorithm to obtain a target stroked image.

[0078] As can be seen from the above, the present application searches for the image contour in the binary image through a preset contour search algorithm to obtain a closed contour, and screens the closed contour to obtain a screened contour, which can avoid the situation where noise, blur, complex texture, etc. affect the image stroke, and then optimizes each sampling point on the screened contour, and constructs a linked list for the optimized sampling points that are less than the preset distance threshold, and performs a vector dot product operation on the optimized sampling points in the linked list, and deletes the corresponding optimized sampling points based on the operation result to obtain the remaining sampling points, and then adds the remaining sampling points corresponding to the local contour that meets the preset curvature change condition in the screened contour to obtain the target sampling points. In this way, the target stroke image obtained by curve fitting using the preset parameterized curve algorithm target sampling points is more accurate, can better process the detail information of complex images, generate a stroke effect with rich details, and the smoothness and naturalness of the image stroke will also be significantly improved.

[0079] It can be seen from the above embodiments that the present application deletes the optimized sampling points based on a preset distance threshold and increases or decreases the corresponding optimized sampling points by a preset curvature threshold. Therefore, the present embodiment specifically describes the target sampling points obtained after the increase or decrease of the optimized sampling points and the curve fitting through the target sampling points.

[0080] Figure 4 A schematic diagram of a contour curve provided in this embodiment, wherein there are 628 sampling points on a given contour curve, and the points on the contour of the curve are represented by [x(t), y(t)], wherein t represents a preset sampling interval, which is initially 0.5. When the sampling points are deleted using a preset distance threshold, the 628 sampling points less than 1 are reduced to 13. Figure 5 A schematic diagram of deleting a sampling point provided in this embodiment. Figure 5 and Figure 4 In comparison, in places where the curvature changes greatly, such as sharp corners, the corresponding sampling points are increased so that the sampling interval in this area is shortened to 0.1. Figure 6 A schematic diagram of increasing sampling points provided in this embodiment, after increasing sampling based on curvature change, additional 49 sampling points are obtained.

[0081] Figure 7A specific irregular image stroke schematic diagram provided for this embodiment, after obtaining the image to be stroked, it is determined whether the image to be stroked has an alpha channel, so as to determine the grayscale image of the image to be stroked based on the determination result, after binarizing the grayscale image, the image contour in the binary image is searched using a preset contour search algorithm to obtain a closed contour, and then the filtered contour is sampled based on a preset sampling rule to obtain each sampling point, and then each sampling point on the filtered contour is optimized, and a linked list is constructed for the optimized sampling points less than a preset distance threshold, and the vector dot product operation is performed on the optimized sampling points in the linked list, and the corresponding optimized sampling points are deleted based on the operation result to obtain the remaining sampling points, and then the remaining sampling points corresponding to the local contour in the filtered contour that meets the preset curvature change condition are added to obtain the target sampling points. In this way, the target stroke image obtained by curve fitting using the preset parameterized curve algorithm target sampling points is more accurate, can better process the detail information of complex images, generate a stroke effect with rich details, and the smoothness and naturalness of the image stroke will also be significantly improved.

[0082] Accordingly, see Figure 8 As shown, the present application also provides an irregular image tracing device, comprising:

[0083] The image binarization module 11 is used to determine whether the image to be stroked has an alpha channel, determine the grayscale image of the image to be stroked based on the determination result, and binarize the grayscale image using an adaptive threshold algorithm to obtain a binary image;

[0084] The contour screening module 12 is used to search for the image contour in the binary image based on a preset contour search algorithm to obtain a closed contour, and screen the closed contour to obtain a screened contour;

[0085] A linked list construction module 13 is used to sample the filtered contour using a preset sampling rule to obtain each sampling point, and optimize each sampling point to obtain an optimized sampling point, and to construct a linked list for the optimized sampling points that are less than a preset distance threshold to obtain a corresponding linked list;

[0086] A sampling point deletion module 14 is used to perform vector normalization and dot product operation on the target vector constructed based on the optimized sampling points in the linked list, so as to delete the optimized sampling points according to the obtained dot product value to obtain the remaining sampling points;

[0087] The curve fitting module 15 is used to increase the remaining sampling points corresponding to the local contours that meet the preset curvature change conditions in the filtered contours to obtain target sampling points, and to fit the target sampling points using a preset parameterized curve algorithm to obtain a target stroke image.

[0088] As can be seen from the above, the present application searches for the image contour in the binary image through a preset contour search algorithm to obtain a closed contour, and screens the closed contour to obtain a screened contour, which can avoid the situation where noise, blur, complex texture, etc. affect the image stroke, and then optimizes each sampling point on the screened contour, and constructs a linked list for the optimized sampling points that are less than the preset distance threshold, and performs a vector dot product operation on the optimized sampling points in the linked list, and deletes the corresponding optimized sampling points based on the operation result to obtain the remaining sampling points, and then adds the remaining sampling points corresponding to the local contour that meets the preset curvature change condition in the screened contour to obtain the target sampling points. In this way, the target stroke image obtained by curve fitting using the preset parameterized curve algorithm target sampling points is more accurate, can better process the detail information of complex images, generate a stroke effect with rich details, and the smoothness and naturalness of the image stroke will also be significantly improved.

[0089] In some specific implementations, the image binarization module 11 may specifically include:

[0090] A first image determination unit, used for determining whether the image to be stroked has an alpha channel;

[0091] A channel extraction unit, configured to extract an alpha channel from the image to be stroked to obtain a grayscale image of the image to be stroked if the image to be stroked has an alpha channel;

[0092] The grayscale image determining unit is used for, if the image to be stroked has no alpha channel, using any RGB channel of the image to be stroked as the alpha channel, and extracting the alpha channel to obtain the grayscale image of the image to be stroked.

[0093] In some specific implementations, the image binarization module 11 may specifically include:

[0094] A second image determination unit, used to determine whether the grayscale image meets a preset brightness change condition;

[0095] A first binarization unit, configured to binarize the grayscale image using a local adaptive threshold algorithm to obtain a binary image if the grayscale image meets a preset brightness change condition;

[0096] The second binarization unit is used to binarize the grayscale image by using the maximum inter-class variance method to obtain a binary image if the grayscale image does not meet the preset brightness change condition.

[0097] In some specific implementations, the profile screening module 12 may specifically include:

[0098] The closed contour screening unit is used to screen the closed contour according to a preset contour screening rule to obtain a screened contour.

[0099] In some specific implementations, the linked list construction module 13 may specifically include:

[0100] A distance value determination unit, used to calculate two adjacent optimized sampling points using a distance formula between two points to obtain a distance value;

[0101] The linked list construction completion unit is used to delete one of the two adjacent optimized sampling points if the distance value is less than a preset distance threshold, and use the remaining optimized sampling points to construct a linked list to obtain a corresponding linked list.

[0102] In some specific implementations, the sampling point deletion module 14 may specifically include:

[0103] a vector determination unit, configured to obtain a first vector based on the first optimized sampling point and the second optimized sampling point of the linked list, and obtain a second vector using the second optimized sampling point and the third optimized sampling point;

[0104] a dot product operation unit, configured to normalize the first vector and the second vector and perform a dot product operation, and determine whether the obtained dot product value satisfies a preset dot product condition;

[0105] The remaining sampling point determining unit is configured to delete the second optimized sampling points to obtain remaining sampling points if the dot product value satisfies a preset dot product condition.

[0106] In some specific implementations, the curve fitting module 15 may specifically include:

[0107] a curvature calculation unit, configured to calculate the curvature of the remaining sampling points corresponding to the local contours satisfying the preset curvature change condition in the screened contours using a curvature formula to obtain a curvature value, and determine whether the curvature value is greater than a preset curvature threshold;

[0108] The curve fitting completion unit is used to add the remaining sampling points on the local contour to obtain target sampling points if the curvature value is greater than a preset curvature threshold, and use a B-spline curve algorithm or a Bezier curve algorithm to fit the target sampling points to obtain a target stroke image.

[0109] Furthermore, the present application also discloses an electronic device. Fig. 9: This is a structural diagram of an electronic device 20 shown according to an exemplary embodiment, and the content in the figure cannot be regarded as any limitation on the scope of use of this application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input and output interface 25, and a communication bus 26. Among them, the memory 22 is used to store a computer program, and the computer program is loaded and executed by the processor 21 to implement the relevant steps in the irregular image stroking method disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0110] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0111] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0112] The operating system 221 is used to manage and control the hardware devices and computer program 222 on the electronic device 20, and can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the irregular image stroking method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks.

[0113] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein the computer program, when executed by a processor, implements the irregular image stroking method disclosed above. For the specific steps of the method, reference may be made to the corresponding contents disclosed in the above embodiments, and no further description will be given here.

[0114] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0115] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0116] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0117] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0118] The technical solution provided by the present application is introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technicians in this field, according to the idea of ​​the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A method for stroking an irregular image, characterized in that: include: Determine whether the image to be stroked has an alpha channel, determine a grayscale image of the image to be stroked based on the determination result, and binarize the grayscale image using an adaptive threshold algorithm to obtain a binary image; Searching for an image contour in the binary image based on a preset contour search algorithm to obtain a closed contour, and screening the closed contour to obtain a screened contour; The filtered contour is sampled using a preset sampling rule to obtain each sampling point, and each sampling point is optimized to obtain an optimized sampling point, and a linked list is constructed for the optimized sampling points that are less than a preset distance threshold to obtain a corresponding linked list; Performing vector normalization and dot product operation on the target vector constructed based on the optimized sampling points in the linked list, so as to delete the optimized sampling points according to the obtained dot product values ​​to obtain the remaining sampling points; Adding remaining sampling points corresponding to the local contours satisfying the preset curvature change condition in the filtered contour to obtain target sampling points, and fitting the target sampling points using a preset parameterized curve algorithm to obtain a target stroke image; The method of increasing the remaining sampling points corresponding to the local contours satisfying the preset curvature change condition in the filtered contour to obtain target sampling points, and fitting the target sampling points using a preset parameterized curve algorithm to obtain a target stroked image includes: Using the curvature formula, the remaining sampling points corresponding to the local contours satisfying the preset curvature change condition in the screened contour are subjected to curvature calculation to obtain a curvature value, and determining whether the curvature value is greater than a preset curvature threshold; If the curvature value is greater than a preset curvature threshold, the remaining sampling points on the local contour are added to obtain target sampling points, and the target sampling points are fitted using a B-spline curve algorithm or a Bezier curve algorithm to obtain a target stroke image; The step of constructing a linked list of the optimized sampling points that are less than a preset distance threshold to obtain a corresponding linked list includes: Calculating two adjacent optimized sampling points using a distance formula between two points to obtain a distance value; If the distance value is less than a preset distance threshold, one of the two adjacent optimized sampling points is deleted, and a linked list is constructed using the remaining optimized sampling points to obtain a corresponding linked list.

2. The irregular image stroke method according to claim 1, characterized in that: The step of determining whether the image to be stroked has an alpha channel and determining a grayscale image of the image to be stroked based on the determination result includes: Determine whether the image to be stroked has an alpha channel; If the image to be stroked has an alpha channel, extracting the alpha channel to obtain a grayscale image of the image to be stroked; If the image to be stroked has no alpha channel, any RGB channel of the image to be stroked is used as the alpha channel, and the alpha channel is extracted to obtain a grayscale image of the image to be stroked.

3. The irregular image stroke method according to claim 1, characterized in that: The step of binarizing the grayscale image using an adaptive threshold algorithm to obtain a binary image includes: Determining whether the grayscale image meets a preset brightness change condition; If the grayscale image meets the preset brightness change condition, binarizing the grayscale image using a local adaptive threshold algorithm to obtain a binary image; If the grayscale image does not meet the preset brightness change condition, the grayscale image is binarized using the maximum inter-class variance method to obtain a binary image.

4. The irregular image stroke method according to claim 1, characterized in that: The step of screening the closed contour to obtain a screened contour comprises: The closed contour is screened by a preset contour screening rule to obtain a screened contour; The preset contour screening rule is to filter the contours whose contour areas do not satisfy the preset area conditions in the closed contour and to filter the contours whose contour perimeters do not satisfy the preset perimeter conditions in the closed contour.

5. The irregular image stroking method according to claim 1, characterized in that: The performing vector normalization and dot product operation on the target vector constructed based on the optimized sampling points in the linked list, and deleting the optimized sampling points according to the obtained dot product values ​​to obtain the remaining sampling points, includes: Obtain a first vector based on the first optimized sampling point and the second optimized sampling point of the linked list, and obtain a second vector using the second optimized sampling point and the third optimized sampling point; Normalizing the first vector and the second vector and performing a dot product operation, and determining whether the obtained dot product value satisfies a preset dot product condition; If the dot product value satisfies a preset dot product condition, the second optimized sampling points are deleted to obtain remaining sampling points.

6. An irregular image tracing device, characterized in that: include: An image binarization module is used to determine whether the image to be stroked has an alpha channel, determine a grayscale image of the image to be stroked based on the determination result, and binarize the grayscale image using an adaptive threshold algorithm to obtain a binary image; A contour screening module, used for searching the image contour in the binary image based on a preset contour search algorithm to obtain a closed contour, and screening the closed contour to obtain a screened contour; A linked list construction module, used to sample the filtered contour using a preset sampling rule to obtain each sampling point, and optimize each sampling point to obtain an optimized sampling point, and to construct a linked list for the optimized sampling points that are less than a preset distance threshold to obtain a corresponding linked list; A sampling point deletion module, used for performing vector normalization and dot product operation on a target vector constructed based on the optimized sampling points in the linked list, so as to delete the optimized sampling points according to the obtained dot product values ​​to obtain remaining sampling points; A curve fitting module, used for adding the remaining sampling points corresponding to the local contours satisfying the preset curvature change condition in the screened contour to obtain target sampling points, and fitting the target sampling points using a preset parameterized curve algorithm to obtain a target stroke image; The curve fitting module is specifically used to calculate the curvature of the remaining sampling points corresponding to the local contours that meet the preset curvature change conditions in the filtered contours using the curvature formula to obtain a curvature value, and determine whether the curvature value is greater than a preset curvature threshold; if the curvature value is greater than the preset curvature threshold, the remaining sampling points on the local contour are added to obtain target sampling points, and the target sampling points are fitted using a B-spline curve algorithm or a Bezier curve algorithm to obtain a target stroke image; The linked list construction module is specifically used to calculate two adjacent optimized sampling points using a distance formula between two points to obtain a distance value; if the distance value is less than a preset distance threshold, one of the two adjacent optimized sampling points is deleted, and the remaining optimized sampling points are used to construct a linked list to obtain a corresponding linked list.

7. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the irregular image stroking method according to any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that: Used to store a computer program, wherein when the computer program is executed by a processor, the irregular image stroke method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Character image vectorization method and system based on framework instruction

    CN103942552A

  • Contour extraction method and device, equipment and storage medium

    CN114565627A