A method, apparatus, electronic device, medium, and product for generating line graphs.

By generating smooth line graphs through edge detection and optimization algorithms, the problem of unstable line graph generation quality in existing technologies is solved, and high-quality patterned line graph generation is achieved.

CN119068076BActive Publication Date: 2025-12-02LINGDI (ZHEJIANG) TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410509262.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-25
Publication Date
2025-12-02
Estimated Expiration
2044-04-25

AI Technical Summary

Technical Problem

Existing line graph generation methods, based on neural networks and deep learning, suffer from problems such as a lack of sample instances and unstable quality, making it difficult to generate high-quality patterned line graphs.

Method used

By performing edge detection on the image, the contour points of the pattern are obtained, the edge curve is constructed, the contour points with the lowest replacement value are selected, and a smooth line graph is generated. Adaptive Canny edge detection, differential edge detection and other algorithms are used, combined with Zhang-Suen thinning algorithm and Douglas-Puk algorithm to optimize the edge curve.

Benefits of technology

It improves the quality of line graphs, generates smooth and rounded edge curves, supports further geometric calculations and editing, and enhances the pattern style effect.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119068076B_ABST
    Figure CN119068076B_ABST
Patent Text Reader

Abstract

This specification provides a method, apparatus, electronic device, medium, and product for generating line graphs. The method may include: performing edge detection on an image to obtain contour points of a pattern in the image; constructing an edge curve in the image based on selected points among the contour points, wherein the selected points are contour points located within a specified range of the edge curve and having the lowest cost; and generating a line graph corresponding to the image based on the edge curve.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This specification relates to the field of garment manufacturing technology, and in particular to a method, apparatus, electronic device, medium, and product for generating line graphs. Background Technology

[0002] In modern society, the demand for pattern generation in the garment manufacturing industry is increasing. As an important component of clothing design, patterns not only affect the aesthetics of clothing, but are also closely related to brand image and cultural heritage.

[0003] In pattern generation, line drawings are commonly used to represent the outline, texture, or structure of a pattern, and are a widely used pattern design method. However, in reality, manually drawing pattern outlines requires designers to independently identify the outline and draw the edge shapes, which can be very time-consuming and labor-intensive, especially for complex patterns. With the digitalization of clothing becoming a growing trend, using computer technology to generate line drawings corresponding to patterns has become an important area of ​​focus.

[0004] Current line graph generation methods rely on neural networks and style transfer from deep learning to simulate and generate patterned line graphs. However, these methods are heavily influenced by sample examples, resulting in problems such as insufficient sample instances and unstable quality. Summary of the Invention

[0005] To overcome the problems existing in related technologies, this specification provides a method, apparatus, electronic device, medium, and product for generating line graphs.

[0006] According to a first aspect of any embodiment of this specification, a method for generating a line graph is provided, the method comprising:

[0007] Edge detection is performed on the image to obtain the contour points of the pattern in the image;

[0008] Based on the selected points among the contour points, an edge curve in the image is constructed, wherein the selected points are contour points located within a specified range of the edge curve and have the lowest cost.

[0009] Based on the edge curve, a line graph corresponding to the image is generated.

[0010] According to a second aspect of any embodiment of this specification, a line graph generating apparatus is provided, the apparatus comprising:

[0011] The contour point acquisition module is used to perform edge detection on the image and acquire the contour points of the pattern in the image;

[0012] An edge curve construction module is used to construct an edge curve in an image based on selected points among the contour points, wherein the selected points are contour points located within a specified range of the edge curve and have the lowest cost.

[0013] The line graph generation module is used to generate a line graph corresponding to the image based on the edge curve.

[0014] According to a third aspect of any embodiment of this specification, an electronic device is provided, comprising:

[0015] processor;

[0016] Memory used to store processor-executable instructions;

[0017] The processor executes the executable instructions to implement the methods described in any embodiment of this specification.

[0018] According to a fourth aspect of any embodiment of this specification, a computer-readable storage medium is provided that stores computer instructions thereon, which, when executed by a processor, implement the steps of the method as described in any embodiment of this specification above.

[0019] According to a fifth aspect of any embodiment of this specification, a computer program product is provided having a computer program / instructions stored thereon, which, when executed by a processor, implement the steps of the method as described in any embodiment of this specification above.

[0020] The technical solutions provided in the embodiments of this specification may include the following beneficial effects:

[0021] As can be seen from the above embodiments, by performing edge detection on the image, the contour points of the pattern in the image are obtained. Based on the selected points that are within a specified range of the edge curve and have the lowest cost, the edge curve of the image is constructed. According to the edge curve, the corresponding line graph of the image is generated. By continuously adding contour points that are close to the edge curve and have the lowest cost to construct the edge curve, the adjacent contour points in the edge curve are close to each other and do not bend at large angles. Thus, a smooth and rounded edge curve is displayed in the generated line graph, improving the quality of the line graph corresponding to the pattern. This allows users to further perform geometric calculations and other operations on the curves in the line graph to obtain the pattern style effect required by the user.

[0022] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this specification. Attached Figure Description

[0023] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0024] Figure 1 This is a flowchart illustrating a method for generating a line graph according to an exemplary embodiment of this specification;

[0025] Figure 2 This is a schematic diagram of a patterned image shown in this specification according to an exemplary embodiment;

[0026] Figure 3 This is a schematic diagram of a grayscale image with transparent areas removed, according to an exemplary embodiment of this specification.

[0027] Figure 4 This is a schematic diagram of a contour point image according to an exemplary embodiment of this specification;

[0028] Figure 5 This is a schematic diagram of an edge skeleton image according to an exemplary embodiment of this specification;

[0029] Figure 6 This is a flowchart illustrating an edge curve reduction method according to an exemplary embodiment of this specification;

[0030] Figure 7 This is a schematic diagram of a line graph shown in this specification according to an exemplary embodiment;

[0031] Figure 8 This is a flowchart illustrating an edge detection method according to an exemplary embodiment of this specification;

[0032] Figure 9 This is a flowchart illustrating an edge curve construction method according to an exemplary embodiment of this specification;

[0033] Figure 10 This is a flowchart illustrating another method for generating line graphs according to an exemplary embodiment of this specification;

[0034] Figure 11 This specification is a schematic diagram illustrating the structure of an electronic device according to an exemplary embodiment.

[0035] Figure 12 This is a block diagram illustrating a line graph generation apparatus according to an exemplary embodiment of this specification. Detailed Implementation

[0036] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this specification. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this specification as detailed in the appended claims.

[0037] The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to be limiting of this specification. The singular forms “a,” “the,” and “the” as used in this specification and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.

[0038] It should be understood that although the terms first, second, third, etc., may be used in this specification to describe various information, this information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this specification, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."

[0039] Currently, common line graph generation methods are based on style transfer using neural networks and deep learning to simulate and generate patterned line graphs. However, these methods are affected by the availability of sample examples and suffer from problems such as insufficient sample instances and unstable quality.

[0040] To address the aforementioned problems, this specification proposes a method for generating line graphs. The following embodiments are provided to further illustrate this specification:

[0041] Please see Figure 1 , Figure 1 This is a flowchart illustrating a line graph generation method according to an exemplary embodiment of this specification. The line graph generation method can be applied to terminal devices such as computers and tablet computers, and may include the following steps:

[0042] Step 102: Perform edge detection on the image to obtain the contour points of the pattern in the image.

[0043] In this step, the terminal device can receive the image input by the user that needs to be converted into a line graph.

[0044] Terminal devices use edge detection methods such as adaptive Canny edge detection and differential edge detection to perform edge detection on the input image, obtain the edges corresponding to the patterns in the image, and acquire the contour points that constitute the edges in the image.

[0045] The image may include one or more patterns, and the edges are the outlines that constitute the patterns. Contour points are the pixels in the image that form the edges corresponding to the patterns; contour points are used to clearly define the outline shape of the patterns.

[0046] Furthermore, there may be opaque and transparent areas in the image. Before performing edge detection on the image and obtaining the contour points of the pattern in the image, the terminal device can perform binarization on the image based on a preset intermediate value to remove the transparent areas in the image.

[0047] Specifically, the terminal device divides the pixels in the transparent area into completely transparent and completely opaque regions by binarizing the median value, and then sets all pixels in the completely transparent area to the same 0, thereby removing the transparent area.

[0048] The median value is the middle value of the pixel value range of the alpha channel. For example, when the pixel value range of the alpha channel is 0 to 255, the median value is 128; when the pixel value range of the alpha channel is 0 to 1, the median value is 0.5.

[0049] The terminal device performs grayscale conversion on the pixels in the image after removing the transparent areas, converting the RGB (Red, Green, Blue, the three primary colors) channel values ​​of the image into grayscale values, reducing the dimensionality of the color information in the image, and obtaining the corresponding grayscale image.

[0050] To further illustrate the removal of transparent areas and grayscale conversion, Figure 2 A schematic diagram of an image with a pattern is shown. Figure 2 The image 201 shown is a colored image with patterns and alpha channels received by the terminal device from user input.

[0051] Figure 3 A schematic diagram of a grayscale image with transparent regions removed is shown. The terminal device binarizes image 201, sets the pixels of transparent region 2011 to 0, and removes transparent region 2011 from image 201. Then, image 201 is converted to grayscale to obtain grayscale image 301 with transparent region 2011 removed.

[0052] Figure 4 A schematic diagram of a contour point image is shown. The terminal device can perform edge detection on the grayscale image 301 after removing the transparent area 2011 to obtain a contour point image 401. The contour point image 401 is an image that retains only the contour points that constitute the pattern contour in the image 201.

[0053] As mentioned above, by binarizing the image according to a preset intermediate value and removing transparent areas, the visual consistency of the image can be guaranteed; by converting the pixels in the image to grayscale, the visual dimension of the image is reduced, and features can be calculated more efficiently in subsequent image processing.

[0054] Furthermore, after obtaining the outline points of the pattern in the image, the terminal device expands the image according to the preset structural element, using the preset search radius as the radius of the structural element, thereby increasing the width of the edges and connecting broken edges.

[0055] The structuring element is used to cover and influence the neighborhood of the contour points, and can be elliptical, rectangular, or other shapes. The search radius can be the radius of the structuring element pre-specified by the user.

[0056] The terminal device uses contour thinning algorithms such as Zhang-Suen thinning algorithm and Hilditch thinning algorithm to thin the dilated image and obtain the thinned contour points.

[0057] Taking the Zhang-Suen thinning algorithm as an example, the terminal device iteratively deletes pixels in the dilated image until it can no longer be thinned, thereby extracting the skeleton or center line of the dilated image.

[0058] Figure 5 A schematic diagram of an edge skeleton image is shown, which the terminal device uses. Figure 4 The contour points in the image shown are dilated and refined to obtain the dilated and refined edge skeleton image 501. The edge skeleton image 501 is an image that retains only the contour points after dilation and refinement in the contour point image 401.

[0059] As mentioned above, by dilating the image according to preset structural elements, the width and edge of the contour points can be increased; based on the contour thinning algorithm, the thinned contour points can be obtained, and the skeleton of the contour points can be extracted, making the contour points even thinner.

[0060] Step 104: Based on the selected points in the contour points, construct the edge curve in the image. The selected points are the contour points located within a specified range of the edge curve and with the minimum cost value. The cost value is calculated based on the cost function and the contour points in the edge curve.

[0061] In this step, the terminal device first selects an outline point that does not yet belong to the edge curve from the outline points to create an edge curve, and selects outline points within the specified range of the edge curve that do not form an edge curve as neighboring points.

[0062] Based on the cost function and the contour points in the edge curve, calculate the cost value of each neighboring point, and select the neighboring point with the smallest cost value. Add the selected point to the edge curve until no neighboring points can be found within the specified range of the edge curve, at which point the edge curve is complete.

[0063] The terminal device can also compare the cost of the selected point with a preset cost threshold. If the cost of the selected point is less than the cost threshold, the selected point is added to the edge curve. If the cost of the selected point is greater than or equal to the cost threshold, the selected point is not added to the edge curve.

[0064] The selected point is the contour point within the specified range of the edge curve that has the lowest cost. The neighboring point is the contour point within the specified range of the edge curve that does not form the edge curve.

[0065] Neighboring points include, but are not limited to: the neighboring point corresponding to the first endpoint and the neighboring point corresponding to the second endpoint. The neighboring point corresponding to the first endpoint is a contour point located within a specified range corresponding to the first endpoint, and the neighboring point corresponding to the second endpoint is a contour point located within a specified range corresponding to the second endpoint.

[0066] For example, the specified range of the edge curve can be a range centered on the first endpoint with a specified radius for finding nearby points, or a range centered on the second endpoint with a specified radius for finding nearby points.

[0067] An edge curve is a line that forms the outline of a pattern in an image and is composed of continuous outline pixels. An edge curve can have two endpoints, namely the first endpoint and the second endpoint. If there is only one outline point in an edge curve, the first endpoint and the second endpoint can be the same outline point.

[0068] The cost is calculated based on the cost function and the contour points in the edge curve. The cost function ensures that the line segment formed by the selected point and the edge curve does not deviate from the direction already formed by the edge curve. The cost threshold is used to filter out neighboring points that deviate from the direction already formed by the edge curve; the cost threshold can be the square of the specified neighboring point search radius.

[0069] The cost value is calculated based on the cost function and the contour points in the edge curve. Specifically, the vector formed by the second-to-last point to the first-to-last point at the endpoint of the edge curve is added to the vector formed by the third-to-last point to the second-to-last point by a first preset multiple to obtain the unit vector in the new direction.

[0070] Obtain the neighboring point vector formed by the nearest point and the last first point. Subtract the second preset multiple of the unit vector in the new direction from the square of the length of the neighboring point vector to obtain the cost corresponding to the neighboring point.

[0071] The first and second preset multiples are predetermined through experiments. Preferably, the first preset multiple is 0.47 and the second preset multiple is 0.99.

[0072] Furthermore, after constructing the edge curves in an image, there will be some redundant data in the edge curves because the pixels in the image are usually very close together, which is not conducive to geometric editing operations. Terminal devices can use the Douglas-Puk algorithm and the isoline simplification algorithm to reduce the number of pixels in the edge curves.

[0073] Please see Figure 6 , Figure 6 A flowchart of an edge curve point reduction method is shown, which may include the following steps:

[0074] Step 602: Construct the line segments corresponding to the edge curves.

[0075] In this step, the terminal device constructs a line segment corresponding to the edge curve between the first and second endpoints of the edge curve. The line segment is a straight line between the first and second endpoints of the edge curve.

[0076] Step 604: Obtain the distance from the fifth pixel in the edge curve to the line segment.

[0077] In this step, the terminal device calculates the distance from each contour point in the edge curve to the line segment. The contour point with the largest distance is selected as the fifth pixel.

[0078] The fifth pixel is the contour point in the edge curve that is the furthest from the line segment. It can be the midpoint between the first endpoint and the second endpoint, or any other contour point between the first endpoint and the second endpoint.

[0079] Step 606: If the distance is less than or equal to the distance threshold, delete the contour points between the first endpoint and the second endpoint.

[0080] In this step, if the distance is less than or equal to a preset distance threshold, the terminal device deletes the contour points between the first endpoint and the second endpoint.

[0081] Step 608: If the distance is greater than the distance threshold, retain the fifth pixel in the edge curve, and repeat the process of dividing the edge curve with the fifth pixel as the boundary. Iterate through the divided edge curves until there are no contour points in the edge curve that are less than or equal to the distance threshold.

[0082] In this step, if the distance is greater than the distance threshold, the terminal device retains the fifth pixel in the edge curve. Using the retained fifth pixel as the boundary, the edge curve is divided into two edge curves. Steps 602 to 608 are repeated iteratively for each edge curve until no more contour points can be discarded. Contour points in the edge curve whose distance to the line segment is less than or equal to the distance threshold are continuously deleted, while contour points whose distance is greater than the distance threshold are retained, finally resulting in a simplified edge curve.

[0083] As described above, by constructing a line segment between the first and second endpoints of the edge curve, the distance from the fifth pixel point in the edge curve to the line segment is obtained. If the distance is less than or equal to the distance threshold, the contour point between the first and second endpoints is deleted. If the distance is greater than the distance threshold, the fifth pixel point in the edge curve is retained. The edge curve is then reduced by removing redundant data, resulting in a simplified edge curve that is basically similar in shape to the original edge curve. This facilitates the user's geometric editing of the edge curve in the line graph.

[0084] Step 106: Generate a line graph corresponding to the image based on the edge curve.

[0085] In this step, the terminal device can repeatedly execute step 104, which involves selecting points from the contour points to construct the edge curves of the image, until all edge curves in the image are constructed, generating a line graph corresponding to the image. The line graph is used to display all the edge curves that constitute the pattern contour.

[0086] Figure 7 A schematic diagram of a line graph is shown. The terminal device constructs the edge curves in the image based on the contour points in the edge skeleton image 501, thus obtaining... Figure 7 The diagram shown is a line graph 701 that includes all the edge curves that make up the pattern.

[0087] The line graph generation method in this embodiment obtains the contour points of the pattern in the image by performing edge detection on the image. Based on the selected points that are within a specified range of the edge curve and have the lowest cost, the edge curve of the image is constructed. According to the edge curve, the corresponding line graph of the image is generated. By continuously adding contour points that are close to the edge curve and have the lowest cost to construct the edge curve, the adjacent contour points in the edge curve are close to each other and do not have large-angle bends. Thus, the generated line graph displays a smooth and rounded edge curve, improves the quality of the line graph corresponding to the pattern, and supports users to further perform geometric calculations and other operations on the curves in the line graph to obtain the pattern style effect required by the user.

[0088] In the foregoing embodiments, edge detection of an image was described, the contour points of a pattern were obtained, the edge curves of the image were constructed, and a line graph corresponding to the image was generated. In the following embodiments, the adaptive Canny edge detection algorithm will be used as an example to provide a more detailed explanation of how to perform edge detection on an image, and this method can be applied to any of the embodiments described above.

[0089] In one embodiment, please refer to Figure 8 , Figure 8 This is a flowchart illustrating an edge detection method according to an exemplary embodiment of this specification. The edge detection method may include the following steps:

[0090] Step 802: Perform convolution calculation on the image to obtain the filtered image.

[0091] In this step, the terminal device can perform convolution calculations on the grayscale converted image to obtain the filtered image.

[0092] For example, the terminal device applies a 5th-order Gaussian filter to the grayscale converted image. Since images typically contain noise, such as compression noise and changes in ambient light, Gaussian filtering can reduce noise and smooth the image. Based on the principle of Gaussian distribution (normal distribution), a 5x5 Gaussian filter template operator is created, and image smoothing is achieved by weighted averaging the image through convolution.

[0093] Applying Gaussian filtering to an image can smooth it out, reducing the impact of noise on edge detection and decreasing the computational complexity of edge detection algorithms. Since operations such as gradient calculation and non-maximum suppression on pixels are sensitive to high-frequency information, overly sharp or complex image boundaries can lead to unstable results. Gaussian filtering can smooth and blur image boundaries, reducing high-frequency information and preventing false positive edges at noisy points, thus improving the accuracy of edge detection.

[0094] Step 804: Calculate the gradient magnitude and gradient direction of each pixel in the filtered image to obtain the gradient map corresponding to the filtered image.

[0095] In this step, the terminal device uses image gradient operators such as Sobel, Prewitt, and Roberts to perform convolution operations on the filtered image, calculate the gradient magnitude and gradient direction of each pixel in the filtered image, and obtain the gradient map corresponding to the filtered image.

[0096] Taking the Sobel operator as an example, the terminal device creates 3x3 Sobel operators in both the horizontal and vertical directions. Using these two sets of 3x3 matrices, convolution is performed on the filtered image. Approximate brightness differences in the horizontal and vertical directions of the filtered image are detected, and the gradient magnitude and direction of each pixel are calculated accordingly, resulting in gradient maps in both the horizontal and vertical directions.

[0097] The gradient magnitude is the square root of the sum of the squares of the gradients in two directions, representing the rate of change of grayscale value for each pixel in the corresponding direction. The gradient direction indicates the trend or direction of the grayscale value change. The Sobel operator is a discrete differential operator used for edge detection.

[0098] Since the edges of patterns in an image typically exhibit large variations in grayscale values, and gradients represent the rate of change in an image, the intensity changes more significantly at edges, resulting in higher gradient magnitudes. By calculating gradient magnitudes, we can identify locations with large gradients in the image, which often correspond to edge positions. Using gradient maps allows for more accurate edge localization.

[0099] Step 806: Determine the gradient direction region of the first pixel based on the gradient ratio of the first pixel in the gradient map and the preset tangent value.

[0100] In this step, after obtaining the gradient map corresponding to the filtered image, the terminal device determines the gradient direction region where each pixel in the gradient map is located.

[0101] Taking the determination of the gradient direction region of the first pixel as an example, the terminal device calculates the gradient ratio of the gradient magnitudes of the first pixel in the vertical and horizontal directions, compares the gradient ratio with a preset tangent value, and determines the gradient direction region of the first pixel. This avoids using the vertical and horizontal gradient magnitudes as xy coordinates and calculating the corresponding coordinates in the polar coordinate system: angle and distance. Directly comparing the gradient ratio with the preset tangent value can calculate the gradient direction region more quickly without the need for complex angle calculations.

[0102] The preset tangent value is the tangent value at a specific angle, used to classify pixels in the same gradient direction region. Taking specific angles of 22.5° and 67.5° as examples, by comparing the gradient ratio corresponding to the first pixel with the tangent values ​​of 22.5° and 67.5° respectively, the gradient direction region of the first pixel can be quickly determined.

[0103] When the gradient ratio corresponding to the first pixel is less than or equal to the tangent value of 22.5°, the gradient direction region of the first pixel is determined to be a horizontal region; when the gradient ratio corresponding to the first pixel is greater than or equal to the tangent value of 67.5°, the gradient direction region of the first pixel is determined to be a vertical region; when the gradient ratio corresponding to the first pixel is greater than the tangent value of 22.5° and less than the tangent value of 67.5°, the gradient direction region of the first pixel is determined to be a diagonal region.

[0104] In this gradient map, the first pixel represents the degree of change in local intensity within the image, i.e., the rate of change of grayscale values. The first pixel has two attributes: gradient magnitude and gradient direction. The gradient ratio is the ratio of the vertical to horizontal gradient magnitudes of pixels in the gradient map.

[0105] A gradient direction region refers to a region in a gradient map that consists of pixels with similar or consistent gradient directions. Gradient direction regions include: horizontal regions, vertical regions, and diagonal regions.

[0106] By calculating the gradient direction region of pixels in the gradient map, the direction of pixels in the gradient map can be determined, which helps to obtain more accurate edges in the subsequent non-maximum suppression.

[0107] Step 808: Determine the second pixel corresponding to the first pixel based on the gradient direction region.

[0108] In this step, the terminal device searches for pixels adjacent to the first pixel in the gradient direction region based on the gradient direction region of the first pixel, and determines the second pixel corresponding to the first pixel.

[0109] The second pixel is the pixel adjacent to the first pixel in the direction corresponding to the gradient direction region. If the gradient direction region of the first pixel is a horizontal region, the second pixel is the two pixels adjacent to the first pixel in the horizontal direction corresponding to the horizontal region.

[0110] If the gradient direction region of the first pixel is a vertical region, then the second pixel is the two pixels adjacent to the first pixel in the vertical direction corresponding to the vertical region.

[0111] If the gradient direction region of the first pixel is a diagonal region, it is necessary to further determine whether the first pixel is located in a 45° diagonal region or a 135° diagonal region.

[0112] If the horizontal gradient magnitude and the vertical gradient magnitude of the first pixel are both greater than 0 or both less than 0, the first pixel is located in the diagonal region of 45°, and the second pixel is the two pixels located in the upper right and lower left directions adjacent to the first pixel in the 45° direction.

[0113] If the horizontal gradient magnitude and the vertical gradient magnitude of the first pixel are not both greater than 0 or both less than 0, the first pixel is located in the diagonal region of 135°, and the second pixel is the two pixels located in the 135° direction adjacent to the first pixel, namely the upper left and lower right pixels.

[0114] Step 810: Based on the gradient magnitude of the first pixel and the gradient magnitude of the second pixel, retain or delete the first pixel in the gradient map.

[0115] In this step, the terminal device compares the gradient magnitude of the first pixel and the gradient magnitude of the second pixel. Since the gradient magnitude may be large at local locations along the edge contour in the image, the most visually obvious location is generally the location of the local maximum gradient magnitude.

[0116] If the gradient magnitude of the first pixel is greater than that of the second pixel, retain the first pixel in the gradient map. If the gradient magnitude of the first pixel is less than or equal to that of the second pixel, delete the first pixel in the gradient map.

[0117] As described above, the gradient direction region of the first pixel is calculated based on the gradient ratio of the first pixel in the gradient map and a preset tangent value. Only the gradient ratio of the vertical gradient magnitude and the horizontal gradient magnitude needs to be calculated to quickly determine the gradient direction region of the pixel.

[0118] Furthermore, based on the gradient direction region, a second pixel adjacent to the first pixel in the direction corresponding to the gradient direction region is determined. If the gradient magnitude of the first pixel is greater than that of the second pixel, the first pixel in the gradient map is retained. If the gradient magnitude of the first pixel is less than or equal to that of the second pixel, the first pixel in the gradient map is deleted. This achieves non-maximum suppression of the pixels in the gradient map, ensuring that only the real pixels in the edges are retained, while the responses in other places are suppressed. This refines and polishes the edges in the image, making the edges clearer and more accurate, and making them closer to the outline of the actual pattern.

[0119] Edge detection algorithms may produce false positive edge responses due to noise or texture in the image. By performing non-maximum suppression in the direction corresponding to the gradient direction region, these false positive edge responses can be eliminated while refining and thinning the edges in the image, thereby improving the accuracy of edge detection.

[0120] Step 812: Based on the threshold determination algorithm, obtain the high threshold and low threshold corresponding to the gradient map.

[0121] In this step, since the locally largest gradient magnitude may be generated by details such as noise, it is necessary to filter the gradient magnitude. The terminal device obtains the high and low thresholds corresponding to the gradient map based on threshold determination algorithms such as Otsu's thresholding (OTSU) and fixed thresholding.

[0122] Taking the Otsu's method as an example, the terminal device can obtain a global threshold for the image. Using the global threshold, the pixels in the gradient map are divided into two parts with the largest inter-class variance. The global threshold is used as the high threshold for the gradient magnitude, and 0.5 times the global threshold is used as the low threshold for the gradient magnitude.

[0123] High and low thresholds are used to filter the gradient magnitude of each pixel in the gradient map.

[0124] Step 814: Determine the contour points based on the high and low thresholds.

[0125] In this step, the terminal device filters the pixels in the gradient map based on high and low thresholds to determine the contour points that belong to the edge curve.

[0126] If the gradient magnitude of the first pixel in the gradient map is greater than or equal to the high threshold, then the gradient change of the first pixel is strong, and the first pixel is determined to be a contour point. If the gradient magnitude of the first pixel is less than or equal to the low threshold, then although the first pixel has the largest local gradient magnitude, the gradient change of the first pixel is still relatively small compared to other pixels. The first pixel may be a noise or other detail location, and the first pixel is determined not to be a contour point.

[0127] If the gradient magnitude of the first pixel is greater than the low threshold and less than the high threshold, it means that although the gradient magnitude of the first pixel is relatively small, it is still higher than the low threshold, and the first pixel may belong to the contour point.

[0128] The terminal device needs to further filter pixels that may belong to the contour point. The eight pixels adjacent to the first pixel that may belong to the contour point are taken as the third pixel. If at least one of the third pixels corresponding to the first pixel that may belong to the contour point is a contour point, then the first pixel is determined to be a contour point.

[0129] That is, if the gradient magnitude of the first pixel is greater than the low threshold, the gradient magnitude of the first pixel is less than the high threshold, and the third pixel corresponding to the first pixel belongs to the contour point, then the first pixel is determined to belong to the contour point.

[0130] By adaptively setting high and low thresholds, pixels in the gradient map are classified into strong edges, weak edges, and non-edges based on the gradient magnitude.

[0131] Strong edges are pixels with gradient magnitudes greater than or equal to the high threshold, which often correspond to real edges; weak edges are pixels with gradient magnitudes greater than the low threshold but less than the high threshold, which may be noise, texture, or weak edges; non-edges are pixels with gradient magnitudes less than or equal to the low threshold, which are not pixels in real edges.

[0132] The terminal device can continuously search for all pixels that may belong to the contour point, find its 8 adjacent positions, and if a pixel is determined to belong to the contour point, then the pixel that may belong to the contour point is confirmed to belong to the contour point.

[0133] The terminal device can also continuously search for all pixels that are determined to belong to the contour point, find its 8 adjacent positions, and if there is a pixel that may belong to the contour point, then confirm that the pixel that may belong to the contour point belongs to the contour point, until no new points that may belong to the edge are found.

[0134] As described above, by determining whether a pixel in the gradient map belongs to a contour point, if the gradient magnitude of the first pixel is greater than or equal to the high threshold, the first pixel is determined to belong to a contour point; if the gradient magnitude of the first pixel is less than or equal to the low threshold, the first pixel is determined not to belong to a contour point; if the gradient magnitude of the first pixel is greater than the low threshold and less than the high threshold, and the third pixel corresponding to the first pixel belongs to a contour point, the first pixel is determined to belong to a contour point. This process determines whether a pixel in the gradient map belongs to a contour point or not, filters out pixels in the true edge, suppresses noise, and enhances edge connectivity, thereby improving the accuracy and stability of edge detection.

[0135] The terminal device retains only the pixels that are identified as contour points in the image, and deletes the pixels that are not contour points in the image, thus obtaining the contour points of the edge curves that constitute the pattern in the image.

[0136] As mentioned above, by performing convolution calculations on the image to obtain a filtered image, image noise can be reduced, image smoothing can be achieved, and gradient calculation can be made more stable. The gradient magnitude and gradient direction of each pixel in the image are calculated to obtain the corresponding gradient map. Based on the threshold determination algorithm, the high threshold and low threshold corresponding to the gradient map are obtained. Based on the high threshold and low threshold, the contour points are determined, avoiding misjudging non-edge areas such as noise or texture as edges, and further improving the accuracy of edge detection.

[0137] In the foregoing embodiments, edge detection of an image was described to determine contour points within the edges. The following embodiments will provide a more detailed explanation of how to construct edge curves in an image, and these embodiments can be applied to any of the above embodiments.

[0138] In one embodiment, the terminal device expands the edge curve by continuously increasing the proximity of the points and satisfying the cost function, connecting the obtained discrete contour points into a smooth and rounded curve to display the shape of the pattern.

[0139] Please see Figure 9 , Figure 9 This is a flowchart illustrating an edge curve construction method according to an exemplary embodiment of this specification. The edge curve construction method may include the following steps:

[0140] Step 902: Determine whether there are contour points in the image that do not form edge curves.

[0141] In this step, the terminal device determines whether there are contour points in the image that do not form edge curves.

[0142] If there are contour points in the image that do not form an edge curve, then proceed to step 904.

[0143] If there are no contour points in the image that do not form an edge curve, then proceed to step 928.

[0144] Step 904: Select the fourth pixel in the image that does not form an edge curve.

[0145] In this step, the terminal device selects the fourth pixel in the image that does not form an edge curve. The fourth pixel is a contour point in the image that does not form an edge curve and is used to create a new edge curve.

[0146] Step 906: Create the edge curve corresponding to the fourth pixel.

[0147] In this step, the terminal device creates an edge curve corresponding to the fourth pixel. The fourth pixel is then added to the edge curve.

[0148] The edge curve is used to extend the new contour point connected to the fourth pixel point. At this time, the contour point in the edge curve is only the fourth pixel point.

[0149] Step 908: Within the specified range corresponding to the first endpoint of the edge curve, find the nearest point corresponding to the first endpoint.

[0150] In this step, the terminal device searches for all contour points around the first endpoint of the edge curve that have not yet been added to the edge curve within a specified range centered on the first endpoint of the edge curve and with a specified radius for finding nearby points as the radius. These points are then used as nearby points corresponding to the first endpoint.

[0151] Step 910: Determine if there are any neighboring points corresponding to the first endpoint.

[0152] In this step, the terminal device determines whether there is a neighboring point corresponding to the first endpoint within a specified range corresponding to the first endpoint.

[0153] If there is a neighboring point corresponding to the first endpoint, then proceed to step 912.

[0154] If there is no nearest point to the first endpoint, proceed to step 922.

[0155] Step 912: Determine whether the number of pixels is less than the preset threshold.

[0156] In this step, the terminal device determines whether the number of pixels on the edge curve is greater than or equal to a preset threshold. The number of pixels refers to the number of contour points on the edge curve. The preset threshold is used to determine whether to select a point.

[0157] Since when the number of pixels is less than the preset threshold, only the distance between the nearest point and the first endpoint needs to be considered, selecting the nearest point to the first endpoint may result in the edge curve not being smooth enough.

[0158] Therefore, setting the preset quantity threshold to three ensures that there are enough three pixels on the edge curve when calculating the cost value, while also ensuring that the newly added contour point is the selected point with the smallest cost value among the neighboring points and the cost value is less than the cost threshold, making the edge curve smoother.

[0159] If the number of pixels on the edge curve is less than the preset threshold, then continue to step 914.

[0160] If the number of pixels on the edge curve is greater than or equal to the preset number threshold, then proceed to step 916.

[0161] Step 914: Add the nearest neighboring point to the first endpoint to the edge curve.

[0162] In this step, when the number of pixels on the edge curve is less than a preset threshold, the terminal device sorts the neighboring points on the image according to the length between each neighboring point and the first endpoint in ascending order, and adds the nearest neighboring point to the edge curve as a new first endpoint. Based on the new first endpoint, step 908 is continued to expand the new contour points in the edge curve.

[0163] As described above, if the number of pixels in the edge curve is less than a preset threshold, the nearest neighboring point to the first endpoint is selected as the selected point. This ensures that the extended contour points are close to the endpoints in the edge curve when the number of pixels is less than the preset threshold, making the edge curve smooth and rounded.

[0164] Step 916: Determine whether the minimum cost is less than the cost threshold.

[0165] In this step, when the number of pixels on the edge curve is greater than or equal to a preset threshold, the terminal device calculates the cost value of neighboring points. The minimum cost value among the neighboring points is selected and compared with the cost threshold to determine whether the minimum cost value is less than the cost threshold.

[0166] If the minimum cost is less than the cost threshold, then proceed to step 918.

[0167] If the minimum cost is greater than or equal to the cost threshold, then proceed to step 922.

[0168] Step 918: Select the nearest point corresponding to the smallest cost value as the selected point.

[0169] In this step, the terminal device selects the nearest point corresponding to the smallest cost value as the selected point corresponding to the first endpoint.

[0170] Step 920: Add the selected point to the edge curve.

[0171] In this step, the terminal device adds the selected point to the edge curve and uses the selected point as the new first endpoint. Based on the new first endpoint, step 908 is then executed to expand the new contour point in the edge curve.

[0172] As described above, by selecting the fourth pixel point that makes up the edge curve in the image, an edge curve corresponding to the fourth pixel point is created. If the number of pixels on the edge curve is greater than or equal to a preset threshold, the nearest point with the lowest cost is selected as the selected point and added to the edge curve. This achieves the goal of finding a nearby selected point that will not bend at a large angle among the nearby points around the endpoint of the edge curve, so that the newly added selected point will not deviate from the direction in which the edge curve is formed.

[0173] Step 922: Determine whether the second endpoint in the edge curve has been calculated.

[0174] In this step, if the terminal device does not have any neighboring points in the contour points, or the cost of the neighboring points is greater than or equal to the cost threshold, and there are no new contour points connected to the first endpoint in the image, it is determined whether the neighboring points corresponding to the second endpoint in the edge curve have been calculated.

[0175] If the second endpoint in the edge curve has not been calculated, proceed to step 924.

[0176] If the second endpoint in the edge curve has been calculated, proceed to step 926.

[0177] Step 924: Construct the edge curve based on the second endpoint of the edge curve.

[0178] In this step, if there are no neighboring points among the contour points, or if the cost of a neighboring point is greater than or equal to the cost threshold, the terminal device uses the second endpoint in the edge curve as the new first endpoint. Based on the new first endpoint, step 908 is continued to expand the new contour points in the edge curve and construct the edge curve.

[0179] As described above, by constructing an edge curve based on the second endpoint of the edge curve when there are no neighboring points in the contour points, or when the cost of neighboring points is greater than or equal to the cost threshold, the contour key points can be extended at the other endpoint of the edge curve without large-angle bending.

[0180] Step 926: Edge curve construction complete.

[0181] In this step, there are no new contour points in the image that can be added to the edge curve, and the edge curve construction is complete.

[0182] Step 928: Determine that all edge curves in the image have been constructed.

[0183] In this step, the terminal device determines that all edge curves in the image have been constructed, and all contour points are connected to form smooth, rounded edge curves.

[0184] To further illustrate the process of generating line charts Figure 10 A flowchart of another method for generating line charts is shown, which may include the following steps:

[0185] Step 1002: Receive the image and nearest-neighbor search radius input by the user.

[0186] Please refer to the following in this step. Figure 2 The terminal device receives a patterned image 201 input by the user and a specified nearest-neighbor search radius.

[0187] Step 1004: Remove the transparent areas from the image and convert it to grayscale.

[0188] Please refer to the following in this step. Figure 3 The terminal device removes the transparent region 2011 from the input image 201 and converts the image after removing the transparent region 2011 into a grayscale image 301.

[0189] Step 1006: Perform adaptive Canny edge detection on the grayscale image to obtain contour points.

[0190] Please refer to the following in this step. Figure 4The terminal device performs adaptive Canny edge detection on the grayscale image 301 to obtain the contour points that constitute the pattern contour in the image 201, and obtains the contour point image 401 that retains only the contour points.

[0191] Step 1008: Expand and refine the contour points.

[0192] Please refer to the following in this step. Figure 5 The terminal device dilates and refines the contour points in the contour point image to obtain the dilated and refined edge skeleton image 501.

[0193] Step 1010: Construct edge curves based on the contour points after expansion and contour refinement.

[0194] In this step, the terminal device expands new contour points at the endpoints of the edge curve based on the dilated and refined contour points in the edge skeleton image to construct the edge curve.

[0195] Step 1012: Perform a point reduction operation on the edge curve.

[0196] In this step, the terminal device performs a point reduction operation on the edge curve, retaining only the contour points whose distance is greater than the distance threshold.

[0197] Step 1014: Generate the line graph corresponding to the image.

[0198] Please refer to the following in this step. Figure 7 The terminal device generates a line graph 701 corresponding to the image based on all edge curves after point reduction, and all edge curves that form the pattern outline on the line graph 701.

[0199] Figure 11 This is a schematic diagram illustrating the structure of an electronic device according to an exemplary embodiment. The electronic device may be, for example, a mobile phone, computer, digital broadcasting terminal, messaging device, game console, tablet device, personal digital assistant, server, smart home appliance, etc. (Reference) Figure 11 At the hardware level, the electronic device includes a processor 1102, an internal bus 1104, a network interface 1106, memory 1108, and non-volatile memory 1110, and may also include other hardware required for business operations. The processor 1102 reads the corresponding computer program from the non-volatile memory 1110 into the memory 1108 and then runs it, forming a line graph generation device at the logical level. Of course, in addition to the software implementation, this application does not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0200] Figure 12 This is a block diagram illustrating a line graph generation apparatus according to an exemplary embodiment of this specification. (Refer to...) Figure 12 The device may include: a contour point acquisition module 1202, an edge curve construction module 1204, and a line graph generation module 1206, wherein:

[0201] The contour point acquisition module 1202 is used to perform edge detection on the image and acquire the contour points of the pattern in the image;

[0202] The edge curve construction module 1204 is used to construct an edge curve in the image based on a selected point among the contour points, wherein the selected point is a contour point located within a specified range of the edge curve and having the lowest cost.

[0203] The line graph generation module 1206 is used to generate a line graph corresponding to the image based on the edge curve.

[0204] In one example, the contour point acquisition module 1202, when performing edge detection on an image and acquiring contour points of a pattern in the image, includes: performing convolution calculation on the image to obtain a filtered image; calculating the gradient magnitude and gradient direction of each pixel in the filtered image to obtain a gradient map corresponding to the filtered image; obtaining a high threshold and a low threshold corresponding to the gradient map based on a threshold determination algorithm; and determining the contour points according to the high threshold and the low threshold.

[0205] In one example, before obtaining the high and low thresholds corresponding to the gradient map based on the threshold determination algorithm, the contour point acquisition module 1202 further includes: determining the gradient direction region of the first pixel based on the gradient ratio of the first pixel in the gradient map and a preset tangent value, wherein the gradient ratio is the ratio of the gradient magnitudes of the first pixel in the vertical and horizontal directions; determining the second pixel corresponding to the first pixel based on the gradient direction region; the second pixel is the pixel adjacent to the first pixel in the direction corresponding to the gradient direction region; if the gradient magnitude of the first pixel is greater than the gradient magnitude of the second pixel, retaining the first pixel in the gradient map; if the gradient magnitude of the first pixel is less than or equal to the gradient magnitude of the second pixel, deleting the first pixel in the gradient map.

[0206] In one example, the contour point acquisition module 1202, when determining the contour point based on the high threshold and the low threshold, includes: if the gradient magnitude of the first pixel in the gradient map is greater than or equal to the high threshold, determining that the first pixel belongs to the contour point; if the gradient magnitude of the first pixel is less than or equal to the low threshold, determining that the first pixel does not belong to the contour point; if the gradient magnitude of the first pixel is greater than the low threshold and less than the high threshold, and the third pixel corresponding to the first pixel belongs to the contour point, determining that the first pixel belongs to the contour point; the third pixel is a pixel adjacent to the first pixel.

[0207] In one example, the edge curve construction module 1204, when constructing an edge curve in an image based on a selected point among the contour points, includes: selecting a fourth pixel in the image, the fourth pixel being a contour point that does not form the edge curve; creating an edge curve corresponding to the fourth pixel; determining the nearest point corresponding to the first endpoint of the edge curve; if the number of pixels in the edge curve is greater than or equal to a preset number threshold, selecting the nearest point with the lowest cost as the selected point; and adding the selected point to the edge curve.

[0208] In one example, the edge curve construction module 1204 is further configured to construct the edge curve based on the second endpoint of the edge curve when there is no neighboring point among the contour points, or when the cost of the neighboring point is greater than or equal to the cost threshold.

[0209] In one example, the edge curve construction module 1204 is further configured to add the nearest neighbor point to the first endpoint to the edge curve if the number of pixels in the edge curve is less than the preset number threshold.

[0210] In one example, before performing edge detection on the image and obtaining the contour points of the pattern in the image, the contour point acquisition module 1202 further includes: performing binarization on the image according to a preset intermediate value, removing transparent areas in the image; and performing grayscale conversion on the pixels in the image.

[0211] In one example, before constructing the edge curve in the image based on selected points in the contour points, the edge curve construction module 1204 further includes: dilating the image according to a preset structural element; and thinning the dilated image based on a contour thinning algorithm to obtain the thinned contour points.

[0212] In one example, the edge curve construction module 1204, after constructing the edge curve in the image, further includes: constructing a line segment corresponding to the edge curve; the line segment is a straight line between the first endpoint and the second endpoint of the edge curve; obtaining the distance from the fifth pixel point in the edge curve to the line segment; if the distance is less than or equal to the distance threshold, deleting the contour point between the first endpoint and the second endpoint; if the distance is greater than the distance threshold, retaining the fifth pixel point in the edge curve.

[0213] The specific implementation process of the functions and roles of each unit in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.

[0214] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of the solution in this specification according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0215] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions, such as a memory including instructions, is also provided, which can be executed by a processor of a line graph generation apparatus to implement the method as described in any of the above embodiments.

[0216] The non-transitory computer-readable storage medium may be ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk and optical data storage device, etc., and this application does not limit it.

[0217] In an exemplary embodiment, a computer program product including a computer program / instructions is also provided, which can be executed by a processor of a line graph generation apparatus to implement the method described in any of the above embodiments.

[0218] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.

[0219] Other embodiments of this specification will readily occur to those skilled in the art upon consideration of the specification and practice of the invention claimed herein. This specification is intended to cover any variations, uses, or adaptations that follow the general principles of this specification and include common knowledge or customary techniques in the art not claimed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this specification are indicated by the following claims.

[0220] It should be understood that this specification is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this specification is limited only by the appended claims.

[0221] The above description is merely a preferred embodiment of this specification and is not intended to limit this specification. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this specification should be included within the scope of protection of this specification.

Claims

1. A method for generating line graphs, characterized in that, The method includes: Edge detection is performed on the image to obtain the contour points of the pattern in the image; Select any contour point from the contour points that does not form an edge curve, and create a new first edge curve; Within a specified range corresponding to the first endpoint of the first edge curve, find the nearest point corresponding to the first endpoint; If the number of pixels on the first edge curve is greater than or equal to a preset threshold, the nearest point with the lowest cost will be selected. If the number of pixels in the first edge curve is less than the preset number threshold, the nearest neighbor to the first endpoint will be selected as the selected point. The selected point is added to the first edge curve as a new first endpoint. The steps of finding nearby points and adding selected points are repeated to construct the first edge curve. Based on all the constructed edge curves, generate the line graph corresponding to the image; The cost value is calculated in the following way: The vector formed from the second-to-last point to the first-to-last point at the endpoint of the first edge curve is added to the vector formed from the third-to-last point to the second-to-last point by a first preset multiple to obtain a unit vector in a new direction. Obtain the nearest point vector formed by the nearest point and the last first point; The cost value corresponding to the neighboring point is obtained by subtracting the second preset multiple of the unit vector in the new direction from the square of the length of the neighboring point vector.

2. The method according to claim 1, characterized in that, The step of performing edge detection on the image to obtain the contour points of the pattern in the image includes: Perform convolution calculation on the image to obtain the filtered image; Calculate the gradient magnitude and gradient direction of each pixel in the filtered image to obtain the gradient map corresponding to the filtered image; Based on the threshold determination algorithm, the high threshold and low threshold corresponding to the gradient map are obtained; The contour points are determined based on the high threshold and the low threshold.

3. The method according to claim 2, characterized in that, Before obtaining the high and low thresholds corresponding to the gradient map using the threshold determination algorithm, the method further includes: Based on the gradient ratio of the first pixel in the gradient map and the preset tangent value, the gradient direction region of the first pixel is determined, wherein the gradient ratio is the ratio of the gradient magnitude of the first pixel in the vertical direction and the horizontal direction. Based on the gradient direction region, a second pixel corresponding to the first pixel is determined; the second pixel is a pixel adjacent to the first pixel in the direction corresponding to the gradient direction region. If the gradient magnitude of the first pixel is greater than the gradient magnitude of the second pixel, the first pixel in the gradient map is retained. If the gradient magnitude of the first pixel is less than or equal to the gradient magnitude of the second pixel, delete the first pixel from the gradient map.

4. The method according to claim 2, characterized in that, Determining the contour point based on the high threshold and the low threshold includes: If the gradient magnitude of the first pixel in the gradient map is greater than or equal to the high threshold, the first pixel is determined to belong to the contour point. If the gradient magnitude of the first pixel is less than or equal to the low threshold, the first pixel is determined not to belong to the contour point. If the gradient magnitude of the first pixel is greater than the low threshold and less than the high threshold, and the third pixel corresponding to the first pixel belongs to the contour point, then the first pixel is determined to belong to the contour point; the third pixel is a pixel adjacent to the first pixel.

5. The method according to claim 1, characterized in that, The method further includes: If no neighboring point exists among the contour points, or if the cost of the neighboring point is greater than or equal to the cost threshold, the first edge curve is constructed based on the second endpoint in the first edge curve. The cost threshold is the square of the specified neighboring point search radius. The cost threshold is used to filter out neighboring points that deviate from the direction already formed by the first edge curve.

6. The method according to claim 1, characterized in that, Before performing edge detection on the image and obtaining the contour points of the pattern in the image, the method further includes: The image is binarized based on a preset intermediate value, and transparent areas in the image are removed. Perform grayscale conversion on the pixels in the image.

7. The method according to claim 1, characterized in that, Before selecting a contour point from the contour points that does not form an edge curve and creating a new first edge curve, the method further includes: The image is dilated according to a preset structural element; Based on the contour thinning algorithm, the dilated image is thinned to obtain the thinned contour points.

8. The method according to claim 1, characterized in that, After constructing the first edge curve and before generating the line graph corresponding to the image based on all constructed edge curves, the method further includes: Construct a line segment corresponding to the edge curve; the line segment is a straight line between the first endpoint and the second endpoint of the edge curve. Obtain the distance from the fifth pixel in the edge curve to the line segment, where the fifth pixel is the contour point in the edge curve with the largest distance to the line segment; If the distance is less than or equal to the distance threshold, delete the contour points between the first endpoint and the second endpoint; If the distance is greater than the distance threshold, the fifth pixel in the edge curve is retained.

9. A line graph generation device, characterized in that, The device includes: The contour point acquisition module is used to perform edge detection on the image and acquire the contour points of the pattern in the image; An edge curve construction module is used to select any contour point from the contour points that does not form an edge curve and create a new first edge curve; within a specified range corresponding to the first endpoint of the first edge curve, find the nearest point corresponding to the first endpoint; if the number of pixels in the first edge curve is greater than or equal to a preset number threshold, select the nearest point with the lowest cost; if the number of pixels in the first edge curve is less than the preset number threshold, select the nearest point closest to the first endpoint; add the selected point to the first edge curve as a new first endpoint, and repeat the steps of finding nearest points and adding selected points to construct the first edge curve; The line graph generation module is used to generate a line graph corresponding to the image based on all the constructed edge curves; The cost value is calculated in the following way: The vector formed from the second-to-last point to the first-to-last point at the endpoint of the first edge curve is added to the vector formed from the third-to-last point to the second-to-last point by a first preset multiple to obtain a unit vector in a new direction. Obtain the nearest point vector formed by the nearest point and the last first point; The cost value corresponding to the neighboring point is obtained by subtracting the second preset multiple of the unit vector in the new direction from the square of the length of the neighboring point vector.

10. An electronic device, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor implements the method as described in any one of claims 1-8 by executing the executable instructions.

11. A computer-readable storage medium storing computer instructions thereon, characterized in that, When executed by the processor, this instruction implements the method as described in any one of claims 1-8.

12. A computer program product having a computer program / instructions stored thereon, characterized in that, When the computer program / instruction is executed by the processor, it implements the method as described in any one of claims 1-8.

Citation Information

Patent Citations

  • Image interpolation method and device

    CN106204453A

  • Canny edge detection method based on bilateral filtering and adaptive threshold

    CN117853510A