Sub-pixel profile extraction method and image processing apparatus
Through filtering, gradient calculation and bifurcation point blocking strategy, independent pixel contour chains are generated and dynamic sub-pixel interpolation is performed, which solves the problems of contour adhesion and insufficient precision in existing methods and realizes the extraction of high-precision sparse edge contours.
Patent Information
- Application Number
- CN202511157569.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-19
- Publication Date
- 2025-10-14
- Estimated Expiration
- 2045-08-19
AI Technical Summary
Existing sub-pixel edge detection methods are difficult to meet the application requirements of high precision and sparse edge contours, especially in complex bifurcation structures, where contour adhesion and accuracy degradation are prone to occur.
By filtering and calculating the gradient of the input image, a binary image of the edge contour is generated, single pixelization and connected domain analysis are performed, bifurcation points are detected and blocked, independent pixel contour chains are generated, and the interpolation model is dynamically selected based on the gradient direction for sub-pixel interpolation.
The integrity and independence of the contour chain under complex bifurcation structures are achieved, the contour positioning accuracy is improved, and clear, continuous and sparse contours without redundant branches are generated to meet the application requirements of high-precision and sparse edge contours.
Smart Images

Figure CN120655670B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of image processing, and in particular to a sub-pixel contour extraction method and an image processing device. Background Art
[0002] With the upgrading of industrialization, machine vision contour extraction systems are widely used in many industries. For example, in the automotive manufacturing industry, the edge contours of parts are extracted for cutting by cutting machines, or the difference between the edge contours of parts after cutting and the contours of designed models are compared to quickly detect burrs, cracks, etc.; in the dispensing industry, the edge contours of products are extracted to quickly produce glue paths for dispensing systems; in the machinery manufacturing industry, the edge contours of metal parts are extracted to quickly detect the size and shape of parts to ensure the accuracy of assembly, etc.
[0003] As industry application requirements become increasingly demanding, the efficiency and accuracy requirements for edge contour extraction are also becoming increasingly higher without changing the equipment cost. Alternatively, the requirements are becoming more diverse. For example, for some special applications, a dense set of contour points is not required, but only a sparse set of points that does not change the original shape of the contour. Currently, the commonly used sub-pixel edge detection method is usually based on the gradient local maximum method, that is, the pixel edge point is found based on the local maximum value of the amplitude in the gradient direction, and then the sub-pixel accuracy is calculated at the pixel edge point based on interpolation or fitting methods. Interpolation-based methods are affected by the degree of match between the actual shape of the data and the fitting curve, and are difficult to meet the application requirements of high precision and sparse edge contours. Summary of the Invention
[0004] The main purpose of this application is to provide a sub-pixel contour extraction method and image processing device, aiming to solve the problem that the currently commonly used sub-pixel edge detection methods are difficult to meet the application requirements of high precision and sparse edge contours.
[0005] To achieve the above objectives, this application proposes a sub-pixel contour extraction method, comprising:
[0006] Filtering the input image and calculating gradient information to obtain a gradient amplitude map, and performing threshold screening and non-maximum suppression on the gradient amplitude map to generate a binary image of the edge contour;
[0007] Performing pixel-wise conversion on the binary image to obtain a binary image with a single pixel width, and performing connected domain analysis on the binary image with a single pixel width to obtain a plurality of connected components;
[0008] detecting a starting point of each of the connected components, and performing contour tracing along a path of the connected component starting from the starting point, wherein when a branch point is encountered during the contour tracing, a connection between a current contour and the branch point is blocked, and contour tracing is iteratively performed with a branch point in a neighborhood of the branch point as a new starting point to generate a plurality of independent pixel contour chains;
[0009] performing sub-pixel interpolation on each of the contour points according to a gradient direction of the contour point to obtain a sub-pixel contour chain.
[0010] In an embodiment, the specific steps of filtering and calculating gradient information of the input image, obtaining a gradient amplitude graph, and performing threshold screening and non-maximum suppression on the gradient amplitude graph to generate a binary image of an edge contour include:
[0011] collecting an image, and performing Gaussian filtering and denoising on the image;
[0012] performing gradient field calculation on the Gaussian filtered image using a gradient operator to generate a horizontal gradient graph, a vertical gradient graph, and a gradient amplitude graph;
[0013] performing gradient intensity screening on the gradient amplitude graph to retain gradient values greater than or equal to a preset threshold;
[0014] performing gradient direction non-maximum suppression on the screened gradient amplitude graph to obtain pixel-level edge points and generate a binary image of an edge contour.
[0015] In an embodiment, the specific steps of detecting a starting point of each of the connected components, and performing contour tracing along a path of the connected component starting from the starting point, wherein when a branch point is encountered during the contour tracing, a connection between a current contour and the branch point is blocked, and contour tracing is iteratively performed with a branch point in a neighborhood of the branch point as a new starting point to generate a plurality of independent pixel contour chains include:
[0016] finding a starting point in each of the connected components;
[0017] starting from the starting point, finding a contour point in a neighborhood of a current point in a preset order, adding the contour point to a current contour chain, and continuing tracing with the contour point as a next current point;
[0018] during the tracing, determining whether the current point is a branch point, when it is detected that the current point is a branch point, setting a pixel value of the current point to 0 to block a connection between a current contour and the branch point, and adding a branch point in a domain of the current point to a branch set, and continuing tracing of the current contour until there is no contour point in the domain of the current point, and completing the tracing of the current contour;
[0019] Based on completing the contour tracing starting from the starting point, the branch contour tracing is iteratively performed with each branch point in the fork collection as a new starting point until all branch contour tracing is completed, thereby generating multiple independent pixel contour chains.
[0020] In one embodiment, the specific steps of determining whether the current point is a bifurcation point include:
[0021] In the neighborhood of the current point, scan the pixels in the diagonal direction and record the number k of pixel values that are 255, and scan the pixels in the orthogonal direction and record the number q of pixel values that are 255;
[0022] When k>1, the current point is a bifurcation point;
[0023] When k=0 and q>1, the current point is a bifurcation point.
[0024] In one embodiment, the specific step of finding a starting point in each of the connected components includes:
[0025] Traverse all points in the current connected component;
[0026] Determine whether the sum of the pixel values of all neighboring pixels within the area of the current point is a preset pixel value, and if the sum of the pixel values of all pixels within the area of the current point is the preset pixel value, set the current point as the starting point;
[0027] When the sum of the pixel values of all pixels in the area of the current point is not a preset pixel value, the pixel point with the smallest y-axis coordinate point in the current connected component is selected as the starting point.
[0028] In one embodiment, the step of iteratively performing branch contour tracing based on completing contour tracing starting from the starting point and taking the branch points in the neighborhood of each bifurcation point in the bifurcation set as new starting points until all branch contour tracing is completed and multiple independent pixel contour chains are generated further includes:
[0029] Based on the horizontal gradient map and the vertical gradient map, the gradient direction of each contour point in the pixel contour chain is calculated.
[0030] In one embodiment, the specific steps of dynamically selecting an interpolation model to perform sub-pixel interpolation on each contour point according to the gradient direction of each contour point in the pixel contour chain to obtain the sub-pixel contour chain include:
[0031] Selecting a corresponding interpolation model according to the gradient direction of each contour point in the pixel contour chain;
[0032] Inputting the coordinates of each contour point in the pixel contour chain into a corresponding interpolation model to calculate the sub-pixel coordinates of each contour point;
[0033] Based on the sub-pixel coordinates of each contour point, a sub-pixel contour chain is generated.
[0034] In addition, to achieve the above objectives, the present application also proposes a sub-pixel contour extraction method, comprising:
[0035] Filtering the input image and calculating gradient information to obtain a gradient amplitude map, and performing threshold screening and non-maximum suppression on the gradient amplitude map to generate a binary image of the edge contour;
[0036] Performing pixel-wise conversion on the binary image to obtain a binary image with a single pixel width, and performing connected domain analysis on the binary image with a single pixel width to obtain a plurality of connected components;
[0037] Detecting the starting point and bifurcation point of each connected component, starting contour tracing from the starting point, and when encountering a bifurcation point during the tracing process, blocking the connection between the current contour and the bifurcation point, and starting a new contour tracing with the bifurcation point as a new starting point until contour tracing of all bifurcation points is completed, thereby generating multiple independent pixel contour chains;
[0038] According to the gradient direction of each contour point in the pixel contour chain, an interpolation model is dynamically selected to perform sub-pixel interpolation on each contour point to obtain a sub-pixel contour chain;
[0039] The sub-pixel contour chain is resampled according to a preset sampling interval to generate a resampled contour chain.
[0040] In one embodiment, the specific steps of resampling the sub-pixel contour chain according to the preset sampling interval to generate the resampled contour chain include:
[0041] Split the sub-pixel contour chain into multiple low-curvature contour segments;
[0042] According to a preset sampling interval, linear interpolation resampling is performed on each of the low curvature contour segments to obtain a resampling point;
[0043] The resampled points of each low-curvature contour segment are sequentially combined to generate a resampled contour chain.
[0044] In addition, to achieve the above-mentioned purpose, the present application also proposes an image processing device, comprising: a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the computer program is configured to implement the steps of the sub-pixel contour extraction method as described above.
[0045] One or more technical solutions proposed in this application have at least the following technical effects:
[0046] The application provides a sub-pixel contour extraction method, which solves the contour adhesion problem through a bifurcation point blocking strategy and an iterative contour tracking mechanism, ensures the integrity and independence of the contour chain under a complex bifurcation structure, improves the contour positioning precision through a dynamic gradient direction adaptive sub-pixel interpolation model, overcomes the limitation of a single interpolation model in a variable gradient scene, eliminates redundant points and realizes the uniform and controllable distribution of contour points through a preset interval resampling operation on the premise of maintaining the geometric characteristics of the contour, and finally, the method can efficiently generate a clear, continuous and non-redundant branch sparse contour expression while ensuring high-precision sub-pixel edge positioning, so as to meet the application requirements of high-precision and sparse edge contour. BRIEF DESCRIPTION OF DRAWINGS
[0047] The drawings incorporated into the specification and constituting a part of the specification show embodiments consistent with the application and, together with the specification, serve to explain the principles of the application.
[0048] In order to more clearly illustrate the technical solutions in the embodiments of the application or the prior art, the drawings needed to be used in the embodiments or the prior art description will be briefly introduced. Obviously, for those skilled in the art, other drawings can also be obtained without creative labor based on these drawings.
[0049] Figure 1 A flowchart is provided for the first embodiment of the sub-pixel contour extraction method of the application.
[0050] Figure 2 A flowchart is provided for the second embodiment of the sub-pixel contour extraction method of the application.
[0051] Figure 3 The gradient amplitude non-maximum suppression edge contour binary image of the first embodiment of the sub-pixel contour extraction method of the application.
[0052] Figure 4 The single-pixelized edge contour binary image of the first embodiment of the sub-pixel contour extraction method of the application.
[0053] Figure 5 The starting point 3x3 field diagram of the first embodiment of the sub-pixel contour extraction method of the application.
[0054] Figure 6 The contour tracking diagram of the first embodiment of the sub-pixel contour extraction method of the application.
[0055] Figure 7 The parabolic interpolation model diagram of the first embodiment of the sub-pixel contour extraction method of the application.
[0056] Figure 8This is a linear interpolation model diagram of an embodiment of a sub-pixel contour extraction method of the present application;
[0057] Figure 9 This is a schematic diagram of sub-pixel coordinate calculation according to an embodiment of a sub-pixel contour extraction method of the present application;
[0058] Figure 10 Schematic diagram of contour segmentation into low-curvature segments and resampling of low-curvature segments according to an embodiment of a sub-pixel contour extraction method of the present application;
[0059] Figure 11 A schematic flow chart of a third embodiment of a sub-pixel contour extraction method provided in this application.
[0060] The purpose, features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0061] It should be understood that the specific embodiments described herein are merely used to explain the technical solutions of the present application and are not intended to limit the present application.
[0062] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0063] The main solutions of the embodiments of this application are:
[0064] This application proposes a sub-pixel contour extraction method, such as Figure 1 Shown, including:
[0065] S100: Filtering the input image and calculating gradient information to obtain a gradient amplitude map, and performing threshold screening and non-maximum suppression on the gradient amplitude map to generate a binary image of the edge contour;
[0066] S200: performing pixel-wise conversion on the binary image to obtain a binary image with a single pixel width, and performing connected domain analysis on the binary image with a single pixel width to obtain a plurality of connected components;
[0067] S300: Detecting the starting point of each connected component, performing contour tracing along the path of the connected component from the starting point, blocking the connection between the current contour and the bifurcation point when encountering a bifurcation point during the tracing process, and iteratively performing contour tracing using a branch point in the neighborhood of the bifurcation point as a new starting point to generate multiple independent pixel contour chains;
[0068] S400: dynamically selecting an interpolation model to perform sub-pixel interpolation on each contour point in the pixel contour chain according to the gradient direction of each contour point to obtain a sub-pixel contour chain.
[0069] Specifically, with the deepening escalation of industrialization, machine vision contour extraction systems have become an indispensable core technology in many manufacturing sectors. In automotive manufacturing, they accurately extract component edge contours, driving cutting equipment for precision machining. They also quickly compare the contour differences between the cut part and the designed model, enabling efficient detection of defects such as burrs and cracks. In the dispensing industry, they rapidly capture product edge morphology and generate precise glue paths to guide dispensing systems. In mechanical manufacturing, they are used to extract metal part edges, accurately measure their size and shape, and ensure seamless assembly. These widespread and critical applications place stringent demands on contour extraction technology: improving both extraction efficiency and accuracy without significantly increasing hardware costs is crucial. More importantly, the diversity of requirements is becoming increasingly prominent. For example, in certain applications, such as path planning, fast matching, or specific feature analysis, a dense, detailed set of contour points is not required. Instead, sparse contour information is required: that is, the number of points is significantly reduced while preserving the original contour geometry to the greatest extent possible.
[0070] Currently, the core principle of sub-pixel edge detection methods widely used in industry is typically based on local gradient maxima. This approach first searches for candidate edge points at the pixel level where the image gradient reaches a local maximum. Then, using mathematical techniques such as interpolation, quadratic interpolation, cubic spline interpolation, or fitting, the edge point locations are calculated with sub-pixel accuracy. However, these mainstream methods face fundamental challenges. Their accuracy relies heavily on a key assumption: the distribution of gradient magnitudes near edges must closely align with the mathematical form of the chosen interpolation or fitting model. In other words, if the grayscale variations near edges in the actual image data deviate significantly from the model's pre-defined curve shape, the calculated sub-pixel locations will introduce systematic model errors, resulting in reduced localization accuracy. This is one of the core reasons why existing methods struggle to meet the aforementioned "high accuracy" requirement. Furthermore, these methods typically generate a large number of densely distributed sub-pixel points along edges to achieve the required accuracy. This directly contradicts the specific requirement of requiring only a sparse set of points that does not alter the original contour shape. Forcibly performing post-processing thinning on dense point sets not only increases computational overhead, but may also destroy the geometric integrity of the contour or introduce new errors.
[0071] Therefore, the current dilemma lies in the fact that traditional sub-pixel edge detection methods, based on local gradient maxima combined with interpolation / fitting, are limited in accuracy by the degree of fit between the model and the actual data, making it difficult to achieve both high precision and sparsity in the resulting form. Seeking an innovative approach that transcends model dependency, directly generates or effectively controls contour sparsity while maintaining or even improving sub-pixel positioning accuracy, is crucial for meeting the diverse and demanding application scenarios of modern industry. An ideal solution requires optimizing the overall strategy for edge representation, rather than simply patching existing processes.
[0072] To address the above dilemma, this application proposes a sub-pixel contour extraction method, comprising steps S100 to S400. In step S100, the original image is converted into a preliminary binary edge contour map, preserving significant edge structures. First, the input image is filtered to suppress noise interference and prevent the subsequent gradient calculation from being affected by high-frequency noise. Next, the horizontal and vertical gradient components of the image are calculated using a gradient operator, resulting in a gradient magnitude map and a gradient direction map, which are used to characterize edge strength and record edge normal angles. The gradient magnitude map is thresholded, retaining strong amplitudes and suppressing weak amplitudes in the gradient magnitude map. Specifically, gradient amplitudes greater than or equal to a preset threshold are retained, while amplitudes less than the threshold are replaced with zero, thereby regenerating the gradient magnitude map. Typically, in image processing, the choice of a preset threshold depends on the specific application scenario and image characteristics. Non-maximum suppression is then performed, detecting each pixel neighborhood along the gradient direction and retaining only pixels with local gradient magnitude maxima. This suppresses the width of coarse edges and refines them to a single-pixel level, generating a binary image of the edge contour. This binary image has edge widths approaching a single pixel but still contains residual branches.
[0073] In step S200, the binary image is pixelated to obtain a binary image with a single pixel width, and a connected domain analysis is performed on the binary image with a single pixel width to obtain multiple connected components. Edges in binary images may appear multi-pixel wide due to incomplete non-maximum suppression or image complexity. In this stage, a refinement algorithm is used to iteratively erode edges until the width of all connected regions is reduced to a single pixel, forming a "skeleton" with a clear topological structure. Connected domain analysis is then performed: all interconnected edge point sets are marked based on the 8-neighborhood rule, and each independent point set is called a connected component. This step decomposes the complex edge network into discrete linear or curvilinear units, each connected component representing a potential continuous contour path, providing an independent processing unit for subsequent path tracing.
[0074] In step S300, the starting point of each connected component is detected, and the contour is traced along the path of the connected component from the starting point. When a bifurcation point is encountered during the tracing process, the connection between the current contour and the bifurcation point is blocked. At the same time, the contour tracing is iteratively performed with the branch point in the neighborhood of the bifurcation point as the new starting point to generate multiple independent pixel contour chains. This step solves the problems of contour breakage and adhesion caused by bifurcation structure in traditional contour tracing, and generates a pixel-level contour chain with clear topological structure and strict independence. Its implementation principle is based on depth-first search and recursive blocking mechanism. By intelligently traversing the path of connected components, it ensures that each output contour chain is a continuous curve without intersection. The specific execution process includes three key stages: starting point positioning, path tracing and bifurcation recursive processing.
[0075] First, endpoint detection is performed on the single-pixel connected components generated by S200. An endpoint is defined as an edge point or any selected point with only one adjacent pixel. Starting from the endpoint, the system connects each point along an eight-neighborhood to form an initial contour chain, dynamically recording visited points to prevent backtracking. When tracing reaches a bifurcation point, a dual response mechanism is triggered: first, the connection between the current contour chain and the bifurcation point is immediately physically severed, terminating the current path and outputting the generated chain as an independent contour; second, the branch point within the bifurcation point is marked as a new starting point, recursively initiating the sub-contour tracing process. This process continues iteratively until all branches of the bifurcation point have been traversed. In this step, the bifurcation point is no longer considered a contour intersection point, but rather the starting point of a sub-contour, completely avoiding contour concatenation caused by multiple paths crossing. The final output is multiple pixel sequences arranged in a strictly connected order. Each sequence represents a geometrically continuous open or closed edge, providing structurally regular basic data for sub-pixel interpolation. This mechanism is particularly suitable for the precise segmentation of complex mesh structures, improving the reliability of subsequent geometric analysis.
[0076] In step S400, based on the gradient direction of each contour point in the pixel contour chain, an interpolation model is dynamically selected to perform sub-pixel interpolation on each contour point to obtain a sub-pixel contour chain. Step S400 uses gradient direction information to guide the selection and execution of the local interpolation model, and achieves a transition in positioning accuracy through adaptive modeling of edge physical characteristics. The interpolation process is divided into two logical layers: dynamic model selection and normal space calculation. In the model selection layer, the system dynamically selects the optimal interpolation model based on the gradient characteristics of the current contour point neighborhood. This on-demand allocation mechanism ensures that the model always matches the physical characteristics of the local edge, thereby avoiding inappropriate interpolation models affecting the accuracy of the sub-pixel contour chain.
[0077] At the execution layer, the gradient magnitude of neighboring pixels along the gradient normal is taken as input, with the current contour point as the center. The selected model is then used to calculate the coordinates of sub-pixel edge intersections. This step fully utilizes the gradient direction information and local grayscale distribution characteristics of the edge to transform the discrete pixel chain into a continuous, high-precision sub-pixel contour chain, significantly improving the accuracy of geometric measurement or shape analysis.
[0078] This application proposes a sub-pixel contour extraction method, in which steps S100-S200 complete the robust extraction and structuring of pixel-level edges; step S300 ensures the topological independence of the contour through intelligent bifurcation processing; and step S400 achieves accuracy transition based on physical information. The whole process takes into account noise resistance, topological correctness and sub-pixel accuracy, and is suitable for scenarios such as industrial inspection and medical imaging that have strict requirements on contour accuracy. The bifurcation point blocking strategy and iterative contour tracking mechanism adopted in this application solve the contour adhesion problem and ensure the integrity and independence of the contour chain under complex bifurcation structures; at the same time, its sub-pixel interpolation model with dynamic gradient direction adaptation improves the contour positioning accuracy and overcomes the limitations of a single interpolation model in variable gradient scenarios to meet the application requirements of high-precision edge contours.
[0079] In one embodiment, the specific steps of step S100, filtering the input image and calculating gradient information, obtaining a gradient magnitude map, and performing threshold screening and non-maximum suppression on the gradient magnitude map to generate a binary image of the edge contour, include:
[0080] An image is acquired and Gaussian filtered to remove noise from the image. A gradient operator is used to calculate the gradient field of the Gaussian filtered image to generate a horizontal gradient map, a vertical gradient map, and a gradient magnitude map. The gradient magnitude map is subjected to gradient intensity screening to retain gradient values greater than or equal to a preset threshold. The screened gradient magnitude map is subjected to gradient direction non-maximum suppression to obtain pixel-level edge points, thereby generating a binary image bw of the edge contour.
[0081] This application captures images and applies Gaussian filtering to suppress high-frequency noise during image acquisition, providing a stable data foundation for gradient calculation. Sobel filtering is then performed to obtain the horizontal gradient map gx, the vertical gradient map gy, and the gradient magnitude map mag. The gradient magnitude map is selectively filtered using a preset threshold to refine edge features. Specifically, the system compares the gradient magnitude (mag) pixel by pixel with a preset threshold, retaining strong magnitudes and suppressing weak magnitudes in the gradient magnitude map. Specifically, gradient magnitudes greater than or equal to the preset threshold are retained, while those less than the threshold are replaced with zero, resulting in the gradient magnitude map mag. This operation essentially determines the binary value of edge saliency. Strong gradient responses typically correspond to real physical boundaries, while weak responses often arise from texture details or noise interference. In the filtered gradient magnitude map (still denoted as mag), the non-zero pixels constitute a set of candidate edge points. Their spatial distribution preliminarily outlines the main structural contours of the target while effectively suppressing irrelevant background interference. Generally, in image processing, the choice of a preset threshold depends on the specific application scenario and image characteristics. There are many ways to set the threshold. Here are some common methods: manual setting, histogram-based threshold selection, adaptive threshold, and automatic threshold determination using algorithms.
[0082] In order to eliminate the multi-pixel width problem of the candidate edge, this step performs local maximum detection under the guidance of the gradient direction to generate a topologically clear single-pixel edge. Initialize the image bw with all pixel values to be 0 and the same size as mag; traverse each non-zero point in mag, and determine the adjacent pixel pairs to be compared according to the gradient direction of the point, such as comparing the left and right pixels in the 0° direction, and comparing the upper right-lower left diagonal pixels in the 45° direction; check whether the gradient amplitude of each pixel position in mag is the local maximum in the 3x3 area in the gradient direction. If so, set the pixel value to 255 at the same position in bw. Therefore, bw is a binary image that describes the edge contour after the non-maximum suppression of the gradient amplitude mag, such as Figure 3 This process obtains pixel-level edge points by comparing the gradient directions, and then performs single-pixel processing to obtain single-pixel-width pixel-level edges, thereby improving the geometric accuracy of edge positioning and avoiding the risk of edge breakage. Figure 4 shown.
[0083] In one embodiment, the step S300 detects the starting point of each connected component, performs contour tracing along the path of the connected component from the starting point, blocks the connection between the current contour and the bifurcation point when a bifurcation point is encountered during the tracing process, and iteratively performs contour tracing using a branch point within the neighborhood of the bifurcation point as a new starting point. The specific steps of generating multiple independent pixel contour chains include steps S310 to S340:
[0084] S310: finding a starting point in each of the connected components;
[0085] S320: starting from the starting point, finding a contour point in the neighborhood of the current point in a preset order, adding the contour point to the current contour chain, and continuing to track with the contour point as the next current point;
[0086] S330: in the tracking process, judging whether the current point is a bifurcation point, when detecting that the current point is a bifurcation point, setting the pixel value of the current point to 0 to block the connection between the current contour and the bifurcation point, at the same time, putting the branch points in the field of the current point into the bifurcation set, and continuing the tracking of the current contour until there is no contour point in the field of the current point, completing the tracking of the current contour;
[0087] S340: based on the completion of the contour tracking starting from the starting point, iteratively performing the tracking of the branch contour with each branch point in the bifurcation set as a new starting point, until the tracking of all branch contours is completed, generating multiple independent pixel contour chains.
[0088] In this embodiment, step S310 is to determine a unique path tracking starting point for each connected component The starting point is determined to ensure the ordered generation of the contour chain, and the positioning of the starting point is an initialization link of the contour tracking, which lays a directional foundation for subsequent path construction. In step S320, the pixel points are connected in order along the connected component to generate a continuous contour chain. Starting from the starting point determined in S310, the search order is preset according to the specific processing situation, such as the clockwise 8-neighborhood point-by-point expansion path, the adjacent point detection: checking the unvisited adjacent pixels of the current point, adding the first point meeting the condition to the contour chain; setting the adjacent point as the new current point and marking it as visited; repeating the above process until there is no valid adjacent point for the current point. This process forms a depth-first search mechanism to dynamically construct a sequence of pixel points arranged in connection order. The core is to maintain the continuity of the path to avoid redundant calculation caused by backtracking, and the output result is a preliminary contour chain with geometric continuity.
[0089] Step S330 identifies the bifurcation structure and cuts off the connection relationship, and buffers the branch task to ensure the independence of the contour. When it is detected that the current point is a bifurcation point, the pixel value of the current point is set to 0 to block the connection between the current contour and the bifurcation point, at the same time, the branch points in the field of the current point are put into the bifurcation set as the starting point of the new contour to be processed, and the tracking of the current contour is continued until there is no contour point in the field of the current point, and the tracking of the current contour is completed. This step solves the problem of multiple path intersection through dynamic topological pruning. After the bifurcation point is physically eliminated, the original connected component is decoupled into multiple independent sub-paths, and the bifurcation set stores all the sub-contour entrances to be processed.
[0090] Step S340 iteratively processes the cached branch tasks based on the generated bifurcation set in S330 to generate all the segmented independent contour chains. A branch point is taken out from the bifurcation set as a new starting point, and the path tracking process in S320 is triggered at the point to generate an independent sub-contour chain. If a new bifurcation point is encountered in the sub-contour tracking, the blocking and caching mechanism in S330 is triggered to update the bifurcation set; when the bifurcation set is empty, all branch processing is completed. This step forms a tree recursive structure, and the bifurcation point is taken as the parent node, and its branch points are taken as the child nodes to start sub-tasks. Finally, multiple completely independent pixel contour chains are output, each of which represents a continuous edge segment without intersection, and the contour adhesion caused by bifurcation is completely eliminated.
[0091] In the embodiment, step S310 locates the starting point, step S320 path tracking constructs the basic path, step S330 blocks the bifurcation point, dynamically decouples the complex connection, and step S340 processes the recursive branch to ensure that all sub-paths are completely extracted. The embodiment physically blocks the bifurcation point to ensure that each contour chain is a simple curve without intersection; the recursive mechanism can process any complex bifurcation level; and the output independent pixel chain can be directly input to S400 for sub-pixel interpolation to avoid interpolation distortion caused by the bifurcation point.
[0092] In an embodiment, the specific steps of determining whether the current point is a bifurcation point include:
[0093] In the neighborhood of the current point, the pixel points in the diagonal direction are scanned and the number k of pixel values of 255 is recorded, and the pixel points in the orthogonal direction are scanned and the number q of pixel values of 255 is recorded; when k>1, the current point is a bifurcation point; when k=0 and q>1, the current point is a bifurcation point.
[0094] It can be understood that whether the current point is a bifurcation point is determined, that is, whether the number k of pixel values of 255 of four pixels p1, p2, p3, and p4 on the diagonal line in the 3x3 field of the current point p0 is greater than 1. If yes, p0 is a bifurcation point, and all pixel coordinates of the remaining k-1 points with pixel values of 255 except the first one are recorded into . Similarly, it is continued to be determined whether the number q of pixel values of 255 of p5, p6, p7, and p8 in the 3x3 field is greater than 1. If yes, if k>1, the q pixel points are added to cross, and if k=0, q-1 pixel points are added to cross. Therefore, all the new starting points of the bifurcation contour recorded in cross are finally recorded.
[0095] In this embodiment, determining whether the current point is a bifurcation point is specifically implemented through a two-stage neighborhood scan, with diagonal scanning and orthogonal scanning complementing each other. Diagonal bifurcations (k>1) are common at Y-shaped intersections, where multiple edge paths intersect at acute angles. The diagonal priority strategy ensures that lateral branches are captured when the main path is extended. Orthogonal bifurcations (k=0 and q>1) are more common at T-junctions or cross intersections, where edges intersect at right angles. Orthogonal scanning prevents missed vertical branching paths. This step solves the problem of contour adhesion and provides robust topological decomposition capabilities for complex mesh structures.
[0096] In one embodiment, the specific steps of finding a starting point in each of the connected components in step S310 include: traversing all points in the current connected component; determining whether the sum of the pixel values of all neighboring pixels in the domain of the current point is a preset pixel value, and when the sum of the pixel values of all pixels in the domain of the current point is the preset pixel value, setting the current point as the starting point; when the sum of the pixel values of all pixels in the domain of the current point is not the preset pixel value, selecting the pixel point with the smallest y-axis coordinate in the current connected component as the starting point.
[0097] It can be understood that the connected components in the traversal Each point point, then at the corresponding position in the single-pixel contour binary image bw, uses this position as the center to determine whether the sum of the pixel values within its 3x3 area excluding itself is equal to the preset pixel value, which is 255 here (the preset pixel value is generally 225). If so, it is considered a starting point. Figure 5 As shown in the figure, it is a schematic diagram of the 3x3 neighborhood of the starting point, where the current point p0 is the current pixel. , then p0 is the starting point. If If there is no starting point that meets the conditions after traversing all the points, it means that this connected component is closed, and the point with the smallest y coordinate can be taken as the starting point.
[0098] In one embodiment, the step of iteratively performing branch contour tracing based on completing contour tracing starting from the starting point and taking each branch point in the bifurcation collection as a new starting point until all branch contour tracing is completed and multiple independent pixel contour chains are generated also includes: calculating the gradient direction of each contour point in the pixel contour chain based on the horizontal gradient map and the vertical gradient map.
[0099] In this embodiment, the gradient images gx and gy in the x and y directions are calculated. The gradient direction of each contour point in , its physical essence is to solve the normal direction of the edge.
[0100] In one embodiment, the step S400 of dynamically selecting an interpolation model to perform sub-pixel interpolation on each contour point in the pixel contour chain according to the gradient direction of each contour point, and obtaining the sub-pixel contour chain specifically includes steps S410 to S430:
[0101] S410: selecting a corresponding interpolation model according to the gradient direction of each contour point in the pixel contour chain;
[0102] S420: Inputting the coordinates of each contour point in the pixel contour chain into a corresponding interpolation model to calculate the sub-pixel coordinates of each contour point;
[0103] S430: Generate a sub-pixel contour chain based on the sub-pixel coordinates of each contour point.
[0104] In this embodiment, the interpolation-based method will be affected by the degree of matching between the actual shape of the data and the fitting curve. If the selected interpolation model is inappropriate, it will affect the accuracy. Therefore, step S410 selects different interpolation models for the edge points in their 3x3 areas according to their gradient directions. The parabolic model is used when the gradient directions are -180, -90, 0, and 90 degrees, and the linear interpolation model is used at the remaining angles. The use of the linear interpolation model is based on the assumption that the gradient amplitude on both sides of the edge changes uniformly and linearly. Step S420 implements coordinate offset correction through the interpolation model, inputs the coordinates of each contour point in the pixel contour chain into the corresponding interpolation model, and calculates the sub-pixel coordinates of each contour point. Step S430, calculates the contour chain The sub-pixel coordinates of each pixel coordinate in get the sub-pixel contour chain .
[0105] Specifically, the gradient magnitude g0, g0+, g0- in the 3x3 region is obtained in the gradient direction of the current point p0, where g0 is the gradient magnitude of the current point, g0+ is the gradient magnitude in the region along the positive gradient direction, and g0- is the gradient magnitude in the region along the negative gradient direction. Since g0 is the local maximum in the region on the gradient direction θ0, , range [-180,180). Therefore g0, g0+, g0- satisfy the equation ,or , based on the aforementioned method for suppressing non-maximum gradient amplitudes. Interpolate the gradient amplitude profiles g0, g0+, and g0- to obtain the coordinates of the extreme point s of the interpolation curve. Generate a line L1 passing through point p0 and oriented toward θ0. Generate a line L2 passing through the interpolated position of s, with the coordinate p1 and a direction perpendicular to θ0. p1 is calculated from the corresponding coordinates of g0, g0+, g0-, and s. The intersection of lines L1 and L2 is the sub-pixel coordinate p2 of point p0.
[0106] For the calculation of the interpolation s on the gradient amplitude g0, g0+, and g0- profiles, the gradient amplitude profile on the p0 gradient direction is quantized into a one-dimensional form with the p0 coordinate being 0 and the other amplitude coordinates being 1 and -1 respectively. The parabolic interpolation model is as follows: Figure 7 , the linear interpolation model is as follows Figure 8 , the interpolation coordinates are as shown by the arrow. For parabolic interpolation, the interpolation function is obtained. , among which if , then s=0. For linear interpolation, a straight line L3 is formed through point p0 and a point with a smaller amplitude between g0+ and g0-, and another straight line L4 is formed. This straight line passes through a point with a larger amplitude between g0+ and g0- and has a slope that is the negative of L3. The interpolation value s is the intersection of L3 and L4. , where if , then s = 0. Since s is interpolated from g0, g0+, g0-, and g0 is a local maximum, s satisfies . Figure 7 , Figure 8 The interpolation diagrams are all calculated on a quantized unit distance, describing the distance scaling factor. Therefore, for practical situations, it is necessary to calculate the actual distance d between two pixels. When the gradient direction of p0 is -180, -90, 0, 90, the distance between the two pixels in the gradient direction is 1; when the gradient direction of p0 is in other directions, the distance between the two pixels in the gradient direction is Therefore, the interpolated value of the amplitude g0, g0+, and g0- profiles of p0 in the gradient direction is d*s.
[0107] The schematic diagram of sub-pixel coordinate calculation is as follows Figure 9 , the gradient direction θ0 at p0 is 150 degrees. Find the gradient magnitude g0, g0+, and g0- profiles along θ0 through p0 and generate a line L. Interpolate the g0, g0+, and g0- profiles to obtain the coordinates of p1. Generate a line L1 through p0 with a direction toward θ0. Generate a line L2 through p1 perpendicular to θ0. Calculate the intersection of L1 and L2 to obtain the sub-pixel coordinate p2.
[0108] like Figure 2 As shown, the present application also proposes a sub-pixel contour extraction method, including:
[0109] S100: Filtering the input image and calculating gradient information to obtain a gradient amplitude map, and performing threshold screening and non-maximum suppression on the gradient amplitude map to generate a binary image of the edge contour;
[0110] S200: performing pixel-wise conversion on the binary image to obtain a binary image with a single pixel width, and performing connected domain analysis on the binary image with a single pixel width to obtain a plurality of connected components;
[0111] S300: Detecting the starting point and bifurcation point of each connected component, starting contour tracing from the starting point, and when encountering a bifurcation point during the tracing process, blocking the connection between the current contour and the bifurcation point, and starting a new contour tracing with a branch point in the neighborhood of the bifurcation point as a new starting point, until contour tracing of all bifurcation points is completed, thereby generating multiple independent pixel contour chains;
[0112] S400: dynamically selecting an interpolation model to perform sub-pixel interpolation on each contour point according to the gradient direction of each contour point in the pixel contour chain to obtain a sub-pixel contour chain;
[0113] S500: resampling the sub-pixel contour chain according to a preset sampling interval to generate a resampled contour chain.
[0114] In this embodiment, steps S100 to S400 are consistent with the steps of the above embodiment and are not repeated here. The difference is that in step S500, the sub-pixel contour chain is resampled according to the preset sampling spacing to generate a resampled contour chain. The original contour is dense in areas with high curvature and sparse in straight sections, resulting in deviations in subsequent feature calculations. The sub-pixel points generated by interpolation may be several times higher than the original pixel points, increasing storage and computing overhead, and the over-sampled area is susceptible to gradient noise interference, resulting in local coordinate oscillations. Step S500 resamples the sub-pixel contour chain according to the sampling spacing sp, making the point set sparse while keeping the shape unchanged. Avoid false extreme values caused by density fluctuations and reduce memory usage. This application proposes a sub-pixel contour extraction method, which solves the contour adhesion problem through a bifurcation point blocking strategy and an iterative contour tracking mechanism, ensuring the integrity and independence of the contour chain under complex bifurcation structures; at the same time, its sub-pixel interpolation model with dynamic gradient direction adaptation improves the contour positioning accuracy and overcomes the limitations of a single interpolation model in variable gradient scenarios; and, through a resampling operation with a preset spacing, while maintaining the geometric characteristics of the contour, it eliminates redundant points and achieves uniform and controllable distribution of contour points. The preset sampling spacing refers to the arc length or approximate arc length distance between two adjacent sampling points after resampling. This spacing can be fixed or adaptive, but here we are discussing fixed spacing. Ultimately, while ensuring high-precision sub-pixel edge positioning, this method can efficiently generate clear, continuous, and sparse contour expressions without redundant branches to meet the application requirements of high-precision and sparse edge contours.
[0115] In one embodiment, the step S500 resamples the sub-pixel contour chain according to a preset sampling interval, and the specific steps of generating the resampled contour chain include steps S510 to S530:
[0116] S510: Segment the sub-pixel contour chain into multiple low-curvature contour segments;
[0117] S520: performing linear interpolation resampling on each of the low curvature contour segments according to a preset sampling interval to obtain a resampling point;
[0118] S530: Combining the resampled points of each low-curvature contour segment in sequence to generate a resampled contour chain.
[0119] In this embodiment, step S510 will The low curvature contour segment is divided into multiple low curvature segments, and then each low curvature contour segment is resampled according to the preset sampling interval sp. The low curvature contour segment is a contour segment in which the directions of two adjacent contour points are almost the same, that is, the angle between the directions of the two adjacent contour points is less than or equal to a certain angle threshold angleThresh, angleThresh>0, and angleThresh=22.5 in this paper. If the angle is greater than angleThresh, a new low curvature contour segment is segmented at (xi,yi), so a contour may be segmented into multiple low curvature contour segments conSeg. .
[0120] Step S520, for each contourSeg, calculate the length of each contour point therein ,in , , so the total chain length of the low curvature segment contourSeg Calculate the number of sampling points based on the chain length len and the sampling spacing sp , , where floor is rounded down, and finally the sampling interval is readjusted Then for the low curvature contour segment It is resampled, and the coordinates of the jth sampling point are calculated based on sp and j. Specifically, , according to the length of l, find which two points it falls between in contourSegLen. If it falls between (xq, yq) and (xq+1, yq+1), that is, , then linear interpolation is performed between (xq, yq) and (xq+1, yq+1) to obtain the sampling point (xsj, ysj).
[0121] Step S530 repeats the above operation and combines the resampled point sets of each low curvature segment in sequence to obtain a complete resampled contour chain.
[0122] In summary, if Figure 11 As shown, in combination with the above embodiments, the specific steps of an embodiment of the present application include:
[0123] The collected image is Gaussian filtered, and then Sobel filtered to obtain the horizontal gradient map gx, vertical gradient map gy and gradient amplitude map mag respectively. The strong amplitude in the gradient amplitude map is retained and the weak amplitude is suppressed, that is, the amplitude of the gradient amplitude greater than or equal to the preset threshold is retained, and the amplitude less than the preset threshold is replaced with 0, and the gradient amplitude map mag is obtained again. Non-maximum suppression is performed on mag, and the image bw with all pixel values of 0 and the same size as mag is initialized. It is traversed to check whether the gradient amplitude of each pixel position in mag is the local maximum in the 3x3 area in the gradient direction. If so, the pixel value at the same position in bw is set to 255. Therefore, bw is a binary image that describes the edge contour after non-maximum suppression of the gradient amplitude mag, such as Figure 3 .
[0124] The edge contour in bw is pixelated to obtain a single-pixel edge contour binary image, such as Figure 4 The 8-connected connected domain analysis of the binary image bw of the single-pixel edge contour is performed to obtain many connected components. Each connected component is a single-pixel contour, which is either a single contour or multiple contours connected with bifurcations. The connected components are , consists of a series of pixel coordinate point sets, which describe the pixel coordinate points with a grayscale value of 255 in the single-pixel contour binary image bw.
[0125] Connected components Contour tracing is performed to obtain an ordered pixel contour from the starting point to the end point. If there is a bifurcation in the connected component, multiple independent pixel contours are generated at the bifurcation. The pixel contour is , the coordinate point set is an integer coordinate, defined as a pixel contour chain, which is an ordered set of coordinate points, that is, point to , point to ..., point to . It is divided into two steps: a: from Find a starting point stPoint in ; b: Start tracking in a 3x3 area from the starting point stPoint until the tracking is completed. The specific steps for a are: traverse For each point point, then at the corresponding position in the single-pixel contour binary image bw, take this position as the center to determine whether the sum of the pixel values in its 3x3 area excluding itself is equal to 255. If so, it is regarded as a starting point. Figure 5 As shown in the figure, it is a schematic diagram of the 3x3 area of the starting point, where p0 is the current pixel. , then p0 is the starting point. If If all the points are traversed and no starting point is found, it means that the connected component is closed, and the starting point is the point with the minimum y coordinate. For b, the specific steps are as follows: if Figure 6 As shown in the profile tracking diagram, firstly, it is judged whether the current point p0 is a bifurcation point, that is, it is judged whether the number k of pixels p1, p2, p3, and p4 on the diagonal line in the 3x3 field of p0 is greater than 1. If yes, p0 is a bifurcation point, and all the pixel coordinates of the remaining k-1 points with the pixel value of 255 are recorded into . Similarly, it is continuously judged whether the number q of pixels p5, p6, p7, and p8 in the 3x3 field is greater than 1. If yes, if k>1, the q pixels are added into cross, and if k=0, q-1 pixels are added into cross. Therefore, finally, all the starting points of the bifurcation profile are recorded in cross. In bw, all the pixel values corresponding to the coordinates in cross are set to 0 to avoid repeated tracking in subsequent profile tracking. For p0, the 3x3 field is tracked, and firstly, it is judged whether the pixels p1, p2, p3, and p4 exist, and if yes, a profile point is tracked and stored in . If the pixels p1, p2, p3, and p4 do not exist, it is continuously judged whether the pixels p5, p6, p7, and p8 exist, and if yes, a profile point is tracked and stored in contour. If no, the tracking is completed. For the new profile point tracked, the bifurcation point in the 3x3 field is continuously judged and tracked, until the tracking is completed. The point in cross is taken as the starting point to repeat the above steps until all the profiles are tracked. Finally, the gradient direction of each profile point in is calculated according to the gradient graphs gx and gy in the x and y directions. .
[0126] The pixel profile chain Calculate the sub-pixel coordinates for each coordinate in . Interpolation-based methods will be affected by the degree of match between the actual shape of the data and the fitting curve. If the selected interpolation model is inappropriate, it will affect the accuracy. Therefore, the article selects different interpolation models for edge points in their 3x3 domains according to their gradient directions. The parabolic model is used when the gradient directions are -180, -90, 0, and 90 degrees, and the linear interpolation model is used at other angles. The use of the linear interpolation model is based on the assumption that the gradient amplitude on both sides of the edge changes uniformly and linearly. Specifically, the gradient amplitudes g0, g0+, and g0- of the 3x3 domain are obtained in the gradient direction of the current point p0, where g0 is the gradient amplitude of the current point, g0+ is the gradient amplitude in the domain along the positive direction of the gradient, and g0- is the gradient amplitude in the domain along the negative direction of the gradient. Since g0 is the local maximum value in the domain on the gradient direction θ0, , range [-180,180). Therefore g0, g0+, g0- satisfy the equation ,or , based on the aforementioned method for suppressing non-maximum gradient amplitudes. Interpolate the gradient amplitude profiles g0, g0+, and g0- to obtain the coordinates of the extreme point s of the interpolation curve. Generate a line L1 passing through point p0 and oriented toward θ0. Generate a line L2 passing through the interpolated position of s, with the coordinate p1 and a direction perpendicular to θ0. p1 is calculated from the corresponding coordinates of g0, g0+, g0-, and s. The intersection of lines L1 and L2 is the sub-pixel coordinate p2 of point p0.
[0127] Specifically, for the calculation of the interpolation s on the gradient amplitude g0, g0+, and g0- profiles, the gradient amplitude profile on the p0 gradient direction is quantized into a one-dimensional form with the p0 coordinate being 0 and the other amplitude coordinates being 1 and -1 respectively. The parabolic interpolation model is as follows: Figure 7 , the linear interpolation model is as follows Figure 8 , the interpolation coordinates are as shown by the arrow s. For parabolic interpolation, the interpolation function , we can conclude , among which if , then s=0. For linear interpolation, a straight line L3 is formed through point p0 and a point with a smaller amplitude between g0+ and g0-, and another straight line L4 is formed. This straight line passes through a point with a larger amplitude between g0+ and g0- and has a slope that is the negative of L3. The interpolation value s is the intersection of L3 and L4. , where if , then s = 0. Since s is interpolated from g0, g0+, g0-, and g0 is a local maximum, s satisfies . Figure 7 , Figure 8The interpolation schematic diagram is the calculation on the quantized unit distance, and describes the scaling factor of the distance. Therefore, the actual distance d of two pixels needs to be calculated for the actual situation. For the gradient direction of p0 being -180, -90, 0, 90, the distance of two pixels in the field in the gradient direction of p0 is 1; for the gradient direction of p0 being the rest directions, the distance of two pixels in the field in the gradient direction of p0 is . Therefore, the interpolation of p0 in the field in the gradient direction of p0, g0, g0+, g0- profile is d*s.
[0128] The schematic diagram of the sub-pixel coordinate calculation is as Figure 9 , the gradient direction θ0 of p0 is 150 degrees. The straight line L is found along the θ0 direction through p0 to find the gradient amplitude g0, g0+, g0- profile and generate the straight line L, and the p1 coordinate is obtained according to the interpolation of the g0, g0+, g0- amplitude profile. The straight line L1 is generated through p0 in the direction of θ0, and the straight line L2 is generated through p1 in the direction perpendicular to θ0. The intersection of L1 and L2 is calculated to obtain the sub-pixel coordinate p2. The sub-pixel contour chain is obtained by calculating the sub-pixel coordinate of each pixel coordinate in the contour chain .
[0129] It is worth noting that after the above steps are completed, the binary image has completed the sub-pixel edge contour extraction, and the following steps are whether to resample the sub-pixel edge contour according to the actual demand of the user to obtain the sparse edge contour.
[0130] Resampling the sub-pixel contour chain according to the sampling interval sp makes the point set sparse while keeping the shape unchanged. Specifically, the contour is segmented into multiple low-curvature segments, and then each low-curvature contour segment is resampled according to sp. The low-curvature contour segment is a segment in which the directions of two adjacent contour points are almost the same, that is, the included angle between the directions of two adjacent contour points is less than or equal to a certain angle threshold angleThresh, angleThresh>0, and angleThresh=22.5, in the text. If the included angle is greater than angleThresh, a new low-curvature contour segment is segmented at (xi, yi), so a contour may be segmented into multiple low-curvature contour segments contourSeg. Among them, . For each contourSeg, the length of each contour point in it is calculated , wherein , , so the total chain length of the low-curvature segment contour contourSeg is . The sampling point number , , where floor is rounded down, and finally the sampling interval is readjusted Then for the low curvature contour segment It is resampled, and the coordinates of the jth sampling point are calculated based on sp and j. Specifically, , according to the length of l, find which two points it falls between in contourSegLen. If it falls between (xq, yq) and (xq+1, yq+1), that is, , then linear interpolation is performed between (xq, yq) and (xq+1, yq+1) to obtain the sampling point (xsj, ysj).
[0131] like Figure 10 The figure shows the segmentation of the sub-pixel contour contourS into low-curvature contour segments contourSeg and the resampling of contourSeg. ContourS is a complete sub-pixel contour chain. Low-curvature segmentation yields three low-curvature contour segments contourSeg. The first segment consists of contour points 0, 1, 2, and 3; the second segment consists of contour points 4, 5, and 6; and the third segment consists of contour points 7, 8, and 9. Resampling is performed on the first low-curvature contour segment, with the jth sampling point falling between the second and third contour points. Linear interpolation is then performed to obtain the sampling point coordinates (xsj, ysj). Repeating this process, the resampled point sets for each low-curvature segment are combined sequentially to obtain the complete resampled contour chain.
[0132] In addition, to achieve the above-mentioned purpose, the present application also proposes an image processing device, comprising: a memory, a processor, and a computer program stored on the memory and capable of running on the processor, wherein the computer program is configured to implement the steps of the sub-pixel contour extraction method as described above. A memory, a processor, and a computer program stored on the memory and capable of running on the processor, wherein the computer program is configured to implement the steps of the sub-pixel contour extraction method as described above. It can be implemented using a main controller, such as a DSP (Digital Signal Process, digital signal processing chip), FPGA (Field Programmable Gate Array, programmable logic gate array chip), MCU (Microcontroller Unit, micro control unit), SOC (System On Chip, system-on-chip), etc.
[0133] It is worth noting that since the image processing device of the present invention is applied to the above-mentioned sub-pixel contour extraction method, the embodiments of the image processing device of the present invention include all technical solutions of all embodiments of the above-mentioned sub-pixel contour extraction method, and the technical effects achieved are also exactly the same, which will not be repeated here.
[0134] The above merely provides part of embodiments of the present application, and does not limit the patent scope of the present application. Any equivalent structure transformation, direct / indirect application in other related technical fields based on the technical concept of the present application, and contents of the present application specification and drawings are included in the patent protection scope of the present application.
Claims
1. A sub-pixel contour extraction method, characterized in that: include: Filtering the input image and calculating gradient information to obtain a gradient amplitude map, and performing threshold screening and non-maximum suppression on the gradient amplitude map to generate a binary image of the edge contour; Performing pixel-wise conversion on the binary image to obtain a binary image with a single pixel width, and performing connected domain analysis on the binary image with a single pixel width to obtain a plurality of connected components; Detecting the starting point of each connected component, performing contour tracing along the path of the connected component from the starting point, blocking the connection between the current contour and the bifurcation point when encountering a bifurcation point during the tracing process, and iteratively performing contour tracing with the branch point in the neighborhood of the bifurcation point as the new starting point, thereby generating multiple independent pixel contour chains; According to the gradient direction of each contour point in the pixel contour chain, an interpolation model is dynamically selected to perform sub-pixel interpolation on each contour point to obtain a sub-pixel contour chain.
2. The sub-pixel contour extraction method according to claim 1, wherein: The specific steps of filtering the input image and calculating gradient information, obtaining a gradient amplitude map, and performing threshold screening and non-maximum suppression on the gradient amplitude map to generate a binary image of the edge contour include: Collecting an image, and performing Gaussian filtering to remove noise on the image; The gradient operator is used to calculate the gradient field of the Gaussian filtered image to generate the horizontal gradient map, vertical gradient map and gradient amplitude map; Performing gradient intensity screening on the gradient magnitude map, and retaining gradient values greater than or equal to a preset threshold; The filtered gradient amplitude map is subjected to non-maximum suppression in the gradient direction to obtain pixel-level edge points and generate a binary image of the edge contour.
3. The sub-pixel contour extraction method according to claim 1, wherein: The specific steps of detecting the starting point of each connected component, tracing the contour along the path of the connected component from the starting point, blocking the connection between the current contour and the bifurcation point when encountering a bifurcation point during the tracing process, and iteratively performing contour tracing with the branch point in the neighborhood of the bifurcation point as the new starting point to generate multiple independent pixel contour chains include: Finding a starting point in each of the connected components; Starting from the starting point, searching for a contour point in the neighborhood of the current point in a preset order, adding the contour point to the current contour chain, and continuing tracking with the contour point as the next current point; During the tracking process, determine whether the current point is a bifurcation point. If it is detected that the current point is a bifurcation point, set the pixel value of the current point to 0 to block the connection between the current contour and the bifurcation point. At the same time, place the branch points in the neighborhood of the current point into the bifurcation collection and continue tracking the current contour until there are no contour points in the area of the current point. The tracking of the current contour is completed. Based on completing the contour tracing starting from the starting point, the branch contour tracing is iteratively performed with each branch point in the fork collection as a new starting point until all branch contour tracing is completed, thereby generating multiple independent pixel contour chains.
4. The sub-pixel contour extraction method according to claim 3, wherein: The specific steps of determining whether the current point is a bifurcation point include: In the neighborhood of the current point, scan the pixels in the diagonal direction and record the number k of pixel values that are 255, and scan the pixels in the orthogonal direction and record the number q of pixel values that are 255; When k>1, the current point is a bifurcation point; When k=0 and q>1, the current point is a bifurcation point.
5. The sub-pixel contour extraction method according to claim 3, wherein: The specific steps of finding a starting point in each of the connected components include: Traverse all points in the current connected component; Determine whether the sum of the pixel values of all neighboring pixels in the neighborhood of the current point is a preset pixel value, and if the sum of the pixel values of all pixels in the neighborhood of the current point is the preset pixel value, set the current point as the starting point; When the sum of the pixel values of all pixels in the neighborhood of the current point is not a preset pixel value, the pixel point with the smallest y-axis coordinate in the current connected component is selected as the starting point.
6. The sub-pixel contour extraction method according to claim 4, wherein: The step of iteratively performing branch contour tracing based on completing contour tracing starting from the starting point and taking each branch point in the fork collection as a new starting point until all branch contour tracing is completed and multiple independent pixel contour chains are generated further includes: Based on the horizontal gradient map and the vertical gradient map, the gradient direction of each contour point in the pixel contour chain is calculated.
7. The sub-pixel contour extraction method according to claim 1, wherein: The specific steps of dynamically selecting an interpolation model to perform sub-pixel interpolation on each contour point according to the gradient direction of each contour point in the pixel contour chain to obtain the sub-pixel contour chain include: Selecting a corresponding interpolation model according to the gradient direction of each contour point in the pixel contour chain; Inputting the coordinates of each contour point in the pixel contour chain into a corresponding interpolation model to calculate the sub-pixel coordinates of each contour point; Based on the sub-pixel coordinates of each contour point, a sub-pixel contour chain is generated.
8. A sub-pixel contour extraction method, characterized in that: include: Filtering the input image and calculating gradient information to obtain a gradient amplitude map, and performing threshold screening and non-maximum suppression on the gradient amplitude map to generate a binary image of the edge contour; Performing pixel-wise conversion on the binary image to obtain a binary image with a single pixel width, and performing connected domain analysis on the binary image with a single pixel width to obtain a plurality of connected components; Detecting the starting point and bifurcation point of each connected component, starting contour tracing from the starting point, and when encountering a bifurcation point during the tracing process, blocking the connection between the current contour and the bifurcation point, and starting a new contour tracing with a branch point in the neighborhood of the bifurcation point as a new starting point, until the contour tracing of all bifurcation points is completed, generating multiple independent pixel contour chains; According to the gradient direction of each contour point in the pixel contour chain, an interpolation model is dynamically selected to perform sub-pixel interpolation on each contour point to obtain a sub-pixel contour chain; The sub-pixel contour chain is resampled according to a preset sampling interval to generate a resampled contour chain.
9. The sub-pixel contour extraction method according to claim 8, wherein: The specific steps of resampling the sub-pixel contour chain according to the preset sampling interval to generate a resampled contour chain include: Split the sub-pixel contour chain into multiple low-curvature contour segments; According to a preset sampling interval, linear interpolation resampling is performed on each of the low curvature contour segments to obtain a resampling point; The resampled points of each low-curvature contour segment are sequentially combined to generate a resampled contour chain.
10. An image processing device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the sub-pixel contour extraction method according to any one of claims 1 to 9.
Citation Information
Patent Citations
A sub-pixel edge detection method and system
CN109741356A
Morphological feature measurement method based on image extraction
CN119785047A