Connected domain marking method and device, equipment and medium

By using the address cache to store the idle tag value in the connected domain tag, and directly reading the tag value from the cache for tagging, the low performance problem caused by traversal search in the prior art is solved, and scanning and marking efficiency is improved.

CN120279053APending Publication Date: 2025-07-08HUNAN GOKE MICROELECTRONICS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510750291.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-06
Publication Date
2025-07-08

AI Technical Summary

Technical Problem

In the prior art, the performance of the connected domain marker is poor, mainly due to the way of traversing and finding the free marker value, resulting in low scanning performance.

Method used

By presetting the address cache to store the empty tag value in the connection domain information table, the free tag value is directly read from the address cache for marking during scanning, avoiding traversal and searching the connection domain information table.

Benefits of technology

Improves the scanning performance of connected domain markers, reduces the time to obtain free mark values, and thus improves the efficiency of the overall marking process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120279053A_ABST
    Figure CN120279053A_ABST
Patent Text Reader

Abstract

The invention discloses a connected domain marking method and device, equipment and a medium, and relates to the technical field of image processing, and the method comprises the steps: reading an idle mark value from a preset address cache if a currently scanned target pixel meets a marking condition during pixel-by-pixel scanning; wherein the idle mark value is a mark value with null information in the connected domain information table; and marking the target pixel by using the idle mark value. According to the method and the device, the address cache is preset to store the mark value of which the information is empty in the connected domain information table, so that when the target pixel meets the marking condition, the target pixel is marked by directly reading the idle mark value from the address cache, the connected domain information table does not need to be traversed and searched, the scanning performance is improved, and the scanning efficiency is improved. Therefore, the performance of connected domain marking is further improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image processing, and particularly relates to a connected component labeling method, device, equipment and medium. Background Art

[0002] Connected component labeling is a very important method in binary image analysis. When implemented, each white pixel (i.e., non-zero pixel) in a binary image is labeled, and white pixels belonging to the same connected component are labeled the same, while white pixels in different connected components have different labels, so that each connected component in the image can be extracted. Connected component extraction can provide accurate positioning for the feature shooting of science fiction movies, can also be used for image recognition and target information extraction in the security industry, and even can be used to obtain parameters such as the position, phase, angle and speed of moving targets in a radar system.

[0003] Currently, the Two-Pass method is often used for connected component labeling. This method is mainly divided into the first scan and the second scan. Among them, during the first scan, when a new label needs to be assigned to the current pixel value, it is necessary to traverse and search for an unused address value in the foregoing part as the new label number. However, the traversing and searching method is time-consuming, resulting in poor scanning performance during the labeling process, and further resulting in poor performance of the entire connected component labeling process.

[0004] In summary, how to improve the performance of connected component labeling is a problem to be solved currently. Summary of the Invention

[0005] In view of this, the purpose of the present invention is to provide a connected component labeling method, device, equipment and medium, which can improve the performance of connected component labeling. The specific scheme is as follows:

[0006] In a first aspect, the present application discloses a connected component labeling method, including:

[0007] When scanning pixel by pixel, if the target pixel currently scanned meets the labeling condition, an idle labeling value is read from a preset address cache; wherein, the idle labeling value is a labeling value with empty information in the connected component information table;

[0008] The target pixel is labeled with the idle labeling value.

[0009] Optionally, the process of caching the idle labeling value into the preset address cache includes:

[0010] When there is no idle labeling value in the connected component information table, target connected components below the target area threshold in the connected component information table are screened out;

[0011] Cache the marking value corresponding to the target connected component in the connected component information table as a new free marking value in the address cache.

[0012] Optionally, the screening of the target connected components below the target area threshold in the connected component information table includes:

[0013] When there are no target connected components below the target area threshold in the connected component information table, accumulate a number of growth steps for the target area threshold to form multiple alternative area thresholds;

[0014] Compare the areas of the connected components in the connected component information table with the multiple alternative area thresholds respectively to determine the target connected components with areas smaller than any of the alternative area thresholds.

[0015] Optionally, the comparing the areas of the connected components in the connected component information table with the multiple alternative area thresholds respectively to determine the target connected components with areas smaller than any of the alternative area thresholds includes:

[0016] Judge whether there are target connected components below any of the alternative area thresholds in the connected component information table;

[0017] If so, use the smallest alternative area threshold when the judgment condition is met as the target area threshold, and delete the target connected components below the smallest alternative area threshold in the connected component information table;

[0018] If not, continue to accumulate growth steps for the multiple alternative area thresholds to form multiple new alternative area thresholds, and continue to judge whether there are target connected components below any of the new alternative area thresholds in the connected component information table.

[0019] Optionally, the marking conditions include:

[0020] All the neighboring pixels of the currently scanned target pixel are zero-value pixels.

[0021] Optionally, the connected component marking method further includes:

[0022] When there is no free marking value in the connected component information table, the per-pixel scan is interrupted, and the currently scanned target pixel is used as the interrupt bit;

[0023] According to the equivalence table synchronized latest before reaching the interrupt bit, rewrite the pixel marking values of the connected components in the binary image, and cache the row pixels before the interrupt bit to the cache unit.

[0024] Optionally, the if the currently scanned target pixel meets the marking condition includes:

[0025] When starting pixel-by-pixel scanning from the interruption bit, it is determined whether the neighboring pixels of the target pixel currently being scanned are all zero-value pixels based on the row pixels before the interruption bit stored in the buffer unit;

[0026] If so, it is determined that the target pixel currently being scanned meets the marking condition.

[0027] In a second aspect, the present application discloses a connected component marking device, including:

[0028] A marking value reading module, configured to, when performing pixel-by-pixel scanning, if the target pixel currently being scanned meets the marking condition, read an idle marking value from a preset address buffer; wherein, the idle marking value is a marking value with empty information in the connected component information table;

[0029] A marking module, configured to mark the target pixel with the idle marking value.

[0030] In a third aspect, the present application discloses an electronic device, including:

[0031] A memory, configured to store a computer program;

[0032] A processor, configured to execute the computer program to implement the steps of the connected component marking method disclosed above.

[0033] In a fourth aspect, the present application discloses a computer-readable storage medium, configured to store a computer program; wherein, when the computer program is executed by a processor, the steps of the connected component marking method disclosed above are implemented.

[0034] In a fifth aspect, the present application discloses a computer program product, including a computer program, and when the computer program is executed by a processor, the steps of the connected component marking method disclosed above are implemented.

[0035] It can be seen that in the present application, when performing pixel-by-pixel scanning, if the target pixel currently being scanned meets the marking condition, an idle marking value is read from a preset address buffer; wherein, the idle marking value is a marking value with empty information in the connected component information table; the target pixel is marked with the idle marking value. In the traditional solution, if the target pixel currently being scanned meets the marking condition, it is necessary to traverse and search for a marking value with empty information in the connected component information table for marking. However, the traversing and searching method is time-consuming, resulting in poor scanning performance during the marking process. In the present application, an address buffer is preset to store the marking values with empty information in the connected component information table. Then, when the target pixel currently being scanned meets the marking condition, the idle marking value is directly read from the address buffer to mark the target pixel, without the need to traverse and search the connected component information table, improving the scanning performance and further improving the performance of connected component marking. Description of the Drawings

[0036] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the accompanying drawings required in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only the embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can also be obtained based on the provided drawings.

[0037] Figure 1 It is a flowchart of a connected component labeling method disclosed in the present application;

[0038] Figure 2 It is a schematic diagram of the initialization of a connected component information table disclosed in the present application;

[0039] Figure 3 It is a schematic diagram of the initialization of an equivalence table disclosed in the present application;

[0040] Figure 4 It is a schematic diagram of the initialization of an equivalence linked list disclosed in the present application;

[0041] Figure 5 It is a schematic diagram of the update process of an equivalence linked list disclosed in the present application;

[0042] Figure 6 It is a schematic diagram of the equivalence of a four-connected component pattern disclosed in the present application;

[0043] Figure 7 It is a schematic diagram of the equivalence of an eight-connected component pattern disclosed in the present application;

[0044] Figure 8 It is a schematic diagram of the structure of a connected component labeling device disclosed in the present application;

[0045] Figure 9 It is a structural diagram of an electronic device disclosed in the present application. Specific Embodiments

[0046] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the scope of protection of the present invention.

[0047] The embodiments of the present application disclose a connected component labeling method, apparatus, device, and medium, which can improve the performance of connected component labeling. By pre-setting an address cache to store the label values with empty information in the connected component information table, when the target pixel scanned currently meets the labeling condition, the free label value can be directly read from the address cache to label the target pixel, without traversing and searching the connected component information table, improving the scanning performance, and thus further improving the performance of connected component labeling.

[0048] See Figure 1 As shown, the embodiments of the present application disclose a connected component labeling method, which includes:

[0049] Step S11: When scanning pixel by pixel, if the target pixel scanned currently meets the labeling condition, read the free label value from a pre-set address cache; wherein, the free label value is the label value with empty information in the connected component information table.

[0050] In this embodiment, when performing connected component labeling on a binary image, each pixel is scanned row by row from left to right. When the target pixel scanned currently meets the labeling condition, the available free label value is directly read from the address cache. It can be understood that in the traditional solution, when the target pixel meets the labeling condition, it is necessary to traverse and search the connected component information table, and use the label value with empty information (i.e., the content is 0) in the connected component information table to label the target pixel. However, the traversing and searching method is time-consuming, resulting in poor scanning performance during the labeling process. In the present application, by pre-setting an address cache to store the label values with empty information in the connected component information table, when labeling the target pixel, it is no longer necessary to traverse and search the connected component information table, but directly read from the address cache, reducing the time to obtain the free label value, thus improving the scanning performance and further improving the performance of connected component labeling.

[0051] Among them, in the specific implementation manner, the labeling condition includes: the neighboring pixels of the target pixel scanned currently are all zero-value pixels.

[0052] First of all, it should be noted that during the connected component labeling process, mainly the non-zero pixels in the binary image are labeled. Therefore, the target pixel here can specifically be a non-zero pixel. Then during the scanning process, if the neighboring pixels of the target pixel scanned currently are all zero-value pixels, it means that a new label value needs to be assigned to the target pixel, so the available free label value is directly read from the address cache.

[0053] In the specific implementation manner, the neighborhood pixels of the target pixel can be determined according to the four-connected domain mode or the eight-connected domain mode. Among them, the judgment area in the four-connected domain mode is the left pixel and the upper pixel of the target pixel. Correspondingly, if both the left pixel and the upper pixel of the currently scanned target pixel are zero-valued pixels, it indicates that a new label value needs to be assigned to the target pixel; in the eight-connected domain mode, the judgment area is the left, upper-left, upper, and upper-right pixels of the target pixel. Correspondingly, if the left, upper-left, upper, and upper-right pixels of the currently scanned target pixel are all zero-valued pixels, it indicates that a new label value needs to be assigned to the target pixel.

[0054] In addition, the connected component information table involved in this application can be constructed based on SRAM (Static Random-Access Memory). For details, see Figure 2 as shown in Figure 2 FIG. is an initialization schematic diagram of a connected component information table disclosed in this application. In the initialization stage, all values in the connected component information table are initially set to 0. The numerical range of the label values in the connected component information table is 0-254. The connected component information table is specifically used to record the area values of each connected component.

[0055] Further, the process of caching the free label value into the preset address cache may specifically include: when there is no free label value in the connected component information table, screening out the target connected components below the target area threshold in the connected component information table; using the label values corresponding to the target connected components in the connected component information table as new free label values and caching them into the address cache.

[0056] In this embodiment, when there is no free label value in the connected component information table or the free label values cached in the address cache have been used up, the scanning needs to be paused first. At this time, the connected component information table is read sequentially. The purpose is to screen out the target connected components below the target area threshold in the connected component information table, that is, to delete these target connected components in the connected component information table; then use the label values corresponding to the target connected components in the connected component information table as new free label values and cache them into the address cache, so that these label values can be reused from the address cache to continue labeling the scanned pixels. In addition, the status of the label values corresponding to the target connected components in the connected component information table can also be updated to free label values.

[0057] That is, to improve the performance of the first scan in the two-pass scan method, the present application uses an address cache to cache the address values with empty content in the connected component information table. Then, when initially performing pixel labeling on the binary image, the range of the address values stored in the address cache is 0-254. When a new label value needs to be provided for the current target pixel during the first scan, an available label value can be directly read from the address cache, instead of obtaining the address value with empty content by traversing and searching the connected component information table, thereby improving the performance of the first scan. Subsequently, when there is no idle label value available as the target label value in the address cache and the connected component information table, the deletion step of the target connected component is executed to obtain new available label values.

[0058] It should also be noted that after reading the idle label value from the address cache for labeling, the status of the used label value can be modified in the connected component information table, and the corresponding connected component can be associated.

[0059] In the specific implementation, screening the target connected components with an area below the target area threshold in the connected component information table includes: when there are no target connected components with an area below the target area threshold in the connected component information table, adding several growth step lengths to the target area threshold to form multiple alternative area thresholds; comparing the areas of the connected components in the connected component information table with the multiple alternative area thresholds respectively to determine the target connected components with an area smaller than any of the alternative area thresholds.

[0060] First of all, it should be pointed out 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, it means that the current deletion fails, and then the deletion is performed by adding a step length on the basis of the initial area threshold inital_area until the deletion is successful. However, such a deletion mechanism has the problem of low efficiency. If the deletion is never successful, the step length will be continuously added, and the comparison operation between the connected component area and the area threshold will be continuously executed.

[0061] In order to improve the deletion efficiency in the stage of deleting connected components, when there are no target connected components with an area below the target area threshold in the connected component information table, the present application adds several growth step lengths to the target area threshold to form multiple alternative area thresholds. When performing the connected component deletion operation, the areas of the connected components in the connected component information table are compared with the multiple alternative area thresholds respectively to determine the target connected components with an area smaller than any of the alternative area thresholds. Among them, when the computing resources of the processor support, in order to improve the comparison efficiency, multiple alternative area thresholds can also be used for comparison simultaneously to determine whether there are target connected components with an area below any of the alternative area thresholds in the connected component information table.

[0062] Further, comparing the areas of the connected components in the connected component information table with multiple said alternative area thresholds respectively to determine the target connected components with areas smaller than any of the said alternative area thresholds includes: determining whether there are target connected components below any of the alternative area thresholds in the connected component information table; if so, taking the smallest alternative area threshold when the judgment condition is met as the target area threshold, and deleting the target connected components below the smallest alternative area threshold in the connected component information table; if not, continue to accumulate the growth step length for multiple alternative area thresholds to form multiple new alternative area thresholds, and continue to determine whether there are target connected components below any of the new alternative area thresholds in the connected component information table.

[0063] That is, in the specific comparison process, it is necessary to determine whether there are target connected components below any of the alternative area thresholds in the connected component information table. If there are, delete all the target connected components below the smallest alternative area threshold in the connected component information table to complete the current connected component deletion operation, and take the smallest alternative area threshold when the judgment condition is met as the target area threshold for the next round of deletion operation. If the deletion is still not successful, continue to accumulate the growth step length for multiple alternative area thresholds to form multiple new alternative area thresholds, and then execute the foregoing judgment step until the deletion is successful.

[0064] In a specific example, when there are no target connected components below the target area threshold in the connected component information table, continuously accumulate the growth step length step_area 8 times on the basis of the target area threshold to generate 8 alternative area thresholds. When deleting, use the 8 alternative area thresholds for judgment at the same time. If there is an effective area threshold among the 8 alternative area thresholds that can make the deletion successful, select the smallest alternative area threshold among the successfully deleted effective area thresholds, and delete the target connected components below the smallest alternative area threshold in the connected component information table to complete the current connected component deletion operation, and take this smallest alternative area threshold as the new target area threshold for subsequent possible deletion operations in the next round. If all 8 alternative area thresholds fail to be deleted, continue to accumulate the growth step length 8 times until the deletion is successful.

[0065] In this way, by accumulating the growth step length 8 times each time to obtain 8 alternative area thresholds for the deletion operation, the area threshold that can be deleted can be quickly found after the deletion fails, thereby improving the deletion efficiency. It should be noted that this embodiment only takes accumulating the growth step length 8 times as an example, and does not limit the specific number of times, as long as it satisfies at least accumulating twice. In addition, it should be noted that the growth step length accumulated each time can be the same or different.

[0066] Step S12: Mark the target pixel using the idle mark value.

[0067] In this embodiment, the target pixel is marked with the free tag value read from the address cache. Further, after the marking is completed, a new connected component is formed. At this time, the connected component information table is updated according to the new connected component. That is, after scanning each target pixel, the connected component information table is updated, so that the current connected component marking situation and the area size of each connected component can be known.

[0068] It can be seen that when the present application performs pixel-by-pixel scanning, if the currently scanned target pixel meets the marking condition, the free tag value is read from the preset address cache; wherein, the free tag value is the tag value with empty information in the connected component information table; the target pixel is marked with the free tag value. In the traditional solution, if the currently scanned target pixel meets the marking condition, it is necessary to traverse and search for the tag value with empty information in the connected component information table for marking. However, the traversing and searching method is time-consuming, resulting in poor scanning performance during the marking process. The present application pre-sets an address cache to store the tag value with empty information in the connected component information table. Then, when the currently scanned target pixel meets the marking condition, the free tag value is directly read from the address cache to mark the target pixel, without having to traverse and search the connected component information table, improving the scanning performance, and thus further improving the performance of connected component marking.

[0069] Further, on the basis of the foregoing embodiment, the connected component marking method of the present application further includes: when there is no free tag value in the connected component information table, the pixel-by-pixel scanning is interrupted, and the currently scanned target pixel is used as the interruption bit; according to the equivalence table synchronized most recently before reaching the interruption bit, the pixel tag values of the connected components in the binary image are rewritten, and the row pixels before the interruption bit are cached to the cache unit.

[0070] From the foregoing content, it can be known that when there is no free tag value in the connected component information table, the scanning needs to be paused first to filter out the target connected components below the target area threshold in the connected component information table to obtain new available free tag values. The pause of scanning here specifically refers to the interruption of pixel-by-pixel scanning, that is, the first scanning interruption in the two-pass scanning method, and the currently scanned target pixel is used as the interruption bit. Then, according to the equivalence table synchronized most recently before reaching the interruption bit, the pixel tag values of the connected components in the binary image are rewritten, and the row pixels before the interruption bit are cached to the cache unit.

[0071] First of all, it should be pointed out that when using the two-pass scanning method for connected component labeling, in the first scan, pixel points are labeled and the equivalence table is updated. In the second scan, according to the updated equivalence table, the labeled value of each pixel point after the first scan is used as the address to read the updated equivalence table, so as to rewrite the original labeled value of the pixel point according to the value in the equivalence table until the interrupt bit at the end of the first scan is scanned, and the second scan is stopped; the first scan of the next round continues to scan from the interrupt bit.

[0072] It can be understood that when the binary image is large, the prior art needs to use the two-pass scanning method for multiple rounds of scanning. For a simple example, assume that the binary image has 9 rows and 9 columns. During the first scan of the first round, it is found that when scanning the 4th pixel point in the 4th row, there is no idle labeled value in the connected component information table at this time, so an interruption occurs, and the 4th pixel point in the 4th row is used as the interrupt bit. Then, the second scan of the first round is executed, that is, starting from the first pixel in the first row, the original labeled value of each pixel point is rewritten in turn according to the value in the equivalence table until all the pixel points before the interrupt bit are rewritten, and then the first scan of the next round is executed starting from the interrupt bit. That is to say, currently, it is necessary to wait until the second scan of the current round is completed before performing the first scan of the next round, resulting in a relatively low overall labeling performance.

[0073] However, in this application, a cache unit is used to cache the row pixels before the interrupt bit. The advantage of doing this is that after caching the row pixels before the interrupt bit into the cache unit, the step of scanning pixel by pixel can continue to be executed starting from the interrupt bit. That is to say, even if the second scan of the current round has not ended, the first scan of the next round can be performed, thereby improving the overall working performance.

[0074] In other words, the strategy adopted in this application is to perform the second scan of the current round and the first scan of the next round simultaneously. Specifically, in this application, the labeled value of the pixels in the connected component in the binary image is rewritten according to the latest synchronized equivalence table before reaching the interrupt bit, and at the same time, the row pixels before the interrupt bit are cached into the cache unit during the rewriting process. When the caching is completed and there is an idle labeled value in the address cache, the pixel-by-pixel scanning can continue with reference to the row pixels before the interrupt bit while rewriting.

[0075] It can be understood that during the first scan of each round, it is necessary to determine whether the neighboring pixels of the target pixel being scanned are all zero-value pixels. In this embodiment, the neighboring pixels of the target pixel are determined according to the four-connected domain mode or the eight-connected domain mode. Whether using a four-neighborhood or an eight-neighborhood, the main reference is the pixel marker values of the pixels on the left side of the target pixel and the pixels in the previous row. Among them, taking the four-connected domain mode as an example, specifically, it is necessary to refer to the pixel on the left side and the pixel above the target pixel. In other words, in the case of determining the marker values of the pixel on the left side and the pixel above the target pixel currently being scanned, the process of the first scan can be started. Therefore, in this embodiment, the row pixels before the interrupt bit in the cache can at least include the pixel data of the row where the interrupt bit is located, can also include the pixel data of the row before the interrupt bit, and can also include the marker values involved in the above pixel data. Thus, the pixel-by-pixel scan after the interrupt bit can be performed with reference to the above pixel data and the involved marker values.

[0076] That is, in a specific embodiment, caching the row pixels before the interrupt bit can specifically refer to caching the row pixels on the left side of the interrupt position and the row pixels of the previous row in the row where the interrupt bit is located. Then, after obtaining the updated equivalence table after the first scan of the first round, the original marker values of the row pixels before the interrupt bit are updated and cached using the equivalence table. After the caching is completed, the first scan of the second round can be continued without waiting for the completion of the second scan of the first round, because during the first scan of the second round, at most only the pixels on the left side of the row where the interrupt bit is located and the pixels of the row above the row where the interrupt bit is located will be used.

[0077] Still taking the above-mentioned 9-row and 9-column binary image as an example, when an interrupt occurs at the 4th pixel point in the 4th row, the pixel marker values before the 4th pixel point in the 4th row are rewritten according to the latest synchronized equivalence table before reaching the interrupt bit. This rewriting can be broken down into two processes. Process one is to rewrite the original marker values of each pixel point in turn according to the values in the equivalence table starting from the 1st pixel in the 1st row according to the traditional scheme. Process two is to update the row pixels before the interrupt bit according to the equivalence table, that is, rewrite the original marker values of the first 3 pixel points in the 4th row and the pixel points in the 3rd row, and cache the rewritten values of the first 3 pixel points in the 4th row and the pixel points in the 3rd row to the cache unit. After the caching is completed, the first scan of the next round can be started from the 4th pixel in the 4th row. Therefore, the marker values of its neighboring pixels are known at this time. When the traditional steps have been executed from the 1st pixel in the 1st row to the 1st pixel point in the 3rd row (or the last pixel point in the 2nd row), the execution of the traditional steps is stopped to avoid repeated rewriting of the first 3 pixel points in the 4th row and the pixel points in the 3rd row.

[0078] Among them, it should also be noted that under the condition of using the four-connected domain mode or the eight-connected domain mode, in order to save the storage space of cache units, it is also possible to only cache the row pixels on the left side of the interruption bit in the row where the interruption position is located, the pixels in the same column as the interruption bit in the previous row, and the row pixels on the right side. For the convenience of understanding, taking the previous example, it is only necessary to cache the first 3 pixel points in the 4th row, and cache the 4th to 9th pixel points in the 3rd row.

[0079] In addition, after the per-pixel scan is interrupted, the row pixels before the interruption bit can be cached into the cache unit first, and then the pixels in the cache unit can be directly rewritten according to the latest synchronized equivalence table before reaching the interruption bit. At the same time, the step of rewriting the original label value of each pixel point according to the value in the equivalence table starting from the starting position or the corresponding interruption bit in the previous round is executed.

[0080] By caching the row pixels before the interruption bit in this application, then at the beginning of the second scan in the current round, while performing the traditional step: that is, starting from the starting position or the corresponding interruption bit in the previous round to rewrite the original label value of each pixel point according to the value in the equivalence table, the row pixels before the interruption bit recorded by the cache unit will also be used to start the first scan of the next round from the current interruption bit in combination with the row pixels before the interruption bit and the rewritten pixel label value, without waiting for the second scan of the current round to be completely completed (that is, completing the rewriting of the original label values of all pixel points between the previous interruption bit and the current interruption bit) before starting the first scan of the next round, thereby improving the overall working performance. And when the traditional step has been executed to the row pixels before the interruption bit, the rewriting is stopped to avoid repeatedly rewriting the original label values of the same part.

[0081] The foregoing embodiments mainly relate to the corresponding marking process when the neighboring pixels of the target pixel being scanned currently are all zero-valued pixels. However, in actual marking situations, there are also cases where the neighboring pixels of the target pixel are all non-zero pixels, or some are zero-valued pixels. Specifically as follows:

[0082] During the scanning process, if all the neighboring pixels of the currently scanned target pixel are zero-valued pixels, a new marking value needs to be assigned to the target pixel; if the neighboring pixels of the target pixel are non-zero pixels and have been marked, the values recorded in the equivalence table are read separately using the marking values of the corresponding neighboring pixels as addresses, and it is determined whether the values read from the equivalence table are equal. If they are equal, the target pixel is marked with the value read from the equivalence table. If the values read from the equivalence table are not equal, it means that there is an equivalence relationship among the marking values of multiple neighboring pixels of the target pixel, and it is necessary to further determine the marking value of the target pixel, and the marking values of these neighboring pixels with an equivalence relationship are called target marking values. It should be noted that when there is only one marked neighboring pixel around the target pixel, the value read from the equivalence table using the marking value of this neighboring pixel as the address can be directly used to mark the target pixel.

[0083] Among them, for the case where there is an equivalence relationship among the marking values of multiple neighboring pixels of the target pixel, the connected component marking method of the present application further includes: during the per-pixel scanning process, a local bitmask is performed on multiple target marking values with an equivalence relationship in the equivalence table in the equivalence linked list to obtain the local equivalence marking value of the scanned target pixel, where the target marking value is the marking value of the neighboring pixel of the target pixel; synchronize the local equivalence marking value of the target pixel to the equivalence table.

[0084] It can be understood that the present application discloses an equivalence linked list. During the per-pixel scanning process, if it is determined according to the equivalence table that there is an equivalence relationship among the marking values of multiple neighboring pixels of the currently scanned target pixel, a local bitmask is performed on these multiple target marking values with an equivalence relationship in the equivalence linked list at the same time, so as to quickly obtain the local equivalence marking value of the target pixel.

[0085] From the foregoing content, it can be seen that the present application can specifically determine the neighboring pixels of the target pixel according to the four-connected domain mode or the eight-connected domain mode. Among them, in the four-connected domain mode, the judgment area is the left pixel and the upper pixel of the target pixel. When reading the equivalence table using the marking values of the left pixel and the upper pixel as addresses, if the values stored correspondingly in the equivalence table are not equal, it means that there is an equivalence relationship; in the eight-connected domain mode, the judgment area is the pixels on the left, upper left, upper, and upper right of the target pixel. When reading the equivalence table using the marking values of the pixels in the judgment area as addresses, if the values stored correspondingly in the equivalence table are not equal, it means that there is an equivalence relationship.

[0086] For ease of understanding, the content of the equivalence table and the equivalence linked list will be described below. First, refer to Figure 3 as shown Figure 3The figure is a schematic diagram of the initialization of an equivalence table disclosed in this application. In the initialization stage, each address value on the left side in the equivalence table is equal to the value stored on its right side, and the numerical range is 0-254. Additionally, it should be noted that the equivalence table in this application is constructed based on REG (Register), rather than SRAM. Compared with SRAM which can only access one address space at a time, REG can access multiple address spaces at a time, thereby further improving the update efficiency of the equivalence table.

[0087] In addition, referring to Figure 4 as shown in Figure 4 The figure is a schematic diagram of the initialization of an equivalence linked list disclosed in this application. In the embodiment of this application, a 255×255 SRAM can be specifically used as the equivalence linked list. The column index of the equivalence linked list is the linked list address value, and the row index is the bit value. Their numerical ranges are both 0-254. Among them, the linked list address value corresponds to the marker value, and the bit value corresponds to the address value in the equivalence table.

[0088] In the initialization stage, the bit corresponding to each address depth in the equivalence linked list is initialized to 1, and other bits are initialized to 0, so that the linked list values on the diagonal in the equivalence linked list are all 1, and the linked list values in the remaining areas are 0. It should be noted that all the linked list values in each row of the equivalence linked list constitute the equivalence mask corresponding to the linked list address value.

[0089] Therefore, in the specific implementation, the local bit masking of multiple target marker values with equivalence relationships in the equivalence table in the equivalence linked list can specifically include: reading the equivalence linked list according to the multiple target marker values to obtain the 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; determining the local equivalence marker value of the target pixel indicated by the merged mask.

[0090] That is, after reading the equivalence table with the neighborhood pixel marker values of the target pixel as addresses respectively, if it is determined that there is an equivalence relationship at the position of the target pixel, these neighborhood pixel marker values are determined as multiple target marker values with equivalence relationships in the equivalence table.

[0091] Furthermore, this application reads the equivalence linked list with the target marker value as the linked list address value to obtain the equivalence masks corresponding to each target marker value respectively, and then merges the equivalence masks corresponding to the multiple target marker values respectively to obtain a merged mask.

[0092] The specific merging method is to perform an OR operation on these equivalence masks, and use the result of the OR operation as the merged mask. Among them, the value of 1 on the corresponding equivalence bit in the result of the OR operation indicates that there is an equivalence at the corresponding bit value.

[0093] Further, determine the local equivalent tag value of the target pixel indicated by the merged mask.

[0094] It should be noted that after merging the equivalent masks corresponding to the multiple target tag values respectively to obtain the merged mask, it further includes: updating the equivalent mask with the lowest number of mask bits among the equivalent masks corresponding to the multiple target tag values to the merged mask.

[0095] It can be understood that after calculating the merged mask in this application, the merged mask needs to be rewritten into the equivalent linked list. Specifically, in this application, the equivalent mask with the lowest number of mask bits among the equivalent masks corresponding to the multiple target tag values is updated to the merged mask. In other words, the minimum tag value is determined from the multiple target tag values, and then the merged mask is written into the linked list address corresponding to the minimum tag value to update the original equivalent mask stored in this linked list address.

[0096] In addition, it should also be noted that the specific process of determining the local equivalent tag value of the target pixel indicated by the merged mask is as follows: after writing the merged mask into the equivalent linked list, according to the bit values corresponding to the linked list values of 1 in the merged mask, the address values with equivalent relationships can be determined from the equivalent table, and then the minimum value is determined from the values stored in these address values, and the minimum value is used as the local equivalent tag value of the target pixel.

[0097] Further, after obtaining the local equivalent tag value of the scanned target pixel by performing a local bit mask on multiple target tag values with equivalent relationships in the equivalent table in the equivalent linked list, the local equivalent tag value is synchronized to the equivalent table to update the equivalent table.

[0098] In the specific implementation manner, the above-mentioned synchronization of the local equivalent tag value of the target pixel to the equivalent table includes: replacing the multiple target tag values in the equivalent table with the local equivalent tag value of the target pixel. That is, after determining the local equivalent tag value of the target pixel, the values corresponding to the multiple target tag values with equivalent relationships in the equivalent table are all replaced with this local equivalent tag value. In this way, this application can update the values in all equivalent tables with equivalent relationships within one time unit according to the OR operation result in the equivalent linked list, thereby improving the update efficiency of the equivalent table.

[0099] It can be seen that by setting up the equivalent linked list, this application can quickly determine the local equivalent tag value of the target pixel according to all the target tag values with equivalent relationships in the equivalent table, and then synchronize it to the equivalent table, thereby improving the update efficiency of the equivalent table and further improving the overall performance.

[0100] To more conveniently understand the content of the equivalent linked list, the following is byFigure 5 For example, a detailed description is as follows:

[0101] After rotating Figure 5 it ninety degrees to the right and viewing it, it shows that the first column is an equivalent linked list, the second column is an equivalent table, and the third column is a simplified diagram of a binary image. It should be noted that considering that the complete equivalent linked list and equivalent table take up a large amount of space, here the equivalent linked list and equivalent table are only exemplified by an address range of 0 - 6. Additionally, the yellow pixels in the binary image represent non-zero pixels, and the red pixel represents the position of the current scan.

[0102] Step 1: Obtain the initialized equivalent linked list, equivalent table, and the original binary image. Among them, the linked list values on the diagonal in the equivalent linked list are all 1, and the linked list values in the remaining areas are 0; each address value on the left in the equivalent table is equal to the value stored on its right.

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

[0104] The specific process is as follows:

[0105] When scanning the first yellow pixel in the first row, it can be marked as 1. When scanning the second yellow pixel in the first row, since its left neighboring pixel is a zero-valued pixel, a new label value 2 is assigned to it. Similarly, the third yellow pixel in the first row is marked as 3.

[0106] Then scan the second row. When scanning the first yellow pixel in the second row, since its left neighboring pixel is a zero-valued pixel and the label value of the upper neighboring pixel is 1, it is also marked as 1. When scanning the second yellow pixel, both its left neighboring pixel and the upper neighboring pixel are non-zero pixels and have been marked. Therefore, the label values of the corresponding neighboring pixels (i.e., 1 and 2) are used as addresses to read the values recorded in the equivalent table respectively. Reading 1 and 2 from the equivalent table, and since they are not equal, it indicates that there is an equivalence relationship at the current position. That is, it means that there is an equivalence relationship between the target label values with address values 1 and 2 in the equivalent table.

[0107] Furthermore, using the target label values 1 and 2 as the linked list address values to read the equivalent linked list, the equivalent mask corresponding to the target label value 1 read from the equivalent linked list is "0100000", and the equivalent mask corresponding to the target label value 2 is "0010000". Then, perform an OR operation on these two equivalent masks to obtain the OR operation result "0110000", that is, obtain the merged mask. Then compare the sizes of the two target label values, and determine the minimum label value 1 from them. Write the merged mask into the linked list address corresponding to 1, thereby obtainingFigure 5 Schematic diagram of the third equivalent linked list in the first column. Then, determine the bit values corresponding to the linked list values of 1 in the merge mask from the equivalent linked list, and it can be known that the values corresponding to address value 1 and address value 2 in the equivalent table should be the same. At the same time, rewrite the values at these two positions, and the rewritten value is the minimum of the two. In this example, the values corresponding to address value 1 and address value 2 in the equivalent table are both written as 1.

[0108] Step 3: Continue pixel scanning according to the above method. When the third yellow pixel in the third row is scanned, since its left neighborhood pixel and the upper neighborhood pixel are both non-zero pixels and have been marked, the corresponding neighborhood pixel mark values (i.e., 1 and 3) are used as addresses to read the values recorded in the equivalent table respectively. The values 1 and 3 are read from the equivalent table, and they are not equal, indicating that there is also an equivalent relationship at the current position. Then, read the equivalent masks corresponding to 1 and 3 from the equivalent linked list, which are 0110000 and 0001000 respectively. Then perform an OR operation to get 0111000, and write the result of the OR operation into the linked list address corresponding to 1 in the equivalent linked list, so as to obtain Figure 5 Schematic diagram of the fourth equivalent linked list in the first column. Then, according to the value of the OR operation result, it can be known that the values corresponding to address value 1 and address value 3 in the equivalent table should be the same. At the same time, rewrite the values at these two positions, and the rewritten value is the minimum of the two, that is, rewrite it as 1. The subsequent scanning process is similar.

[0109] In addition, as Figure 6 and Figure 7 shown, Figure 6 is the equivalent schematic diagram of the four-connected domain mode, Figure 7 is the equivalent schematic diagram of the eight-connected domain mode. The red pixel in the figure represents the position of the current scan. Figure 6 When marking the red pixel, the mark values of its left and upper neighborhood pixels need to be referred to. From the foregoing content, it can be known that the position of the red pixel should be marked as the minimum of the two, that is, marked as 1. Figure 7 When marking the red pixel, the mark values of its left, upper left, upper, and upper right neighborhood pixels need to be referred to. From the foregoing content, it can be known that the position of the red pixel should be marked as the minimum of them, that is, marked as 1.

[0110] Refer to Figure 8 shown, the present application discloses a connected component labeling device, including:

[0111] A mark value reading module 11, configured to, when performing pixel-by-pixel scanning, if the currently scanned target pixel meets the marking condition, read an idle mark value from a preset address cache; wherein, the idle mark value is the mark value with empty information in the connected component information table;

[0112] A marking module 12 is used to mark the target pixel by using the idle marking value.

[0113] It can be seen that when the present application performs pixel-by-pixel scanning, if the currently scanned target pixel meets the marking condition, an idle marking value is read from a preset address cache; wherein, the idle marking value is a marking value with empty information in the connected component information table; the target pixel is marked by using the idle marking value. In the traditional solution, if the currently scanned target pixel meets the marking condition, it is necessary to traverse and search for a marking value with empty information in the connected component information table for marking. However, the traversal and search method is time-consuming, resulting in poor scanning performance during the marking process. In the present application, an address cache is preset to store the marking values with empty information in the connected component information table. Then, when the currently scanned target pixel meets the marking condition, the idle marking value is directly read from the address cache to mark the target pixel, without the need to traverse and search the connected component information table, improving the scanning performance, and thus further improving the performance of connected component marking.

[0114] The execution process of the above device can refer to the execution process of the above connected component marking method, which will not be elaborated here. The device also has the same beneficial effects as those in the above method embodiments.

[0115] Figure 9 It is a schematic structural diagram of an electronic device provided in an embodiment of the present 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. Among them, the memory 22 is used to store a computer program, and the computer program is loaded and executed by the processor 21 to implement the relevant steps in the connected component marking method executed by the electronic device disclosed in any of the foregoing embodiments.

[0116] 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 is any communication protocol applicable to the technical solution of the present application, which will not be specifically limited here; the input / output interface 25 is used to obtain external input data or output data to the outside, and its specific interface type can be selected according to specific application needs, which will not be specifically limited here.

[0117] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), or PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the wake state, also known as the CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a GPU (Graphics Processing Unit), and the GPU is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may further include an AI (Artificial Intelligence) processor, and the AI processor is used to process computational operations related to machine learning.

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

[0119] Among them, the operating system 221 is used to manage and control each hardware device and the computer program 222 on the electronic device 20, so as to realize the operation and processing of the massive data 223 in the memory 22 by the processor 21. It may be Windows, Unix, Linux, etc. In addition to the computer program that can be used to complete the connectivity domain marking method executed by the electronic device 20 disclosed in any of the foregoing embodiments, the computer program 222 may further include computer programs that can be used to complete other specific tasks. The data 223 may include not only the data transmitted by external devices received by the electronic device, but also the data collected by its own input / output interface 25, etc.

[0120] Furthermore, the embodiments of the present application also disclose a computer-readable storage medium. When the computer program stored in the storage medium is loaded and executed by a processor, the steps of the connectivity domain marking method disclosed in any of the foregoing embodiments are realized.

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

[0122] In this specification, the various embodiments are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. For the same or similar parts among the various embodiments, reference can be made to each other. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple. For the relevant parts, reference can be made to the description in the method section.

[0123] Those skilled in the art can further realize that the units and algorithm steps of the examples described in combination with the embodiments disclosed in this article can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of the examples have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner 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 to exceed the scope of this application.

[0124] The steps of the methods or algorithms described in combination with the embodiments disclosed in this article can be directly implemented by hardware, software modules executed by a processor, or a combination of the two. The software modules can be placed in a random access memory (Random Access Memory, i.e., RAM), internal memory, read-only memory (Read-Only Memory, i.e., ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disks, removable disks, compact disc read-only memory (Compact Disc Read-Only Memory, i.e., CD-ROM), or any other form of storage medium well-known in the technical field.

[0125] Finally, it should also be noted that in this text, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising said element.

[0126] The above has introduced in detail a connected component labeling method, apparatus, device and storage medium provided by the present invention. Specific examples are used herein to elaborate on the principle and implementation manner of the present invention. The description of the above embodiments is only used to help understand the method and its core idea of the present invention; at the same time, for those of ordinary skill in the art, according to the idea of the present invention, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to the present invention.

Claims

1. A connected component labeling method, characterized in that, Including: During per-pixel scanning, if the currently scanned target pixel meets the marking condition, read the idle marking value from a preset address cache; wherein, the idle marking value is the marking value with empty information in the connected component information table; Mark the target pixel with the idle marking value.

2. The connected component labeling method according to claim 1, characterized in that The process of caching the idle marking value into a preset address cache includes: When there is no idle marking value in the connected component information table, filter out the target connected components in the connected component information table that are below the target area threshold; Cache the marking values corresponding to the target connected components in the connected component information table as new idle marking values into the address cache.

3. The connected component labeling method according to claim 2, characterized in that, The filtering out of the target connected components in the connected component information table that are below the target area threshold includes: When there are no target connected components in the connected component information table that are below the target area threshold, accumulate a plurality of growth steps to the target area threshold to form multiple alternative area thresholds; Compare the areas of the connected components in the connected component information table with the multiple alternative area thresholds respectively to determine the target connected components whose areas are smaller than any of the alternative area thresholds.

4. The connected component labeling method according to claim 3, wherein The comparing the areas of the connected components in the connected component information table with the multiple alternative area thresholds respectively to determine the target connected components whose areas are smaller than any of the alternative area thresholds includes: Judge whether there are target connected components in the connected component information table that are below any of the alternative area thresholds; If so, use the smallest alternative area threshold when the judgment condition is reached as the target area threshold, and delete the target connected components in the connected component information table that are below the smallest alternative area threshold; If not, continue to accumulate growth steps to the multiple alternative area thresholds to form multiple new alternative area thresholds, and continue to judge whether there are target connected components in the connected component information table that are below any of the new alternative area thresholds.

5. The connected component labeling method according to claim 1, wherein The marking condition includes: All the neighboring pixels of the currently scanned target pixel are zero-value pixels.

6. The connected component labeling method according to any one of claims 1 to 5, characterized in that, Also including: When there is no idle marking value in the connected component information table, the per-pixel scanning is interrupted, and the currently scanned target pixel is used as the interrupt bit; According to the equivalence table synchronized latest before reaching the interrupt bit, rewrite the pixel marking values of the connected components in the binary image, and cache the row pixels before the interrupt bit into the cache unit.

7. The connected component labeling method according to claim 6, wherein The "if the currently scanned target pixel meets the marking condition" includes: When starting per-pixel scanning from the interrupt bit, judge whether all the neighboring pixels of the currently scanned target pixel are zero-value pixels based on the row pixels before the interrupt bit stored in the cache unit; If so, determine that the currently scanned target pixel meets the marking condition.

8. A connected component labeling device, characterized in that Including: A marking value reading module, configured to, during per-pixel scanning, if the currently scanned target pixel meets the marking condition, read the idle marking value from a preset address cache; wherein, the idle marking value is the marking value with empty information in the connected component information table; A marking module, configured to mark the target pixel with the idle marking value.

9. An electronic device, characterized in that, Including: A memory, configured to store a computer program; A processor, configured to execute the computer program to implement the steps of the connected component marking method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, For storing a computer program; wherein, when the computer program is executed by a processor, the steps of the connected component labeling method according to any one of claims 1 to 7 are implemented.