Connected component marking method and device, electronic equipment and storage medium
By using a run-length encoding-based connected component labeling method, the problems of low processing efficiency and high resource consumption in existing technologies are solved, and more efficient connected component labeling processing is achieved.
Patent Information
- Application Number
- CN202510947786.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-10
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2045-07-10
AI Technical Summary
Existing connected component labeling algorithms are inefficient and resource-intensive, including iterative algorithms, two-step traversal algorithms based on global equivalence tables, and two-step traversal algorithms based on local equivalence tables.
A connected component labeling method based on run-length encoding is adopted. By establishing a row run-length index table and a run-length encoding table, the run-length index table is scanned from top to bottom, and each row is processed. Equivalence relations are established through the run-length label list and the equivalence class table to update the connected component labels.
It improves the processing efficiency of connected component labeling, reduces resource consumption, and achieves more efficient connected component labeling.
Smart Images

Figure CN120431116B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing, and more specifically, to a method, apparatus, electronic device, and storage medium for marking connected components. Background Technology
[0002] Connected component labeling (CCL) is an important operation in image processing, primarily used to identify and segment independent regions in an image. It is based on the connectivity of pixels.
[0003] The purpose of connected component labeling is to transform an image from a pixel-level perspective to a region-level perspective, assigning the same labels to pixels within the same region to facilitate the calculation of region features for detection and recognition purposes. Connected component labeling is essentially a pixel grouping problem, based on pixel similarity (e.g., grayscale levels) and connectivity (spatial relationships).
[0004] Figure 1 Example of connected component labeling, such as Figure 1 As shown in (a), after a grayscale image is converted to a binary image (with 1 representing the foreground and 0 representing the background), the connected component labeling operation aggregates pixels labeled 1 into connected regions, which are called connected components, or blobs. Connected component labeling also applies to pixels labeled 0 or other labels; see [link to documentation] for details. Figure 1 (b) in the middle.
[0005] If the pixel is marked as 1 and Belonging to the same connected component Then there exists a class belonging to The pixel sequence marked as 1 ,in , , yes The neighboring pixels, Therefore, the definition of a connected component depends on the definition of its neighborhood. In Blob analysis, three different neighborhood definitions are commonly used: 8-neighborhood, 4-neighborhood, and 6-neighborhood.
[0006] Commonly used connected component labeling algorithms in related technologies include iterative algorithms, two-step traversal algorithms based on global equivalence tables, and two-step traversal algorithms based on local equivalence tables. However, using these algorithms for connected component labeling results in low processing efficiency and high resource consumption. Summary of the Invention
[0007] The main objective of this invention is to disclose a connected component marking method, apparatus, electronic device, and storage medium, so as to at least solve the problems of low processing efficiency and large resource consumption in related technologies that use iterative algorithms, or two-step algorithms based on global equivalence tables, or two-step algorithms based on local equivalence tables to perform connected component marking.
[0008] According to one aspect of the present invention, a method for marking connected components is provided.
[0009] The connected component labeling method provided by the present invention includes: for the acquired image data, establishing a corresponding row run-length index table and run-length encoding table; scanning the run-length index table from top to bottom and processing the run-length row by row; traversing the run-length encoding table, for the currently traversed run, determining whether the run-length is adjacent to the first run-length in the previous row; if the run-length is adjacent to the first run-length in the previous row, assigning the connected component label of the first run-length to the run-length; for other run-lengths in the previous row that are adjacent to the run-length after the first run-length, establishing an equivalence relation between the connected component label of the current run-length and the connected component labels of the other run-lengths, and updating the equivalence class table; traversing the run-length encoding table again, if the connected component label of the currently traversed run-length is 0, creating a new connected component label for the run-length; otherwise, updating the connected component label of the run-length with the label in the equivalence class table.
[0010] The above-mentioned process of establishing a corresponding row run-length index table for the acquired image data includes: establishing an index for the run-length of each row of the image data, wherein the row run-length index table includes the following parameters: the row number of each row, the number corresponding to the first run in each row, and the number corresponding to the last run in each row.
[0011] The above-mentioned process of establishing a corresponding run-length encoding table for the acquired image data includes: for the image data, encoding the corresponding run-length encoding table from left to right row by row, and for each run in each row, representing it with the row number, the left endpoint identifier, and the right endpoint identifier, wherein the run-length encoding table includes the following parameters: each run number, each run number, each run left endpoint identifier, each run right endpoint identifier, and the connected component label of each run.
[0012] The above-mentioned connected component marking method further includes: in the process of connected component marking, equivalence class processing is implemented through a run-length marker list and an equivalence class list, wherein the run-length marker list includes the following parameters: the connected component marker of the run, the equivalence class marker of the run, and the equivalence class marker link pointer, and the equivalence class list includes the following parameters: the equivalence class marker of the run, and the head pointer of the equivalence class marker link pointer.
[0013] The equivalence relation established between the connected component markers of this run and the connected component markers of the other runs includes one of the following:
[0014] When the equivalence class marker to which the connected component marker I1 of the run belongs and the equivalence class marker to which the connected component marker I2 of the other run belong are both 0, a new equivalence class is created, I1 and I2 are assigned to this equivalence class, I1 is used as the equivalence class marker, I1 is set as the head of the equivalence class marker linked list, and I2 is connected to the tail of I1.
[0015] If the equivalence class marker to which the connected component marker I1 of the run belongs is equal to and not 0 of the equivalence class marker to which the connected component marker I2 of the other run belongs, then no operation is performed.
[0016] When the equivalence class marker to which the connected component marker I1 of the run belongs is not 0, and the equivalence class marker to which the connected component marker I2 of the other run belongs is 0, I2 is merged into the equivalence class to which I1 belongs, I2 is set as the head of the equivalence class marker linked list, and connected to the head of the equivalence class to which I1 belongs.
[0017] When the equivalence class to which the connected component marker I1 of the run belongs is marked as 0, and the equivalence class to which the connected component marker I2 of the other run belongs is not marked as 0, I1 is merged into the equivalence class to which I2 belongs, I1 is set as the head of the equivalence class marker linked list, and connected to the head of the equivalence class to which I2 belongs.
[0018] When the equivalence class marker to which the connected component marker I1 belongs in the run is not 0 and is not equal to the equivalence class marker to which the connected component marker I2 belongs in the other run, update all the markers of the equivalence class to which I2 belongs to the equivalence class marker to which I1 belongs, and connect the head of the linked list of the equivalence class markers to which I1 belongs to the tail of the linked list of the equivalence class markers to which I2 belongs.
[0019] After traversing the run-length encoding table again, the process further includes: scanning the run-length index table from bottom to top and processing the run-length row by row; traversing the run-length encoding table, and for the currently traversed run-length, updating the connected component label of the run-length using the equivalence class label in the equivalence class table.
[0020] According to another aspect of the present invention, a connected component marking device is also provided.
[0021] The connected component marking device according to the present invention includes: a building module, configured to build a corresponding row run-length index table and run-length encoding table for the acquired image data; a first scanning module, configured to scan the run-length index table from top to bottom and process the run-length row by row; a first traversal module, configured to traverse the run-length encoding table and, for the currently traversed run-length, determine whether the run-length is adjacent to the first run-length in the previous row; a processing module, configured to, if the run-length is adjacent to the first run-length in the previous row, assign the connected component marking of the first run-length to the run-length, and for other run-lengths in the previous row that are adjacent to the run-length after the first run-length, establish an equivalence relation between the connected component marking of the current run-length and the connected component markings of the other run-lengths, and update the equivalence class table; and a second traversal module, configured to traverse the run-length encoding table again, and, if the connected component marking of the currently traversed run-length is 0, create a new connected component marking for the run-length, otherwise, update the connected component marking of the run-length with the markings in the equivalence class table.
[0022] The aforementioned connected component marking device further includes: a second scanning module, used to scan the run-length index table from bottom to top and process the run-length row by row; and a third traversal module, used to traverse the run-length encoding table and, for the currently traversed run-length, update the connected component marking of the run-length using the equivalence class marking in the equivalence class table.
[0023] According to another aspect of the present invention, an electronic device is provided.
[0024] An electronic device according to the present invention includes: a processor and a memory, the memory being used to store executable instructions of the processor, wherein the processor is configured to perform the connected component marking method described above by executing the executable instructions.
[0025] According to another aspect of the present invention, a computer-readable storage medium is provided.
[0026] The computer-readable storage medium according to the present invention includes a stored computer program, wherein, when the computer program is executed, it controls the device in which the computer-readable storage medium is located to perform the connected component marking method described in any of the preceding claims.
[0027] The connected component marking method, apparatus, electronic device, and storage medium provided by this invention, in the connected component (Blob) marking processing flow, the input of connected component marking is run-length encoded data oriented towards the image, and the output is run-length encoded data oriented towards the Blob. Compared with related technologies that use iterative algorithms, or two-pass algorithms based on global equivalence tables, or two-pass algorithms based on local equivalence tables to perform connected component marking, the connected component marking method based on run-length encoding provided by this invention is more efficient and consumes fewer resources. Attached Figure Description
[0028] To more clearly illustrate the embodiments of the present invention or the technical solutions in 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 merely exemplary, and those skilled in the art can derive other embodiments based on the provided drawings without creative effort.
[0029] Figure 1 This is a schematic diagram of connected component labeling in related technologies;
[0030] Figure 2 This is a flowchart of a connected component marking method according to an embodiment of the present invention;
[0031] Figure 3 This is a schematic diagram of the run-length encoding data structure according to an example of the present invention;
[0032] Figure 4 This is a schematic diagram of a binary image according to an example of the present invention;
[0033] Figure 5 It is based on Figure 4 The diagram shows the connected component equivalence class representation of the example shown.
[0034] Figure 6 This is a flowchart illustrating the top-down scanning operation in the connected component marking method according to a preferred embodiment of the present invention;
[0035] Figure 7 This is a flowchart illustrating the bottom-up scanning process in the connected component marking method according to a preferred embodiment of the present invention.
[0036] Figure 8 This is a structural block diagram of a connected component marking device according to an embodiment of the present invention;
[0037] Figure 9 This is a structural block diagram of a connected component marking device according to a preferred embodiment of the present invention;
[0038] Figure 10 This is a structural block diagram of an electronic device according to a preferred embodiment of the present invention. Detailed Implementation
[0039] The following specific embodiments illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. 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.
[0040] The specific implementation of the present invention will now be described in detail with reference to the accompanying drawings.
[0041] According to an embodiment of the present invention, a method for marking connected components is provided.
[0042] Figure 2 This is a flowchart of a connected component marking method according to an embodiment of the present invention. Figure 2 As shown, the connected component labeling method includes:
[0043] Step S201: For the acquired image data, establish the corresponding row run-length index table and run-length encoding table;
[0044] Step S202: Scan the run index table from top to bottom and process the run row by row;
[0045] Step S203: Traverse the run-length encoding table. For the currently traversed run, determine whether the run is adjacent to the first run in the previous row.
[0046] Step S204: If the current run is adjacent to the first run in the previous row, assign the connected component label of the first run to the run. For other runs in the previous row that are adjacent to the current run after the first run, establish an equivalence relation between the connected component label of the current run and the connected component labels of the other runs, and update the equivalence class table.
[0047] Step S205: Traverse the run-length encoding table again. If the connected component marker of the currently traversed run is 0, create a new connected component marker for the run. Otherwise, update the connected component marker of the run with the marker in the equivalence class table.
[0048] In related technologies, commonly used connected component labeling algorithms include iterative algorithms, two-step traversal algorithms based on global equivalence tables, and two-step traversal algorithms based on local equivalence tables. However, these connected component labeling algorithms are inefficient and resource-intensive. Figure 2 The connected component labeling method shown takes image-oriented run-length encoded data as input and outputs blob-oriented run-length encoded data as output. The run-length encoded connected component labeling method provided by this invention is more efficient and consumes fewer resources.
[0049] In the preferred implementation, the run-length index table is scanned row by row from top to bottom, and each run is processed row by row, with the run-length encoding table traversed twice. During the first traversal, if the currently traversed run is adjacent to a run in the previous row, the connected component label PERM_LABEL of the first adjacent run in the previous row is assigned to the current run label PERM_LABEL. For the second adjacent run in the previous row, and for all subsequent runs adjacent to the second adjacent run in the previous row, an equivalence relation is established between each adjacent run label PERM_LABEL and the current run label PERM_LABEL, and the equivalence relation table is updated. During the second traversal, if the current run label PERM_LABEL is zero, a new label is created; otherwise, the current label PERM_LABEL is updated using the labels from the equivalence class table.
[0050] In step S201 above, establishing a corresponding row run index table for the acquired image data may further include the following processing: establishing an index for the run of each row of the image data, wherein the row run index table includes the following parameters: the row number of each row, the number corresponding to the first run in each row, and the number corresponding to the last run in each row.
[0051] In step S201 above, the process of establishing a corresponding run-length encoding table for the acquired image data may further include the following: For the image data, a corresponding run-length encoding table is established by encoding each row from left to right. For each run in each row, it is represented by the row number, the left endpoint identifier, and the right endpoint identifier. The run-length encoding table includes the following parameters: each run number, each run number, each run left endpoint identifier, each run right endpoint identifier, and the connected component label of each run.
[0052] The following combination Figure 3 The preferred embodiments described above are further described below.
[0053] Figure 3 This is a schematic diagram of the run-length encoding data structure according to an example of the present invention. Figure 3 The binary image shown in (a) uses 1 to represent the foreground and 0 to represent the background. In the Blob analysis process, the input of the connected component labels is image-oriented run-length encoded data, which includes two tables: a row run-length index table (see [link to table] for details). Figure 3 (b) in the table and the run-length encoding table (see details) Figure 3 (c) in the middle.
[0054] The row run index table is used to create an index for each row of the input image. ROW_NUM is the row number, ROW_START is the number of the first run in the current row, and ROW_END is the number of the last run in the current row. For example, ... Figure 3 In (a) there are 5 rows, so the corresponding ROW_NUM in (b) are 1, 2, 3, 4 and 5 respectively; in the first row there are two runs, the first run is numbered 1 and the last run (i.e. the second run) is numbered 2; in the second row there are two runs, the first run is numbered 3 and the last run (i.e. the second run) is numbered 4; and so on, until the row run index table is completed.
[0055] The run-length encoding table encodes the input image row by row from left to right. Each run is represented by the row number ROW, the left endpoint identifier START_COL, and the right endpoint identifier END_COL; PERM_LABEL is the connected component label of the run; and RL_NUM is the run number. For example, Figure 3 In (a) of the diagram, there are 7 runs, with run numbers RL_NUM of 1, 2, 3, 4, 5, 6, and 7. The row number ROW for runs 1 and 2 is 1, for runs 3 and 4 it is 2, for runs 5 and 6 it is 3, and for run 7 it is 5. The left endpoint identifier START_COL for run 1 is 1 (which can be represented by the column number, i.e., column 1), and the right endpoint identifier END_COL for run 1 is 2 (which can be represented by the column number, i.e., column 2). PERM_LABEL is the connectivity label for the runs. The purpose of connectivity labeling is to label each run with PERM_LABEL so that all runs belonging to the same connectivity component have the same PERM_LABEL value. Figure 3 As shown in (c), the initial value can be 0.
[0056] During the connected component marking process, equivalence class processing is implemented through a run-length marker list and an equivalence class list. The run-length marker list includes the following parameters: the connected component marker of the run, the equivalence class marker of the run, and the equivalence class marker link pointer. The equivalence class list includes the following parameters: the equivalence class marker of the run, and the head pointer of the equivalence class marker link pointer.
[0057] The following combination Figure 4 and Figure 5 The preferred embodiments described above are further described below.
[0058] Figure 4 This is a schematic diagram of a binary image according to an example of the present invention. Figure 4The binary image shown has two rows, encoded from left to right. Each run is represented by the row number ROW, the left endpoint identifier START_COL, and the right endpoint identifier END_COL; PERM_LABEL is the connected component label of the run; RL_NUM is the run number. Figure 5 In (a), there are 4 runs, with corresponding run numbers RL_NUM of 1, 2, 3 and 4. The row number ROW corresponding to the 1st, 2nd and 3rd runs is 1, and the row number ROW corresponding to the 4th run is 2. The first run has a left endpoint identifier START_COL of 4, a right endpoint identifier END_COL of 10, and a connected component identifier PERM_LABEL of 1. The second run has a left endpoint identifier START_COL of 20, a right endpoint identifier END_COL of 24, and a connected component identifier PERM_LABEL of 2. The third run has a left endpoint identifier START_COL of 30, a right endpoint identifier END_COL of 38, and a connected component identifier PERM_LABEL of 3. The fourth run has a left endpoint identifier START_COL of 7, a right endpoint identifier END_COL of 35, and a connected component identifier PERM_LABEL of 1.
[0059] During the connected component marking process, equivalence class processing is implemented using a run-length label list and an equivalence class list. For example... Figure 4 The run-length marker list shown in (b) records the run-length markers and their corresponding equivalence class markers. PERM_LABEL is the connected component marker of the run; LABEL is the equivalence class marker of the run; NEXT is the link pointer of the equivalence class markers, which forms a linked list structure with all the markers in the equivalence class.
[0060] like Figure 4 The equivalence class table shown in (c) records the equivalence class markers. LABEL is the equivalence class marker; EQ_CLASS is the head pointer of the equivalence class marker linked list.
[0061] In step S104 above, establishing the equivalence relationship between the connected component markers of the run and the connected component markers of the other runs may include one of the following:
[0062] When the equivalence class marker to which the connected component marker I1 of the run belongs and the equivalence class marker to which the connected component marker I2 of the other run belong are both 0, a new equivalence class is created, I1 and I2 are assigned to this equivalence class, I1 is used as the equivalence class marker, I1 is set as the head of the equivalence class marker linked list, and I2 is connected to the tail of I1.
[0063] If the equivalence class marker to which the connected component marker I1 of the run belongs is equal to and not 0 of the equivalence class marker to which the connected component marker I2 of the other run belongs, then no operation is performed.
[0064] When the equivalence class marker to which the connected component marker I1 of the run belongs is not 0, and the equivalence class marker to which the connected component marker I2 of the other run belongs is 0, I2 is merged into the equivalence class to which I1 belongs, I2 is set as the head of the equivalence class marker linked list, and connected to the head of the equivalence class to which I1 belongs.
[0065] When the equivalence class to which the connected component marker I1 of the run belongs is marked as 0, and the equivalence class to which the connected component marker I2 of the other run belongs is not marked as 0, I1 is merged into the equivalence class to which I2 belongs, I1 is set as the head of the equivalence class marker linked list, and connected to the head of the equivalence class to which I2 belongs.
[0066] When the equivalence class marker to which the connected component marker I1 belongs in the run is not 0 and is not equal to the equivalence class marker to which the connected component marker I2 belongs in the other run, update all the markers of the equivalence class to which I2 belongs to the equivalence class marker to which I1 belongs, and connect the head of the linked list of the equivalence class markers to which I1 belongs to the tail of the linked list of the equivalence class markers to which I2 belongs.
[0067] In the preferred implementation process, the equivalence relationship between the two (connected) runs is established as described below, which can be found by referring to... Figure 4 and Figure 5 To understand, among which, Indicates tour The PERM_LABEL value, Indicates run marker The equivalence class label to which it belongs.
[0068] Input: Two (adjacent) run tokens and ;
[0069] Description: The following five scenarios can be handled separately:
[0070] Case 1: , Create a new equivalence class and put... and To be classified into this category, For equivalence class labeling, Set the head of the equivalence class marker list as the first element, and... Connected to The tail.
[0071] Case 2: No action is taken.
[0072] Case 3: , .Bundle merge into The equivalence class to which it belongs will Set the head of the equivalence class marker list as the first element and connect it to the first element. The head of the equivalence class to which it belongs.
[0073] Case 4: , .Bundle merge into The equivalence class to which it belongs will Set the head of the equivalence class marker list as the first element and connect it to the first element. The head of the equivalence class to which it belongs.
[0074] Case 5: , .Bundle The tags of all equivalence classes are updated to The equivalence class tag will The head of the equivalence class marker list is connected to the link that will The tail of the equivalence class marker list.
[0075] For example, such as Figure 4 As shown, run 4 (the run with RL-NUM = 4) is adjacent to run 1 (the run with RL-NUM = 1), run 2 (the run with RL-NUM = 2), and run 3 (the run with RL-NUM = 3), respectively. Figure 5 As shown in (a), the connectivity component marker PERM_LABEL for run 4 is 1, for run 2 it is 2, and for run 3 it is 3. Therefore, the markers of all equivalence classes to which runs 2 and 3 belong are updated to the marker 1 of the equivalence class to which run 4 belongs. The head of the linked list of markers for the equivalence class to which run 4 belongs is connected to the tail of the linked list of markers for the equivalence class to which run 2 belongs, and the head of the linked list of markers for the equivalence class to which run 4 belongs is connected to the tail of the linked list of markers for the equivalence class to which run 3 belongs. The equivalence class table is then updated. See [link to documentation] for details. Figure 5 (b) and (c) in the text.
[0076] After performing step S105, the following processing may also be included: scanning the run index table from bottom to top and processing the run row by row; traversing the run encoding table, and for the currently traversed run, updating the connected component label of the run using the equivalence class label in the equivalence class table.
[0077] In summary, the run-length encoding-based connected component labeling method provided by the applicant generally consists of two parts: first, scanning the run-length index table row by row from top to bottom, performing two traversals of the current row of runs; then, scanning the run-length index table row by row from bottom to top, performing one traversal of the current row of runs, and updating the connected component labels of runs in the run-length encoding table through the run-length label table and the equivalence class table.
[0078] The following combination Figure 6 and Figure 7 A preferred embodiment of the run-length-based connected component labeling method is further described.
[0079] Figure 6 This is a flowchart illustrating the top-down scanning operation in the connected component marking method according to a preferred embodiment of the present invention.
[0080] Step S601: Begin the top-down line-by-line scanning process.
[0081] Step S602: Traverse the run-length index table from top to bottom, processing each run row by row.
[0082] Step S603: Traverse the current row.
[0083] Step S604: Determine whether the current run and the previous run are adjacent. If yes, proceed to step S605; otherwise, proceed to step S606.
[0084] Step S605: If the current run's PERM_LABEL is zero, assign the same PERM_LABEL to the adjacent run; otherwise, establish an equivalence relation between the two run's PERM_LABELs and update the equivalence class table.
[0085] Step S606: Determine whether the current row has been traversed. If yes, proceed to step S607; otherwise, proceed to step S604.
[0086] Step S607: Traverse the current run again. If the current run's PERM_LABEL is zero, create a new PERM_LABEL; otherwise, update the current PERM_LABEL with the PERM_LABEL from the equivalence class table.
[0087] Step S608: Determine if all rows have been traversed. If yes, proceed to step S609. Otherwise, return to step S603.
[0088] Step S609: The top-down line-by-line scanning process is complete.
[0089] Figure 7 This is a flowchart illustrating the bottom-up scanning operation in the connected component marking method according to a preferred embodiment of the present invention. Figure 7As shown, the bottom-up scan operation in this connected component marking method includes the following processes:
[0090] Step S701: Begin the bottom-up line-by-line scanning process.
[0091] Step S702: Traverse the row run-length index table from bottom to top and process the run-length row by row.
[0092] Step S703: Traverse the current run and update the current run marker PERM_LABEL with the markers in the equivalence class table.
[0093] Step S704: The bottom-up line-by-line scanning process is complete.
[0094] When traversing the row run-length index table from bottom to top and processing the runs row by row, use an equivalence class table (see [link]). Figure 5 In (c) of the run-length encoding table, the connected component marker PERM_LABEL for run 3 is updated to 1, changing PERM_LABEL from 3 to 1. This is done using the equivalence class table (see [link to table]). Figure 5 In (c) of the run-length encoding table, the LABEL marker in the run-length encoding table is updated to the connected component marker PERM_LABEL of run 2, changing PERM_LABEL from 2 to 1.
[0095] According to an embodiment of the present invention, a connected component marking device is provided.
[0096] Figure 8 This is a structural block diagram of a connected component marking device according to an embodiment of the present invention. Figure 8 As shown, the connected component marking device includes: a building module 80, used to build a corresponding row run-length index table and run-length encoding table for the acquired image data; a first scanning module 82, used to scan the run-length index table from top to bottom and process the run-length row by row; a first traversal module 84, used to traverse the run-length encoding table, and for the currently traversed run, determine whether the run-length is adjacent to the first run-length in the previous row; a processing module 86, used to assign the connected component mark of the first run-length to the run-length if the run-length is adjacent to the first run-length in the previous row, and for other runs in the previous row that are adjacent to the run-length after the first run-length, establish an equivalence relationship between the connected component mark of the current run-length and the connected component marks of the other runs-length, and update the equivalence class table; and a second traversal module 88, used to traverse the run-length encoding table again, and if the connected component mark of the currently traversed run-length is 0, then create a new connected component mark for the run-length, otherwise, update the connected component mark of the run-length with the mark in the equivalence class table.
[0097] use Figure 8The connected component marking device shown takes image-oriented run-length encoded data as input and outputs blob-oriented run-length encoded data as output. Using the connected component marking device provided by this invention for connected component marking is more efficient and consumes fewer resources.
[0098] like Figure 9 As shown, the connected component marking device may further include: a second scanning module 90, used to scan the run index table from bottom to top and process the run row by row; and a third traversal module 92, used to traverse the run encoding table and update the connected component marking of the run with the equivalence class marking in the equivalence class table for the currently traversed run.
[0099] It should be noted that the aforementioned connected component marking device can be referred to in the corresponding document. Figures 1 to 7 The relevant descriptions and effects in the illustrated embodiments are for understanding purposes only and will not be repeated here.
[0100] According to embodiments of the present invention, an electronic device is also provided.
[0101] Figure 10 This is a structural block diagram of an electronic device according to a preferred embodiment of the present invention. Figure 10 As shown, the electronic device according to the present invention includes: a memory 100 and a processor 102, wherein the memory 100 is used to store computer execution instructions of the processor 102; and the processor 102 is configured to execute any of the above-described connected component marking methods by executing the executable instructions.
[0102] Processor 102 may be a central processing unit (CPU). Processor 102 may also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or combinations thereof.
[0103] The memory 100, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer-executable programs, and modules, such as the program instructions / modules corresponding to the connected component marking method in this embodiment of the invention. The processor executes various functional applications and data processing by running the non-transitory software programs, instructions, and modules stored in the memory.
[0104] The memory 100 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created by the processor, etc. Furthermore, the memory may include high-speed random access memory and non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, the memory 100 may optionally include memory remotely located relative to the processor, which can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0105] One or more of the above modules are stored in the memory 100, and when executed by the processor 102, they perform the following: Figures 1 to 7 The connected component labeling method in the illustrated embodiment.
[0106] For specific details regarding the aforementioned electronic devices, please refer to the relevant documentation. Figures 1 to 7 The relevant descriptions and effects in the illustrated embodiments are for understanding purposes only and will not be repeated here.
[0107] According to embodiments of the present invention, a computer-readable storage medium is also provided. A computer program is stored thereon, which, when executed by a processor, is implemented to perform the connected component labeling method provided in any of the preceding embodiments.
[0108] Computer-readable storage media can be memory, for example, volatile memory or non-volatile memory, or both. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced Synchronous DRAM (ESDRAM), Sync Link DRAM (SLDRAM), and Direct Rambus RAM (DRRAM).
[0109] In summary, using the embodiments provided by this invention, in the connected component (Blob) marking process, the input to connected component marking is run-length encoded data oriented towards the image, and the output is run-length encoded data oriented towards the Blob. Compared to related technologies that use iterative algorithms, or two-pass algorithms based on global equivalence tables, or two-pass algorithms based on local equivalence tables to perform connected component marking, the run-length encoding-based connected component marking method provided by this invention is more efficient and consumes fewer resources.
[0110] The above specific embodiments further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made on the basis of the technical solution of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for marking connected components, characterized in that, include: For the acquired image data, a corresponding row run-length index table and a run-length encoding table are established. Establishing the corresponding row run-length index table includes: creating an index for the run-lengths of each row of the image data. The row run-length index table includes the following parameters: row number, the number corresponding to the first run in each row, and the number corresponding to the last run in each row. Establishing the corresponding run-length encoding table includes: for the image data, encoding the run-lengths from left to right in a corresponding run-length encoding table. For each run in each row, it is represented by the row number corresponding to the run, the left endpoint identifier of the run, and the right endpoint identifier of the run. The run-length encoding table includes the following parameters: run number, row number corresponding to each run, left endpoint identifier of each run, right endpoint identifier of each run, and connected component label of each run. Scan the run-length index table from top to bottom and process the run-length row by row; Traverse the run-length encoding table. For the currently traversed run, determine whether the run is adjacent to the first run in the previous row. If the run is adjacent to the first run in the previous row, then the connected component tag of the first run is assigned to the run. For other runs in the previous row that are adjacent to the run after the first run, an equivalence relation is established between the connected component tags of the run and the connected component tags of the other runs, and the equivalence class table is updated. In the process of connected component tagging, equivalence class processing is implemented through the run tag list and the equivalence class table. The run tag list includes the following parameters: the connected component tag of the run, the equivalence class tag of the run, and the equivalence class tag link pointer. The equivalence class table includes the following parameters: the equivalence class tag of the run, and the head pointer of the equivalence class tag link pointer. The run-length encoding table is traversed again. If the connected component marker of the currently traversed run is 0, a new connected component marker is created for the run. Otherwise, the connected component marker of the run is updated with the marker in the equivalence class table.
2. The method according to claim 1, characterized in that, The equivalence relation established between the connected component markers of this run and the connected component markers of the other runs includes one of the following: When the equivalence class marker to which the connected component marker I1 of the run belongs and the equivalence class marker to which the connected component marker I2 of the other run belong are both 0, a new equivalence class is created, I1 and I2 are assigned to this equivalence class, I1 is used as the equivalence class marker, I1 is set as the head of the equivalence class marker linked list, and I2 is connected to the tail of I1. If the equivalence class marker to which the connected component marker I1 of the run belongs is equal to and not 0 of the equivalence class marker to which the connected component marker I2 of the other run belongs, then no operation is performed. When the equivalence class marker to which the connected component marker I1 of the run belongs is not 0, and the equivalence class marker to which the connected component marker I2 of the other run belongs is 0, I2 is merged into the equivalence class to which I1 belongs, I2 is set as the head of the equivalence class marker linked list, and connected to the head of the equivalence class to which I1 belongs. When the equivalence class to which the connected component marker I1 of the run belongs is marked as 0, and the equivalence class to which the connected component marker I2 of the other run belongs is not marked as 0, I1 is merged into the equivalence class to which I2 belongs, I1 is set as the head of the equivalence class marker linked list, and connected to the head of the equivalence class to which I2 belongs. When the equivalence class marker to which the connected component marker I1 belongs in the run is not 0 and is not equal to the equivalence class marker to which the connected component marker I2 belongs in the other run, update all the markers of the equivalence class to which I2 belongs to the equivalence class marker to which I1 belongs, and connect the head of the linked list of the equivalence class markers to which I1 belongs to the tail of the linked list of the equivalence class markers to which I2 belongs.
3. The method according to claim 1 or 2, characterized in that, After iterating through the run-length encoding table again, the process also includes: Scan the run-length index table from bottom to top and process the run-length row by row; Traverse the run-length encoding table. For the currently traversed run, update the connected component label of the run using the equivalence class label in the equivalence class table.
4. A connected component marking device, characterized in that, include: A module is established to create a corresponding row run-length index table and a run-length encoding table for the acquired image data. The creation of the corresponding row run-length index table includes: creating an index for the run-lengths of each row of the image data. The row run-length index table includes the following parameters: the row number of each row, the number corresponding to the first run in each row, and the number corresponding to the last run in each row. The creation of the corresponding run-length encoding table includes: for the image data, encoding the corresponding run-length encoding table from left to right for each row. For each run in each row, it is represented by the row number corresponding to the run, the left endpoint identifier of the run, and the right endpoint identifier of the run. The run-length encoding table includes the following parameters: each run number, the row number corresponding to each run, the left endpoint identifier of each run, the right endpoint identifier of each run, and the connected component label of each run. The first scanning module is used to scan the run-length index table from top to bottom and process the run-length row by row; The first traversal module is used to traverse the run-length encoding table. For the run currently traversed, it determines whether the run is adjacent to the first run in the previous row. The processing module is configured to assign the connected component label of the first run to the run when it is adjacent to the first run in the previous row; and to establish an equivalence relation between the connected component labels of the run and the connected component labels of the other runs after the first run in the previous row, and update the equivalence class table. During the connected component labeling process, equivalence class processing is implemented through a run label list and an equivalence class table. The run label list includes the following parameters: the connected component label of the run, the equivalence class label of the run, and the equivalence class label link pointer. The equivalence class table includes the following parameters: the equivalence class label of the run, and the head pointer of the equivalence class label link pointer. The second traversal module is used to traverse the run-length encoding table again. If the connected component marker of the currently traversed run is 0, a new connected component marker is created for the run; otherwise, the connected component marker of the run is updated with the marker in the equivalence class table.
5. The apparatus according to claim 4, characterized in that, Also includes: The second scanning module is used to scan the run-length index table from bottom to top and process the run-length row by row; The third traversal module is used to traverse the run-length encoding table. For the currently traversed run, the connected component label of the run is updated using the equivalence class label in the equivalence class table.
6. An electronic device, characterized in that, include: A processor and a memory, the memory being used to store executable instructions of the processor, wherein the processor is configured to perform the connected component marking method of any one of claims 1 to 3 by executing the executable instructions.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored computer program, wherein, when the computer program is executed, it controls the device on which the computer-readable storage medium is located to perform the connected component labeling method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Run length-based one-scan connected component labeling method and hardware structure
CN108876701A
Online real-time detection method for circular non-coding mark points
CN115861024A
