Image contour extraction method and system based on run-length connectivity analysis

By using a run-length connectivity analysis-based method, the input image is scanned line by line to generate run-length codes, a sub-contour data structure is established, connectivity states are distinguished, and sub-contours are created, grown, or connected. This solves the problems of incomplete contour extraction and high complexity in existing technologies, and achieves efficient and accurate contour extraction and nested relationship construction.

CN121458747APending Publication Date: 2026-02-03ZHENGZHOU RES INST OF MECHANICAL ENG CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511538947.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-27
Publication Date
2026-02-03

AI Technical Summary

Technical Problem

Existing contour extraction methods are prone to incomplete extraction of inner contours or loss of hierarchical relationships when dealing with complex topological structures. They have high computational complexity and are sensitive to noise, making them unsuitable for online processing. Traditional run-length extraction methods have biases in extracting concave structures in the horizontal direction and lack an efficient mechanism to describe the inclusion relationship between inner and outer contours.

Method used

A run-length connectivity analysis-based approach is used to scan the input image line by line to generate run-length codes, establish a sub-contour data structure, and distinguish six typical connectivity states by judging the connectivity relationship between adjacent run-length rows. Sub-contour creation, growth, or connection operations are then performed, the relationship between inner and outer contours is recorded, and the closed contour and topology are output.

Benefits of technology

It enables contour extraction and nesting relationship construction to be completed in a single scan, improving the completeness and accuracy of contour extraction, reducing computational complexity and memory usage, and is suitable for high-resolution images and real-time detection scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121458747A_ABST
    Figure CN121458747A_ABST
Patent Text Reader

Abstract

The invention provides an image contour extraction method and system based on run-length connectivity analysis, and relates to the technical field of image processing. The method comprises the following steps: scanning an image line by line to generate run length codes, constructing a data structure comprising the left side and the right side of a sub-contour, judging six communication states according to a communication relationship between adjacent run lengths, and executing the creation, growth and connection of the sub-contour according to the six communication states. And recording the inner and outer contour relation in the connection process, and finally outputting a complete closed contour and a topological hierarchical structure thereof at one time, thereby realizing synchronization of contour extraction and structure expression, and being efficiently suitable for complex image analysis.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing technology, and in particular to an image contour extraction method and system based on run-length connectivity analysis. Background Technology

[0002] Image contour extraction, a core task in computer vision and image processing, is a crucial prerequisite for tasks such as target recognition, defect detection, and image analysis, and can be widely applied in scenarios such as medical image analysis and industrial quality inspection. Contours, as boundary representations of target objects, effectively simplify image information, highlight key features, and provide foundational data for subsequent shape analysis, target matching, and classification. For example, in PCB bare board defect detection, the accuracy of contour extraction directly affects the recognition of defects such as short circuits, open circuits, and protrusions; in the field of autonomous driving, accurate extraction of road and vehicle contours is a crucial prerequisite for navigation and obstacle avoidance. Therefore, the efficiency, accuracy, and robustness of contour extraction methods directly determine the performance ceiling of the entire vision system.

[0003] Existing contour extraction methods are mainly divided into three categories: contour tracking, sliding window, and run-length encoding-based methods. Contour tracking connects pixels sequentially to form closed paths, which is simple to implement, but requires random access to the entire image data, resulting in high memory consumption and difficulty in handling complex topological structures, easily leading to incomplete inner contour extraction or loss of hierarchical relationships. Sliding window methods gradually construct contour segments through local neighborhood analysis, avoiding global storage, but require repeated access to pixels, resulting in high computational complexity and sensitivity to noise, easily producing broken or redundant edges. Run-length encoding-based methods reduce data volume by compressing the representation of consecutive pixels within a row, but most require two scans (marking connected components before extracting contours), which cannot meet the needs of online processing. Traditional run-length encoding methods have biases in contour extraction of horizontally concave structures and lack an efficient mechanism to describe the inclusion relationship between inner and outer contours.

[0004] Therefore, there is an urgent need for a contour extraction method that requires only one scan, supports complex structures, is parallelizable, and can accurately construct contour nesting relationships to meet the requirements of speed, accuracy, and robustness in industrial inspection. Summary of the Invention

[0005] To overcome the shortcomings of existing technologies, the purpose of this invention is to provide an image contour extraction method and system based on run-length connectivity analysis, which can simultaneously output complete closed contours and internal and external hierarchical relationships, achieving contour results in one step.

[0006] To achieve the above objectives, the present invention provides the following solution:

[0007] An image contour extraction method based on run-length connectivity analysis includes:

[0008] The input image is scanned line by line to generate run-length encoding;

[0009] Establish a sub-contour data structure; the sub-contour data structure includes a left side sub-contour and a right side sub-contour.

[0010] Based on the run-length encoding, the connectivity relationship between two adjacent rows of runs is determined, run-length connectivity state analysis is performed, and six typical connectivity states are distinguished.

[0011] Depending on the different connectivity states, sub-contour creation, growth, or connection operations are performed respectively;

[0012] During the connection process of the sub-contours, the relationship between the inner and outer contours of each sub-contour is determined and recorded;

[0013] Output all closed contours and topologies.

[0014] Preferably, the input image is scanned line by line to generate run-length encoding, including:

[0015] Represent the journey as ,in and This represents the starting and ending column positions of the run in the current row. This indicates the row position to which the journey belongs.

[0016] Preferably, the data structure of the sub-contour includes:

[0017] The left side of the sub-contour contains a pairing pointer p_paired, a step pointer p_next, a sub-contour pointer p_sub, a sibling contour pointer p_sub, a sub-contour type type, a left growth point list List_L, and a right growth point list List_R; the right side of the sub-contour contains a pairing pointer p_paired and a step pointer p_next.

[0018] Preferably, the connectivity determination of runs between adjacent rows adopts 4-connectivity, specifically including:

[0019] Same line Each sub-run on is represented as Record the previous line as the father's travel route. ;

[0020] Search sequentially within the parent runway for parent runways that have an overlap region with the child runway along the x-axis and whose overlap region length is greater than 0. Determine that the child run is connected to the corresponding parent run;

[0021] If no parent run that meets the conditions is found in the parent run, the run is considered disconnected.

[0022] The connectivity relationships of the parent run in the child run are retrieved and determined according to the symmetry rule in order to statistically distinguish six connectivity states.

[0023] Preferably, the connectivity states include: no parent, no child, initial, branching, converging, and terminating.

[0024] Preferably, the sub-contour creation, growth, or connection operations are performed according to different connectivity states, including:

[0025] Create child outlines corresponding to no parent and branching;

[0026] Initial and final sub-contour growth;

[0027] Childless and intersection correspond to child contour connections.

[0028] Preferably, initialization is performed before creating, growing, or connecting sub-contours according to different connectivity states, the initialization including:

[0029] Treat the image border as the outermost inner contour;

[0030] Create an activity linked list List_A and an activity outline pointer p_A to maintain the current activity sub-outline order relationship;

[0031] Add the right-hand C0R and left-hand C0L of C0 to List_A in sequence, and initialize p_A to point to C0R;

[0032] In this context, List_A and p_A are used to determine the position and order of insertion, update and connection during the creation, growth or connection of sub-contours based on the connectivity state.

[0033] Preferably, the following two connectivity states correspond to the creation of sub-contours:

[0034] When a child run without parent is encountered, a pair of child outlines are created temporarily as outer outlines and inserted after p_A. The left and right endpoints of the child run are added to the head of List_L and the tail of List_R on the left side of the corresponding child outline, respectively, and p_A is updated to point to the right side of the newly created child outline.

[0035] When a bifurcation occurs, create a pair of sub-contours that are temporarily inner contours and insert them into the position after p_A. Add the right endpoint of the previous sub-run and the left endpoint of the next sub-run to the head of List_L and the tail of List_R on the left side of the corresponding sub-contour, respectively, and update p_A to point to the right side of the newly created sub-contour.

[0036] Preferably, the following two connectivity states correspond to the connection of the sub-contour:

[0037] When a parent run with no children is encountered, the left and right sides of the child profile corresponding to the left and right endpoints of the parent run are connected;

[0038] When a connection occurs, the left side of the child contour extended from the left endpoint of the current parent run connects with the right side of the child contour extended from the right endpoint of the previous parent run, and a connection point is generated one unit inward from the corresponding position of the child run. The left and right connection points are added to the head of List_L and the tail of List_R on the left side of the corresponding child contour, respectively.

[0039] An image contour extraction system based on run-length connectivity analysis includes:

[0040] The run-length generation unit is used to scan the input image line by line to generate run-length codes;

[0041] A sub-contour construction unit is used to establish a sub-contour data structure; the sub-contour data structure includes a left side of the sub-contour and a right side of the sub-contour.

[0042] The connectivity determination unit is used to determine the connectivity relationship between two adjacent rows of runs based on the run-length encoding, perform run-length connectivity analysis, and distinguish six typical connectivity states: no parent, no child, initial, branching, converging, and terminating.

[0043] The contour update unit is used to perform sub-contour creation, growth, or connection operations according to different connectivity states.

[0044] The topology relationship recording unit is used to determine and record the relationship between the inner and outer contours of each sub-contour during the connection process of the sub-contours.

[0045] The contour output unit is used to output all closed contours and topologies.

[0046] According to specific embodiments provided by the present invention, the present invention discloses the following technical effects:

[0047] This invention achieves precise control over the contour generation, splitting, and closure processes by performing run-length encoding on the input image and classifying adjacent run-lengths based on their connectivity status (no parent, no child, initial, branching, intersection, termination). This effectively overcomes the shortcomings of traditional pixel tracking or edge detection methods, which are prone to contour breakage, closure failure, or omission of inner contours in complex concave boundaries and nested regions. This invention can completely extract both the outer contour and the internal hole contour, significantly improving the completeness and accuracy of contour extraction.

[0048] This invention, during the sub-contour creation, growth, and connection operations, simultaneously utilizes the pairing relationship between the left (CL) and right (CR) sides of the sub-contours to determine and record the inclusion relationship and inner / outer hierarchical structure between contours. Without relying on subsequent topology reconstruction or secondary traversal, it can output all closed contours and their topological relationships in one go. Compared to existing methods, this invention avoids the computational redundancy and misjudgment problems caused by the separation of contour extraction and contour hierarchy construction, significantly enhancing the method's structured expressive power and result usability.

[0049] This invention utilizes run-length encoding instead of pixel-by-pixel scanning and combines it with an active linked list to maintain the currently active sub-contours, significantly reducing the amount of image data processing and maintaining linear or near-linear time complexity for the contour extraction process, thereby improving overall operating efficiency and memory utilization. This invention enables fast and stable contour extraction in high-resolution images, industrial online inspection, medical image analysis, and real-time image processing scenarios, demonstrating high efficiency, scalability, and engineering application value. Attached Figure Description

[0050] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0051] Figure 1 A flowchart of the method provided in an embodiment of the present invention;

[0052] Figure 2 The diagram shows the run-length connectivity and contour of the embodiment of the present invention. Detailed Implementation

[0053] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0054] The purpose of this invention is to provide an image contour extraction method and system based on run-length connectivity analysis, which has a fast processing speed, low memory usage, and is suitable for real-time detection and large-scale image processing scenarios.

[0055] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0056] Figure 1 The method flowchart provided in the embodiments of the present invention is as follows: Figure 1 As shown, this invention provides an image contour extraction method based on run-length connectivity analysis, comprising:

[0057] Step 100: Scan the input image line by line to generate run-length encoding;

[0058] Step 200: Establish the sub-contour data structure; the sub-contour data structure includes the left side and the right side of the sub-contour;

[0059] Step 300: Determine the connectivity between two adjacent rows of runs based on the run-length encoding, perform run-length connectivity state analysis, and distinguish six typical connectivity states;

[0060] Step 400: Based on different connectivity states, perform sub-contour creation, growth, or connection operations respectively;

[0061] Step 500: During the connection process of the sub-contours, determine and record the relationship between the inner and outer contours of each sub-contour;

[0062] Step 600: Output all closed contours and topologies.

[0063] Preferably, the input image is scanned line by line to generate run-length encoding, including:

[0064] For a given row of image data, pixels with the same grayscale value arranged horizontally can be considered as consecutive symbols. Replacing these consecutive symbols with strings can significantly reduce data storage (for example, "333111188" can be encoded as "3214 82"). In this invention, the run is represented as (x1, x2, y), where x1 and x2 represent the starting and ending column positions of the run, and y represents the row position to which the run belongs.

[0065] Preferably, a sub-contour data structure is established, including a left side and a right side of the sub-contour, comprising:

[0066] The data structure for the left side of the sub-contour (CL) includes: a pairing pointer p_paired, pointing to the right side of its paired sub-contour; a step pointer p_next, pointing to the right side of the next adjacent sub-contour; a sub-contour pointer p_sub, pointing to the next level contour of the current contour; a sibling contour pointer p_sub, pointing to the same level contour of the current contour; a sub-contour type type, which is divided into outer sub-contour (type=1) and inner sub-contour (type=2); a left growth point linked list list_L, used to record the trajectory of the left side of the sub-contour extending along the left endpoint of the run; and a right growth point linked list list_R, used to record the trajectory of the right side of the sub-contour extending along the right endpoint of the run.

[0067] The data structure for the right side of a sub-contour (CR) includes: a pairing pointer p_paired, which points to the left side of the sub-contour it is paired with; and a step pointer p_next, which points to the left side of the next adjacent sub-contour.

[0068] Preferably, based on the run-length encoding, the connectivity between two adjacent rows of runs is determined, run-length connectivity state analysis is performed, and six typical connectivity states are distinguished, including:

[0069] (1) When a child run cannot find a parent run that is connected to it in the parent run, such a child run is called a "parentless" child run;

[0070] (2) When a parent run does not find a child run connected to it in the child run, such a parent run is called a "childless" parent run;

[0071] (3) If a child run finds a parent run connected to it for the first time in the parent run, and the parent run also finds a child run connected to it for the first time (and vice versa), this connection is called initial connection;

[0072] (4) If a parent run finds a child run connected to it for the nth time (n>1), it means that the parent run is connected to multiple child runs in succession, and it is called a forked connection.

[0073] (5) If a sub-run finds a parent run connected to it for the nth time (n>1), it means that the sub-run is connected to multiple parent runs in succession, and it is called convergent connectivity.

[0074] (6) When a pair of connected child runs and parent runs are no longer connected to any more runs in the same row, it is called a terminated connection.

[0075] In this invention, the "connectivity" of runs between adjacent rows is defined as "4-connectivity", that is, when the overlap of two runs in the x-axis direction of two adjacent rows is greater than 0, the two runs are said to be in a connected state.

[0076] Preferably, the sub-contour creation, growth, or connection operations are performed according to the different connectivity states, including:

[0077] Consider the image border as an outermost inner contour, denoted as C0. Create a dynamic structure "active linked list List_A + active contour pointer p_A", with the initial contents of List_A being C0R and C0L, and p_A initialized to point to C0R.

[0078] The following two connectivity states correspond to the creation of sub-contours:

[0079] When a child run with no parent appears, a pair of child outlines, temporarily serving as outer outlines, are created and inserted after the active outline pointer p_A. The left and right endpoints of the child run are added to the head of List_L and the tail of List_R on the left side of the newly created child outline, respectively. Finally, p_A is updated to point to the right side of the newly created child outline. Figure 2 As shown, in line 1, a child run without a parent causes the creation of C1; in line 4, a child run without a parent causes the creation of C3; and in line 6, a child run without a parent causes the creation of C4.

[0080] When a forked connection occurs, a pair of sub-contours, temporarily designated as inner contours, is created and inserted after the active contour pointer p_A. The right endpoint of the previous sub-run and the left endpoint of the next sub-run are added to the head of List_L and the tail of List_R on the left side of the newly created sub-contour, respectively. Finally, p_A is updated to point to the right side of the newly created sub-contour. Figure 2 As shown, in line 2, the bifurcation connection causes the creation of C2; in line 7, the bifurcation connection causes the creation of C5.

[0081] The following two connectivity states correspond to the growth of the sub-contour:

[0082] When initial connectivity occurs, the left endpoint of the currently connected subrun is added to the head of the corresponding sub-contour's left-hand linked list List_L, while p_A remains unchanged; For example... Figure 2 As shown, rows 2 through 8 show that initial connectivity causes the growth of C1.

[0083] When a connection termination occurs, the right side of the sub-contour grows along the right endpoint of the sub-run. The left side of the currently paired sub-contour is found using the pairing pointer p_paired on the right side of the sub-contour. Then, the right endpoint of the sub-run is added to the tail of the right growth point linked list List_R of the found left side of the sub-contour, and p_A is updated to point to the second position after itself (p_A-> next -> next). For example... Figure 2 As shown, lines 2 through 8 terminate the connection, causing C1 to grow.

[0084] The following two connectivity states correspond to the connection of sub-contours:

[0085] When a parent run with no children appears, the left and right sides of the child contours corresponding to the left and right endpoints of that parent run are connected; for example... Figure 2 As shown, in line 5, the parent run with "no child" causes a connection between C3L and C3R; in line 9, the parent run with "no child" causes a connection between C1L and C5L; in line 9, the parent run with "no child" causes a connection between C1R and C5R.

[0086] When a connection occurs, the left side of the child contour extending from the left endpoint of the current parent run will be connected to the right side of the child contour extending from the right endpoint of the previous parent run. Simultaneously, an intersection will occur at the corresponding position in the child run (one unit inward). The left and right intersection points will be added to the head of the List_L linked list and the tail of the List_R linked list on the left side of the corresponding child contour, respectively. For example... Figure 2 As shown, in row 8, the confluence connection causes a connection between C2L and C4L; in row 8, the confluence connection causes a connection between C2R and C4R.

[0087] Preferably, during the sub-contour connection process, determining and recording the inner and outer contour relationships of each sub-contour includes:

[0088] When a connection occurs in a parent run with no children, let the left and right sides of the connected child contours be CLx and CRY, respectively. The relationship between the inner and outer contours can be divided into four cases:

[0089] When the paired pointers p_paired of CLx and CRy point to each other, corresponding to case 1: At this time, the type value of CLx is 1, and CLx and CRy form a closed outer contour. Let M be the left side of the sub-contour pointed to by p_A->p_paired. At this time, the relationship between the inner and outer contours of CLx and M is determined according to the value of M.type. When the type value is 1, CLx is a sibling contour of M, and when the type value is 0, CLx and M are sub-contours.

[0090] When the paired pointers p_paired of CLx and CRY do not point to each other, the following operations are performed first: CLx.p_paired->p_paired = CRY.p_paired; CRy.p_paired->p_paired = CLx.p_paired. The type values ​​of CLx and CRY.p_paired are compared. If they are equal, it corresponds to case 2: This indicates that two different inner sub-contours are connected, and the inner contour and sibling contour contained in CLx also become the inner contour and sibling contour of CRY.p_paired. If the type values ​​of CLx and CRY.p_paired are different and CLx.type = 0, it corresponds to case 3: In this case, the inner contour of CLx becomes the sibling contour of CRY.p_paired, and the sibling contour of CLx becomes the inner contour of CRY.p_paired. If the type values ​​of CLx and CRY.p_paired are different and CLx.type=1, then it corresponds to case 4: In this case, the inner contour of CLx will become the inner contour of CRY.p_paired, and the sibling contour of CLx will also become the sibling contour of CRY.p_paired.

[0091] When a connection occurs at a junction, let the left and right sides of the connected sub-contours be CLx and CRY, respectively. The relationship between the inner and outer contours can also be divided into four cases:

[0092] When the paired pointers p_paired of CLx and CRy point to each other, corresponding to case 1: At this time, the type value of CLx is 0, and CLx and CRy form a closed inner contour. Let M be the left side of the sub-contour pointed to by p_A->p_paired. At this time, the relationship between the inner and outer contours of CLx and M is determined according to the value of M.type. When the type value is 1, CLx is the inner contour of M. When the type value is 0, CLx and M are contours of the same level.

[0093] When the paired pointers p_paired of CLx and CRY do not point to each other, the following operations are performed first: CLx.p_paired->p_paired = CRY.p_paired; CRy.p_paired->p_paired = CLx.p_paired. The type values ​​of CLx and CRY.p_paired are compared. If they are equal, it corresponds to case 2: This indicates that two different outer child contours are connected, and the inner contour and sibling contour contained in CLx also become the inner contour and sibling contour of CRY.p_paired. If the type values ​​of CLx and CRY.p_paired are different and CLx.type = 1, it corresponds to case 3: In this case, the inner contour of CLx becomes the sibling contour of CRY.p_paired, and the sibling contour of CLx becomes the inner contour of CRY.p_paired. If the type values ​​of CLx and CRY.p_paired are different and CLx.type=0, then the corresponding case 4 is: at this time, the inner contour of CLx will become the inner contour of CRY.p_paired, and the sibling contour of CLx will also become the sibling contour of CRY.p_paired.

[0094] Ultimately, all closed contours of the image and their topology can be output.

[0095] As an optional implementation, as shown in Table 1, when this invention is used for contour extraction of PCB bare board images, the input is a binary conductor segmentation image obtained from the upstream detection stage. Step 100 involves scanning the image line by line to generate run-length encoding. This represents a continuous pixel segment within a row; based on the run-length encoding, connectivity between adjacent rows is determined, and processing is driven by six states: "no parent, no child, initial, fork, intersection, and termination"; in step 400, a sub-contour is created when there is no parent or fork, growth is advanced when there is initial or termination, and connection is completed when there is no child or intersection; in step 500, the inner and outer membership of each contour is marked by using the pairing of the left CL and right CR of the sub-contour and the order relationship of the active linked list; finally, in step 600, the closed contour and topology are output to distinguish the outer contour of the trace from the inner contour of the via and hole, and to locate the suspected short circuit and open circuit areas as abnormal contours for downstream judgment.

[0096] Table 1. Correspondence between processing steps and data structures in the image contour extraction example.

[0097] As another optional implementation, when this invention is used for the appearance quality inspection of metal stampings or machined parts, the input is a binary boundary map of the part area. Steps 100 to 300 generate run-length encoding and complete adjacent row connectivity determination and state analysis. In step 400, the part's outer contour and perforation contour are created, grown, and connected according to six states. In step 500, the hierarchical relationship between the outer contour and holes is recorded through the pairing relationship of CL and CR and the position of the active linked list. In step 600, all closed contours and topologies are output to achieve extraction of external dimensions, measurement of hole diameter and hole spacing, and comparison of abnormal contours at burrs or notches, thereby supporting online quality inspection and factory verification.

[0098] As another optional implementation, when the present invention is used for extracting organ or lesion contours from medical image slices, the input is a binary mask obtained from upstream segmentation. Step 100 obtains run-length encoding; step 300 determines connectivity between parent and child rows and categorizes them into six connectivity states; step 400 completes the creation, growth, and connection of sub-contours of the target region; step 500 records the inclusion relationships of internal contours such as cavities and necrotic areas in real time based on CL / CR pairing; and finally, step 600 outputs closed contours and topology for morphological index extraction and subsequent report generation, avoiding the time overhead caused by multiple traversals and topology reconstruction in traditional methods.

[0099] As another optional implementation, when extracting lane lines and curb contours in road scenes, the input of this invention is a binary boundary map obtained by the front-end perception module. Run-length encoding is formed and connectivity analysis is completed through steps 100 to 300; based on the state-driven mechanism in step 400, sub-contours of each road surface element are continuously created, grown, and connected; in step 500, the inner and outer layers of structures such as medians and road islands are recorded through CL / CR pairing and active linked lists; in step 600, a set of closed contours and topology is output at once, providing stable geometric boundary input for path planning and the generation of passable areas, and meeting real-time processing requirements.

[0100] Corresponding to the above method, this embodiment also provides an image contour extraction system based on run-length connectivity analysis, including:

[0101] The run-length generation unit is used to scan the input image line by line to generate run-length codes;

[0102] A sub-contour construction unit is used to establish a sub-contour data structure; the sub-contour data structure includes a left side of the sub-contour and a right side of the sub-contour.

[0103] The connectivity determination unit is used to determine the connectivity relationship between two adjacent rows of runs based on the run-length encoding, perform run-length connectivity analysis, and distinguish six typical connectivity states: no parent, no child, initial, branching, converging, and terminating.

[0104] The contour update unit is used to perform sub-contour creation, growth, or connection operations according to different connectivity states.

[0105] The topology relationship recording unit is used to determine and record the relationship between the inner and outer contours of each sub-contour during the connection process of the sub-contours.

[0106] The contour output unit is used to output all closed contours and topologies.

[0107] The beneficial effects of this invention are as follows:

[0108] (1) The present invention proposes an image contour extraction method based on run-length connectivity analysis. By performing run-length encoding, run-length connectivity analysis, creation, generation and connection of sub-contours on the input image, the contour extraction task can be completed in only one scan and the nested contour relationship can be constructed.

[0109] (2) The run-length connectivity analysis method proposed in this invention can effectively guide the creation, generation and connection of sub-contours during the scanning process by distinguishing six typical connectivity states.

[0110] (3) The sub-contour connection method proposed in this invention distinguishes four different connection states based on two different connectivity states, thereby realizing the determination of the topological structure between contours while extracting the contours.

[0111] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the systems disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple; relevant parts can be referred to the method section.

[0112] This document uses specific examples to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. Furthermore, those skilled in the art will recognize that, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. An image contour extraction method based on run-length connectivity analysis, characterized in that, include: The input image is scanned line by line to generate run-length encoding; Establish a sub-contour data structure; the sub-contour data structure includes a left side sub-contour and a right side sub-contour. Based on the run-length encoding, the connectivity relationship between two adjacent rows of runs is determined, run-length connectivity state analysis is performed, and six typical connectivity states are distinguished. Depending on the different connectivity states, sub-contour creation, growth, or connection operations are performed respectively; During the connection process of the sub-contours, the relationship between the inner and outer contours of each sub-contour is determined and recorded; Output all closed contours and topologies.

2. The image contour extraction method based on run-length connectivity analysis according to claim 1, characterized in that, The input image is scanned line by line to generate run-length encoding, including: Represent the journey as ,in and This represents the starting and ending column positions of the run in the current row. This indicates the row position to which the journey belongs.

3. The image contour extraction method based on run-length connectivity analysis according to claim 1, characterized in that, The data structure of the sub-contour includes: The left side of the sub-contour contains a pairing pointer p_paired, a step pointer p_next, a sub-contour pointer p_sub, a sibling contour pointer p_sub, a sub-contour type type, a left growth point list List_L, and a right growth point list List_R; the right side of the sub-contour contains a pairing pointer p_paired and a step pointer p_next.

4. The image contour extraction method based on run-length connectivity analysis according to claim 2, characterized in that, The connectivity determination for runs between two adjacent rows uses 4-connectivity, specifically including: Same line Each sub-run on is represented as Record the previous line as the father's travel route. ; Search sequentially within the parent runway for parent runways that have an overlap region with the child runway along the x-axis and whose overlap region length is greater than 0. Determine that the child run is connected to the corresponding parent run; If no parent run that meets the conditions is found in the parent run, the run is considered disconnected. The connectivity relationships of the parent run in the child run are retrieved and determined according to the symmetry rule in order to statistically distinguish six connectivity states.

5. The image contour extraction method based on run-length connectivity analysis according to claim 1, characterized in that, The connectivity states include: no parent, no child, initial, branching, converging, and terminated.

6. The image contour extraction method based on run-length connectivity analysis according to claim 5, characterized in that, Depending on the different connectivity states, sub-contour creation, growth, or connection operations are performed, including: Create child outlines corresponding to no parent and branching; Initial and final sub-contour growth; Childless and intersection correspond to child contour connections.

7. The image contour extraction method based on run-length connectivity analysis according to claim 1, characterized in that, Initialization is performed before creating, growing, or connecting sub-contours according to different connectivity states. This initialization includes: Treat the image border as the outermost inner contour; Create an activity linked list List_A and an activity outline pointer p_A to maintain the current activity sub-outline order relationship; Add the right-hand C0R and left-hand C0L of C0 to List_A in sequence, and initialize p_A to point to C0R; In this context, List_A and p_A are used to determine the position and order of insertion, update and connection during the creation, growth or connection of sub-contours based on the connectivity state.

8. The image contour extraction method based on run-length connectivity analysis according to claim 7, characterized in that, The following two connectivity states correspond to the creation of sub-contours: When a child run without parent is encountered, a pair of child outlines are created temporarily as outer outlines and inserted after p_A. The left and right endpoints of the child run are added to the head of List_L and the tail of List_R on the left side of the corresponding child outline, respectively, and p_A is updated to point to the right side of the newly created child outline. When a bifurcation occurs, create a pair of sub-contours that are temporarily inner contours and insert them into the position after p_A. Add the right endpoint of the previous sub-run and the left endpoint of the next sub-run to the head of List_L and the tail of List_R on the left side of the corresponding sub-contour, respectively, and update p_A to point to the right side of the newly created sub-contour.

9. The image contour extraction method based on run-length connectivity analysis according to claim 7, characterized in that, The following two connectivity states correspond to the connection of sub-contours: When a parent run with no children is encountered, the left and right sides of the child profile corresponding to the left and right endpoints of the parent run are connected; When a connection occurs, the left side of the child contour extended from the left endpoint of the current parent run connects with the right side of the child contour extended from the right endpoint of the previous parent run, and a connection point is generated one unit inward from the corresponding position of the child run. The left and right connection points are added to the head of List_L and the tail of List_R on the left side of the corresponding child contour, respectively.

10. An image contour extraction system based on run-length connectivity analysis, characterized in that, include: The run-length generation unit is used to scan the input image line by line to generate run-length codes; A sub-contour construction unit is used to establish a sub-contour data structure; the sub-contour data structure includes a left side of the sub-contour and a right side of the sub-contour. The connectivity determination unit is used to determine the connectivity relationship between two adjacent rows of runs based on the run-length encoding, perform run-length connectivity analysis, and distinguish six typical connectivity states: no parent, no child, initial, branching, converging, and terminating. The contour update unit is used to perform sub-contour creation, growth, or connection operations according to different connectivity states. The topology relationship recording unit is used to determine and record the relationship between the inner and outer contours of each sub-contour during the connection process of the sub-contours. The contour output unit is used to output all closed contours and topologies.