Image contour smoothing method and device, electronic equipment and storage medium
By determining the set of reference contour points in image contour smoothing and performing linear fitting, the problems of excessive smoothing and high-frequency information suppression in the prior art are solved, and the accuracy of image contour smoothing is improved.
Patent Information
- Application Number
- CN202411654605.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2025-04-15
AI Technical Summary
The prior art tends to be excessively smoothed during the smoothing of image contours, resulting in problems such as suppression of high-frequency information and low smoothing accuracy.
By determining the set of reference contour points corresponding to the contour points to be smoothed in the image contour according to the preset number of smooth reference points, performing straight lines, obtaining the fitted straight lines, and mapping the contour points to be smoothed onto the fitted straight lines, obtaining the smoothed contour points.
Reduce the impact of noise and error, avoid excessive smoothing, improve the accuracy of image contour smoothing, and make the smoothed contour points closer to the edge of the real object.
Smart Images

Figure CN119831879A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of image processing technology, and in particular relates to an image contour smoothing method, device, electronic device and storage medium. Background Art
[0002] In industrial applications, it is necessary to extract sub-pixel-precision contours, segment, fit, filter, measure and calculate contour features, and detect target contour defect information. Smoothing image contours can correct the current contour point position to remove noise and better describe the target contour position.
[0003] In the related art, image blurring techniques such as Gaussian filtering, median filtering or bilateral filtering are usually used to smooth the image contour. These methods reduce image noise and smooth the contour by performing averaging or weighted averaging operations in local areas of the image. However, while reducing noise, these methods also suppress high-frequency information in the image, resulting in over-smoothing and low smoothing accuracy. Summary of the invention
[0004] The present application aims to solve at least one of the technical problems existing in the prior art. To this end, the present application proposes an image contour smoothing method, device, electronic device and storage medium to improve the accuracy of image contour smoothing.
[0005] In a first aspect, the present application provides an image contour smoothing method, comprising:
[0006] Determine a reference contour point set corresponding to the contour points to be smoothed in the image contour according to a preset number of smoothing reference points;
[0007] Performing straight line fitting on the reference contour points in the reference contour point set to obtain a fitting straight line;
[0008] The contour points to be smoothed are mapped onto the fitting straight line to obtain smoothed contour points.
[0009] According to the image contour smoothing method of the present application, a reference contour point set corresponding to the contour points to be smoothed in the image contour is determined according to a preset number of smoothing reference points; a straight line is fitted to the reference contour points in the reference contour point set to obtain a fitted straight line; and the contour points to be smoothed are mapped to the fitted straight line to obtain smoothed contour points. The embodiment of the present application determines a reference contour point set for straight line fitting according to a preset number of smoothing reference points, and the reference contour points are spatially adjacent or similar to the contour points to be smoothed, and can provide useful information about the local shape of the contour, so that the fitted straight line represents the best linear approximation of these points in the local area, and the contour points to be smoothed are mapped to this fitted straight line, so that the smoothed contour points are closer to the edge of the real object, thereby reducing the influence of noise and error, and reducing the problem of over-smoothing, and improving the accuracy of image contour smoothing.
[0010] According to an embodiment of the present application, determining a reference contour point set corresponding to contour points to be smoothed in the image contour according to a preset number of smoothing reference points includes:
[0011] Dividing the image contour according to the number of threads to obtain a plurality of sub-contours, wherein each thread corresponds to a sub-contour;
[0012] The reference contour point set corresponding to the contour points to be smoothed in each sub-contour is determined according to the preset number of smoothing reference points.
[0013] In this embodiment, the image contour is divided according to the number of threads, each thread corresponds to a sub-contour, so that multiple sub-contours can be processed in parallel, thereby improving the processing speed. In addition, the smoothing process of each sub-contour can be performed based on its local features, rather than a global one-size-fits-all approach, so that the local changes and features of the contour can be captured more accurately, thereby improving the accuracy of contour smoothing.
[0014] According to an embodiment of the present application, determining a reference contour point set corresponding to contour points to be smoothed in the image contour according to a preset number of smoothing reference points includes:
[0015] In a preset range centered on the contour point to be smoothed, n contour points closest to the contour point to be smoothed are selected as reference contour points; wherein n represents the number of smoothing reference points.
[0016] In this embodiment, n contour points closest to the contour point to be smoothed are selected as reference contour points within a preset range centered on the contour point to be smoothed, so that the reference contour points can closely reflect the contour features around the contour point to be smoothed, and more accurately capture the contour changes around the contour point to be smoothed, so that when performing straight line fitting, the local trend of the contour can be more realistically reflected, which not only improves the accuracy of contour smoothing and reduces the error caused by noise, but also because the selection of the reference contour point set is based on the local neighborhood, the natural shape and characteristics of the contour can be maintained, avoiding contour distortion caused by over-smoothing.
[0017] According to an embodiment of the present application, determining a reference contour point set corresponding to contour points to be smoothed in the image contour according to a preset number of smoothing reference points includes:
[0018] Taking the contour point to be smoothed as the center, select 0.5n contour points arranged before the contour point to be smoothed as reference contour points, and select 0.5n contour points arranged after the contour point to be smoothed as reference contour points, where n represents the number of smoothing reference points.
[0019] In this embodiment, by taking the contour point to be smoothed as the center and selecting 0.5n contour points in the front and back as reference contour points, the reference contour point set can be evenly distributed on the contour, covering the local area before and after the contour point to be smoothed, so that the fitting straight line can better reflect the real trend of the contour in the local area. Since the reference contour point set is symmetrically selected, the deviation caused by local contour fluctuation or noise can be effectively reduced, and the accuracy of mapping contour points to the fitting straight line can be improved. In addition, symmetrical selection can also reduce deformation that may occur during the smoothing process while maintaining the continuity of the contour.
[0020] According to an embodiment of the present application, the number of smoothing reference points is an odd number greater than or equal to 3.
[0021] In this embodiment, by selecting an odd number of smooth reference points, a clear center point can be provided in the direct fitting process. This center point plays an anchoring role in the fitting process, reduces conflicts and ambiguities in the straight line fitting process, makes the fitting straight line more certain, and makes the fitting process more stable.
[0022] According to an embodiment of the present application, performing straight line fitting on the reference contour points in the reference contour point set to obtain a fitting straight line includes:
[0023] Obtaining a first coordinate mean value of each reference contour point in a reference contour point set corresponding to a previous contour point to be smoothed;
[0024] Calculate the second coordinate mean of each reference contour point in the reference contour point set corresponding to the contour point to be smoothed according to the first coordinate mean;
[0025] The slope and intercept of the fitting straight line are calculated according to the deviation between each reference contour point in the reference contour point set corresponding to the contour point to be smoothed and the second coordinate mean.
[0026] In this embodiment, the coordinate mean calculated in the previous step is used to calculate the coordinate mean of each reference contour point in the reference contour point set corresponding to the current contour point to be smoothed, so that only a small amount of addition and subtraction operations are required each time the coordinate mean is calculated, instead of recalculating the average value of the entire point set, which effectively reduces repeated calculations and improves the overall calculation efficiency.
[0027] In a second aspect, the present application provides an image contour smoothing device, comprising:
[0028] A determination module, used to determine a reference contour point set corresponding to the contour points to be smoothed in the image contour according to a preset number of smoothing reference points;
[0029] A fitting module, used for performing straight line fitting on the reference contour points in the reference contour point set to obtain a fitting straight line;
[0030] A mapping module is used to map the contour points to be smoothed onto the fitting straight line to obtain smoothed contour points.
[0031] According to the image contour smoothing device of the present application, a reference contour point set corresponding to the contour points to be smoothed in the image contour is determined according to a preset number of smoothing reference points; a straight line is fitted to the reference contour points in the reference contour point set to obtain a fitted straight line; and the contour points to be smoothed are mapped to the fitted straight line to obtain smoothed contour points. The embodiment of the present application determines a reference contour point set for straight line fitting according to a preset number of smoothing reference points, and the reference contour points are spatially adjacent or similar to the contour points to be smoothed, and can provide useful information about the local shape of the contour, so that the fitted straight line represents the best linear approximation of these points in the local area, and the contour points to be smoothed are mapped to this fitted straight line, so that the smoothed contour points are closer to the edge of the real object, thereby reducing the influence of noise and error, and reducing the problem of over-smoothing, and improving the accuracy of image contour smoothing.
[0032] In a third aspect, the present application provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the image contour smoothing method as described in the first aspect above is implemented.
[0033] In a fourth aspect, the present application provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the image contour smoothing method as described in the first aspect above is implemented.
[0034] In a fifth aspect, the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a program or instruction to implement the image contour smoothing method as described in the first aspect above.
[0035] In a sixth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the image contour smoothing method as described in the first aspect above.
[0036] The above one or more technical solutions in the embodiments of the present application have at least one of the following technical effects:
[0037] According to the image contour smoothing method of the present application, a reference contour point set corresponding to the contour points to be smoothed in the image contour is determined according to a preset number of smoothing reference points; a straight line is fitted to the reference contour points in the reference contour point set to obtain a fitted straight line; and the contour points to be smoothed are mapped to the fitted straight line to obtain smoothed contour points. The embodiment of the present application determines a reference contour point set for straight line fitting according to a preset number of smoothing reference points, and the reference contour points are spatially adjacent or similar to the contour points to be smoothed, and can provide useful information about the local shape of the contour, so that the fitted straight line represents the best linear approximation of these points in the local area, and the contour points to be smoothed are mapped to this fitted straight line, so that the smoothed contour points are closer to the edge of the real object, thereby reducing the influence of noise and error, and reducing the problem of over-smoothing, and improving the accuracy of image contour smoothing.
[0038] Furthermore, in some embodiments, the image contour is divided according to the number of threads, each thread corresponds to a sub-contour, so that multiple sub-contours can be processed in parallel, thereby improving the processing speed. In addition, the smoothing process of each sub-contour can be performed based on its local features, rather than a global one-size-fits-all approach, so that the local changes and features of the contour can be captured more accurately, thereby improving the accuracy of contour smoothing.
[0039] Furthermore, in some embodiments, by selecting n contour points closest to the contour point to be smoothed within a preset range centered on the contour point to be smoothed as reference contour points, the reference contour points can closely reflect the contour features around the contour point to be smoothed, and more accurately capture the contour changes around the contour point to be smoothed, so that when performing straight line fitting, the local trend of the contour can be more realistically reflected, which not only improves the accuracy of contour smoothing and reduces the error caused by noise, but also because the selection of the reference contour point set is based on the local neighborhood, it can also maintain the natural shape and characteristics of the contour, avoiding contour distortion caused by over-smoothing.
[0040] Furthermore, in some embodiments, by taking the contour point to be smoothed as the center and selecting 0.5n contour points in the front and back as reference contour points, the reference contour point set can be evenly distributed on the contour, covering the local area before and after the contour point to be smoothed, so that the fitting line can better reflect the real trend of the contour in the local area. Since the reference contour point set is symmetrically selected, the deviation caused by local contour fluctuation or noise can be effectively reduced, and the accuracy of mapping contour points to the fitting line can be improved. In addition, symmetrical selection can also reduce deformation that may occur during the smoothing process while maintaining the continuity of the contour.
[0041] Furthermore, in some embodiments, by selecting an odd number of smooth reference points, a clear center point can be provided in the direct fitting process. This center point acts as an anchor in the fitting process, reduces conflicts and ambiguities in the straight line fitting process, and makes the fitting straight line more certain and the fitting process more stable.
[0042] Furthermore, in some embodiments, the coordinate mean calculated in the previous step is used to calculate the coordinate mean of each reference contour point in the reference contour point set corresponding to the current contour point to be smoothed, so that only a small amount of addition and subtraction operations are required each time the coordinate mean is calculated, instead of recalculating the average value of the entire point set, which effectively reduces repeated calculations and improves the overall calculation efficiency.
[0043] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0045] Figure 1 is a flow chart of an image contour smoothing method provided in an embodiment of the present application;
[0046] Figure 2 is a schematic diagram of an image contour before smoothing provided in an embodiment of the present application;
[0047] Figure 3 is a schematic diagram of mapping contour points to be smoothed to a fitting straight line provided in an embodiment of the present application;
[0048] Figure 4 is a schematic diagram of a smoothed image contour provided in an embodiment of the present application;
[0049] Figure 5 is a schematic diagram of the structure of an image contour smoothing device provided in an embodiment of the present application;
[0050] Figure 6 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
[0052] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0053] The image contour smoothing method, device, electronic device and storage medium provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings through specific embodiments and their application scenarios.
[0054] The image contour smoothing method may be applied to a terminal, and may be specifically executed by hardware or software in the terminal.
[0055] The terminal includes, but is not limited to, a portable communication device such as a mobile phone or tablet computer with a touch-sensitive surface (e.g., a touch screen display and / or a touch pad). It should also be understood that in some embodiments, the terminal may not be a portable communication device, but a desktop computer with a touch-sensitive surface (e.g., a touch screen display and / or a touch pad).
[0056] In the following various embodiments, a terminal including a display and a touch-sensitive surface is described. However, it should be understood that the terminal may include one or more other physical user interface devices such as a physical keyboard, a mouse and a joystick.
[0057] The image contour smoothing method provided in the embodiment of the present application may be executed by an electronic device or a functional module or functional entity in the electronic device that can implement the image contour smoothing method. The electronic devices mentioned in the embodiment of the present application include but are not limited to mobile phones, tablet computers, computers, cameras, and wearable devices. The image contour smoothing method provided in the embodiment of the present application is described below using an electronic device as an example of the execution subject.
[0058] like Figure 1 As shown, the image contour smoothing method includes: step 110, step 120 and step 130.
[0059] Step 110: Determine a reference contour point set corresponding to the contour points to be smoothed in the image contour according to a preset number of smoothing reference points.
[0060] In the embodiment of the present application, the image contour refers to the line connecting the edges of the object in the image, which describes the outline of the object. Figure 2 As shown. In digital image processing, a contour is a representation of the boundary of an object, usually composed of a series of pixels that define the outer boundary of the object. Contours can be open (such as curves) or closed (such as polygons). Contour points are the pixels that make up the outline of the image, and these pixels are the exact location of the edge of the object in the image. In image processing, contour points can be obtained through edge detection algorithms, such as Canny edge detector, Sobel operator, etc.
[0061] In some embodiments, for an image, the image contour can be detected from the image. For example, this can be achieved by converting the image into a grayscale image and then performing a binarization process. After the binarization process, the findContours function in the OpenCV library can be used to detect the contour. In one example, after acquiring the image, the image can be preprocessed, such as denoising, contrast enhancement, etc., to improve the accuracy of edge detection, and the edges in the image can be identified by edge detection algorithms such as Canny, Sobel, Prewitt, Laplacian, etc. Among them, the edge detection algorithm can determine the position of the edge by calculating the gradient of the image. The detected edge points are connected to form a continuous image contour, and the pixel points on the image contour are contour points.
[0062] In some embodiments, the process of smoothing the image contour may be to process each contour point on the image contour, or to selectively process some contour points on the image contour, for example, to select the contour point with the largest curvature change on the image contour. The contour point to be smoothed is the contour point that needs to be smoothed.
[0063] In an embodiment of the present application, for the contour points to be smoothed, a set of reference contour points can be determined, and this set of reference contour points is the reference contour point set corresponding to the contour points to be smoothed. The reference contour points in the reference contour point set can be field points around the contour points to be smoothed, or contour points selected by an algorithm such as the least squares method. The number of reference contour points can be determined based on a preset number of smoothing reference points. Too many smoothing reference points may result in a large amount of calculation and lead to over-smoothing. Too few smoothing reference points may cause the subsequent fitted straight line to differ too much from the contour. The number of smoothing reference points can be a value entered by the user, or a value determined based on hardware resources.
[0064] Step 120 , performing straight line fitting on the reference contour points in the reference contour point set to obtain a fitting straight line.
[0065] In the embodiment of the present application, through straight line fitting, a best fitting straight line can be found from the scattered reference contour points, so that the total distance from these reference contour points to the straight line is minimized. The fitted straight line can be used to approximate the shape of the contour, reduce the complexity of the data, and retain key information. Specifically, after obtaining the reference contour point set, the reference contour points in the reference contour point set can be fitted with a straight line fitting method, such as the least squares method, to obtain a fitted straight line.
[0066] Step 130: Map the contour points to be smoothed onto the fitting line to obtain smoothed contour points.
[0067] In the embodiment of the present application, the contour point to be smoothed is mapped to the fitting line, and a mapping point on the fitting line can be found. The mapping point is the point on the fitting line closest to the contour point to be smoothed, and the mapping point is the smoothed contour point corresponding to the contour point to be smoothed. Figure 3 As shown, the mapping point of the contour point Pi to be smoothed on the straight line is Pj
[0068] Specifically, the projection coordinates of the contour point on the straight line can be calculated by calculating the vertical distance from the contour point to be smoothed to the fitting line and according to the vertical distance and the direction vector of the straight line. The calculated projection coordinates are used as the new contour point coordinates to replace the original coordinates of the contour point to be smoothed. In this way, each contour point to be smoothed in the image contour is mapped to its corresponding fitting line, thereby obtaining the smoothed contour points corresponding to each contour point to be smoothed, and finally outputting the smoothed contour corresponding to the image contour, such as Figure 4 shown.
[0069] According to the image contour smoothing method of the present application, a reference contour point set corresponding to the contour points to be smoothed in the image contour is determined according to a preset number of smoothing reference points; a straight line is fitted to the reference contour points in the reference contour point set to obtain a fitted straight line; and the contour points to be smoothed are mapped onto the fitted straight line to obtain smoothed contour points. The embodiment of the present application determines a reference contour point set for straight line fitting according to a preset number of smoothing reference points, and the reference contour points are spatially adjacent or similar to the contour points to be smoothed, and can provide useful information about the local shape of the contour, so that the fitted straight line represents the best linear approximation of these points in the local area, and the contour points to be smoothed are mapped onto this fitted straight line, so that the smoothed contour points are closer to the edge of the real object, thereby reducing the influence of noise and error, and reducing the problem of over-smoothing, and improving the accuracy of image contour smoothing.
[0070] In some embodiments, determining a reference contour point set corresponding to the contour point to be smoothed in the image contour according to a preset number of smoothing reference points includes:
[0071] The image contour is divided according to the number of threads to obtain multiple sub-contours, wherein each thread corresponds to a sub-contour;
[0072] The reference contour point set corresponding to the contour points to be smoothed in each sub-contour is determined according to the preset number of smoothing reference points.
[0073] In this embodiment, the number of threads used to process the image contour may be determined based on the number of cores of a CPU (Central Processing Unit), the size and complexity of the image, and the expected processing speed.
[0074] The entire image contour can be divided into equal or unequal parts according to the number of threads so that each thread has a workload. Equal division allows each thread to process the same number of contour points, while unequal division allows dynamic allocation based on the distribution of contour points or other factors. The thread pool can be used to manage the creation, execution, and destruction of threads, assign a sub-contour to each thread for processing, and independently process the contour points in the corresponding sub-contour to determine the reference contour point set and perform subsequent smoothing. Each thread can process the assigned sub-contours in parallel, thereby significantly reducing the overall processing time, especially when processing large images or complex contours.
[0075] In this embodiment, the image contour is divided according to the number of threads, each thread corresponds to a sub-contour, so that multiple sub-contours can be processed in parallel, thereby improving the processing speed. In addition, the smoothing process of each sub-contour can be performed based on its local features, rather than a global one-size-fits-all approach, so that the local changes and features of the contour can be captured more accurately, thereby improving the accuracy of contour smoothing.
[0076] In some embodiments, determining a reference contour point set corresponding to the contour point to be smoothed in the image contour according to a preset number of smoothing reference points includes:
[0077] In a preset range centered on the contour point to be smoothed, n contour points closest to the contour point to be smoothed are selected as reference contour points; wherein n represents the number of smoothing reference points.
[0078] In this embodiment, a preset range centered on the contour point to be smoothed may be determined, and then the distances between each contour point within the preset range and the contour point to be smoothed are calculated, and the n contour points closest to the contour point to be smoothed are selected as reference contour points.
[0079] In this embodiment, n contour points closest to the contour point to be smoothed are selected as reference contour points within a preset range centered on the contour point to be smoothed, so that the reference contour points can closely reflect the contour features around the contour point to be smoothed, and more accurately capture the contour changes around the contour point to be smoothed, so that when performing straight line fitting, the local trend of the contour can be more realistically reflected, which not only improves the accuracy of contour smoothing and reduces the error caused by noise, but also because the selection of the reference contour point set is based on the local neighborhood, the natural shape and characteristics of the contour can be maintained, avoiding contour distortion caused by over-smoothing.
[0080] In some embodiments, determining a reference contour point set corresponding to the contour point to be smoothed in the image contour according to a preset number of smoothing reference points includes:
[0081] Taking the contour point to be smoothed as the center, select 0.5n contour points arranged before the contour point to be smoothed as reference contour points, and select 0.5n contour points arranged after the contour point to be smoothed as reference contour points, where n represents the number of smoothing reference points.
[0082] In this embodiment, for the contour point to be smoothed, 0.5n contour points arranged before the contour point to be smoothed can be selected as reference contour points, and 0.5n contour points arranged after the contour point to be smoothed can be selected as reference contour points, so that the reference contour points are evenly distributed in the local area before and after the smoothed contour point.
[0083] In some embodiments, the number of smoothing reference points is an odd number greater than or equal to three.
[0084] In this embodiment, by selecting an odd number of smooth reference points, a clear center point can be provided in the direct fitting process. This center point plays an anchoring role in the fitting process, reduces conflicts and ambiguities in the straight line fitting process, makes the fitting straight line more certain, and makes the fitting process more stable.
[0085] It should be noted that if the number of smoothing reference points is an odd number greater than or equal to 3, 0.5n contour points arranged before the contour point to be smoothed are selected as reference contour points, and 0.5n contour points arranged after the contour point to be smoothed are selected as reference contour points. The calculated 0.5n is not an integer. The 0.5n contour points arranged before the contour point to be smoothed can be rounded up, and the 0.5n contour points arranged after the contour point to be smoothed can be rounded down; or, the 0.5n contour points arranged before the contour point to be smoothed can be rounded down, and the 0.5n contour points arranged after the contour point to be smoothed can be rounded up, so that the number of reference contour points is equal to the number of smoothing reference points.
[0086] In this embodiment, by taking the contour point to be smoothed as the center and selecting 0.5n contour points in the front and back as reference contour points, the reference contour point set can be evenly distributed on the contour, covering the local area before and after the contour point to be smoothed, so that the fitting straight line can better reflect the real trend of the contour in the local area. Since the reference contour point set is symmetrically selected, the deviation caused by local contour fluctuation or noise can be effectively reduced, and the accuracy of mapping contour points to the fitting straight line can be improved. In addition, symmetrical selection can also reduce deformation that may occur during the smoothing process while maintaining the continuity of the contour.
[0087] In some embodiments, performing straight line fitting on reference contour points in the reference contour point set to obtain a fitting straight line includes:
[0088] Obtain the first coordinate mean of each reference contour point in the reference contour point set corresponding to the previous contour point to be smoothed;
[0089] Calculate the second coordinate mean of each reference contour point in the reference contour point set corresponding to the contour point to be smoothed according to the first coordinate mean;
[0090] The slope and intercept of the fitting line are calculated according to the deviation between each reference contour point in the reference contour point set corresponding to the contour point to be smoothed and the mean value of the second coordinate.
[0091] In this embodiment, the process of smoothing the image contour can be to process each contour point on the image contour, and perform traversal processing according to the arrangement order of the contour points in the image contour. The current contour point traversed is the contour point to be smoothed. Therefore, the reference contour point set corresponding to the current contour point to be smoothed is {(X a ,Y a ),(X a+1 ,Y a+1 )…(X a+n-1 , Y a+n-1 )}, then the reference contour point set corresponding to the previous contour point to be smoothed is {(X a-1 ,Y a-1 ),(X a ,Y a )…(X a+n-2 , Y a+n-2 )}. The reference contour point set corresponding to the previous contour point to be smoothed is {(X a-1 ,Y a-1 ),(X a ,Y a )…(X a+n-2 , Y a+n-2 )}, the mean value of the horizontal coordinate is fAvgPointPreX, and the mean value of the vertical coordinate is fAvgPointPreY. The reference contour point set corresponding to the current contour point to be smoothed can be calculated as {(X a ,Y a ),(X a+1 ,Y a+1 )…(X a+n-1 , Y a+n-1 )} the mean value of the horizontal coordinate fAvgPointX=fAvgPointPreX+(X a+n-1 -X a-1 ) / n, the vertical coordinate mean fAvgPointY=fAvgPointPreY+(Y a+n-1 -Y a-1 ) / n, in this way, compared with recalculating the average value of the entire point set, n-2 addition operations can be saved.
[0092] Then, the slope and intercept of the fitting line can be calculated based on the deviation between each reference contour point in the reference contour point set corresponding to the contour point to be smoothed and the mean value of the second coordinate. The specific calculation process is as follows:
[0093] In order to fully consider the errors of the x-axis and y-axis, the traditional fitting straight line equation y=kx+b, which can only optimize the error in the x-axis direction, is converted to Ax+By+C=0; in this way, the errors in the x- and y-axis directions can be better optimized.
[0094] The reference contour point set corresponding to the current contour point to be smoothed is {(X a ,Y a ),(X a+1 ,Y a+1 )…(X a+n-1 , Y a+n-1 )}, fit the equation of the straight line Ax+By+C=0, then the problem can be transformed into a problem with unknowns A, B, C, so that the distance from the reference contour points in the reference contour point set to the straight line Ax+By+C=0 is minimized.
[0095] The sum of the squares of the distances from the reference contour points to the straight line is: According to the properties of the straight line, we can get A 2 +B 2 =1, so the problem of fitting a straight line is transformed into finding The minimum value of .
[0096] The reference contour point set corresponding to the current contour point to be smoothed is {(X a ,Y a ),(X a+1 ,Y a+1 )…(X a+n-1 , Y a+n-1 )}, then the reference contour point set corresponding to the previous contour point to be smoothed is {(X a-1 ,Y a-1 ),(X a ,Y a )…(X a+n-2 , Y a+n-2 )}, the reference contour point set corresponding to the current contour point to be smoothed can be calculated as {(X a ,Y a ),(X a+1 ,Y a+1 )…(X a+n-1 , Y a+n-1 )} the mean value of the horizontal coordinate fAvgPointX=fAvgPointPreX+(X a+n-1 -X a-1 ) / n, the vertical coordinate mean fAvgPointY=fAvgPointPreY+(Ya+n-1 -Y a-1 ) / n.
[0097] The process of solving A, B, and C by partial derivative of f(x) is as follows: traverse the reference contour point set {(X a ,Y a ),(X a+1 ,Y a+1 )…(X a+n-1 , Y a+n-1 )} a reference contour point (X i ,Y i ).
[0098] for (traverse the reference contour point set)
[0099] {
[0100] fX=X i -fAvgPointX;
[0101] fY=Y i -fAvgPointY;
[0102] fSumXX+=fX*fX;
[0103] fSumXY+=fX*fY;
[0104] fSumYY+=fY*fY;
[0105] }
[0106] fDifXXYY=-fSumXX+fSumYY;
[0107] slope=(fDifXXYY+sqrt((fDifXXYY)*(fDifXXYY)+4.0*fSumXY*fSumXY)) / (2.0*fSumXY);
[0108] intercept=fAvgPointY-slope*fAvgPointX;
[0109] A = slope;
[0110] B = -1.0;
[0111] C = intercept;
[0112] Where fX represents the reference contour point (X i ,Y i ) and fAvgPointX, fY represents the reference contour point (X i ,Y i) is the deviation from fAvgPointY, fSumXX, fSumXY, fSumYY and fDifXXYY are intermediate variables, slope represents the slope of the line, and intercept represents the intercept of the line.
[0113] In this embodiment, the coordinate mean calculated in the previous step is used to calculate the coordinate mean of each reference contour point in the reference contour point set corresponding to the current contour point to be smoothed, so that only a small amount of addition and subtraction operations are required each time the coordinate mean is calculated, instead of recalculating the average value of the entire point set, which effectively reduces repeated calculations and improves the overall calculation efficiency.
[0114] The image contour smoothing method provided in the embodiment of the present application can be executed by an image contour smoothing device. In the embodiment of the present application, the image contour smoothing device provided in the embodiment of the present application is described by taking the image contour smoothing device executing the image contour smoothing method as an example.
[0115] The embodiment of the present application also provides an image contour smoothing device.
[0116] like Figure 5 As shown, the image contour smoothing device comprises:
[0117] A determination module 510 is used to determine a reference contour point set corresponding to the contour points to be smoothed in the image contour according to a preset number of smoothing reference points;
[0118] A fitting module 520 is used to perform straight line fitting on the reference contour points in the reference contour point set to obtain a fitting straight line;
[0119] The mapping module 530 is used to map the contour points to be smoothed onto the fitting line to obtain the smoothed contour points.
[0120] According to the image contour smoothing device of the present application, a reference contour point set corresponding to the contour points to be smoothed in the image contour is determined according to a preset number of smoothing reference points; a straight line is fitted to the reference contour points in the reference contour point set to obtain a fitted straight line; and the contour points to be smoothed are mapped onto the fitted straight line to obtain smoothed contour points. The embodiment of the present application determines a reference contour point set for straight line fitting according to a preset number of smoothing reference points, and the reference contour points are spatially adjacent or similar to the contour points to be smoothed, and can provide useful information about the local shape of the contour, so that the fitted straight line represents the best linear approximation of these points in the local area, and the contour points to be smoothed are mapped onto this fitted straight line, so that the smoothed contour points are closer to the edge of the real object, thereby reducing the influence of noise and error, and reducing the problem of over-smoothing, and improving the accuracy of image contour smoothing.
[0121] In some embodiments, the determination module 510 is further configured to:
[0122] The image contour is divided according to the number of threads to obtain multiple sub-contours, wherein each thread corresponds to a sub-contour;
[0123] The reference contour point set corresponding to the contour points to be smoothed in each sub-contour is determined according to the preset number of smoothing reference points.
[0124] In some embodiments, the determination module 510 is further configured to:
[0125] In a preset range centered on the contour point to be smoothed, n contour points closest to the contour point to be smoothed are selected as reference contour points; wherein n represents the number of smoothing reference points.
[0126] In some embodiments, the determination module 510 is further configured to:
[0127] Taking the contour point to be smoothed as the center, select 0.5n contour points arranged before the contour point to be smoothed as reference contour points, and select 0.5n contour points arranged after the contour point to be smoothed as reference contour points, where n represents the number of smoothing reference points.
[0128] In some embodiments, the fitting module 520 is further configured to:
[0129] Obtain the first coordinate mean of each reference contour point in the reference contour point set corresponding to the previous contour point to be smoothed;
[0130] Calculate the second coordinate mean of each reference contour point in the reference contour point set corresponding to the contour point to be smoothed according to the first coordinate mean;
[0131] The slope and intercept of the fitting line are calculated according to the deviation between each reference contour point in the reference contour point set corresponding to the contour point to be smoothed and the mean value of the second coordinate.
[0132] The image contour smoothing device in the embodiment of the present application can be an electronic device, or a component in the electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal, or other devices other than a terminal. Exemplarily, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a palmtop computer, a vehicle-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.
[0133] The image contour smoothing device in the embodiment of the present application may be a device having an operating system. The operating system may be a Microsoft (Windows) operating system, an Android (Android) operating system, an IOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.
[0134] In some embodiments, Figure 6 As shown, an embodiment of the present application also provides an electronic device 600, including a processor 601, a memory 602, and a computer program stored in the memory 602 and executable on the processor 601. When the program is executed by the processor 601, each process of the above-mentioned image contour smoothing method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.
[0135] It should be noted that the electronic devices in the embodiments of the present application include the above-mentioned mobile electronic devices and non-mobile electronic devices.
[0136] An embodiment of the present application also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the various processes of the above-mentioned image contour smoothing method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0137] The processor is the processor in the electronic device in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
[0138] An embodiment of the present application also provides a computer program product, including a computer program, which implements the above-mentioned image contour smoothing method when executed by a processor.
[0139] The processor is the processor in the electronic device in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
[0140] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface and the processor are coupled, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned embodiment based on the image contour smoothing method, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0141] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0142] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes 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 one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0143] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0144] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
[0145] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples", or "some examples" means that the specific features, structures, materials, or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0146] Although the embodiments of the present application have been shown and described, those skilled in the art will appreciate that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present application, and that the scope of the present application is defined by the claims and their equivalents.
Claims
1. A method for smoothing an image contour, characterized in that: include: Determine a reference contour point set corresponding to the contour points to be smoothed in the image contour according to a preset number of smoothing reference points; Performing straight line fitting on the reference contour points in the reference contour point set to obtain a fitting straight line; The contour points to be smoothed are mapped onto the fitting straight line to obtain smoothed contour points.
2. The method according to claim 1, characterized in that The step of determining a reference contour point set corresponding to the contour points to be smoothed in the image contour according to a preset number of smoothing reference points includes: Dividing the image contour according to the number of threads to obtain a plurality of sub-contours, wherein each thread corresponds to a sub-contour; The reference contour point set corresponding to the contour points to be smoothed in each sub-contour is determined according to the preset number of smoothing reference points.
3. The method according to claim 1, characterized in that: The step of determining a reference contour point set corresponding to the contour points to be smoothed in the image contour according to a preset number of smoothing reference points includes: In a preset range centered on the contour point to be smoothed, n contour points closest to the contour point to be smoothed are selected as reference contour points; wherein n represents the number of smoothing reference points.
4. The method according to claim 1, characterized in that The step of determining a reference contour point set corresponding to the contour points to be smoothed in the image contour according to a preset number of smoothing reference points includes: Taking the contour point to be smoothed as the center, select 0.5n contour points arranged before the contour point to be smoothed as reference contour points, and select 0.5n contour points arranged after the contour point to be smoothed as reference contour points, where n represents the number of smoothing reference points.
5. The method according to claim 1, characterized in that The number of smoothing reference points is an odd number greater than or equal to 3.
6. The method according to claim 1, characterized in that The performing straight line fitting on the reference contour points in the reference contour point set to obtain a fitting straight line comprises: Obtaining a first coordinate mean value of each reference contour point in a reference contour point set corresponding to a previous contour point to be smoothed; Calculate the second coordinate mean of each reference contour point in the reference contour point set corresponding to the contour point to be smoothed according to the first coordinate mean; The slope and intercept of the fitting straight line are calculated according to the deviation between each reference contour point in the reference contour point set corresponding to the contour point to be smoothed and the second coordinate mean.
7. An image contour smoothing device, characterized in that: include: A determination module, used to determine a reference contour point set corresponding to the contour points to be smoothed in the image contour according to a preset number of smoothing reference points; A fitting module, used for performing straight line fitting on the reference contour points in the reference contour point set to obtain a fitting straight line; A mapping module is used to map the contour points to be smoothed onto the fitting straight line to obtain smoothed contour points.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method according to any one of claims 1 to 6 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.