Parallel connected domain analysis method based on neighborhood labeling, computer equipment and storage medium
By parallelizing the search for parent and root nodes, merging regions, and utilizing GPU hardware acceleration and hash optimization methods, this paper addresses the efficiency bottleneck of traditional connected component analysis algorithms in high-resolution images and real-time applications, achieving efficient and robust connected component analysis.
Patent Information
- Application Number
- CN202511892999.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-15
- Publication Date
- 2026-03-20
AI Technical Summary
Traditional connected component analysis algorithms are difficult to parallelize efficiently, especially in applications that process high-resolution images or require real-time processing, where they suffer from large synchronization overhead and complex communication logic.
We employ a parallel approach to find the parent and root nodes in a grayscale image, establish an initial region, and merge mergeable regions. We utilize the acceleration capabilities of parallel computing hardware such as GPUs and use a hash optimization method involving grouped local reduction and global merging to calculate the area of connected components.
It significantly improves the processing speed and efficiency of connected component analysis, reduces atomic conflicts, enhances the robustness of the algorithm in parallel computing environments, and supports fast processing and real-time applications of high-resolution images.
Smart Images

Figure CN121707810A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to a parallelized connected component analysis method, computer device, and storage medium based on neighborhood labeling. Background Technology
[0002] Connected component analysis is a fundamental and crucial technique in computer vision and image processing. Its purpose is to find and label interconnected sets of pixels with the same pixel value in an image. This technique is widely used in many scenarios such as object recognition, defect detection, medical image analysis, and optical character recognition (OCR).
[0003] Traditional connected component analysis algorithms, such as the Two-Pass Algorithm, can accurately label connected components, but their inherent sequential processing logic makes them difficult to parallelize efficiently. In applications processing high-resolution images or requiring real-time performance, their serial execution becomes a performance bottleneck. With the development of parallel computing hardware such as Graphics Processing Units (GPUs), developing algorithms that fully utilize hardware parallelism has become a technological trend. While some parallelization attempts exist, they often introduce significant synchronization overhead or complex communication logic when handling complex region adjacency relationships and merging conflicts, resulting in unsatisfactory parallel efficiency and complex algorithm implementation.
[0004] Therefore, the market urgently needs a connected component analysis method with a clear computational structure, high parallelism, and the ability to efficiently process large-scale images.
[0005] The above information is provided as background information only to aid in understanding the present invention, and does not constitute an assertion or admission that any of the above content can be used as prior art relative to the present invention. Summary of the Invention
[0006] This invention provides a parallelized connected component analysis method, computer device, and storage medium based on neighborhood labeling to solve the problems existing in the prior art.
[0007] To achieve the above objectives, the present invention provides the following technical solution:
[0008] In a first aspect, the present invention provides a parallelized connected component analysis method based on neighborhood labeling, the method comprising:
[0009] S101. Use a parallel approach to find the parent node of each pixel in the grayscale image;
[0010] S102. Using a parallel approach, find the root node of each pixel based on its parent node;
[0011] S103. Using a parallel approach, pixels belonging to the same root node are grouped into an initial region, and the corresponding root node number is used as the number of the initial region.
[0012] S104. Using a parallel approach, find the boundary points between adjacent and mergeable initial regions.
[0013] S105. Using a parallel approach, establish mapping relationships between adjacent and mergeable initial regions to obtain mapping groups;
[0014] S106. Establish the final mapping relationship between multiple regions in a parallel manner;
[0015] S107. Using a parallel approach, based on the final mapping relationship between multiple regions, update the number of the initial region to which all pixels belong to the number of the initial region to which they are finally mapped, in order to complete the connected component labeling.
[0016] S108. Adopting the acceleration approach of grouping local reduction and global merging, hash optimization is used to calculate the area of each connected component.
[0017] Further, in the parallelized connected component analysis method based on neighborhood labeling, step S101 includes:
[0018] S1011. Using a parallel approach, the gray value of each pixel in the grayscale image is compared sequentially with the gray values of neighboring pixels in a preset neighborhood.
[0019] S1012. If the absolute value of the grayscale difference between the pixel and one of the adjacent pixels is less than a preset first threshold, then the corresponding adjacent pixel is determined as the parent node of the pixel.
[0020] S1013. If the absolute value of the grayscale difference between the pixel and any of the adjacent pixels is not less than a preset first threshold, then the parent node of the pixel is determined to be itself.
[0021] Furthermore, in the parallelized connected component analysis method based on neighborhood labeling, the preset neighborhood is the top-left neighborhood, the top neighborhood, the top-right neighborhood, and the left neighborhood.
[0022] Furthermore, in the parallelized connected component analysis method based on neighborhood labeling, step S102 includes:
[0023] S021. Using a parallel approach, trace upwards along the parent node of each pixel;
[0024] S1022. If a pixel is found whose parent node is itself, then the pixel whose parent node is itself is taken as the root node of the pixel; wherein, the root node of the pixel whose parent node is itself is also itself.
[0025] Furthermore, in the parallelized connected component analysis method based on neighborhood labeling, step S104 includes:
[0026] S1041. Using a parallel approach, compare the number of the initial region to which each pixel belongs with the number of the initial region to which its neighboring pixels belong.
[0027] S1042. If the numbers are different and the grayscale difference between the two is less than the preset second threshold, then the two initial regions to which they belong are mergeable regions, and the pixel is marked as the region boundary point.
[0028] Furthermore, in the parallelized connected component analysis method based on neighborhood labeling, step S105 includes:
[0029] S1051. Using a parallel approach, continuously count the boundary points of the region along a preset direction;
[0030] S1052. Map the numbers of the initial regions to which these consecutive regional boundary points belong to to the numbers of the adjacent and mergeable initial regions to obtain a mapping group.
[0031] Furthermore, in the parallelized connected component analysis method based on neighborhood labeling, step S1052 includes:
[0032] S10521. When the number of consecutive regional boundary points exceeds a preset threshold, the numbers of the initial regions to which these consecutive regional boundary points belong are mapped to the numbers of the adjacent and mergeable initial regions to obtain a mapping group.
[0033] Furthermore, in the parallelized connected component analysis method based on neighborhood labeling, step S106 includes:
[0034] S1061. Using a parallel approach, all related mapping groups are ultimately mapped to the initial region with the smallest number among them, thereby establishing the final mapping relationship between multiple regions.
[0035] In a second aspect, the present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the parallelized connected component analysis method based on neighborhood labeling as provided in the first aspect above.
[0036] Thirdly, the present invention provides a computer-readable storage medium having computer-executable instructions stored thereon, which are executed by a computer processor to implement the parallelized connected component analysis method based on neighborhood labeling as provided in the first aspect above.
[0037] Compared with the prior art, the present invention has the following beneficial effects:
[0038] This invention provides a parallelized connected component analysis method, computer device, and storage medium based on neighborhood labeling. Through highly parallel design, the steps of finding parent nodes, root nodes, and region boundary points, establishing mappings, and renumbering are all designed to be independently parallel computations. This fully utilizes the acceleration capabilities of parallel computing hardware such as GPUs, significantly improving processing speed. It is also easily scalable and can efficiently process large-scale high-resolution images. Furthermore, by employing a hash optimization method of grouped local reduction and global merging to calculate the area of each connected component, it effectively reduces atomic collisions, improves statistical efficiency, and further enhances the robustness of the algorithm in a parallel computing environment. Thus, it not only significantly improves the efficiency of the connected component analysis algorithm but also enables rapid processing of high-resolution images, providing strong support for real-time and large-scale applications in the fields of computer vision and image processing.
[0039] The present invention has other features and advantages, which will be apparent from or will be set forth in detail in the accompanying drawings and the following detailed description, which together serve to explain the particular principles of the invention. Attached Figure Description
[0040] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0041] Figure 1 This is a flowchart illustrating a parallelized connected component analysis method based on neighborhood labeling provided in Embodiment 1 of the present invention.
[0042] Figure 2 This is a schematic diagram of the original grayscale image provided in Embodiment 1 of the present invention;
[0043] Figure 3 This is a schematic diagram of the parent node relationship diagram provided in Embodiment 1 of the present invention;
[0044] Figure 4This is a schematic diagram of the example image provided in Embodiment 1 of the present invention being initially divided into 3 independent regions;
[0045] Figure 5 This is a schematic diagram of the boundary diagram provided in Embodiment 1 of the present invention;
[0046] Figure 6 This is a schematic diagram of the mapping relationship between region 2 and region 3 provided in Embodiment 1 of the present invention;
[0047] Figure 7 This is a schematic diagram of the final marking result provided in Embodiment 1 of the present invention;
[0048] Figure 8 This is a schematic diagram of the processing results of multiple images of different scenes provided in Embodiment 1 of the present invention;
[0049] Figure 9 This is a schematic diagram of the structure of a computer device provided in Embodiment 2 of the present invention. Detailed Implementation
[0050] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0051] Example 1
[0052] Please refer to Figure 1 , Figure 1 This is a flowchart illustrating a parallelized connected component analysis method based on neighborhood labeling, provided in Embodiment 1 of the present invention. This method is suitable for scenarios with high requirements for computational efficiency and accuracy, such as high-resolution image processing, real-time object recognition, defect detection, and medical image analysis. By employing a highly parallelized processing flow, it fully utilizes the acceleration capabilities of parallel computing hardware (such as GPUs) to improve the speed and efficiency of connected component analysis. Simultaneously, it uses specific optimization methods to calculate the area of connected components, enhancing the robustness of the algorithm in a parallel computing environment. The method specifically includes the following steps:
[0053] S101. Use a parallel approach to find the parent node of each pixel in the grayscale image;
[0054] It's important to note that in connected component analysis, determining the parent node of each pixel is fundamental to constructing connectivity relationships. By finding the parent node, we can initially establish the hierarchical relationships between pixels, preparing for subsequent searches for the root node and the determination of connected components.
[0055] Since the parent node lookup operation for each pixel is independent and does not depend on the lookup results of other pixels, it is possible to perform parent node lookups on all pixels in the image simultaneously in parallel. For example, in a GPU, different regions of the image can be assigned to different computing cores, with each core responsible for handling the parent node lookup task for a portion of the pixels, thereby significantly reducing the lookup time.
[0056] In one embodiment of this example, step S101 can be further refined to include the following steps:
[0057] S1011. Using a parallel approach, the gray value of each pixel in the grayscale image is compared sequentially with the gray values of neighboring pixels in a preset neighborhood.
[0058] This invention uses a 4x4 original grayscale image, such as... Figure 2 For example.
[0059] Specifically, the preset neighborhood consists of the top-left neighborhood, the top neighborhood, the top-right neighborhood, and the left neighborhood. These four neighborhoods are chosen based on common considerations regarding the connectivity of image pixels. These neighborhoods can cover the relatively close adjacent areas around each pixel, helping to accurately determine the connectivity relationships between pixels. In practical applications, the range and direction of the neighborhood can also be adjusted according to specific needs and image characteristics.
[0060] S1012. If the absolute value of the grayscale difference between the pixel and one of the adjacent pixels is less than a preset first threshold, then the corresponding adjacent pixel is determined as the parent node of the pixel.
[0061] It should be noted that the absolute value of the grayscale difference between a pixel and its neighboring pixels is calculated and compared with a preset first threshold. When the absolute value of the grayscale difference between a neighboring pixel and the current pixel is less than the threshold, it indicates that the two pixels are relatively close in grayscale value and have a certain degree of similarity. They may belong to the same connected region in the image, so the neighboring pixel is determined as the parent node of the current pixel.
[0062] For example, if the preset first threshold is 5, when the absolute value of the difference between the grayscale value of the current pixel and a neighboring pixel is less than 5, that neighboring pixel is defined as the "parent node" of the current pixel. The choice of this threshold needs to be made reasonably based on the specific characteristics of the image and the analysis requirements. If the threshold is set too high, pixels from different connected components may be incorrectly merged; if the threshold is set too low, pixels from the same connected component may be separated, affecting the accuracy of connected component analysis.
[0063] S1013. If the absolute value of the grayscale difference between the pixel and any of the adjacent pixels is not less than a preset first threshold, then the parent node of the pixel is determined to be itself.
[0064] It should be noted that when the absolute value of the grayscale difference between a pixel and all its neighboring pixels in a preset neighborhood is not less than a preset first threshold, it indicates that the current pixel has a large difference in grayscale value with its neighboring pixels, and the connectivity condition is not met. In this case, the pixel has no neighboring pixels connected to it in its local area, so it is determined as its parent node.
[0065] In this case, the pixel is actually defined as the "root node". Because the root node is the starting point of a connected component, and no other pixel can be its parent node, its parent node is itself. This step ensures that every pixel in the image has a definite parent node, even if it is not connected to any neighboring pixels.
[0066] After this step is completed, each pixel in the image has a definite parent node, thus forming a parent node relationship graph, such as... Figure 3 As shown, this parent-node relationship graph visually illustrates the hierarchical relationships and connectivity information between pixels in the image, providing crucial foundational data for subsequent steps such as finding the root node, dividing the initial region, and establishing mapping relationships.
[0067] S102. Using a parallel approach, find the root node of each pixel based on its parent node;
[0068] It's important to note that the root node represents a connected component, and finding the root node determines the connected component to which each pixel ultimately belongs. By tracing upwards from the parent node until the node without a parent node, i.e., the root node, the pixel's affiliation within the connected component is clearly defined.
[0069] Similar to finding the parent node, the root node search process for each pixel is also independent. Given the parent node of each pixel, the root node search can be performed on each pixel in parallel. Different computational cores can handle the tracing process of different pixels simultaneously, improving search efficiency.
[0070] In one embodiment of this example, step S102 can be further refined to include the following steps:
[0071] S021. Using a parallel approach, trace upwards along the parent node of each pixel;
[0072] It should be noted that tracing upwards along the parent node chain of each pixel means starting from the current pixel, continuously searching for its parent node, and then searching for the parent node's parent node, repeating this process until a node that satisfies a specific condition is found. In this process, the connected component information to which each pixel belongs is gradually determined.
[0073] S1022. If a pixel is found whose parent node is itself, then the pixel whose parent node is itself is taken as the root node of the pixel; wherein, the root node of the pixel whose parent node is itself is also itself.
[0074] It's important to note that when tracing the parent node chain, finding a pixel whose parent node is itself means that the starting point of the connected component, i.e., the root node, has been reached. Since the root node has no other pixels as its parent, its parent is itself. At this point, this pixel whose parent node is itself is determined as the root node of all pixels on the current tracing path.
[0075] The parent node is itself, and the pixel itself is also the root node. This reflects the special property of the root node: it is the identifier and starting point of a connected component. In this way, it can be ensured that each pixel can find the root node of its connected component, thus achieving preliminary region division of the image.
[0076] S103. Using a parallel approach, pixels belonging to the same root node are grouped into an initial region, and the corresponding root node number is used as the number of the initial region.
[0077] It should be noted that this step involves grouping pixels with the same root node together to form an initial region, and assigning a unique number (i.e., root node number) to each initial region. This allows for the preliminary division of connected components in the image, preparing for subsequent region merging and final labeling.
[0078] Since the pixel set operations corresponding to different root nodes are independent of each other, pixel set and number assignment can be performed on each root node in parallel. For example, in a GPU, different computing cores can process the pixel set tasks corresponding to different root nodes separately, while assigning numbers to these initial regions.
[0079] After this step, the example image is initially divided into 3 independent regions, as follows: Figure 4 As shown, this indicates that by finding the root node and initially dividing the connected components, pixels with similar gray values and that are connected have been grouped together, providing a foundation for subsequent more precise connected component analysis and labeling.
[0080] After this step, the root node to which each pixel in the image belongs is determined, thus completing the initial region division of the image. This initial division is based on the connectivity and gray-level similarity between pixels, providing an important reference for subsequent operations such as connected component merging and optimization.
[0081] S104. Using a parallel approach, find the boundary points between adjacent and mergeable initial regions.
[0082] It should be noted that after initially defining the initial regions, it is necessary to find the boundary points between adjacent initial regions that meet the merging criteria. These boundary points are crucial for determining whether the initial regions can be merged; by finding these boundary points, it can be determined which initial regions need to be merged.
[0083] For different regions in an image, the boundary points between their adjacent initial regions can be found in parallel. For example, the image can be divided into multiple sub-regions, and each computing core is responsible for finding the boundary points within one sub-region. The location of the boundary points is determined by exchanging and judging information between adjacent sub-regions.
[0084] In one embodiment of this example, step S104 can be further refined to include the following steps:
[0085] S1041. Using a parallel approach, compare the number of the initial region to which each pixel belongs with the number of the initial region to which its neighboring pixels belong.
[0086] It should be noted that for each pixel in the image, its initial region number is obtained, and then compared sequentially with the initial region numbers of adjacent pixels within a preset neighborhood (such as the top-left neighborhood, top neighborhood, top-right neighborhood, and left neighborhood). Through this comparison, it is possible to preliminarily determine whether there is any possible connectivity between the current pixel's region and its adjacent regions.
[0087] S1042. If the numbers are different and the grayscale difference between the two is less than the preset second threshold, then the two initial regions to which they belong are mergeable regions, and the pixel is marked as the region boundary point.
[0088] It should be noted that when the initial region number of the current pixel is different from that of its neighboring pixels, it indicates that these two pixels may belong to different initial regions. Further examination of their grayscale difference reveals that if the difference is less than a preset second threshold, it means that the two pixels are quite similar in grayscale value and likely belong to the same connected component. However, due to limitations in the previous steps, they were incorrectly segmented into different initial regions. Therefore, the two initial regions to which these two pixels belong are determined to be mergeable regions, and the current pixel is marked as the region boundary point.
[0089] The selection of the preset second threshold needs to be reasonably set based on the specific characteristics of the image and the analysis requirements. It is similar to the first threshold in the previous steps, but can be adjusted according to the needs of different stages. If the threshold is set too high, it may incorrectly merge regions of different connected components; if the threshold is set too low, it may miss some regions that really need to be merged, affecting the accuracy of connected component analysis.
[0090] All identified boundary point information is recorded in a memory address `labelCombine` of the same size as the original image, forming a structure like this: Figure 5 The boundary map shown is a visual representation of the boundaries between regions in the image that need to be merged, providing clear guidance for subsequent connected component merging operations.
[0091] by Figure 4 For example, point (2,2) in region 2 and point (2,1) in region 3 are adjacent. Figure 2 The original grayscale values show that the grayscale difference between the two points is less than the threshold of 5 (assuming the preset second threshold is 5). In step S104, when processing point (2,2), it is found that its initial region number is different from that of the adjacent point (2,1), and the grayscale difference meets the condition of being less than the threshold. Therefore, region 2 and region 3 are determined to be mergeable regions, and point (2,2) is marked as the region boundary point. Similarly, point (2,1) will be processed in a similar way. By traversing all pixels in parallel, the boundaries between all similar regions that need to be merged can be found.
[0092] After this step is completed, a boundary map is obtained, recording the boundary point information of all regions. This boundary map clearly shows which initial regions need to be merged, providing accurate location information for subsequent connected component merging operations.
[0093] S105. Using a parallel approach, establish mapping relationships between adjacent and mergeable initial regions to obtain mapping groups;
[0094] It should be noted that establishing a mapping relationship between adjacent and merging initial regions is to clarify which initial regions need to be merged together, and the corresponding relationships after the merger. Mapping groups facilitate subsequent region merging and numbering update operations.
[0095] Since the mapping relationship establishment operations between different adjacent initial regions are independent of each other, they can be performed in parallel. Each computing core can be responsible for a portion of the mapping relationship establishment task for adjacent initial regions, determining the mapping relationship and forming a mapping group based on the boundary point information and merging conditions.
[0096] In one embodiment of this example, step S105 can be further refined to include the following steps:
[0097] S1051. Using a parallel approach, continuously count the boundary points of the region along a preset direction;
[0098] It should be noted that the preset direction is usually set based on the connectivity characteristics of the image pixels, such as the horizontal direction (left → right) or the vertical direction (top → bottom). Choosing an appropriate direction helps to efficiently capture continuous sequences of boundary points and avoid missing key merging information.
[0099] Statistical process description: Starting from a specific "starting point" pixel (such as the first boundary point in the upper left corner of the image), adjacent pixels are checked sequentially along a preset direction to see if they are region boundary points. If multiple consecutive pixels are marked as boundary points, a continuous sequence of boundary points is formed, providing a basis for establishing subsequent mapping relationships.
[0100] S1052. Map the numbers of the initial regions to which these consecutive regional boundary points belong to to the numbers of the adjacent and mergeable initial regions to obtain a mapping group.
[0101] It should be noted that for the statistically obtained sequence of consecutive boundary points, the initial region number and the numbers of adjacent regions are analyzed. If two initial regions are connected by consecutive boundary points and meet the merging conditions (such as the grayscale difference being less than a preset threshold), then the number of one region is mapped to the number of the other region, forming an "A→B" mapping relationship.
[0102] By processing all consecutive boundary point sequences in parallel, multiple sets of mapping relationships can be established simultaneously, and finally integrated into a complete mapping group. For example, in Figure 5 In the boundary map, by analyzing continuous boundary points, a mapping relationship of "Region 2 → Region 3" can be established (e.g., Figure 6 As shown in the figure, this indicates that region 2 and region 3 need to be merged.
[0103] Specifically, S1052 can be further refined to include the following steps:
[0104] S10521. When the number of consecutive regional boundary points exceeds a preset threshold, the numbers of the initial regions to which these consecutive regional boundary points belong are mapped to the numbers of the adjacent and mergeable initial regions to obtain a mapping group.
[0105] It should be noted that, to enhance the robustness of the algorithm, a threshold for the number of consecutive boundary points is set (e.g., 3 or 5). A mapping relationship is only established when the number of consecutive boundary points exceeds this threshold. This design effectively filters out pseudo-connected regions caused by image noise and avoids erroneous merging due to accidental pixel value fluctuations.
[0106] Noise typically manifests as isolated or short sequences of boundary points. By using threshold filtering, only sequences of boundary points with significant continuity are retained, ensuring that the mapping relationship is based on the true boundaries of connected regions, thus improving the accuracy and stability of the algorithm.
[0107] by Figure 5 and Figure 6 For example, after identifying the boundary point between region 2 and region 3 in step S104, step S105 counts consecutive boundary points along the horizontal direction. If more than three consecutive boundary points are found from (2,1) to (2,3) (exceeding a preset threshold), a mapping relationship of "region 2 → region 3" is established. This mapping indicates that region 2 and region 3 actually belong to the same connected domain and need to be merged into one region in subsequent steps.
[0108] After this step is completed, a complete mapping group is formed, clarifying the correspondence between all the initial regions that need to be merged. These mapping relationships provide a direct basis for subsequent steps S106 (establishing the final mapping relationship) and S107 (updating pixel numbers), ensuring that the connected component merging operation is accurate and efficient.
[0109] S106. Establish the final mapping relationship between multiple regions in a parallel manner;
[0110] It should be noted that after establishing the mapping group of adjacent initial regions, there may be cases where multiple initial regions are merged multiple times to form a larger connected region. Therefore, it is necessary to further establish the final mapping relationship between multiple regions to accurately reflect the final state after merging all initial regions.
[0111] Parallel algorithms can be used to further process and analyze the mapping group, comprehensively considering the merging relationships between multiple regions to establish the final mapping relationship. For example, parallel graph algorithms or parallel data structures can be used to process the mapping group and determine the target region that each initial region will ultimately map to.
[0112] In one embodiment of this example, step S106 can be further refined to include the following steps:
[0113] S1061. Using a parallel approach, all related mapping groups are ultimately mapped to the initial region with the smallest number among them, thereby establishing the final mapping relationship between multiple regions.
[0114] It should be noted that the previous step only established a direct mapping between adjacent regions. In complex images, many-to-one or transitive mapping relationships such as A→B, B→C, and D→C often occur. This step aims to globally merge these scattered pairwise mapping relationships, ensuring that all initial regions ultimately belonging to the same connected component can be mapped to a unique root region. This invention employs an efficient parallel approach, using memory blocks such as LabelGroups and LabelLinks to record and process the associations between different mapping groups. By comparing and linking the numbers of these mapping groups in parallel, the algorithm can ultimately map all associated regions to the number of the initial region with the smallest number, thereby establishing a global and final mapping relationship.
[0115] Suppose that in image analysis, the following mapping groups are obtained after step S105: Mapping group 1 is "Region 3 → Region 5", mapping group 2 is "Region 5 → Region 7", and mapping group 3 is "Region 2 → Region 7". In step S106, through parallel processing, LabelGroups and LabelLinks are used to record and analyze the relationships between these mapping groups. It is found that these three mapping groups are related because they all form transitive mapping relationships around Region 5 and Region 7. After comparing the numbers of Regions 2, 3, 5, and 7, assuming that Region 2 has the smallest number, then Regions 3, 5, and 7 are all mapped to Region 2, ultimately establishing the final mapping relationships "Region 3 → Region 2", "Region 5 → Region 2", and "Region 7 → Region 2". This indicates that Regions 2, 3, 5, and 7 ultimately belong to the same connected component, with Region 2 as the root region.
[0116] After this step is completed, a global and final mapping relationship is successfully established. All initial regions that ultimately belong to the same connected component are mapped to a unique root region. These final mapping relationships provide accurate guidance for the subsequent S107 step (updating pixel numbers), ensuring that all pixels belonging to the same connected component can be correctly updated to the same number, thereby completing the merging of connected components and obtaining accurate and complete connected component labeling results.
[0117] S107. Using a parallel approach, based on the final mapping relationship between multiple regions, update the number of the initial region to which all pixels belong to the number of the initial region to which they are finally mapped, in order to complete the connected component labeling.
[0118] It should be noted that this step is the final step in completing the final connected component labeling. Based on the globally unique mapping relationship established in the previous steps, all pixels in the image are traversed in parallel.
[0119] The initial region numbers of each pixel are updated based on the final mapping relationship, ensuring that each pixel's number corresponds to its final connected component, thus completing the connected component labeling task for the entire image. This is the core step of connected component analysis; updating the numbers clearly identifies each connected component in the image.
[0120] Since the numbering update operation for each pixel depends only on the final mapping relationship of its initial region and is independent of the update operations for other pixels, the numbering updates for all pixels can be performed in parallel. Different computing cores can process the numbering update tasks for different pixels simultaneously, improving update efficiency.
[0121] For example, in this embodiment, all pixels initially belonging to region 2 will have their region number updated to 3. After this step, all pixels belonging to the same connected component in the image will have the same, unique region number, thus obtaining... Figure 7 The final labeling result is shown.
[0122] S108. Adopting the acceleration approach of grouping local reduction and global merging, hash optimization is used to calculate the area of each connected component.
[0123] It should be noted that after completing the connected component labeling, it is usually necessary to statistically analyze the characteristics of each region, such as its area.
[0124] Calculating the area of each connected component is an important application of connected component analysis. By calculating the area, we can obtain information about the size of the connected components, providing a reference for subsequent tasks such as object recognition and defect detection. Employing a grouped local reduction and global merging approach, along with hash optimization methods, can improve statistical efficiency and reduce collisions during computation.
[0125] Specific methods:
[0126] Grouped Local Reduction: The image is divided into multiple groups, and the pixels within each group undergo local area reduction. For example, within each group, the number of pixels belonging to the same connected component is accumulated to obtain the local area statistics of each connected component within the group.
[0127] Global merging: The local area statistics of each group are globally merged to obtain the final area statistics of each connected region in the entire image.
[0128] Hash optimization: Hash tables are used to store and manage the number and area information of connected components. Hash functions can quickly locate and access relevant information of connected components, reducing the time complexity of lookup and update operations, while effectively reducing atomic collisions and improving statistical efficiency.
[0129] Specifically, each computational workgroup (such as a thread block in the GPU) maintains an independent hash table in its high-speed local memory. Threads within a workgroup count the occurrences of region numbers in the image patches they are responsible for in parallel and accumulate the results into their local hash tables. Because the operations are performed in local memory, contention for atomic operations on global memory is greatly reduced. After all workgroups have completed their local statistics, one or a small number of threads merge the results from all local hash tables into a global counter, thus efficiently and accurately completing the area calculation for all regions.
[0130] To demonstrate the application effects of the embodiments of the present invention in real and complex scenarios, this embodiment provides the processing results of multiple images from different scenarios, such as... Figure 8 As shown in the attached figure, there are three sets of comparison images. The left side of each set shows the original grayscale image, and the right side shows the connected component labeling result obtained after processing by the method of this invention. In the result image, each independent color represents an independent connected component identified by the algorithm. As can be seen from the image, whether it is a well-structured building or a complexly shaped tree and sky, the method of this invention can effectively segment it into a large number of richly detailed connected regions. This intuitively verifies the effectiveness, accuracy, and robustness of this invention in practical applications.
[0131] Although this invention frequently uses terms such as parent node, root node, and initial region, the possibility of using other terms is not excluded. These terms are used merely for the convenience of describing and explaining the essence of this invention; interpreting them as any additional limitation would contradict the spirit of this invention.
[0132] This invention provides a parallelized connected component analysis method based on neighborhood labeling. Through highly parallel design, the steps of finding parent nodes, root nodes, and region boundary points, establishing mappings, and renumbering are all designed to be independently parallel computations. This fully utilizes the acceleration capabilities of parallel computing hardware such as GPUs, significantly improving processing speed. It is also easily scalable and can efficiently process large-scale high-resolution images. Furthermore, by employing a hash optimization method of grouped local reduction and global merging to calculate the area of each connected component, atomic collisions are effectively reduced, statistical efficiency is improved, and the robustness of the algorithm in a parallel computing environment is further enhanced. Thus, it not only significantly improves the efficiency of the connected component analysis algorithm but also enables rapid processing of high-resolution images, providing strong support for real-time and large-scale applications in the fields of computer vision and image processing.
[0133] Example 2
[0134] Figure 9 This is a schematic diagram of the structure of a computer device provided in Embodiment 2 of the present invention. Figure 9A block diagram of an exemplary computer device 12 suitable for implementing embodiments of the present invention is shown. Figure 9 The computer device 12 shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of the present invention.
[0135] like Figure 9 As shown, the computer device 12 is represented in the form of a general-purpose computing device. The components of the computer device 12 may include, but are not limited to: one or more processors or processing units 16, system memory 28, and bus 18 connecting different system components (including system memory 28 and processing unit 16).
[0136] Bus 18 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.
[0137] Computer device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by computer device 12, including volatile and non-volatile media, removable and non-removable media.
[0138] System memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. Computer device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be used to read and write non-removable, non-volatile magnetic media (…). Figure 9 Not shown; usually referred to as a "hard drive"). Although Figure 9 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 via one or more data media interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of the present invention.
[0139] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 42 typically perform the functions and / or methods described in the embodiments of the present invention.
[0140] Computer device 12 can also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), and with one or more devices that enable a user to interact with the computer device 12, and / or with any device that enables the computer device 12 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed via input / output (I / O) interface 22. Furthermore, computer device 12 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 20. As shown, network adapter 20 communicates with other modules of computer device 12 via bus 18. It should be understood that, although... Figure 9 As not shown, it can be used in conjunction with computer device 12 with other hardware and / or software modules, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0141] The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, such as implementing the parallelized connected component analysis method based on neighborhood labeling provided in the embodiments of the present invention.
[0142] Example 3
[0143] Embodiment 3 of the present invention provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the parallelized connected component analysis method based on neighborhood labeling as provided in all embodiments of the present invention.
[0144] Any combination of one or more computer-readable media may be used. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus, or device.
[0145] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of sending, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.
[0146] Program code contained on a computer-readable medium may be transmitted using any suitable medium, including—but not limited to—wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0147] Computer program code for performing the operations of this invention can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0148] Finally, it should be noted that although the above embodiments have been described in the description and drawings of this invention, this should not limit the scope of patent protection of this invention. Any technical solutions that are based on the essential concept of this invention, utilize the content described in the description and drawings of this invention to make equivalent structural or procedural substitutions or modifications, as well as the direct or indirect application of the technical solutions of the above embodiments to other related technical fields, are all included within the scope of patent protection of this invention.
Claims
1. A parallelized connected component analysis method based on neighborhood labeling, characterized in that, The method includes: S101. Use a parallel approach to find the parent node of each pixel in the grayscale image; S102. Using a parallel approach, find the root node of each pixel based on its parent node; S103. Using a parallel approach, pixels belonging to the same root node are grouped into an initial region, and the corresponding root node number is used as the number of the initial region. S104. Using a parallel approach, find the boundary points between adjacent and mergeable initial regions. S105. Using a parallel approach, establish mapping relationships between adjacent and mergeable initial regions to obtain mapping groups; S106. Establish the final mapping relationship between multiple regions in a parallel manner; S107. Using a parallel approach, based on the final mapping relationship between multiple regions, update the number of the initial region to which all pixels belong to the number of the initial region to which they are finally mapped, in order to complete the connected component labeling. S108. Adopting the acceleration approach of grouping local reduction and global merging, hash optimization is used to calculate the area of each connected component.
2. The parallelized connected component analysis method based on neighborhood labeling according to claim 1, characterized in that, S101 includes: S1011. Using a parallel approach, the gray value of each pixel in the grayscale image is compared sequentially with the gray values of neighboring pixels in a preset neighborhood. S1012. If the absolute value of the grayscale difference between the pixel and one of the adjacent pixels is less than a preset first threshold, then the corresponding adjacent pixel is determined as the parent node of the pixel. S1013. If the absolute value of the grayscale difference between the pixel and any of the adjacent pixels is not less than a preset first threshold, then the parent node of the pixel is determined to be itself.
3. The parallelized connected component analysis method based on neighborhood labeling according to claim 2, characterized in that, The preset neighborhood is the top-left neighborhood, the top neighborhood, the top-right neighborhood, and the left neighborhood.
4. The parallelized connected component analysis method based on neighborhood labeling according to claim 1, characterized in that, S102 includes: S021. Using a parallel approach, trace upwards along the parent node of each pixel; S1022. If a pixel is found whose parent node is itself, then the pixel whose parent node is itself is taken as the root node of the pixel; wherein, the root node of the pixel whose parent node is itself is also itself.
5. The parallelized connected component analysis method based on neighborhood labeling according to claim 1, characterized in that, S104 includes: S1041. Using a parallel approach, compare the number of the initial region to which each pixel belongs with the number of the initial region to which its neighboring pixels belong. S1042. If the numbers are different and the grayscale difference between the two is less than the preset second threshold, then the two initial regions to which they belong are mergeable regions, and the pixel is marked as the region boundary point.
6. The parallelized connected component analysis method based on neighborhood labeling according to claim 1, characterized in that, S105 includes: S1051. Using a parallel approach, continuously count the boundary points of the region along a preset direction; S1052. Map the numbers of the initial regions to which these consecutive regional boundary points belong to to the numbers of the adjacent and mergeable initial regions to obtain a mapping group.
7. The parallelized connected component analysis method based on neighborhood labeling according to claim 6, characterized in that, S1052 includes: S10521. When the number of consecutive regional boundary points exceeds a preset threshold, the numbers of the initial regions to which these consecutive regional boundary points belong are mapped to the numbers of the adjacent and mergeable initial regions to obtain a mapping group.
8. The parallelized connected component analysis method based on neighborhood labeling according to claim 1, characterized in that, S106 includes: S1061. Using a parallel approach, all related mapping groups are ultimately mapped to the initial region with the smallest number among them, thereby establishing the final mapping relationship between multiple regions.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the parallelized connected component analysis method based on neighborhood labeling as described in any one of claims 1-8.
10. A computer-readable storage medium having computer-executable instructions stored thereon, characterized in that, The computer-executable instructions are executed by a computer processor to implement the parallelized connected component analysis method based on neighborhood labeling as described in any one of claims 1-8.
Citation Information
Cited By
Millimeter wave radar boiler heating surface tube crack detection method based on GPU parallelization
CN122016873A