A connected domain marking method, device, equipment and medium

By performing local bitmasking on multiple target marker values ​​that have equivalence relationships in the equivalence list, the local equivalence marker values ​​of the target pixels can be quickly determined and synchronized, solving the problem of low update efficiency of the equivalence list and improving the overall performance of connected component marking.

CN120411155BActive Publication Date: 2026-08-04HUNAN GOKE MICROELECTRONICS CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HUNAN GOKE MICROELECTRONICS CO LTD
Filing Date
2025-06-06
Publication Date
2026-08-04

AI Technical Summary

Technical Problem

In existing technologies, the updating efficiency of equivalence tables is low, which affects the overall performance of connected component labeling.

Method used

By performing local bitmasking on multiple target marker values ​​that have equivalence relationships in the equivalence list, the local equivalence marker values ​​of the target pixels can be quickly determined and synchronized to the equivalence list, thereby improving the update efficiency of the equivalence list.

Benefits of technology

This improves the efficiency of updating the equivalence table, thereby enhancing the overall performance of connected component labeling.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120411155B_ABST
    Figure CN120411155B_ABST
Patent Text Reader

Abstract

The application discloses a connected domain marking method and device, equipment and medium, and relates to the technical field of image processing. In the process of pixel-by-pixel scanning, local bit masks are performed on multiple target marking values in an equivalence table that have an equivalence relationship in an equivalence list to obtain a local equivalence marking value of a scanned target pixel, and the target marking value is a neighborhood pixel marking value of the target pixel. The local equivalence marking value of the target pixel is synchronized to the equivalence table. By setting the equivalence list, the application can perform local bit masks on all multiple target marking values in the equivalence table that have an equivalence relationship, thereby quickly obtaining the local equivalence marking value of the target pixel, and then synchronizing to the equivalence table, thereby improving the updating efficiency of the equivalence table and further improving the overall performance.
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 a method, apparatus, device, and medium for connecting component labeling. Background Technology

[0002] Connected component labeling is a crucial method in binary image analysis. It involves labeling each white pixel (non-zero pixel) in a binary image. White pixels belonging to the same connected component have the same label, while white pixels in different connected components have different labels, thus allowing the extraction of each connected component from the image. Connected component extraction can provide accurate localization for feature extraction in science fiction films, and can also be used for image recognition and target information extraction in the security industry, and even for acquiring parameters such as the position, phase, angle, and velocity of moving targets in radar systems.

[0003] Currently, the Two-Pass method is commonly used for connected component labeling. This method mainly consists of a first scan and a second scan. The first scan primarily involves updating pixel labels and the equivalence table. The updated equivalence table is then used in the second scan to rewrite the pixel labels. It is evident that the update speed of the equivalence table reflects the performance of connected component labeling. However, the current equivalence table can only access one address space at a time, resulting in low update efficiency.

[0004] In summary, improving the update efficiency of the equivalence table to enhance overall performance is a problem that needs to be solved. Summary of the Invention

[0005] In view of this, the purpose of this invention is to provide a method, apparatus, device, and medium for marking connected components, which can improve the update efficiency of equivalence tables, thereby improving overall performance. The specific solution is as follows:

[0006] Firstly, this application discloses a method for labeling connected components, including:

[0007] During the pixel-by-pixel scanning process, a local bitmask is performed on multiple target marker values ​​that have equivalence relationships in the equivalence list to obtain the local equivalence marker value of the scanned target pixel. The target marker value is the neighboring pixel marker value of the target pixel.

[0008] The local equivalence tag value of the target pixel is synchronized to the equivalence table.

[0009] Optionally, the step of performing local bitmasking on multiple target tag values ​​that have equivalence relationships in the equivalence list includes:

[0010] Read the equivalent linked list based on the multiple target tag values ​​to obtain the equivalent mask corresponding to each of the multiple target tag values;

[0011] The equivalent masks corresponding to the multiple target marker values ​​are merged to obtain a merged mask;

[0012] Determine the local equivalence marker value of the target pixel indicated by the merge mask.

[0013] Optionally, after merging the equivalent masks corresponding to the multiple target marker values ​​to obtain the merged mask, the method further includes:

[0014] The equivalent mask with the lowest number of mask bits among the equivalent masks corresponding to the multiple target mark values ​​is updated to the merged mask.

[0015] Optionally, synchronizing the local equivalence tag value of the target pixel to the equivalence table includes:

[0016] Replace multiple target marker values ​​in the equivalence table with the local equivalence marker values ​​of the target pixels.

[0017] Optionally, the pixel-by-pixel scanning includes:

[0018] Read the row pixels before the interrupt bit stored in the cache unit, and perform pixel-by-pixel scanning with the row pixels as a reference. The interrupt bit is the position of the target pixel being scanned when there is no free flag value in the connected component information table.

[0019] Optionally, when no free marker value exists in the connected component information table, the method further includes:

[0020] The pixel-by-pixel scan is interrupted, and the pixel marker values ​​of the connected components in the binary image are rewritten according to the latest synchronized equivalence table before reaching the interruption bit. During the rewriting process, the row pixels before the interruption bit are cached to the cache unit, so that after the caching is completed, the step of reading the row pixels before the interruption bit stored in the cache unit is executed.

[0021] Optionally, during the pixel-by-pixel scanning process, the method further includes:

[0022] If no free flag value exists in the connected component information table, target connected components below the target area threshold in the connected component information table are filtered out, and the flag value corresponding to the target connected component in the connected component information table is cached as a new free flag value in the address cache.

[0023] During pixel-by-pixel scanning, a new free marker value is read from the address cache, and the currently scanned pixel is marked using the new free marker value to form a new target connected component. The connected component information table is then updated based on the new target connected component.

[0024] Optionally, the step of filtering out target connected components below the target area threshold in the connected component information table includes:

[0025] When there is no target connected component below the target area threshold in the connected component information table, several growth steps are added to the target area threshold to form multiple candidate area thresholds.

[0026] Determine whether there exists a target connected component in the connected component information table that is below any candidate area threshold;

[0027] If so, the minimum candidate area threshold when the judgment condition is met will be used as the target area threshold, and the target connected components below the minimum candidate area threshold in the connected component information table will be deleted.

[0028] If not, continue to accumulate the growth step size for multiple candidate area thresholds.

[0029] Secondly, this application discloses a connected component marking device, comprising:

[0030] The masking module is used to perform local bitmasking on multiple target marker values ​​that have equivalence relationships in the equivalence list during the pixel-by-pixel scanning process, so as to obtain the local equivalence marker value of the scanned target pixel, wherein the target marker value is the neighboring pixel marker value of the target pixel;

[0031] A synchronization module is used to synchronize the local equivalence tag value of the target pixel to the equivalence table.

[0032] Thirdly, this application discloses an electronic device, including:

[0033] Memory, used to store computer programs;

[0034] A processor for executing the computer program to implement the steps of the aforementioned disclosed connected component labeling method.

[0035] Fourthly, this application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the steps of the aforementioned disclosed connected component labeling method.

[0036] Fifthly, this application discloses a computer program product, including a computer program that, when executed by a processor, implements the steps of the aforementioned disclosed connected component labeling method.

[0037] As can be seen, during the pixel-by-pixel scanning process, local bitmasking is performed on multiple target marker values ​​that have equivalence relationships in the equivalence list to obtain the local equivalence marker value of the scanned target pixel. The target marker value is the neighboring pixel marker value of the target pixel. The local equivalence marker value of the target pixel is then synchronized to the equivalence list.

[0038] Beneficial Effects: This application discloses an equivalence linked list. During pixel-by-pixel scanning, if the neighboring pixel marker values ​​of the currently scanned target pixel are determined to have an equivalence relationship according to the equivalence list, then these multiple target marker values ​​with equivalence relationships are locally bitmasked in the equivalence linked list to quickly obtain the local equivalence marker value of the target pixel. This local equivalence marker value is then synchronized to the equivalence list. In other words, by setting up an equivalence linked list, this application can quickly determine the local equivalence marker value of the target pixel based on all target marker values ​​with equivalence relationships in the equivalence list, and then synchronize it to the equivalence list, thereby improving the update efficiency of the equivalence list and further enhancing overall performance. Attached Figure Description

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

[0040] Figure 1 Here is a flowchart of a connected component labeling method disclosed in this application;

[0041] Figure 2 This is a schematic diagram illustrating the initialization of an equivalence table disclosed in this application;

[0042] Figure 3 This is a schematic diagram illustrating the initialization of an equivalent linked list disclosed in this application;

[0043] Figure 4 This is a schematic diagram illustrating the initialization of a connected component information table as disclosed in this application;

[0044] Figure 5 This is a schematic diagram illustrating the update process of an equivalent linked list disclosed in this application;

[0045] Figure 6 This is a schematic diagram illustrating the equivalent of a four-connected domain mode disclosed in this application;

[0046] Figure 7 This is a schematic diagram illustrating the equivalent of an eight-connected domain model disclosed in this application;

[0047] Figure 8 This is a schematic diagram of a connected domain marking device disclosed in this application;

[0048] Figure 9 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation

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

[0050] This application discloses a connected component labeling method, apparatus, device, and medium. By setting up an equivalence linked list, this application can perform local bitmasking on multiple target label values ​​that have equivalence relationships in the equivalence list at the same time, thereby quickly obtaining the local equivalence label value of the currently scanned target pixel, and then synchronizing it to the equivalence list, thereby improving the update efficiency of the equivalence list and further improving the overall performance.

[0051] See Figure 1 As shown in the figure, this application discloses a connected component labeling method, which includes:

[0052] Step S11: During the pixel-by-pixel scanning process, a local bitmask is performed on multiple target marker values ​​that have equivalence relationships in the equivalence list to obtain the local equivalence marker value of the scanned target pixel. The target marker value is the neighboring pixel marker value of the target pixel.

[0053] First, it should be noted that when labeling connected components in a binary image, each pixel is scanned row by row from left to right to label the non-zero pixels in the binary image.

[0054] The target pixel mentioned in this article refers to the currently scanned pixel involved in the processing of the equivalence table or equivalence linked list during the pixel-by-pixel scanning process. This target pixel can be a non-zero pixel.

[0055] It should be noted that during the scanning process, if all neighboring pixels of the currently scanned target pixel are zero-value pixels, a new label value needs to be assigned to the target pixel. If the neighboring pixels of the target pixel are non-zero pixels and have already been labeled, the corresponding neighboring pixel label value is used as the address to read the values ​​recorded in the equivalence table, and it is determined whether the values ​​read from the equivalence table are equal. If they are equal, the target pixel is labeled using the value read from the equivalence table. If the values ​​read from the equivalence table are not equal, it indicates that there is an equivalence relationship between the label values ​​of multiple neighboring pixels of the target pixel, and the label value of the target pixel needs to be further determined. These neighboring pixel label values ​​with equivalence relationships are called the target label value. It should be noted that when there is only one labeled neighboring pixel around the target pixel, the value read from the equivalence table using that neighboring pixel label value as the address can be used directly to label the target pixel.

[0056] Specifically, this application discloses an equivalence linked list. During pixel-by-pixel scanning, if it is determined from the equivalence list that there is an equivalence relationship between multiple neighboring pixel marker values ​​of the currently scanned target pixel, then these multiple target marker values ​​with equivalence relationships are locally bitmasked in the equivalence linked list to quickly obtain the local equivalent marker values ​​of the target pixel.

[0057] In specific implementations, the neighboring pixels of the target pixel can be determined according to either a four-connected-domain pattern or an eight-connected-domain pattern. In the four-connected-domain pattern, the judgment region is the pixel to the left and the pixel above the target pixel. When the equivalence table is read using the left pixel marker value and the top pixel marker value as addresses, if the corresponding stored values ​​in the equivalence table are not equal, it indicates that an equivalence relationship exists. In the eight-connected-domain pattern, the judgment region is the pixels to the left, top-left, top, and top-right of the target pixel. When the equivalence table is read using the pixel marker values ​​within the judgment region as addresses, if the corresponding stored values ​​in the equivalence table are not equal, it indicates that an equivalence relationship exists.

[0058] To facilitate understanding, the contents of equivalence lists and equivalence linked lists are explained below. First, refer to... Figure 2 As shown, Figure 2 This is a schematic diagram of the initialization of an equivalence table disclosed in this application. During the initialization phase, each address value on the left side of the equivalence table is equal to the value stored on its right side, and the value range is 0-254. It should also be noted that the equivalence table in this application is constructed based on REG (Register) rather than SRAM (Static Random-Access Memory). Compared with SRAM, which can only access one address space at a time, REG can access multiple address spaces at once, thereby further improving the update efficiency of the equivalence table.

[0059] Additionally, see Figure 3 As shown, Figure 3 This is a schematic diagram of the initialization of an equivalent linked list disclosed in this application. Specifically, in this embodiment, a 255×255 SRAM can be used as the equivalent linked list. The column index of the equivalent linked list is the linked list address value, and the row index is the bit value. The value range of both is 0-254. The linked list address value corresponds to the tag value, and the bit value corresponds to the address value in the equivalent list.

[0060] During the initialization phase, the bit corresponding to each address depth in the equivalent linked list is initialized to 1, and the other bits are initialized to 0. This results in the linked list values ​​on the diagonal being all 1, and the linked list values ​​in the remaining areas being 0. It should be noted that all the linked list values ​​in each row of the equivalent linked list, or the linked list values ​​in each row being 1 and their positions, constitute the equivalent mask corresponding to the linked list address value.

[0061] Therefore, in a specific implementation, the step of performing local bitmasking on multiple target marker values ​​that have equivalence relationships in the equivalence linked list includes: reading the equivalence linked list according to the multiple target marker values ​​to obtain equivalence masks corresponding to the multiple target marker values ​​respectively; merging the equivalence masks corresponding to the multiple target marker values ​​respectively to obtain a merged mask; and determining the local equivalence marker value of the target pixel indicated by the merged mask.

[0062] That is, after reading the equivalence table using the neighboring pixel tag values ​​of the target pixel as addresses, if it is determined that there is an equivalence relationship at the location of the target pixel, then these neighboring pixel tag values ​​are determined as multiple target tag values ​​that have an equivalence relationship in the equivalence table.

[0063] Furthermore, this application reads the equivalent linked list using the target tag value as the linked list address value to obtain the equivalent mask corresponding to each target tag value, and then merges the equivalent masks corresponding to multiple target tag values ​​to obtain the merged mask.

[0064] The specific merging method is to perform an OR operation on these equivalent masks, and then use the result of the OR operation as the merge mask. In the OR operation result, the value of the corresponding equivalent bit is 1, which means that the bit values ​​are equivalent.

[0065] Furthermore, the local equivalent marker value of the target pixel indicated by the merge mask is determined.

[0066] It should be noted that after merging the equivalent masks corresponding to the multiple target mark values ​​to obtain the merged mask, the process further includes updating the equivalent mask with the lowest number of mask bits among the multiple equivalent masks corresponding to the target mark values ​​to the merged mask.

[0067] Understandably, after calculating the merge mask, this application needs to rewrite the merge mask into the equivalent linked list. Specifically, this application updates the equivalent mask with the lowest number of mask bits among the equivalent masks corresponding to multiple target tag values ​​to the merge mask. In other words, it determines the minimum tag value from multiple target tag values ​​and then writes the merge mask into the linked list address corresponding to the minimum tag value to update the original equivalent mask stored in the linked list address.

[0068] Furthermore, it should be noted that the specific process of determining the local equivalence marker value of the target pixel indicated by the merge mask is as follows: after writing the merge mask into the equivalence linked list, the address values ​​with equivalence relationships can be determined from the equivalence list based on the bit values ​​corresponding to the linked list values ​​of 1 in the merge mask. Then, the minimum value is determined from the values ​​stored in these address values, and the minimum value is used as the local equivalence marker value of the target pixel.

[0069] Step S12: Synchronize the local equivalence tag value of the target pixel to the equivalence table.

[0070] In this embodiment, by performing local bitmasking on multiple target marker values ​​that have equivalence relationships in the equivalence list, the local equivalence marker values ​​of the scanned target pixels are obtained, and then the local equivalence marker values ​​are synchronized to the equivalence list to update the equivalence list.

[0071] In a specific implementation, synchronizing the local equivalence marker value of the target pixel to the equivalence table includes: replacing multiple target marker values ​​in the equivalence table with the local equivalence marker value of the target pixel. That is, after determining the local equivalence marker value of the target pixel, all values ​​corresponding to multiple target marker values ​​with equivalence relationships in the equivalence table are replaced with that local equivalence marker value. In this way, this application can update the values ​​in all equivalence tables with equivalence relationships within a single time unit based on the OR operation result in the equivalence linked list, thereby improving the update efficiency of the equivalence table.

[0072] As can be seen, this application discloses an equivalence linked list. During pixel-by-pixel scanning, if the neighboring pixel marker values ​​of the currently scanned target pixel are determined to have an equivalence relationship according to the equivalence list, then these multiple target marker values ​​with equivalence relationships are locally bitmasked in the equivalence linked list to quickly obtain the local equivalence marker value of the target pixel. The local equivalence marker value of the target pixel is then synchronized to the equivalence list. In other words, by setting up an equivalence linked list, this application can quickly determine the local equivalence marker value of the target pixel based on all target marker values ​​with equivalence relationships in the equivalence list, and then synchronize it to the equivalence list, thereby improving the update efficiency of the equivalence list and further improving overall performance.

[0073] Furthermore, based on the foregoing embodiments, the pixel-by-pixel scanning includes:

[0074] Read the row pixels before the interrupt bit stored in the cache unit, and perform pixel-by-pixel scanning with the row pixels as a reference. The interrupt bit is the position of the target pixel being scanned when there is no free flag value in the connected component information table.

[0075] Furthermore, when no free marker value exists in the connected component information table, the method further includes:

[0076] The pixel-by-pixel scan is interrupted, and the pixel marker values ​​of the connected components in the binary image are rewritten according to the latest synchronized equivalence table before reaching the interruption bit. During the rewriting process, the row pixels before the interruption bit are cached to the cache unit, so that after the caching is completed, the step of reading the row pixels before the interruption bit stored in the cache unit is executed.

[0077] First, it should be noted that when using the two-pass scanning method for connected component labeling, the first scan is used to label pixels and update the equivalence table. In the second scan, based on the updated equivalence table, the pixel label value after the first scan is used as the address to read the updated equivalence table, and the original label value of the pixel is rewritten according to the value in the equivalence table. This process continues until the interrupt bit at the end of the first scan is reached, at which point the second scan stops. The next round of the first scan continues from the interrupt bit.

[0078] Understandably, when dealing with large binary images, a two-pass scanning method is needed for multiple rounds of scanning. For example, suppose a binary image has 9 rows and 9 columns. During the first scan of the first round, if the fourth pixel in the fourth row is found to have no free marker value in the connected component information table, an interruption occurs, and the fourth pixel in the fourth row becomes the interrupt bit. The second scan of the first round then proceeds, starting from the first pixel in the first row and rewriting the original marker value of each pixel according to the values ​​in the equivalence table, until all pixels before the interrupt bit are rewritten. Then, the first scan of the next round begins from the interrupt bit. In other words, currently, the second scan of the current round must be completed before the first scan of the next round begins, resulting in low overall marking performance.

[0079] This application uses a buffer unit to buffer the row pixels before the interrupt bit. As mentioned above, the interrupt bit is located in the binary image of the connected component label, specifically the position of the target pixel being scanned when there is no free label value in the connected component information table. Therefore, the buffered row pixels can be used as a reference for the subsequent pixel-by-pixel scanning process. That is, when the target pixel is scanned later, the buffered row pixels can be used to determine the neighboring pixel information of these target pixels.

[0080] Overall, to improve overall performance, this application adopts a strategy of simultaneously performing the second scan of the current round and the first scan of the next round. Specifically, this application rewrites the pixel marker values ​​of connected components in the binary image based on the latest synchronized equivalence table before reaching the interrupt bit. During the rewriting process, the row pixels before the interrupt bit can be cached to the cache unit. It is understandable that, in the first scan of each round, it is necessary to determine whether there is an equivalence relationship between the pixel marker values ​​of multiple neighboring pixels of the currently scanned target pixel. This embodiment determines the neighboring pixels of the target pixel based on a four-connected component mode or an eight-connected component mode. Regardless of whether four-neighbor or eight-neighbor mode is used, the pixel marker values ​​of the left and upper rows of the currently scanned pixel are mainly referenced. Specifically, taking the four-connected component mode as an example, the left and upper pixels of the target pixel are specifically referenced. In other words, the first scan process can be completed once the marker values ​​of the left and upper pixels of the currently scanned target pixel are determined.

[0081] Therefore, this application caches the row pixels before the interrupt bit. At the start of the second scan in the current round, while performing the traditional steps—namely, rewriting the original marker value of each pixel based on the value in the equivalence table starting from the beginning position or the corresponding interrupt bit in the previous round—it also updates the row pixels before the interrupt bit according to the equivalence table and uses the cached value to record the rewritten values ​​of the row pixels before the interrupt bit. After caching, the first scan of the next round can begin from the current interrupt bit without waiting for the second scan of the current round to be completely completed (i.e., after rewriting the original marker values ​​of all pixels between the previous interrupt bit and the current interrupt bit). This improves overall performance. Furthermore, when the traditional steps have reached the row pixels before the interrupt bit, the rewriting stops, avoiding repeated rewriting of the same part of the original marker values.

[0082] In a specific embodiment, caching the row pixels before the interrupt bit can specifically refer to caching the row pixels to the left of the interrupt bit and the row pixels in the row above the interrupt bit. After the first scan of the first round is completed and the updated equivalence table is obtained, the original tag values ​​of the row pixels in the row cache are updated using the equivalence table. After the update is complete, the first scan of the second round can continue without waiting for the second scan of the first round to complete. Therefore, the first scan of the second round will at most utilize the pixels to the left of the interrupt bit and the pixels in the row above the interrupt bit.

[0083] Taking the aforementioned binary image with 9 rows and 9 columns as an example, when an interruption occurs at the 4th pixel in the 4th row, the pixel marker values ​​before the 4th pixel in the 4th row are rewritten according to the latest synchronized equivalence table before reaching the interruption point. This rewriting can be divided into two processes. The first process is to rewrite the original marker value of each pixel sequentially according to the values ​​in the equivalence table, starting from the 1st pixel in the 1st row, following the traditional scheme.

[0084] The second process can update the row pixels before the interrupt bit according to the equivalence table, that is, rewrite the original tag values ​​of the first 3 pixels of the 4th row and each pixel of the 3rd row, and cache the rewritten values ​​of the first 3 pixels of the 4th row and each pixel of the 3rd row into the cache unit.

[0085] It should also be noted that when the traditional steps have been executed from the first pixel of row 1 to the first pixel of row 3 (or the last pixel of row 2), the execution of the traditional steps is stopped to avoid rewriting the first 3 pixels of row 4 and each pixel of row 3.

[0086] Alternatively, in some examples, the above process two can also be to cache the rewritten values ​​of the first 3 pixels of the 4th row and each pixel of the 3rd row into the cache unit after process one has been rewritten.

[0087] After caching is complete, the first scan of the next round can begin from the fourth pixel of the fourth row, as the neighboring pixel values ​​are now known. It's also important to note that when using 4-connected or 8-connected domain mode, to save cache unit storage space, you can cache only the pixels to the left of the interrupt position in the row containing the interrupt, the pixels in the previous row in the same column as the interrupt position, and the pixels to the right of the interrupt position. For clarity, using the previous example, this means only the first three pixels of the fourth row need to be cached, and pixels 4 through 9 of the third row need to be cached.

[0088] In addition, after a pixel-by-pixel scan is interrupted, the row pixels before the interruption bit can be cached in a cache unit first. Then, the pixels in the cache unit can be rewritten according to the latest synchronized equivalence table before reaching the interruption bit. After that, pixel-by-pixel scanning can continue using the latest pixel in the cache unit as a reference. At the same time, the step of rewriting the original tag value of each pixel according to the value in the equivalence table can be performed, starting from the starting position or the corresponding interruption bit of the previous round.

[0089] Furthermore, based on the foregoing embodiments, during the pixel-by-pixel scanning process, the method further includes:

[0090] If no free flag value exists in the connected component information table, target connected components below the target area threshold in the connected component information table are filtered out, and the flag value corresponding to the target connected component in the connected component information table is cached as a new free flag value in the address cache.

[0091] During pixel-by-pixel scanning, a new free marker value is read from the address cache, and the currently scanned pixel is marked using the new free marker value to form a new target connected component. The connected component information table is then updated based on the new target connected component.

[0092] First, it should be noted that this application also involves a connected component information table, which can be constructed based on SRAM. See details... Figure 4 As shown, Figure 4 This is a schematic diagram of the initialization of a connected component information table disclosed in this application. During the initialization phase, all values ​​in the connected component information table are initialized to 0. The numerical range of the address values ​​in the connected component information table is 0-254. The connected component information table is specifically used to record the area value of each connected component.

[0093] Understandably, when initially using the two-pass scanning method on a binary image, if it's determined that a new tag value needs to be assigned to the scanned target pixel, the connected component information table needs to be traversed and searched. Address values ​​with a value of 0 (i.e., free tag values) in the information table are used as new tag values ​​to mark the target pixel. Therefore, when no free tag value exists in the connected component information table, the scanning needs to be paused. At this point, the connected component information table is read sequentially. The purpose is to filter out target connected components below the target area threshold in the connected component information table and delete these target connected components from the table. Simultaneously, the contents related to the tag values ​​corresponding to the target connected components in the equivalence table are also deleted. Subsequently, the tag values ​​corresponding to the target connected components in the connected component information table can be cached as new free tag values ​​in the address cache, allowing these tag values ​​to be reused to mark scanned pixels later.

[0094] Specifically, during subsequent pixel-by-pixel scanning, new free marker values ​​are directly read from the address cache, eliminating the need to traverse the entire connected component information table. This reduces the time spent obtaining available marker values ​​and improves scanning performance. The new free marker values ​​are then used to mark the currently scanned pixels, forming new target connected components. The connected component information table is then updated based on these new target connected components. In other words, the connected component information table is updated after scanning each target pixel, allowing the system to determine the current connected component marking status and the area of ​​each connected component.

[0095] To further improve the performance of the first scan, an address cache can be used to cache address values ​​that are empty in the connected component information table. That is, when initially marking pixels in the binary image, the address cache stores address values ​​ranging from 0 to 254. If a new marker value is needed for the current target pixel during the first scan, an available marker value can be read directly from the address cache, without needing to traverse and search the connected component information table to obtain an empty address value, thus improving the performance of the first scan. Subsequently, if no free marker value for the target is found in the address cache, the target connected component is deleted.

[0096] In a specific implementation, the above-mentioned filtering out target connected components below the target area threshold in the connected component information table includes:

[0097] When there is no target connected component below the target area threshold in the connected component information table, several growth steps are added to the target area threshold to form multiple candidate area thresholds.

[0098] Determine whether there exists a target connected component in the connected component information table that is below any candidate area threshold;

[0099] If so, the minimum candidate area threshold when the judgment condition is met will be used as the target area threshold, and the target connected components below the minimum candidate area threshold in the connected component information table will be deleted.

[0100] If not, continue to accumulate the growth step size for multiple candidate area thresholds.

[0101] First, it should be noted that currently, when performing connected component deletion, if the area values ​​of all connected components in the connected component information table are greater than the initial area threshold `inital_area`, the deletion fails. Then, deletion is attempted again by incrementing the growth step `step_area` on top of the initial area threshold `inital_area` until successful. However, this deletion mechanism is inefficient. If deletion fails repeatedly, the growth step will continuously increase, and the comparison between the connected component area and the area threshold will be performed repeatedly.

[0102] To improve the efficiency of connected component deletion, this application, when no target connected component below the target area threshold exists in the connected component information table, accumulates several growth steps to the target area threshold, forming multiple candidate area thresholds. During the connected component deletion operation, these multiple candidate area thresholds are used simultaneously for judgment; that is, it is determined whether any target connected component below any candidate area threshold exists in the connected component information table. If so, the target connected component below the smallest candidate area threshold in the connected component information table is deleted to complete the current connected component deletion operation. The smallest candidate area threshold at which the judgment condition is met is then used as the target area threshold for the next round of deletion. If deletion is still unsuccessful, the growth steps are continuously accumulated for the multiple candidate area thresholds until deletion is successful.

[0103] In a specific example, if no target connected component below the target area threshold exists in the connected component information table, the growth step size `step_area` is continuously incremented eight times based on the target area threshold to generate eight candidate area thresholds. During deletion, these eight candidate area thresholds are used simultaneously for evaluation. If one of the eight candidate area thresholds is a valid area threshold that allows for successful deletion, the smallest candidate area threshold is selected from these valid thresholds, and the target connected component below this smallest candidate area threshold in the connected component information table is deleted to complete the current connected component deletion operation. This smallest candidate area threshold is then used as the new target area threshold for the next round of deletion operations. If all eight candidate area thresholds fail to delete, the growth step size is incremented eight more times until deletion is successful.

[0104] In this way, by accumulating eight growth steps each time, eight candidate area thresholds are obtained for deletion operations. This allows for the rapid identification of a removable area threshold after a deletion failure, thereby improving deletion efficiency. It should be noted that this embodiment only uses accumulating eight growth steps as an example and does not limit the specific number of times, as long as at least two accumulations are required.

[0105] To make it easier to understand, the following is an example. Figure 5 Taking an example, the technical solution of this application will be described in detail:

[0106] Will Figure 5 Rotating 90 degrees to the right reveals that the first column is an equivalence list, the second column is an equivalence table, and the third column is a simplified representation of the binary image. It's important to note that, considering the full equivalence lists and tables would take a considerable amount of space, only examples with address ranges 0-6 are provided here. Additionally, yellow pixels in the binary image represent non-zero pixels, and red pixels indicate the current scan position.

[0107] Step 1: Obtain the initialized equivalent linked list, equivalence table, and original binary image. In the equivalent linked list, the values ​​of the linked lists on the diagonal are all 1, while the values ​​of the linked lists in the remaining areas are 0; each address value on the left side of the equivalence table is equal to the value stored on its right side.

[0108] Step 2: Scan each pixel in the binary image row by row from left to right to mark the non-zero pixels (i.e., the yellow pixels in the image). Figure 5 Specifically, the four-connected domain model is used to determine the neighboring pixels of the currently scanned pixel.

[0109] The specific process is as follows:

[0110] When the first yellow pixel in the first row is scanned, it can be marked as 1. When the second yellow pixel in the first row is scanned, since its left neighboring pixel is a zero-value pixel, it is given a new mark value of 2. Similarly, the third yellow pixel in the first row is marked as 3.

[0111] Next, the second row is scanned. When the first yellow pixel in the second row is scanned, since its left neighboring pixel has a zero value and its upper neighboring pixel has a value of 1, it is also marked as 1. When the second yellow pixel is scanned, both its left and upper neighboring pixels are non-zero pixels and have already been marked. Therefore, the corresponding neighboring pixel mark values ​​(i.e., 1 and 2) are used as addresses to read the values ​​recorded in the equivalence table. The equivalence table reads 1 and 2, which are not equal, indicating that there is an equivalence relationship at the current position. That is, the target mark values ​​with addresses 1 and 2 in the equivalence table have an equivalence relationship.

[0112] Furthermore, using target flag values ​​1 and 2 as linked list addresses, the equivalent linked list is read. The equivalent mask corresponding to target flag value 1 is found to be "0100000", and the equivalent mask corresponding to target flag value 2 is "0010000". These two equivalent masks are then ORed to obtain the result "0110000", which is the merge mask. The two target flag values ​​are then compared, and the smallest flag value, 1, is determined. The merge mask is then written into the linked list address corresponding to 1, thus obtaining... Figure 5 The diagram shows the third equivalent linked list in the first column. Next, we determine the bit values ​​corresponding to the 1 value in the linked list of the merge mask from the equivalent linked list. This tells us that the values ​​corresponding to address values ​​1 and 2 in the equivalent list should be the same. We then rewrite the values ​​at these two positions to the minimum of the two values. In this example, we write the values ​​corresponding to address values ​​1 and 2 in the equivalent list as 1.

[0113] Step 3: Continue pixel scanning using the method described above. When scanning the third yellow pixel in the third row, since its left and upper neighboring pixels are all non-zero pixels and have been marked, use the corresponding neighboring pixel mark values ​​(i.e., 1 and 3) as addresses to read the values ​​recorded in the equivalence table. Reading 1 and 3 from the equivalence table, they are not equal, indicating that an equivalence relationship also exists at the current position. Then, using 1 and 3, read the equivalence linked list to obtain the equivalence mask corresponding to 1 as 0110000 and the equivalence mask corresponding to 3 as 0001000. Perform an OR operation to obtain 0111000, and then write the OR result into the linked list address corresponding to 1 in the equivalence linked list, thus obtaining... Figure 5 The diagram shows the fourth type of equivalent linked list in the first column. Next, based on the result of the OR operation, we know that the values ​​corresponding to address 1 and address 3 in the equivalent list should be the same. We then rewrite the values ​​at these two positions to the minimum of the two, which is 1. Subsequent scanning processes follow the same principle.

[0114] In addition, such as Figure 6 and Figure 7 As shown, Figure 6 This is a schematic diagram illustrating the equivalence of four-connected domain patterns. Figure 7 This is a schematic diagram illustrating the equivalence of an 8-connected domain. The red pixels in the diagram represent the current scan position. Figure 6 When marking a red pixel, it is necessary to refer to the marking values ​​of its neighboring pixels to the left and above. As mentioned above, the position of the red pixel should be marked with the minimum value of the two, that is, marked as 1. Figure 7 When marking a red pixel, it is necessary to refer to the marking values ​​of its neighboring pixels to the left, top left, top, and top right. As mentioned above, the position of the red pixel should be marked with the minimum value among them, that is, marked as 1.

[0115] See Figure 8 As shown, this application discloses a connected component labeling device, comprising:

[0116] The masking module 11 is used to perform local bitmasking on multiple target marker values ​​that have equivalence relationships in the equivalence list during the pixel-by-pixel scanning process, so as to obtain the local equivalence marker value of the scanned target pixel, wherein the target marker value is the neighboring pixel marker value of the target pixel;

[0117] The synchronization module 12 is used to synchronize the local equivalence tag value of the target pixel to the equivalence table.

[0118] As can be seen, the connected component labeling device of this application discloses an equivalence linked list. During pixel-by-pixel scanning, if the neighboring pixel label values ​​of the currently scanned target pixel are determined to have an equivalence relationship according to the equivalence list, then these multiple target label values ​​with equivalence relationships are locally bitmasked in the equivalence linked list to quickly obtain the local equivalence label value of the target pixel. The local equivalence label value of the target pixel is then synchronized to the equivalence list. That is, by setting the equivalence linked list, this application can quickly determine the local equivalence label value of the target pixel based on all target label values ​​with equivalence relationships in the equivalence list, and then synchronize it to the equivalence list, thereby improving the update efficiency of the equivalence list and further improving the overall performance.

[0119] The execution process of the above-mentioned device can be referred to the execution process of the above-mentioned connected component labeling method, and will not be repeated here. The device also has the same beneficial effects as the above-mentioned method embodiments.

[0120] Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Specifically, it may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the connected component labeling method performed by the electronic device disclosed in any of the foregoing embodiments.

[0121] In this embodiment, the power supply 23 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 25 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.

[0122] The processor 21 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 21 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 21 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.

[0123] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk or optical disk, etc. The resources stored on it include operating system 221, computer program 222 and data 223, etc., and the storage method can be temporary storage or permanent storage.

[0124] The operating system 221 manages and controls the various hardware devices and computer programs 222 on the electronic device 20 to enable the processor 21 to perform calculations and processing on the massive amounts of data 223 in the memory 22. The operating system 221 can be Windows, Unix, Linux, etc. The computer program 222, in addition to including a computer program capable of performing the connected component labeling method disclosed in any of the foregoing embodiments, may further include computer programs capable of performing other specific tasks. The data 223 may include data received by the electronic device from external devices, as well as data collected by its own input / output interface 25.

[0125] Furthermore, embodiments of this application also disclose a computer-readable storage medium storing a computer program, which, when loaded and executed by a processor, implements the connected component labeling method steps disclosed in any of the foregoing embodiments.

[0126] Furthermore, embodiments of this application also disclose a computer program product, including a computer program / instructions, which, when executed by a processor, implement the steps of the connected component labeling method disclosed in any of the foregoing embodiments.

[0127] 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 apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section.

[0128] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0129] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, compact disc read-only memory (CD-ROM), or any other form of storage medium known in the art.

[0130] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0131] The above provides a detailed description of the connected component labeling method, apparatus, device, and storage medium provided by the present invention. Specific examples have been used 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. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A connected component labeling method, characterized by, include: During pixel-by-pixel scanning, local bitmasking is performed on multiple target marker values ​​that have equivalence relationships in the equivalence linked list to obtain the local equivalence marker values ​​of the scanned target pixels. Specifically, during scanning, if a target pixel's neighboring pixels are non-zero pixels and have already been marked, the corresponding neighboring pixel marker value is used as an address to read the values ​​recorded in the equivalence list. It is then determined whether the values ​​read from the equivalence list are equal. If they are equal, the target pixel is marked using the values ​​read from the equivalence list. If the values ​​read from the equivalence list are not equal, it is determined that there is an equivalence relationship between the multiple neighboring pixel marker values ​​of the target pixel, and the neighboring pixel marker values ​​with the equivalence relationship are used as the target marker values. The equivalence list is used to store address values ​​and the corresponding equivalence marker values. The equivalence linked list is a two-dimensional matrix, where the column index is the equivalence linked list address value and the corresponding marker value, and the row index is the bit value and the corresponding address value in the equivalence list. Replace multiple target marker values ​​in the equivalence table with the local equivalence marker values ​​of the target pixels; Specifically, the step of performing local bitmasking on multiple target marker values ​​that have equivalence relationships in the equivalence linked list involves: reading the equivalence linked list using the target marker value as the address value to obtain the equivalence mask corresponding to each target marker value; merging the equivalence masks corresponding to multiple target marker values ​​to obtain a merged mask; and determining the local equivalence marker value of the target pixel indicated by the merged mask. The step of merging the equivalent masks corresponding to multiple target marker values ​​to obtain a merged mask is specifically: performing an OR operation on the equivalent mask and using the result of the OR operation as the merged mask; the equivalent mask is a row bit vector in the equivalent linked list corresponding to a certain address value of the equivalent linked list. The step of determining the local equivalence marker value of the target pixel indicated by the merged mask is as follows: based on the bit value corresponding to the linked list value of 1 in the merged mask, the address value with equivalence relationship is determined from the equivalence table, the minimum value is determined from the equivalence marker values ​​corresponding to the address values ​​with equivalence relationship, and the minimum value is used as the local equivalence marker value of the target pixel.

2. The connected component labeling method of claim 1, wherein, After merging the equivalent masks corresponding to the multiple target marker values ​​to obtain the merged mask, the process further includes: The equivalent mask with the lowest number of mask bits among the equivalent masks corresponding to the multiple target mark values ​​is updated to the merged mask.

3. The connected component labeling method of claim 1, wherein, The pixel-by-pixel scan includes: Read the row pixels before the interrupt bit stored in the cache unit, and perform pixel-by-pixel scanning with the row pixels as a reference. The interrupt bit is the position of the target pixel being scanned when there is no free flag value in the connected component information table.

4. The connected component labeling method of claim 3, wherein, When no free marker value exists in the connected component information table, the method further includes: The pixel-by-pixel scan is interrupted, and the pixel marker values ​​of the connected components in the binary image are rewritten according to the latest synchronized equivalence table before reaching the interruption bit. During the rewriting process, the row pixels before the interruption bit are cached to the cache unit, so that after the caching is completed, the step of reading the row pixels before the interruption bit stored in the cache unit is executed.

5. The method of claim 1, wherein, During the pixel-by-pixel scanning process, the method further includes: If no free flag value exists in the connected component information table, target connected components below the target area threshold in the connected component information table are filtered out, and the flag value corresponding to the target connected component in the connected component information table is cached as a new free flag value in the address cache. During pixel-by-pixel scanning, a new free marker value is read from the address cache, and the currently scanned pixel is marked using the new free marker value to form a new target connected component. The connected component information table is then updated based on the new target connected component.

6. The connected component labeling method of claim 5, wherein, The process of filtering out target connected components below the target area threshold in the connected component information table includes: When there is no target connected component below the target area threshold in the connected component information table, several growth steps are added to the target area threshold to form multiple candidate area thresholds. Determine whether there exists a target connected component in the connected component information table that is below any candidate area threshold; If so, the minimum candidate area threshold when the judgment condition is met will be used as the target area threshold, and the target connected components below the minimum candidate area threshold in the connected component information table will be deleted. If not, continue to accumulate the growth step size for multiple candidate area thresholds.

7. A connected component labeling apparatus characterized by comprising: include: The masking module is used to perform local bitmasking on multiple target marker values ​​that have equivalence relationships in the equivalence linked list during pixel-by-pixel scanning to obtain the local equivalence marker values ​​of the scanned target pixels. Specifically, during scanning, if a target pixel's neighboring pixels are non-zero pixels and have already been marked, the corresponding neighboring pixel marker values ​​are used as addresses to read the values ​​recorded in the equivalence list. The module then determines whether the values ​​read from the equivalence list are equal. If they are equal, the target pixel is marked using the values ​​read from the equivalence list. If the values ​​read from the equivalence list are not equal, an equivalence relationship is determined between the multiple neighboring pixel marker values ​​of the target pixel, and the neighboring pixel marker values ​​with the equivalence relationship are used as the target marker values. The equivalence list stores address values ​​and the corresponding equivalence marker values. The equivalence linked list is a two-dimensional matrix, where column indices are equivalence linked list address values ​​corresponding to marker values, and row indices are bit values ​​corresponding to address values ​​in the equivalence list. A synchronization module is used to replace multiple target marker values ​​in the equivalence table with the local equivalence marker values ​​of the target pixels; Specifically, the step of performing local bitmasking on multiple target marker values ​​that have equivalence relationships in the equivalence linked list involves: reading the equivalence linked list using the target marker value as the address value to obtain the equivalence mask corresponding to each target marker value; merging the equivalence masks corresponding to multiple target marker values ​​to obtain a merged mask; and determining the local equivalence marker value of the target pixel indicated by the merged mask. The step of merging the equivalent masks corresponding to multiple target marker values ​​to obtain a merged mask is specifically: performing an OR operation on the equivalent mask and using the result of the OR operation as the merged mask; the equivalent mask is a row bit vector in the equivalent linked list corresponding to a certain address value of the equivalent linked list. The step of determining the local equivalence marker value of the target pixel indicated by the merged mask is as follows: based on the bit value corresponding to the linked list value of 1 in the merged mask, the address value with equivalence relationship is determined from the equivalence table, the minimum value is determined from the equivalence marker values ​​corresponding to the address values ​​with equivalence relationship, and the minimum value is used as the local equivalence marker value of the target pixel.

8. An electronic device, comprising: include: Memory, used to store computer programs; A processor for executing the computer program to implement the steps of the connected component labeling method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, Used to store a computer program; wherein, when the computer program is executed by a processor, it implements the steps of the connected component labeling method as described in any one of claims 1 to 6.