Methods, apparatus, electronic devices, and storage media for image edge contour extraction
By employing adaptive region partitioning and multi-core parallel scanning, the problem of broken edge detection results in complex textures or high-noise images by the Canny edge detection algorithm is solved, enabling fast and continuous extraction of image edge contours to meet the needs of different image content.
Patent Information
- Application Number
- CN202511040032.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-28
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2045-07-28
AI Technical Summary
Existing Canny edge detection algorithms are prone to causing broken or discontinuous edge detection results when processing complex textures or high-noise images, failing to accurately capture local details and affecting subsequent contour connection and shape reconstruction.
By adaptively dividing the image into regions, using multi-core parallel scanning and preset distance threshold filtering, and dynamically updating reference points, cross-regional contour fitting and merging are achieved, ensuring the continuity and coherence of the contours.
It improves the speed and accuracy of image edge contour extraction, enabling rapid extraction of continuous contours from large amounts of data and high-resolution images, adapting to varying needs in different image content and complex backgrounds.
Smart Images

Figure CN120543579B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image contour extraction technology, and in particular to a method, apparatus, electronic device, and storage medium for image edge contour extraction. Background Technology
[0002] Image edge and contour extraction technology is a fundamental step in computer vision and image processing, widely used in fields such as object recognition, scene analysis, medical imaging, and autonomous driving. By accurately extracting the edges and contours of objects, the system can better understand and analyze image content, thereby improving the performance of subsequent tasks such as recognition, segmentation, and tracking, and providing a solid foundation for information extraction in complex environments.
[0003] Currently, among mainstream image edge contour extraction methods, the Canny edge detection algorithm is widely used due to its high detection accuracy and good noise suppression effect. This algorithm extracts image edge contours through multi-level processing (such as noise filtering, gradient calculation, non-maximum suppression, and double threshold detection). In practical applications, it has the advantages of simple implementation and high efficiency. However, the overall process is relatively fixed and difficult to adaptively optimize for different scenarios. When the image has complex textures or high noise, the Canny edge detection algorithm's fixed threshold and global processing approach can easily lead to broken or discontinuous edge detection results, failing to accurately capture details and thus affecting subsequent contour connection and shape reconstruction. Summary of the Invention
[0004] In view of this, this application provides a method, apparatus, electronic device, and storage medium for image edge contour extraction to solve the problem of insufficient accuracy in global noise and local detail processing.
[0005] A first aspect of this application provides a method for extracting image edge contours, the method comprising:
[0006] Edge detection and adaptive region segmentation are performed on the received target image to obtain a region matrix;
[0007] Perform multi-core parallel scanning and contour point filtering on each sub-region in the region matrix to obtain a linked list of contour point coordinates for each sub-region.
[0008] Based on the preset first distance threshold and the contour point coordinate chain, the contour points of each sub-region are subjected to single-region neighbor point filtering to obtain an initial contour trajectory chain set.
[0009] Based on the boundaries of each sub-region, the initial contour trajectory linked list set is subjected to cross-region contour fitting point extraction processing to obtain the dataset of points to be verified.
[0010] Based on the preset second distance threshold and the region arrangement data in the region matrix, the dataset of points to be verified is subjected to cross-regional neighbor point filtering to obtain a set of fitting points.
[0011] The initial contour trajectory linked list set is merged across regions based on the set of fitted points to obtain the edge contour trajectory linked list set.
[0012] In an optional implementation, the step of performing edge detection and adaptive region segmentation on the received target image to obtain a region matrix includes:
[0013] The received target image is converted to grayscale and denoised to obtain a standardized grayscale image;
[0014] Edge detection processing is performed on the standardized grayscale image to obtain a contour grayscale image;
[0015] The contour grayscale image is adaptively divided into regions based on a preset segmentation threshold to obtain the region matrix.
[0016] In an optional implementation, the step of performing multi-core parallel scanning and contour point filtering on each sub-region in the region matrix to obtain a linked list of contour point coordinates for each sub-region includes:
[0017] According to the preset scanning order, each sub-region in the region matrix is subjected to multi-core parallel scanning and reading processing of pixel coordinates and pixel values to obtain the coordinate-pixel value mapping table corresponding to each sub-region.
[0018] Based on the preset color threshold and the coordinate-pixel value mapping table, each sub-region is subjected to contour point filtering processing to obtain a set of contour point coordinates with pixel values greater than the color threshold.
[0019] The contour point coordinate set is sorted according to the scanning order to obtain a linked list of contour point coordinates for each sub-region.
[0020] In an optional implementation, the step of performing single-region neighbor point filtering on the contour points of each sub-region based on a preset first distance threshold and the contour point coordinate linked list to obtain an initial contour trajectory linked list set includes:
[0021] Step S31: Perform distance calculation on the contour points of each sub-region according to the contour point coordinate linked list to obtain the contour point distance dataset for each sub-region.
[0022] Step S32: Extract the first and second data of the contour point coordinate linked list to obtain the reference point;
[0023] Step S33: Based on the preset first distance threshold and the reference point, perform single-region neighbor point filtering on the contour points of each sub-region to obtain contour connection points whose distance from the reference point is less than or equal to the first distance threshold.
[0024] Step S34: Store the reference point in a preset contour trajectory linked list, and dynamically update the reference point according to the contour connection point;
[0025] Step S35: Repeat steps S33 to S34 until all distance data in the contour point distance dataset are greater than the first distance threshold, in order to obtain an initial contour trajectory linked list;
[0026] Step S36: Based on the initial contour trajectory linked list, perform overlapping data deletion processing on the contour point coordinate linked list to update the contour point coordinate linked list;
[0027] Repeat steps S31 to S36 until the data in the contour point coordinate linked list is cleared, and sort and summarize the data in the initial contour trajectory linked list according to the generation order of the initial contour trajectory linked list to obtain the initial contour trajectory linked list set.
[0028] In an optional implementation, the step of performing cross-regional contour fitting point extraction processing on the initial contour trajectory linked list set according to the boundary of each sub-region to obtain the dataset of points to be verified includes:
[0029] The initial contour trajectory linked list is processed by extracting the first and last data to obtain the contour end coordinate set;
[0030] Distance calculation is performed based on the boundary of each sub-region and the coordinate set of the contour end to obtain the boundary distance dataset between the boundary of each sub-region and the contour end.
[0031] Based on the preset boundary distance threshold and the boundary distance dataset, cross-region fitting point extraction processing is performed on the initial contour trajectory linked list set to obtain a dataset of points to be verified in each sub-region whose distance from the boundary is less than or equal to the boundary distance threshold.
[0032] In an optional implementation, the step of performing cross-regional neighbor point filtering on the dataset of points to be verified based on a preset second distance threshold and the region arrangement data in the region matrix to obtain a set of fitting points includes:
[0033] Based on the region arrangement data in the region matrix, the dataset of points to be verified is processed by classifying adjacent region data to obtain the coordinate set of calibration points to be verified.
[0034] Perform cross-regional distance calculation processing on the coordinate set of the calibration points to be verified to obtain the distance set to be verified;
[0035] Based on the preset second distance threshold and the distance set to be verified, the coordinate set of the calibration points to be verified is subjected to cross-regional neighbor point filtering processing to obtain a set of fitting points in the distance set to be verified whose distance to be verified is less than or equal to the second distance threshold.
[0036] In an optional implementation, the method further includes:
[0037] Step S71: Extract the first and last data of the edge contour trajectory linked list set to obtain the first and last coordinate sets of each edge contour.
[0038] Step S72: Perform distance calculation and distance comparison processing based on the preset starting point coordinates and the set of first and last coordinates to obtain the coordinates of the first execution point with the smallest distance, and perform trajectory chain list data extraction processing on the edge contour trajectory chain list set based on the coordinates of the first execution point to obtain the first executed edge contour trajectory chain list in the edge contour trajectory chain list set, and use the first executed edge contour trajectory chain list as the currently executed edge contour trajectory chain list.
[0039] Step S73: Perform distance calculation and distance comparison processing based on the coordinates of the last contour point in the currently executed edge contour trajectory chain list and the set of the first and last coordinates to obtain the coordinates of the second execution point with the smallest distance, and perform trajectory chain list data extraction processing on the edge contour trajectory chain list set based on the coordinates of the second execution point to obtain the second execution edge contour trajectory chain list in the edge contour trajectory chain list set.
[0040] Step S74: Based on the edge contour trajectory linked list of the second execution and the edge contour trajectory linked list of the current execution, perform data deletion processing on the first and last coordinate sets to update the first and last coordinate sets, and use the edge contour trajectory linked list of the second execution as the edge contour trajectory linked list of the current execution.
[0041] Repeat steps S73 to S74 until the data in the edge contour trajectory linked list is cleared, and sort the edge contour trajectory linked list according to the extraction order to obtain the image edge contour drawing instructions.
[0042] A second aspect of this application provides an apparatus for extracting image edge contours, the apparatus comprising:
[0043] The edge detection module is used to perform edge detection and adaptive region segmentation on the received target image to obtain a region matrix;
[0044] The background removal module is used to perform multi-core parallel scanning and contour point filtering on each sub-region in the region matrix to obtain a linked list of contour point coordinates for each sub-region.
[0045] The region contour module is used to perform single-region neighbor point filtering on the contour points of each sub-region according to a preset first distance threshold and the contour point coordinate chain list, so as to obtain an initial contour trajectory chain list set.
[0046] The verification point module is used to perform cross-regional contour fitting point extraction processing on the initial contour trajectory linked list set according to the boundary of each sub-region to obtain the verification point dataset.
[0047] The fitting verification module is used to perform cross-regional neighbor point filtering on the dataset of points to be verified based on a preset second distance threshold and the arrangement data of regions in the region matrix, so as to obtain a set of fitting points.
[0048] The contour merging module is used to perform cross-region merging processing on the initial contour trajectory linked list set based on the fitted point combination set, so as to obtain the edge contour trajectory linked list set.
[0049] A third aspect of this application provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the image edge contour extraction method as described above.
[0050] A fourth aspect of this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the image edge contour extraction method described above:
[0051] In summary, this application includes at least the following beneficial technical effects:
[0052] 1. By dividing the image into multiple regions and utilizing multi-core parallel scanning, the processing speed is greatly improved, enabling rapid contour extraction from large data volumes and high-resolution images.
[0053] 2. Using a preset first distance threshold, reference points are dynamically updated by filtering neighboring points within a single region to form an initial contour trajectory linked list. A preset second distance threshold is then used to filter neighboring points across regions, thereby achieving a smooth connection of contour data between multiple regions. This effectively eliminates noise points and ensures the continuity and coherence of the contour.
[0054] 3. A dynamic update strategy and iterative mechanism are adopted in the process of contour point selection and trajectory update, so that the extraction results can be adjusted and optimized in real time to adapt to the changing needs of different image content and complex backgrounds. Attached Figure Description
[0055] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0056] Figure 1 This is a flowchart of an image edge contour extraction method provided in an embodiment of this application;
[0057] Figure 2 This is a functional block diagram of an image edge contour extraction device provided in an embodiment of this application;
[0058] Figure 3 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0059] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0060] like Figure 1 The diagram shows a flowchart of an image edge contour extraction method provided in an embodiment of this application. The image edge contour extraction method provided in this embodiment includes the following steps.
[0061] Step S1: Perform edge detection and adaptive region segmentation on the received target image to obtain a region matrix.
[0062] It should be understood that the received target image is usually a color image, containing three color channels: red, green, and blue. To simplify the image data, the original three-channel data is converted into single-channel data (i.e., the color image is converted into a grayscale image), so that subsequent processing only needs to consider brightness information, reducing computational complexity. This application embodiment uses a weighted average method to achieve grayscale conversion of the target image. Specifically, for each pixel in the target image, based on preset contribution weight coefficients for each channel to brightness, the red, green, and blue channel values of that pixel are weighted and summed to obtain the grayscale value of that pixel. The contribution weight coefficients are based on measurements of human eye sensitivity to different colors. This compresses multi-channel data into single-channel data while preserving image brightness information.
[0063] After conversion to grayscale, the grayscale image may contain noise introduced by factors such as sensor noise and environmental interference, which can adversely affect subsequent edge detection. Therefore, a denoising algorithm is applied to the grayscale image to reduce random noise caused by hardware or the environment, ensuring the accuracy of true edge information in the image. Common denoising algorithms include, but are not limited to, median filtering or Gaussian filtering. For example, this embodiment uses median filtering for grayscale image denoising, where the preset filtering window is a 3×3 rectangular window. Starting from the upper left corner of the image, the window is moved row by row and column by column. For each pixel (i,j) as the center of the rectangular window, all pixel grayscale values within the rectangular window are extracted, resulting in 3×3 grayscale values. The grayscale values within the window are arranged in ascending order, and the value in the middle position after sorting is taken as the median, thus replacing the original grayscale value of the center pixel (i,j) with the median. Furthermore, the denoised grayscale image is standardized to ensure that the pixel values are within a specific range. This application employs a linear normalization method. Based on the offset of the gray value of each pixel in the image relative to the minimum gray value and the range of gray values in the image, the offset corresponding to the gray value of each pixel (i,j) in the image is normalized to [0,1]. Thus, based on the offset corresponding to each pixel (i,j) and the target range, the gray value of each pixel (i,j) is mapped to the target range to ensure that all image data are within the same numerical range.
[0064] For standardized grayscale images, edge detection algorithms are needed to extract edge information, forming a contour grayscale image containing only contour information. Edge detection is used to detect regions in the image where pixel values change drastically; these regions typically correspond to the boundaries, shape contours, or texture breaks of objects in the image. Edge detection is based on image gradient information, using changes in local pixel grayscale values to determine edge locations. Commonly used methods include the Sobel operator and the Canny operator. Specifically, in this embodiment, the Sobel operator is used to calculate the gradient values in the horizontal and vertical directions for each pixel in the standardized grayscale image. By calculating the grayscale changes in the horizontal and vertical directions respectively, the direction and intensity information of edges in the image are obtained. Then, based on the Pythagorean theorem, a composite value of the two-dimensional gradient (i.e., the gradient values in the horizontal and vertical directions) is calculated to obtain the overall grayscale change intensity of each pixel. Regions with higher intensity are considered edge candidate regions. Furthermore, the composite value of each pixel is thresholded according to a preset gradient threshold to determine edge candidate points. The gradient threshold is determined empirically or by preset parameters. Low-intensity gradient regions are filtered out by thresholding, retaining only edge information with significant grayscale changes. The thresholded image is stored to form a contour grayscale image. Edge points are typically displayed with high grayscale values (e.g., 255) in the contour grayscale image, while non-edge points are displayed with low grayscale values (e.g., 0), forming a binarized or grayscale edge image that reflects the contour information of the target object.
[0065] Finally, to improve data processing efficiency and multi-core parallel computing capabilities, the entire contour grayscale image is divided into several sub-regions based on the number of CPU logical cores. Each sub-region can be processed in parallel by an independent processing unit, avoiding slow processing speeds caused by large data volumes in a single processing unit. Specifically, the image pixel width is obtained from the image metadata, and the segmentation width of a single sub-region is calculated based on the segmentation threshold set according to the number of CPU logical cores. The contour grayscale image is then divided sequentially according to the segmentation width, with each sub-region corresponding to a continuous pixel interval in the horizontal direction. For example, the first sub-region is from pixel coordinate 0 to w-1, and the second sub-region is from pixel coordinate w to 2w-1. If the total width is not divisible by the segmentation threshold, the remaining portion is treated as the last sub-region (i.e., the corresponding portion is merged into the last sub-region). All the resulting sub-regions are organized sequentially into a region matrix. The region matrix is a two-dimensional array or linked list structure, where each element stores the pixel data and its position information within the corresponding sub-region.
[0066] Step S2: Perform multi-core parallel scanning and contour point filtering on each sub-region in the region matrix to obtain a linked list of contour point coordinates for each sub-region.
[0067] It should be understood that each sub-region has fixed starting coordinates and size in the image. According to a preset scanning order, typically from left to right and from top to bottom, pixels within each sub-region are scanned one by one. This embodiment employs multi-core parallel scanning to utilize the parallel computing power of multi-core processors, distributing the entire region matrix across independent processing units, simultaneously reading pixel information from multiple regions, thereby significantly shortening the overall data extraction time and improving processing efficiency. Specifically, during scanning, for each pixel within a sub-region, its position is represented by (i,j), where i is the row coordinate, j is the column coordinate, and the pixel value is denoted as I(i,j). Further, during the scanning process, the coordinates and corresponding pixel values of all pixels are recorded in a mapping table. Each entry in the mapping table includes the coordinates (i,j) and the value I(i,j). The coordinates and pixel values of all pixels within the region are extracted according to the preset scanning order and stored in the mapping table. The generation process of the coordinate-pixel value mapping table must ensure data integrity and non-repetition; each pixel is recorded only once, and the recording is performed according to the requirements of the data structure. After the data is read, each record in the coordinate-pixel value mapping table contains the location information and pixel value of a single pixel within that sub-region.
[0068] It should be understood that after grayscale conversion and noise reduction, the pixel values of the true contour areas in the image usually exhibit higher grayscale values, while the pixel values of noise and background areas are lower. Further, contour points that meet specific color threshold conditions are extracted from the coordinate-pixel value mapping table. Contour points represent the boundaries of objects in the image or other areas with significant grayscale changes. By comparing the pixel value of each pixel, it is determined whether the value is greater than a preset color threshold, thus filtering out points with higher grayscale values. The color threshold is usually determined based on experimental data; for example, 127 is often used as the judgment standard in grayscale images. Specifically, each record in the coordinate-pixel value mapping table is judged according to the color threshold. If the pixel value is greater than the color threshold, the point is determined to be a contour point. The entire filtering process traverses the coordinate-pixel value mapping table one by one according to a preset scanning order, ensuring that all data is judged without omission. Simultaneously, when using hardware parallel computing capabilities, each processing unit independently filters the data in its sub-region, ensuring that data does not interfere with each other during parallel processing, and that all contour points that meet the conditions are correctly recorded. The filtered results constitute a contour point coordinate set.
[0069] In this case, the contour point data in the contour point coordinate set is not arranged in spatial order. To ensure the continuity and order of subsequent contour trajectory generation, the contour point data in the contour point coordinate set needs to be sorted to form an ordered contour point coordinate linked list. During the sorting process, the data is arranged according to the order determined during the scanning process, thereby ensuring that the contour point data extracted in each sub-region can reflect the true spatial distribution in the image, facilitating subsequent neighbor point selection and trajectory merging processing. Specifically, each record in the contour point coordinate set is initially sorted according to its row coordinates; if two records have the same row coordinates, a secondary sort is performed according to their column coordinates. The sorting algorithm can use a stable algorithm such as quicksort, mergesort, or other algorithms suitable for sorting large amounts of data to ensure that the sorted data order is completely consistent with the original scanning order. In the implementation process, the contour point coordinate set in each sub-region is used as input, and after being processed by the sorting algorithm, an ordered linked list structure is output. Each node in this linked list contains the coordinate information of the contour points, and they are linked sequentially according to a preset order to form a continuous data sequence. The sorting algorithm can be further optimized in a parallel computing environment by distributing the sorting tasks of multiple sub-regions to each independent core and generating a complete ordered linked list (i.e., a linked list of contour point coordinates) in a unified manner during the data merging stage.
[0070] Step S3: Based on the preset first distance threshold and the contour point coordinate linked list, perform single-region neighbor point filtering on the contour points of each sub-region to obtain an initial contour trajectory linked list set.
[0071] To clarify the spatial distances between contour points in each sub-region, accurately determining which points are spatially close to each other, thus facilitating the construction of continuous contour trajectories and preventing trajectory breaks due to excessively large distances between adjacent points during subsequent processing, the Euclidean distance between each pair of points in each sub-region is calculated based on the positions of points in the contour point coordinate linked list. This yields a dataset describing the mutual distances between points within the sub-region (i.e., the contour point distance dataset). It should be understood that each record in the contour point coordinate linked list obtained for each sub-region contains the pixel row and column coordinates of the point in the image. Based on Euclidean geometry, the straight-line distance on a two-dimensional plane is calculated for each pair of contour points in the contour point coordinate linked list to quantify the spatial relationships between contour points, thereby forming the contour point distance dataset corresponding to each sub-region. This dataset can be stored in a matrix or list format, where each element of the matrix represents the distance between two corresponding points. A pre-determined scanning order is used during distance calculation to ensure the data corresponds to the order of points in the linked list. Multi-core parallel technology is employed to distribute large-scale distance calculation tasks across multiple processing units, accelerating the overall computation speed. During the calculation process, all distance data is recorded, which makes it easy to directly find the distance value between the current reference point and other points in the neighbor point filtering later.
[0072] The contour point coordinate list is sorted according to a preset scanning order, with the first and first data points typically located at the edge of the entire region. Therefore, extracting the first and first data points from the contour point coordinate list ensures that the selected reference point is positioned appropriately within the entire contour point sequence, facilitating subsequent determination of whether to connect it to form a continuous trajectory based on its distance from other points. Specifically, when traversing the contour point coordinate list, the first node in the list is used as the reference point. During data extraction, after selecting the reference point, it is recorded and stored in a preset variable or data structure as the starting point for the current trajectory construction. This reference point is not only used for comparing distances with other contour points in subsequent processes but also saved as the first node of the initial trajectory list.
[0073] It should be understood that only points close to the current reference point can form a continuous and smooth contour trajectory during image rendering. If the distance between connection points is too large, breaks or discontinuities in the path may occur during image rendering. Furthermore, based on the extracted reference point and the pre-calculated contour point distance dataset, contour points within the same sub-region are filtered to identify all points whose distance to the reference point is less than or equal to a preset first distance threshold, and these points are designated as contour connection points for the current reference point. Specifically, Euclidean distance data related to the reference point is obtained from the contour point distance dataset based on the current reference point. After obtaining the Euclidean distance data between each point and the current reference point, all points are filtered according to the preset first distance threshold. If a contour point has an Euclidean distance less than or equal to the first distance threshold, then that contour point is identified as a contour connection point for the current reference point. In actual data processing, all contour points in the sub-region that meet the above criteria are aggregated into a contour connection point set. This set serves as a candidate connection point for the current reference point, directly affecting the extension of the subsequent trajectory. A loop traversal method is used during data processing to ensure that all points are checked.
[0074] Furthermore, the current reference point is recorded in a pre-defined contour trajectory linked list, and the reference point is dynamically updated based on the previously selected set of contour connection points, thereby extending and constructing a continuous initial contour trajectory. This process ensures that, starting from the current reference point, contour points that meet the conditions are gradually connected into a continuous trajectory based on proximity. Simultaneously, by dynamically updating the reference point, the trajectory is expanded until all contour points meeting the conditions within the region are included in the trajectory. Specifically, the current reference point is first stored in a pre-defined contour trajectory linked list, which sequentially stores all points forming the trajectory. The list is initially empty, and new reference points are added with each update operation, eventually forming a continuous trajectory. The storage procedure uses a simple data structure insertion operation to ensure that the order remains unchanged and data is not duplicated. Next, the reference point is updated based on the selected set of contour connection points. That is, a contour branch trajectory linked list is established for each contour connection point in the set, ensuring that all contour trajectories originating from the current reference point are completely recorded in the system, avoiding the omission of contour trajectory branches. For each newly established contour branch trajectory list, the subsequent neighbor point selection and dynamic update operations will be performed independently, that is, each branch will be further expanded. In other words, the extension process of each branch is executed independently, separated only in the initial branch operation stage, ensuring that no branch is missed due to a unified update. For each branch trajectory, each contour connection point in the contour connection point set is used as the current reference point for that branch. Next, the remaining contour point coordinate list is used to select connection points adjacent to the updated current reference point, and then the above process is repeated to construct new extension branches or extend the current contour trajectory.
[0075] Furthermore, since the distribution of contour points within sub-regions of an image is usually dense or irregular, multiple iterative updates can gradually connect all eligible contour points to form a continuous and complete trajectory. Therefore, the process of filtering neighboring points and dynamically updating reference points is repeated until all distances between the remaining contour points within the sub-region and the current reference point are greater than a first distance threshold, thus completing the construction of a continuous trajectory within a single region and obtaining an initial contour trajectory linked list. In each iteration, the distance between the current reference point and the remaining contour points is checked, and the loop terminates when the condition is met, preventing points that are spatially distant from each other from being incorrectly connected to the trajectory. The specific iterative execution process is as follows:
[0076] At the beginning of each loop, based on the distance dataset between the current reference point and the remaining contour points, the above steps are used to filter neighboring points, selecting all candidate points whose distance from the current reference point does not exceed the first distance threshold. Then, the above operations are used to expand the trajectory branch or extend the trajectory and update the reference point, while storing the current reference point in the trajectory linked list. After the update is completed, neighboring points are filtered again based on the new reference point. If there is a set of contour connection points that meet the filtering criteria, the filtering and update operations continue; otherwise, the loop exits.
[0077] Since multiple independent contour trajectories may exist within each sub-region, after each trajectory is constructed (i.e., a new initial contour trajectory linked list is generated), used points need to be removed from the candidate data (i.e., the contour point coordinate linked list). The remaining point data will be used to construct the next trajectory. The updated contour point coordinate linked list needs to be synchronously updated after each loop. The already constructed initial contour trajectory linked list and the contour point coordinate linked list are compared, and overlapping data is deleted to update the contour point coordinate linked list, preventing the same contour point from repeatedly participating in trajectory construction in subsequent iterations. Simultaneously, the initial contour trajectory linked lists obtained after multiple loops are sorted and summarized according to the generation order, thus forming the final set of initial contour trajectory linked lists. Specifically, by comparing the initial contour trajectory linked list with the contour point coordinate linked list, a data filtering method is used to delete points already present in the trajectory linked list from the contour point coordinate linked list. The updated contour point coordinate linked list only contains points that did not participate in the current trajectory construction. Next, the above step S3 is executed again on the updated contour point coordinate linked list until all the data in the contour point coordinate linked list is cleared, that is, all contour points in the region that meet the conditions have been included in at least one initial trajectory.
[0078] After the loop completes, all generated initial contour trajectory linked lists are sorted and summarized. The sorting process follows the order in which each trajectory linked list was generated, ensuring that the points within each trajectory conform to the logical order from the start point to the end. Simultaneously, all individually generated trajectory linked lists are aggregated into a single set, namely the initial contour trajectory linked list set. This set can use a list, array, or other suitable set structure to facilitate subsequent trajectory optimization and cross-region merging.
[0079] It should be understood that after the operations of steps S1 to S3 described above, the contour trajectories within each sub-region are identified and represented in the form of an initial contour trajectory linked list. Since some edge contours may be assigned to adjacent different sub-regions during the region division process of the entire target image, after completing the contour trajectory identification within each sub-region, it is necessary to perform fitting judgments and cross-region merging on the contour trajectories within adjacent sub-regions.
[0080] Step S4: Based on the boundaries of each sub-region, perform cross-region contour fitting point extraction processing on the initial contour trajectory linked list set to obtain the dataset of points to be verified.
[0081] After sub-region division, each sub-region inevitably has a boundary. In the multiple initial contour trajectory lists, the starting or ending points of some trajectories are often close to the sub-region boundaries. These endpoint data play a crucial role in subsequent cross-region integration and trajectory fitting. Endpoint data reflects the relationship between the trajectory and the sub-region boundary, providing accurate boundary information for subsequent cross-region fitting. Specifically, firstly, each initial contour trajectory list is stored as a data list, storing several contour points arranged in the generation order. This list has been generated by previous steps and can well reflect the continuous contour structure within the region. During data extraction, it is required that at least the first and last nodes of each list be taken. For example, an initial contour trajectory list is T={P1,……,P}. n}, where each point P n =(x k ,y k () represents the two-dimensional coordinates of the corresponding contour point in the image. The first data P1 and the last data P2 are extracted from this initial contour trajectory linked list. n This forms the contour endpoint data. All the extracted beginning and end data constitute a set ε (i.e., the contour endpoint coordinate set), where each point in the contour endpoint coordinate set represents a possible proximity of a trajectory to the boundary within that region.
[0082] Furthermore, based on the contour endpoint coordinate set and the boundary information of each sub-region, the vertical distance from the endpoint to the boundary is calculated, thus forming a dataset describing the relative positional relationship between the sub-region boundary and the trajectory endpoint. The distance calculation process employs rigorous geometric operations, processing the boundary data and endpoint data of each sub-region sequentially. Specifically, the boundaries of each sub-region have been determined in the adaptive region partitioning. For any sub-region, its boundaries typically include a left boundary, a right boundary, a top boundary, and a bottom boundary. Assuming the sub-region is defined as a rectangular region, its boundaries can be determined using four straight lines, specifically described in pixel coordinates; for example, the left boundary coordinates are x=x. left The right boundary is x=x right Each point P in the contour end coordinate set ε = (x p ,y p All points are located within or near the boundary of a sub-region, requiring the calculation of the shortest distance between them and the boundary line. Taking the calculation of the distance to the left boundary as an example, for a vertical boundary, the distance between point P and the left boundary can be simply expressed as d. left =|x p -x leftEach endpoint P may have different distances from multiple boundaries, but when extracting points for cross-region fitting, the focus is on the distance between the endpoint and the nearest boundary in its sub-region. Therefore, the smallest distance is taken as the boundary distance for that point. Next, the above processing procedure is applied to all endpoints in each sub-region to form the boundary distance dataset for that sub-region. In the boundary distance dataset, the value of each endpoint reflects its proximity to the boundary within that sub-region, which plays a crucial role in determining whether the endpoint is suitable for cross-region fitting.
[0083] Finally, the boundary distance dataset is compared with a preset boundary distance threshold to extract contour endpoint data that are close to the sub-region boundary. These points are called verification points. Verification points are candidate points that need to be verified in subsequent cross-region processing. Their role is to ensure that the trajectories between different sub-regions can be reasonably connected at the boundary, ultimately forming a complete image drawing trajectory. The boundary distance threshold was determined based on experimental data during the system design phase. This value indicates that an endpoint is considered a verification point only if the minimum distance between the endpoint and the sub-region boundary is less than or equal to the boundary distance threshold. In practice, the boundary distance threshold is judged for each endpoint P in the boundary distance dataset. All endpoints are traversed, and endpoints that meet the condition are stored one by one in the verification point set V. The data storage process uses an array or linked list data structure to ensure that all data meeting the condition is recorded. Each selected endpoint contains coordinate information and the distance value between it and the sub-region boundary. This data will serve as important candidate points for cross-region contour fitting.
[0084] Step S5: Based on the preset second distance threshold and the arrangement data of the regions in the region matrix, perform cross-regional neighbor point filtering on the dataset of points to be verified to obtain a set of fitting points.
[0085] It should be understood that the arrangement of regions in the region matrix clearly indicates the spatial location and interrelationships of each region in the image. By grouping the points to be verified according to regions, it can be ensured that the data within each region group is clearly categorized when calculating cross-regional distances. This helps to quickly determine which calibration points are candidate points when connecting across regions. Therefore, based on the arrangement of each sub-region in the region matrix, the dataset of points to be verified can be classified according to their relationship with their respective regions or adjacent regions, forming a set of coordinates for the calibration points to be verified.
[0086] In this system, each sub-region in the region matrix has a defined spatial location and arrangement order within the image, typically arranged in rows and columns. The arrangement data in the region matrix includes information such as the starting coordinates, width, and height of each sub-region. This data can be used to determine whether two points to be verified originate from adjacent regions. Assuming the image is divided into several rows and columns of regions, let each region be represented by its row and column number, such as sub-region R. i,j Let R represent the region in the i-th row and j-th column. Each point P=(x,y) in the dataset to be verified can be mapped to its corresponding sub-region R based on its coordinates. i,j In the middle, the mapping relationship can be determined by whether the x-coordinate and y-coordinate of a point fall within the subregion R. i,j The determination is made within a pixel range. By determining the sub-region number of the point P to be verified, points from the same sub-region and those belonging to adjacent regions (e.g., vertical and horizontal directions) are grouped into the same category. Through classification, points to be verified can be aggregated across regions to form a set of coordinates for the calibration points to be verified. Classification helps reduce interference from irrelevant data in subsequent cross-region distance calculations and ensures that all cross-regional candidate points are classified by region, thus providing a good data organization foundation for subsequent distance calculations.
[0087] Furthermore, to quantify the relative distances between calibration points in different regions, thus providing accurate numerical basis for subsequent filtering based on the second distance threshold, cross-regional distance calculations are performed on the coordinate set of calibration points to be verified, obtaining a set of distances to be verified that describes the spatial relationships between the calibration points. Since the principles used in calculating the distance between calibration points across regions and the distance between a reference point and a contour point within a single region are both Euclidean geometric laws, they will not be elaborated upon here. For details, please refer to step S3 for the process of calculating the distance between a reference point and a contour point within a single region. During cross-regional distance calculations, the distances between all points in the coordinate set of calibration points to be verified should be calculated, and all calculation results should be stored uniformly as a set of distances to be verified. This dataset can be stored in the form of a two-dimensional matrix or a list, with each element representing the distance between different pairs of calibration points, facilitating subsequent filtering operations. The entire cross-regional distance calculation process employs multi-core parallel processing technology, iterating and calculating the distance between any two points in the calibration point set, ensuring that computational efficiency and accuracy are not affected under large-scale data.
[0088] After regional division, it's difficult to guarantee that points on the boundaries of each sub-region are always continuous. Only when the distance between calibration points to be verified in adjacent sub-regions is sufficiently close can they be considered to have the potential for cross-region connectivity. Based on the numerical information in the set of distances to be verified, and combined with a preset second distance threshold, points in the set of calibration point coordinates to be verified are filtered to extract combinations of calibration points whose pairwise distances are less than or equal to each other, thus forming a set of fitting point combinations. The second distance threshold is a parameter determined based on experimental data during the system design phase, and its value reflects the maximum allowable distance range in cross-region connectivity. For each distance in the set of distances to be verified, if there exists a distance to be verified that is less than or equal to the second distance threshold, the corresponding calibration point P is considered to be... a and P b For cross-regional connections, point pairs with sufficient proximity should be recorded as candidate fitting point combinations. When recording, in addition to saving the coordinate data of the point pair, the corresponding distance value should also be recorded for subsequent verification and data traceability. Data storage can be in the form of a list or array, where each record contains a pair of calibration points and their distance information. After this filtering process, the generated set of fitting point combinations only includes calibration point pairs that meet the distance constraints for cross-regional connections, ensuring their practical connection possibility in physical space.
[0089] Step S6: Perform cross-region merging processing on the initial contour trajectory linked list set according to the fitted point combination set to obtain the edge contour trajectory linked list set.
[0090] It should be understood that the initial contour trajectory linked list generated after region division often only reflects the contour connection within each sub-region, and there are breaks at the boundaries of sub-regions, failing to directly reflect the continuous contour information of the entire image. The fitted point combination set provides a quantitative basis for cross-region connections, and the spatial continuity between trajectories of different sub-regions can be determined by matching candidate connection pairs. Each element in the fitted point combination set is a calibration point pair (P... a ,P b The point pair satisfies the second distance threshold criterion, reflecting that the two endpoints from adjacent sub-regions are spatially close enough to have the potential for merging and connecting. Therefore, based on the fitted point combination set, cross-regional candidate connection pairs (i.e., calibration point pairs (P)) can be determined. a ,P bAfter identifying cross-regional candidate connection pairs, the initial contour trajectory linked list set is scanned and matched based on the coordinates of each point in the calibration point pair to obtain the initial contour trajectory linked list corresponding to each endpoint, thereby finding the trajectory where each endpoint of the candidate connection pair is located. After determining the trajectory corresponding to the candidate connection pair, the two initial contour trajectory linked lists are merged according to the merging rules. The merging process involves splicing the two initial contour trajectory linked lists through the candidate connection points to form a longer trajectory linked list. The merging operation needs to ensure a smooth transition and data continuity at the splicing points; therefore, a data fusion algorithm is used during merging to correct for overlapping or approximate data at the connection points. In actual processing, insertion sort and linked list joining techniques are used when merging two trajectories to ensure the accuracy of the data order during the merging process. Multiple checks are required at the candidate connection points during data processing to ensure that no data loss or duplication occurs after merging. The merged trajectory linked list not only records the original trajectory data of each individual but also forms a continuous cross-regional contour line through splicing. After the merging process is completed, a preliminary edge contour trajectory linked list set is obtained.
[0091] In one optional implementation, based on the obtained set of edge contour trajectory linked lists, each merged trajectory data can be sorted, corrected, and integrated. The sorting operation, according to the previously established generation order, uses a simple linked list traversal and sorting algorithm to adjust each trajectory node to the correct order from the start point to the end point. The correction operation ensures that slight displacements caused by data fusion at the merging point are smoothly adjusted, guaranteeing no obvious jumps at the merging point.
[0092] In one optional implementation, the extracted edge contour trajectory list needs to be used in conjunction with a real-world execution device to draw the target image, such as for sewing or 3D printing. To minimize the drawing execution time of the execution device, the edge contour trajectory list needs to be converted into image edge contour drawing instructions based on the parameters of the execution device. This minimizes the distance the execution device needs to travel from the end of the previous trajectory segment to the beginning of the next, reducing idle running time.
[0093] Specifically, for each independent edge contour trajectory linked list in the edge contour trajectory linked list set, its two key nodes, "start" and "end," are extracted to construct a start-end coordinate set. This set includes the start and end coordinates of all trajectory linked lists, visually reflecting the spatial position of each contour in the image, facilitating subsequent distance-based sequential selection. It should be understood that most execution devices are configured with a reset operation when executing instructions (i.e., the drawing component in the execution device resets to a specified position after the current instruction is completed or before an instruction is received). For example, a smart embroidery sewing device has a preset reset instruction, ensuring that the sewing needle is positioned at the upper right edge of the fabric before or after executing the image drawing instruction. Therefore, it is necessary to combine the preset starting point coordinates (i.e., the reset coordinates) of the execution device when executing instructions to calculate the distance between it and all candidate points in the start-end coordinate set, and select the point with the smallest distance as the "first execution point." Therefore, based on the trajectory linked list to which the "first execution point" belongs, the corresponding complete edge contour trajectory linked list is extracted from the edge contour trajectory linked list set as the first executed edge contour trajectory linked list. At the same time, the preset current execution edge contour trajectory linked list is assigned a value based on the first executed edge contour trajectory linked list. The current execution edge contour trajectory linked list is used to guide the drawing device of the execution device to draw the current contour trajectory.
[0094] After completing the drawing of the current execution edge contour trajectory chain, the drawing device of the execution equipment will briefly pause at the end of the trajectory, i.e., the coordinates of the last contour point of the current execution edge contour trajectory chain. To continue drawing the next trajectory, the endpoint with the shortest Euclidean distance from the coordinates of the last contour point in the set of beginning and end coordinates should be selected as the second execution point to minimize the jump distance between the two trajectories and reduce mechanical idle time. Specifically, the coordinates of the last contour point are extracted from the current execution edge contour trajectory chain, and the Euclidean distances between each endpoint in the set of beginning and end coordinates and the last contour point are calculated based on these coordinates. Note that the endpoint coordinate data in the set of beginning and end coordinates used in the above Euclidean distance calculation does not include the coordinates of the beginning and end endpoints in the current execution edge contour trajectory chain. The calculated Euclidean distances are then compared to find the endpoint corresponding to the minimum distance, and this endpoint is selected as the coordinates of the second execution point. Based on the trajectory chain to which the second execution point belongs, the corresponding complete edge contour trajectory chain is extracted from the edge contour trajectory chain set as the edge contour trajectory chain for the second execution.
[0095] After obtaining the edge contour trajectory linked list for the second execution, based on the edge contour trajectory linked list for the second execution and the edge contour trajectory linked list for the current execution, the data with the same endpoints in the first and last coordinate sets are deleted to update the information in the first and last coordinate sets, thereby preventing the already extracted edge contour trajectory linked lists from participating in subsequent loop operations repeatedly. Next, using the edge contour trajectory linked list for the second execution as the updated edge contour trajectory linked list for the current execution, the above chain-like filtering operation based on the last endpoint is repeated until all edge contour trajectory linked lists stored in the edge contour trajectory linked list set have been extracted (i.e., all data in the first and last coordinate sets has been deleted).
[0096] Finally, based on the sequence labels (e.g., timestamps) assigned during the edge contour trajectory list extraction process, each edge contour trajectory list is sorted and combined in a preset ascending order to form a complete image edge contour drawing instruction.
[0097] By employing a cyclical filtering and merging method, the optimal movement path is ensured for the execution device during transitions between contour segments (i.e., each needle lift or idle movement follows the shortest path). This optimizes the drawing process sequence, minimizes mechanical pauses and unnecessary movements, and thus reduces the overall drawing time of the execution device.
[0098] This application is applied to the field of image contour extraction technology. It obtains a region matrix by performing edge detection and region segmentation on the target image. For each sub-region, multi-core parallel scanning and contour point filtering are performed to obtain a linked list of contour point coordinates for each sub-region. A first distance threshold is used to filter the contour points of each sub-region using single-region neighboring points to obtain an initial contour trajectory linked list set. Based on the boundaries of each sub-region, cross-region contour fitting points are extracted to obtain a dataset of points to be verified. A second distance threshold and region arrangement data are used to filter the dataset of points to be verified using cross-region neighboring points to obtain a set of fitted point combinations. Finally, the initial contour trajectory linked list set is merged across regions to obtain an edge contour trajectory linked list set. This application effectively improves the speed, accuracy, and robustness of edge extraction through multiple techniques such as multi-core parallel processing, dynamic neighboring point filtering, and cross-region data fusion, while ensuring good data structure organization and efficient integration with subsequent applications.
[0099] like Figure 2 The diagram shown is a functional block diagram of an image edge contour extraction device provided in an embodiment of this application.
[0100] In some embodiments, the image edge contour extraction device 2 may include multiple functional modules composed of computer program segments. The computer programs for each program segment in the image edge contour extraction device 2 may be stored in the server's memory and executed by at least one processor to perform (see details). Figure 1 (Description) Function of the image edge contour extraction method.
[0101] In this embodiment, the image edge contour extraction device 2 can be divided into multiple functional modules according to its function. These functional modules may include: an edge detection module 21, a background removal module 22, a region contour module 23, a verification point module 24, a fitting verification module 25, a contour merging module 26, and a drawing instruction module 27. The module referred to in this invention is a series of computer program segments that can be executed by at least one processor and perform a fixed function, stored in memory. In this embodiment, the functions of each module will be detailed in subsequent embodiments.
[0102] The edge detection module 21 is used to perform edge detection and adaptive region segmentation processing on the received target image to obtain a region matrix.
[0103] In an optional implementation, the edge detection module 21 is specifically used for:
[0104] The received target image is converted to grayscale and denoised to obtain a standardized grayscale image;
[0105] Edge detection processing is performed on the standardized grayscale image to obtain a contour grayscale image;
[0106] The contour grayscale image is adaptively divided into regions based on a preset segmentation threshold to obtain the region matrix.
[0107] Background removal module 22 is used to perform multi-core parallel scanning and contour point filtering processing on each sub-region in the region matrix to obtain a linked list of contour point coordinates for each sub-region.
[0108] In an optional implementation, the background removal module 22 is specifically used for:
[0109] According to the preset scanning order, each sub-region in the region matrix is subjected to multi-core parallel scanning and reading processing of pixel coordinates and pixel values to obtain the coordinate-pixel value mapping table corresponding to each sub-region.
[0110] Based on the preset color threshold and the coordinate-pixel value mapping table, each sub-region is subjected to contour point filtering processing to obtain a set of contour point coordinates with pixel values greater than the color threshold.
[0111] The contour point coordinate set is sorted according to the scanning order to obtain a linked list of contour point coordinates for each sub-region.
[0112] The region contour module 23 is used to perform single-region neighbor point filtering on the contour points of each sub-region according to a preset first distance threshold and the contour point coordinate chain list, so as to obtain an initial contour trajectory chain list set.
[0113] In an optional implementation, the region contour module 23 is specifically used for:
[0114] Step S31: Perform distance calculation on the contour points of each sub-region according to the contour point coordinate linked list to obtain the contour point distance dataset for each sub-region.
[0115] Step S32: Extract the first and second data of the contour point coordinate linked list to obtain the reference point;
[0116] Step S33: Based on the preset first distance threshold and the reference point, perform single-region neighbor point filtering on the contour points of each sub-region to obtain contour connection points whose distance from the reference point is less than or equal to the first distance threshold.
[0117] Step S34: Store the reference point in a preset contour trajectory linked list, and dynamically update the reference point according to the contour connection point;
[0118] Step S35: Repeat steps S33 to S34 until all distance data in the contour point distance dataset are greater than the first distance threshold, in order to obtain an initial contour trajectory linked list;
[0119] Step S36: Based on the initial contour trajectory linked list, perform overlapping data deletion processing on the contour point coordinate linked list to update the contour point coordinate linked list;
[0120] Repeat steps S31 to S36 until the data in the contour point coordinate linked list is cleared, and sort and summarize the data in the initial contour trajectory linked list according to the generation order of the initial contour trajectory linked list to obtain the initial contour trajectory linked list set.
[0121] The verification point module 24 is used to perform cross-regional contour fitting point extraction processing on the initial contour trajectory linked list set according to the boundary of each sub-region to obtain the verification point dataset.
[0122] In an optional implementation, the verification point module 24 is specifically used for:
[0123] The initial contour trajectory linked list is processed by extracting the first and last data to obtain the contour end coordinate set;
[0124] Distance calculation is performed based on the boundary of each sub-region and the coordinate set of the contour end to obtain the boundary distance dataset between the boundary of each sub-region and the contour end.
[0125] Based on the preset boundary distance threshold and the boundary distance dataset, cross-region fitting point extraction processing is performed on the initial contour trajectory linked list set to obtain a dataset of points to be verified in each sub-region whose distance from the boundary is less than or equal to the boundary distance threshold.
[0126] The fitting verification module 25 is used to perform cross-regional neighbor point filtering on the dataset of points to be verified based on a preset second distance threshold and the arrangement data of regions in the region matrix, so as to obtain a set of fitting points.
[0127] In an optional implementation, the fitting verification module 25 is specifically used for:
[0128] Based on the region arrangement data in the region matrix, the dataset of points to be verified is processed by classifying adjacent region data to obtain the coordinate set of calibration points to be verified.
[0129] Perform cross-regional distance calculation processing on the coordinate set of the calibration points to be verified to obtain the distance set to be verified;
[0130] Based on the preset second distance threshold and the distance set to be verified, the coordinate set of the calibration points to be verified is subjected to cross-regional neighbor point filtering processing to obtain a set of fitting points in the distance set to be verified whose distance to be verified is less than or equal to the second distance threshold.
[0131] The contour merging module 26 is used to perform cross-region merging processing on the initial contour trajectory linked list set according to the fitting point combination set, so as to obtain the edge contour trajectory linked list set.
[0132] In an optional embodiment, the image edge contour extraction device 2 further includes a drawing instruction module 27, which is specifically used for:
[0133] Step S71: Extract the first and last data of the edge contour trajectory linked list set to obtain the first and last coordinate sets of each edge contour.
[0134] Step S72: Perform distance calculation and distance comparison processing based on the preset starting point coordinates and the set of first and last coordinates to obtain the coordinates of the first execution point with the smallest distance, and perform trajectory chain list data extraction processing on the edge contour trajectory chain list set based on the coordinates of the first execution point to obtain the first executed edge contour trajectory chain list in the edge contour trajectory chain list set, and use the first executed edge contour trajectory chain list as the currently executed edge contour trajectory chain list.
[0135] Step S73: Perform distance calculation and distance comparison processing based on the coordinates of the last contour point in the currently executed edge contour trajectory chain list and the set of the first and last coordinates to obtain the coordinates of the second execution point with the smallest distance, and perform trajectory chain list data extraction processing on the edge contour trajectory chain list set based on the coordinates of the second execution point to obtain the second execution edge contour trajectory chain list in the edge contour trajectory chain list set.
[0136] Step S74: Based on the edge contour trajectory linked list of the second execution and the edge contour trajectory linked list of the current execution, perform data deletion processing on the first and last coordinate sets to update the first and last coordinate sets, and use the edge contour trajectory linked list of the second execution as the edge contour trajectory linked list of the current execution.
[0137] Repeat steps S73 to S74 until the data in the edge contour trajectory linked list is cleared, and sort the edge contour trajectory linked list according to the extraction order to obtain the image edge contour drawing instructions.
[0138] It should be understood that the various variations and specific embodiments of the methods provided in the above embodiments are also applicable to the image edge contour extraction apparatus of this embodiment. Through the foregoing detailed description of the image edge contour extraction method, those skilled in the art can clearly understand the implementation method of the image edge contour extraction apparatus of this embodiment. For the sake of brevity, it will not be described in detail here.
[0139] like Figure 3 The diagram shown is a structural schematic of an electronic device provided in an embodiment of this application.
[0140] In a preferred embodiment of the present invention, the electronic device 3 may include, but is not limited to, a memory 31, at least one processor 32, and at least one communication bus 33.
[0141] Those skilled in the art should understand that Figure 3 The structure of the electronic device 3 shown does not constitute a limitation of the embodiments of the present invention. The electronic device 3 may also include more or fewer other hardware or software than shown, or different component arrangements.
[0142] In some embodiments, the electronic device 3 is a device capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes, but is not limited to, microprocessors, application-specific integrated circuits, programmable gate arrays, digital processors, and embedded devices.
[0143] It should be noted that the electronic device 3 is merely an example. Other existing or future electronic products that are suitable for this application should also be included within the scope of protection of this application and are incorporated herein by reference.
[0144] In some embodiments, the memory 31 stores a computer program that, when executed by the at least one processor 32, implements all or part of the steps in the image edge contour extraction method described above. The memory 31 includes a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, disk storage, magnetic tape storage, or any other computer-readable medium capable of carrying or storing data. Further, the computer-readable storage medium may primarily include a program storage area and a data storage area, wherein the program storage area may store an operating system, at least one application program required for a function, etc.
[0145] In some embodiments, the at least one processor 32 is the control unit of the electronic device 3, connecting various components of the electronic device 3 via various interfaces and lines. It executes programs or modules stored in the memory 31 and calls data stored in the memory 31 to perform various functions and process data. For example, when the at least one processor 32 executes a computer program stored in the memory 31, it implements all or part of the steps of the image edge contour extraction method described in this application embodiment; or it implements all or part of the functions of the image edge contour extraction device. The at least one processor 32 may be composed of integrated circuits, such as a single-packaged integrated circuit or multiple integrated circuits with the same or different functions, including combinations of one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips.
[0146] In some embodiments, the at least one communication bus 33 is configured to enable communication between the memory 31 and the at least one processor 32, etc. Although not shown, the electronic device 3 may also include a power supply (e.g., a battery) to power the various components. Preferably, the power supply can be logically connected to the at least one processor 32 via a power management device, thereby enabling functions such as charging, discharging, and power consumption management. The power supply may also include one or more DC or AC power supplies, recharging devices, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components. The electronic device 3 may also include various sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be described in detail here.
[0147] The integrated unit implemented as a software functional module described above can be stored in a computer-readable storage medium. This software functional module, stored in a storage medium, includes several instructions to cause an electronic device (which may be a personal computer, electronic device, or network device, etc.) or processor to execute portions of the methods described in the various embodiments of this application.
[0148] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and other division methods may be used in actual implementation.
[0149] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical units; they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0150] The above are all preferred embodiments of this application, and are not intended to limit the scope of protection of this application. Therefore, all equivalent changes made in accordance with the structure, shape and principle of this application should be covered within the scope of protection of this application.
Claims
1. A method for extracting image edge contours, characterized in that, The method includes: Edge detection and adaptive region segmentation are performed on the received target image to obtain a region matrix; Perform multi-core parallel scanning and contour point filtering on each sub-region in the region matrix to obtain a linked list of contour point coordinates for each sub-region. Based on a preset first distance threshold and the contour point coordinate linked list, the contour points of each sub-region are subjected to single-region neighbor point filtering to obtain an initial contour trajectory linked list set, including: Step S31: Perform distance calculation on the contour points of each sub-region according to the contour point coordinate linked list to obtain the contour point distance dataset for each sub-region. Step S32: Extract the first and second data of the contour point coordinate linked list to obtain the reference point; Step S33: Based on the preset first distance threshold and the reference point, perform single-region neighbor point filtering on the contour points of each sub-region to obtain contour connection points whose distance from the reference point is less than or equal to the first distance threshold. Step S34: Store the reference point in a preset contour trajectory linked list, and dynamically update the reference point according to the contour connection point; Step S35: Repeat steps S33 to S34 until all distance data in the contour point distance dataset are greater than the first distance threshold, in order to obtain an initial contour trajectory linked list; Step S36: Based on the initial contour trajectory linked list, perform overlapping data deletion processing on the contour point coordinate linked list to update the contour point coordinate linked list; Repeat steps S31 to S36 until the data in the contour point coordinate linked list is cleared, and sort and summarize the data in the initial contour trajectory linked list according to the generation order of the initial contour trajectory linked list to obtain the initial contour trajectory linked list set. Based on the boundaries of each sub-region, the initial contour trajectory linked list set is subjected to cross-region contour fitting point extraction processing to obtain the dataset of points to be verified. Based on the preset second distance threshold and the region arrangement data in the region matrix, the dataset of points to be verified is subjected to cross-regional neighbor point filtering to obtain a set of fitting points. The initial contour trajectory linked list set is merged across regions based on the set of fitted points to obtain the edge contour trajectory linked list set.
2. The method for extracting image edge contours according to claim 1, characterized in that, The step of performing edge detection and adaptive region segmentation processing on the received target image to obtain a region matrix includes: The received target image is converted to grayscale and denoised to obtain a standardized grayscale image; Edge detection processing is performed on the standardized grayscale image to obtain a contour grayscale image; The contour grayscale image is adaptively divided into regions based on a preset segmentation threshold to obtain the region matrix.
3. The method for extracting image edge contours according to claim 1, characterized in that, The step of performing multi-core parallel scanning and contour point filtering on each sub-region in the region matrix to obtain a linked list of contour point coordinates for each sub-region includes: According to the preset scanning order, each sub-region in the region matrix is subjected to multi-core parallel scanning and reading processing of pixel coordinates and pixel values to obtain the coordinate-pixel value mapping table corresponding to each sub-region. Based on the preset color threshold and the coordinate-pixel value mapping table, each sub-region is subjected to contour point filtering processing to obtain a set of contour point coordinates with pixel values greater than the color threshold. The contour point coordinate set is sorted according to the scanning order to obtain a linked list of contour point coordinates for each sub-region.
4. The method for extracting image edge contours according to claim 1, characterized in that, The step of performing cross-regional contour fitting point extraction processing on the initial contour trajectory linked list set according to the boundary of each sub-region to obtain the dataset of points to be verified includes: The initial contour trajectory linked list is processed by extracting the first and last data to obtain the contour end coordinate set; Distance calculation is performed based on the boundary of each sub-region and the coordinate set of the contour end to obtain the boundary distance dataset between the boundary of each sub-region and the contour end. Based on the preset boundary distance threshold and the boundary distance dataset, cross-region fitting point extraction processing is performed on the initial contour trajectory linked list set to obtain a dataset of points to be verified in each sub-region whose distance from the boundary is less than or equal to the boundary distance threshold.
5. The method for extracting image edge contours according to claim 1, characterized in that, The step of performing cross-regional neighbor point filtering on the dataset of points to be verified based on a preset second distance threshold and the region arrangement data in the region matrix to obtain a set of fitting points includes: Based on the region arrangement data in the region matrix, the dataset of points to be verified is processed by classifying adjacent region data to obtain the coordinate set of calibration points to be verified. Perform cross-regional distance calculation processing on the coordinate set of the calibration points to be verified to obtain the distance set to be verified; Based on the preset second distance threshold and the distance set to be verified, the coordinate set of the calibration points to be verified is subjected to cross-regional neighbor point filtering processing to obtain a set of fitting points in the distance set to be verified whose distance to be verified is less than or equal to the second distance threshold.
6. The method for extracting image edge contours according to claim 1, characterized in that, The method further includes: Step S71: Extract the first and last data of the edge contour trajectory linked list set to obtain the first and last coordinate sets of each edge contour. Step S72: Perform distance calculation and distance comparison processing based on the preset starting point coordinates and the set of first and last coordinates to obtain the coordinates of the first execution point with the smallest distance, and perform trajectory chain list data extraction processing on the edge contour trajectory chain list set based on the coordinates of the first execution point to obtain the first executed edge contour trajectory chain list in the edge contour trajectory chain list set, and use the first executed edge contour trajectory chain list as the currently executed edge contour trajectory chain list. Step S73: Perform distance calculation and distance comparison processing based on the coordinates of the last contour point in the currently executed edge contour trajectory chain list and the set of the first and last coordinates to obtain the coordinates of the second execution point with the smallest distance, and perform trajectory chain list data extraction processing on the edge contour trajectory chain list set based on the coordinates of the second execution point to obtain the second execution edge contour trajectory chain list in the edge contour trajectory chain list set. Step S74: Based on the edge contour trajectory linked list of the second execution and the edge contour trajectory linked list of the current execution, perform data deletion processing on the first and last coordinate sets to update the first and last coordinate sets, and use the edge contour trajectory linked list of the second execution as the edge contour trajectory linked list of the current execution. Repeat steps S73 to S74 until the data in the edge contour trajectory linked list is cleared, and sort the edge contour trajectory linked list according to the extraction order to obtain the image edge contour drawing instructions.
7. An apparatus for extracting image edge contours, applied to the image edge contour extraction method of claim 1, characterized in that, The device includes: The edge detection module is used to perform edge detection and adaptive region segmentation on the received target image to obtain a region matrix; The background removal module is used to perform multi-core parallel scanning and contour point filtering on each sub-region in the region matrix to obtain a linked list of contour point coordinates for each sub-region. The region contour module is used to perform single-region neighbor point filtering on the contour points of each sub-region according to a preset first distance threshold and the contour point coordinate chain list, so as to obtain an initial contour trajectory chain list set. The verification point module is used to perform cross-regional contour fitting point extraction processing on the initial contour trajectory linked list set according to the boundary of each sub-region to obtain the verification point dataset. The fitting verification module is used to perform cross-regional neighbor point filtering on the dataset of points to be verified based on a preset second distance threshold and the arrangement data of regions in the region matrix, so as to obtain a set of fitting points. The contour merging module is used to perform cross-region merging processing on the initial contour trajectory linked list set based on the fitted point combination set, so as to obtain the edge contour trajectory linked list set.
8. An electronic device, characterized in that, The electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the image edge contour extraction method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the image edge contour extraction method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Image stitching tampering detection method, electronic equipment and storage medium
CN116012398A
Defect detection method and system, electronic equipment and storage medium
CN117611566A