Method and device for determining connected domain and computer equipment

By scanning the runs in the image in columns and gradually expanding the connectivity domain using seed runs, the problems of high time complexity and high computing resource consumption in the prior art are solved, and efficient connectivity domain extraction and labeling are achieved.

CN120013980APending Publication Date: 2025-05-16苏州凌云光工业智能技术有限公司
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510187371.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-20
Publication Date
2025-05-16

AI Technical Summary

Technical Problem

In the prior art, the time complexity of the connectivity domain marking algorithm is high and the computing resource consumption is high, resulting in low processing efficiency.

Method used

By scanning the runs in the image in columns, using seed runs to gradually expand the connectivity domain, using Vector containers instead of linked lists to store run information, reducing dynamic memory application and release.

Benefits of technology

It significantly reduces computing resource consumption, improves the efficiency of connecting domain extraction, reduces redundant calculations, and improves processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120013980A_ABST
    Figure CN120013980A_ABST
Patent Text Reader

Abstract

The invention discloses a method and device for determining a connected domain and computer equipment, and belongs to the field of image processing. The method comprises the following steps: scanning run lengths in an image to be processed according to columns; when any run length is scanned, taking the scanned run length as a seed run length, and extracting run length information corresponding to the seed run length in a run length structure; determining a target connected domain to which the seed run belongs based on the run information; and gradually expanding the target connected domain by taking the seed run length as a starting point until all run lengths included in the target connected domain are obtained, returning to the first step to continue execution, and obtaining all connected domains in the to-be-processed image after all columns in the to-be-processed image are traversed. According to the method, the connected domain is extracted and merged by taking the run length as an object, so that the time complexity is remarkably reduced, and the consumption of computer processing resources can be reduced while the processing efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of image processing, and in particular, relates to a method, device and computer equipment for determining a connected domain. Background Art

[0002] A connected domain refers to an image region composed of pixels with the same pixel value and adjacent positions. Connected domain analysis can effectively separate and identify targets by marking and extracting connected domains in an image, thereby providing basic data for feature extraction, parameter calculation, and tracking of targets. Therefore, connected domain analysis plays a vital role in visual inspection.

[0003] In the related art, connected domain labeling algorithms are mainly divided into two categories: pixel-based connected component labeling algorithms and trip-based connected component labeling algorithms. Pixel-based connected component labeling algorithms usually require scanning each pixel in the image row by row and column by column to determine the connectivity between pixels, which leads to a high time complexity of the algorithm, consumes a lot of computing resources, and has low processing efficiency. The trip-based connected domain labeling algorithm has a complex calculation process and is difficult to implement through hardware. It usually relies on software programming to run on a computer, and its processing efficiency is also very low, and it takes up a lot of processing resources.

[0004] Therefore, how to reduce processing resource consumption and improve the efficiency of connected domain extraction is a problem that needs to be solved urgently. Summary of the invention

[0005] The present application aims to solve at least one of the technical problems existing in the related art. To this end, the present application proposes a method, device and computer equipment for determining a connected domain to reduce the consumption of computer processing resources and improve the efficiency of connecting domain extraction.

[0006] In a first aspect, the present application provides a method for determining a connected domain, the method comprising:

[0007] Scanning the runs in the image to be processed by columns;

[0008] When any run is scanned, the scanned run is used as a seed run, and the run information corresponding to the seed run is extracted from the run structure;

[0009] Determine the target connected domain to which the seed run belongs based on the run information;

[0010] Starting from the seed run, the target connected domain is gradually expanded until all runs included in the target connected domain are obtained, and then the process returns to the first step to continue, and after traversing all columns in the image to be processed, all connected domains in the image to be processed are obtained.

[0011] In the above technical scheme, by scanning the runs in the image to be processed by columns, the number of traversals is reduced, and the repeated redundant operations existing in the row-by-row scanning method are avoided; when any run is scanned, the scanned run is used as a seed run, and the run information corresponding to the seed run is extracted from the run structure, and a Vector container is used instead of a linked list to store the run information, thereby avoiding frequent dynamic memory application and release, and improving memory management efficiency; thus, the target connected domain to which the seed run belongs is determined based on the run information, and the target connected domain is gradually expanded with the seed run as the starting point until all the runs included in the target connected domain are obtained, and then the first step is returned to continue execution, and after traversing all the columns in the image to be processed, all the connected domains in the image to be processed are obtained, thereby gradually expanding the connected domain based on the seed run, and obtaining a complete connected domain at one time, without the need to repeatedly traverse other runs, reducing redundant calculations, and significantly improving processing efficiency.

[0012] According to an embodiment of the present application, the run information corresponding to the seed run includes the row, starting column, and ending column of the seed run; and taking the seed run as the starting point, gradually expanding the target connected domain until all runs included in the target connected domain are obtained, including:

[0013] Determine adjacent rows based on the row where the seed run is located, and search for a target candidate run associated with the seed run in the adjacent rows;

[0014] Determining that the target candidate run belongs to the target connected domain;

[0015] The target candidate run is used as a new seed run, and the step of determining adjacent rows based on the row where the seed run is located is returned to continue execution until all the runs included in the target connected domain are obtained.

[0016] In the above embodiment, the connected domain is obtained by traversing the seed run in combination with the step-by-step expansion mechanism, so that the connected domain marking process is more efficient, all connected regions in the image can be quickly marked, and the memory overhead is reduced.

[0017] In a second aspect, the present application provides a device for determining a connected domain, the device comprising:

[0018] A scanning module, used for scanning the runs in the image to be processed by columns;

[0019] An extraction module, used for, when any run is scanned, taking the scanned run as a seed run, and extracting the run information corresponding to the seed run from the run structure;

[0020] A determination module, used for determining a target connected domain to which the seed run belongs based on the run information;

[0021] An expansion module is used to gradually expand the target connected domain with the seed run as the starting point until all the runs included in the target connected domain are obtained, return to the first step to continue execution, and obtain all the connected domains in the image to be processed after traversing all the columns in the image to be processed.

[0022] In the above technical scheme, by scanning the runs in the image to be processed by columns, the number of traversals is reduced, and the repeated redundant operations existing in the row-by-row scanning method are avoided; when any run is scanned, the scanned run is used as a seed run, and the run information corresponding to the seed run is extracted from the run structure, and a Vector container is used instead of a linked list to store the run information, thereby avoiding frequent dynamic memory application and release, and improving memory management efficiency; thus, the target connected domain to which the seed run belongs is determined based on the run information, and the target connected domain is gradually expanded with the seed run as the starting point until all the runs included in the target connected domain are obtained, and then the first step is returned to continue execution, and after traversing all the columns in the image to be processed, all the connected domains in the image to be processed are obtained, thereby gradually expanding the connected domain based on the seed run, and obtaining a complete connected domain at one time, without the need to repeatedly traverse other runs, reducing redundant calculations, and significantly improving processing efficiency.

[0023] In a third aspect, the present application provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for determining a connected domain as described in the first aspect above is implemented.

[0024] In a fourth aspect, the present application provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method for determining a connected domain as described in the first aspect above is implemented.

[0025] In a fifth aspect, the present application provides a chip, comprising a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run a program or instruction to implement the method for determining a connected domain as described in the first aspect above.

[0026] In a sixth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the method for determining a connected domain as described in the first aspect above.

[0027] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:

[0029] Figure 1 is a schematic diagram of the structure of run-length encoding data provided in some embodiments of the present application;

[0030] Figure 2 is a schematic diagram of an image scene of a method for determining a connected domain provided in some embodiments of the present application;

[0031] Figure 3 is a flowchart of a method for determining a connected domain provided in some embodiments of the present application;

[0032] Figure 4 It is a schematic diagram of the principle of gradually expanding the connected domain based on the seed run provided in some embodiments of the present application;

[0033] Figure 5 It is a schematic diagram of the principle of gradually expanding the connected domain based on the seed run provided in some other embodiments of the present application;

[0034] Figure 6 is a schematic diagram of the principle of gradually expanding a connected domain based on a seed run provided in some other embodiments of the present application;

[0035] Figure 7 is a flowchart of a method for determining a connected domain provided in some other embodiments of the present application;

[0036] Figure 8 is a schematic diagram of the structure of a connected domain determination device provided in some embodiments of the present application;

[0037] Fig. 9 It is a schematic diagram of the structure of a computer device provided in some embodiments of the present application. DETAILED DESCRIPTION

[0038] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.

[0039] Unless otherwise defined, all technical and scientific terms used in this application have the same meanings as those commonly understood by technicians in the technical field of this application; the terms used in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit this application; the terms "including" and "having" in the specification and claims of this application and the above-mentioned drawings and any variations thereof are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of this application or the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order or a primary and secondary relationship.

[0040] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments.

[0041] In the description of this application, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", and "attached" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a direct connection, or an indirect connection through an intermediate medium, or it can be the internal communication of two elements. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood according to specific circumstances.

[0042] The term "and / or" in this application is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this application generally indicates that the associated objects before and after are in an "or" relationship.

[0043] The term "multiple" as used in this application refers to more than two (including two). Similarly, "multiple groups" refers to more than two groups (including two groups), and "multiple sheets" refers to more than two sheets (including two sheets).

[0044] When faced with the problem of improving processing efficiency and reducing computing resource consumption, the relevant technology mainly uses the run linked list method to establish a dynamic linked list of run information, and marks the run nodes by analyzing the connectivity between the run nodes. However, the inventor found in the study that this method requires frequent application and release of dynamic memory during operation, and frequent memory operations will significantly increase the CPU usage and reduce system efficiency, and this effect is particularly obvious in high-speed operation scenarios. In addition, the application and release efficiency of heap memory is lower than that of stack memory, which will further affect the performance of the algorithm.

[0045] In view of this, the present application aims to solve the performance bottleneck of the traditional algorithm, convert the pixel-by-pixel processing of the image into the run-by-run processing, significantly reduce the computational complexity, and abandon the traditional run-length linked list form, and store the run-length information through the vector container to significantly reduce the memory consumption and occupancy. In view of the disadvantages of the vector container in the algorithm time complexity, the inventor combines the connected domain method based on pixel marking with the run-length information, and proposes a new connected domain marking algorithm, that is, based on scanning the run by column and using the queue to expand the connected domain, it can achieve efficient connected domain marking without relying on the linked list, significantly reduce the consumption of computing resources, and thus improve the overall performance of the algorithm.

[0046] The following is an explanation of the terms used in this article.

[0047] The vector container is a dynamic array that supports efficient random access and dynamic expansion. The vector container can dynamically store the indexes and information of multiple runs or connected domains, without the need to frequently apply for and release dynamic memory, thus reducing the usage of computer storage resources.

[0048] Runlength is a compression method in image processing that represents a continuous segment of pixels with the same value. In a binary image, a runlength can describe a row segment of a connected region. Runlength can be used to quickly access and analyze connected regions. Figure 1 The run-length encoding data format is shown, where AAAA is the row end flag and FFFF is the frame end flag. The runs are stored in sequence by row, and each row of run-length encoding data includes the row number Y of the row, as well as the start column number X_start and the end column number X_end of each run. Usually, there is a defect flag before the start column number X_start of each run, which is used to indicate whether there is a defect or abnormality at that position.

[0049] The following describes in detail the method for determining a connected domain provided in the embodiment of the present application through specific embodiments and application scenarios in conjunction with the accompanying drawings.

[0050] The method for determining a connected domain provided in the embodiment of the present application can be applied to Figure 2In the image scene shown, Figure 2 A portion of an image is shown as an example for explanation. The image includes multiple runs 1 to 10. Before the connected domain is extracted, the computer device has determined all the runs in the image. In other words, the method for determining the connected domain in the present application is executed on the basis that the run-length encoding has been done in the hardware.

[0051] The method for determining a connected domain provided in the embodiment of the present application may be executed by a computer device or a functional module or functional entity in the computer device that can implement the method. The method for determining a connected domain provided in the embodiment of the present application is described below using a computer device as an example of an execution subject.

[0052] like Figure 3 As shown, the method for determining the connected domain includes: steps 310 to 340.

[0053] Step 310: Scan the runs in the image to be processed by columns.

[0054] Since the runs are stored row by row, in order to reduce the number of traversals and avoid repeated operations, in the embodiment of the present application, the computer device scans the runs in the image column by column in the direction of columns to further improve the processing efficiency.

[0055] Step 320: When any run is scanned, the scanned run is used as a seed run, and the run information corresponding to the seed run is extracted from the run structure.

[0056] The run-length structure is a compressed representation used to describe continuous pixel segments in a row of an image. The run-length structure is used to store run-length information. The run-length structure stores the row number where the run is located, the column number where the run starts, the column number where the run ends, and the mark status of the run. An image usually contains multiple runs, so each run in the image can be stored in different containers according to the row number.

[0057] When any run is scanned, the computer device uses the scanned run as a seed run and searches for the run structure to extract the run information corresponding to the seed run. Figure 2 As shown, the computer device scans column by column from left to right. When scanning the first column, the computer device scans run 2, uses the run 2 as a seed run, and takes out the run information corresponding to the run 2 from the corresponding run structure.

[0058] Step 330: Determine the target connected domain to which the seed run belongs based on the run information.

[0059] The computer device determines which connected domain the seed run belongs to based on the run information of the seed run, which is called the target connected domain. If the seed run belongs to a connected domain that has been marked before, the computer device skips the seed run and goes to step 310 to continue scanning the next run. If the seed run does not belong to any connected domain marked before, it means that the seed run belongs to a new connected domain, and the computer device uses the new connected domain as the target connected domain and creates a new connected domain container (also called a blob structure), which is used to store the runs belonging to the new connected domain. The computer device adds the seed run to the connected domain container and updates the marking state of the seed run to the marked state.

[0060] Step 340: Starting from the seed run, gradually expand the target connected domain until all the runs included in the target connected domain are obtained, return to the first step to continue execution, and after traversing all the columns in the image to be processed, obtain all the connected domains in the image to be processed.

[0061] Afterwards, the computer device takes the seed run as the starting point and gradually expands to the adjacent rows to find other runs connected to the current seed run. The other runs connected to the current seed run also belong to the target connected domain. Therefore, the computer device also adds the other runs connected to the current seed run to the target connected domain to achieve the expansion of the target connected domain. After processing all the runs in the current column, the computer device continues to scan the next column and repeats the above steps 320 to 340 until the entire image is traversed, and finally all the connected domains in the image to be processed are obtained.

[0062] The method for determining a connected domain provided in an embodiment of the present application reduces the number of traversals by scanning the runs in the image to be processed by columns, and avoids repeated redundant operations in the row-by-row scanning method; when any run is scanned, the scanned run is used as a seed run, and the run information corresponding to the seed run is extracted from the run structure, and a Vector container is used instead of a linked list to store the run information, thereby avoiding frequent dynamic memory application and release, and improving memory management efficiency; thus, the target connected domain to which the seed run belongs is determined based on the run information, and the target connected domain is gradually expanded with the seed run as the starting point until all the runs included in the target connected domain are obtained, and the first step is returned to continue execution, and after traversing all the columns in the image to be processed, all the connected domains in the image to be processed are obtained, thereby gradually expanding the connected domain based on the seed run, and obtaining a complete connected domain at one time, without the need to repeatedly traverse other runs, reducing redundant calculations, and significantly improving processing efficiency.

[0063] The run information includes the row where the run is located, the starting column, the ending column and the marking state. Accordingly, in some embodiments, starting from the seed run, the target connected domain is gradually expanded until all the runs included in the target connected domain are obtained, including: determining adjacent rows based on the row where the seed run is located, and searching for target candidate runs associated with the seed run in the adjacent rows; determining that the target candidate run belongs to the target connected domain; using the target candidate run as a new seed run, and returning to the step of determining adjacent rows based on the row where the seed run is located to continue executing until all the runs included in the target connected domain are obtained.

[0064] When a run is scanned, the computer device uses the run as a seed run, and then gradually expands the target connected domain to which it belongs. Specifically, the computer device uses the current seed run as a basis to expand the connected domain to the adjacent rows. The adjacent rows include the previous row and the next row. For example, for the second row, its adjacent rows include the first row and the third row. The computer device determines one or more candidate runs in the adjacent rows, and makes connectivity judgments on the one or more candidate runs respectively, and then determines the target candidate run associated with the seed run from the one or more candidate runs. Among them, the target candidate run is associated with the seed run, which means that the target candidate run is connected to the seed run.

[0065] When the target candidate run is connected to the seed run, the computer device can determine that the target candidate run also belongs to the current target connected domain, and then the computer device merges the connected domains, that is, adds the target candidate run to the target connected domain. Then, the computer device uses the target candidate run as a new seed run, that is, as a new starting point, and repeats the above process for cyclic expansion until all runs in the target connected domain are marked.

[0066] like Figure 4 , Figure 5 and Figure 6As shown, it is assumed that runs 1 to 5 in the image are all in an unmarked state. The computer device uses run 1 in the 4th row as a seed run, and traverses the runs in the 3rd and 5th rows respectively to determine the target candidate runs. In the 3rd row, the computer device can determine two candidate runs: run 2 and run 4. Among them, the target candidate run associated with run 1 is run 2, and run 4 is not connected to run 1, so run 4 is not associated with run 1. In the 4th row, run 5 is not connected to run 1, so there is no target candidate run associated with run 1 in the 4th row. Afterwards, the computer device uses run 2 as a new seed run, and determines its adjacent rows as rows 2 and 4, and then determines the target candidate runs associated with run 2 in the adjacent rows. Similarly, in row 2, the computer device can determine that the target candidate run associated with run 2 is run 3; and in row 4, since run 1 has been marked, run 1 is skipped, and there are no other candidate runs connected to run 2 in row 4. Therefore, by looping, the computer device can obtain the target connected domain A with fewer scanning times, and the target connected domain A includes run 1, run 2 and run 3.

[0067] In the above embodiment, the connected domain is obtained by traversing the seed run in combination with the step-by-step expansion mechanism, so that the connected domain marking process is more efficient, all connected regions in the image can be quickly marked, and the memory overhead is reduced.

[0068] Accordingly, in some embodiments, searching for a target candidate run associated with a seed run in adjacent rows includes: determining one or more candidate runs in an unmarked state in the adjacent rows; for any candidate run, determining whether the targeted candidate run is connected to the seed run in at least one preset direction; and when the targeted candidate run is connected to the seed run in at least one preset direction, determining the targeted candidate run as a target candidate run associated with the seed run.

[0069] The computer device determines the adjacent rows based on the row where the seed run is located, and searches for unmarked runs in the adjacent rows as candidate runs. For each candidate run, the computer device determines whether it is connected to the current seed run in at least one preset direction. The preset direction includes but is not limited to one or more of the upper left, upper right, upper left, lower right, and lower right.

[0070] If the candidate run is connected to the seed run in at least one preset direction, the computer device marks the candidate run as a target candidate run and adds the target candidate run to the current connected domain, namely the target connected domain, to achieve an expansion of the target connected domain.

[0071] In the above embodiment, by screening unmarked candidate runs and performing connectivity judgment in combination with preset directions, connected runs can be quickly identified and accurately screened, redundant calculations can be reduced, and the accuracy of connected domain marking can be improved.

[0072] When expanding a connected domain, how to reduce redundant calculations, especially how to efficiently identify and process unmarked runs in adjacent rows, is still one of the bottlenecks for improving algorithm performance. To this end, in some embodiments, in adjacent rows, one or more candidate runs in an unmarked state are determined, including: obtaining the total number of runs in the adjacent rows; judging whether the number of runs in an unmarked state in the adjacent rows is consistent with the total number of runs; skipping the adjacent rows when the number of runs in an unmarked state is consistent with the total number of runs; and determining one or more candidate runs in an unmarked state when the number of runs in an unmarked state is inconsistent with the total number of runs. By improving the traditional connected domain expansion method, an optimization algorithm based on run marking state and candidate run number judgment is proposed. The algorithm can effectively reduce unnecessary run traversal and improve the speed and accuracy of connected domain expansion through accurate state judgment.

[0073] That is, when the computer device traverses a row of the image, it first determines the total number of runs in the current row and the adjacent rows. The total number of runs represents the number of runs that need to be processed in the row. During the run traversal process of the current row, the computer device determines the number of runs in the adjacent rows that are in an unmarked state. If the number of unmarked runs is consistent with the total number of runs in the row, it means that all runs in the row have been marked, and the row can be skipped to avoid meaningless repeated checks. If the number of unmarked runs is inconsistent with the total number of runs, the computer device needs to further determine which runs are in an unmarked state. These runs are candidate runs, and the judgment of connected domain expansion needs to be performed.

[0074] In the above embodiment, by judging the consistency between the number of unmarked runs in adjacent rows and the total number of runs, the rows that do not need to be processed can be effectively skipped, thereby reducing the time complexity of the algorithm; and when processing each row of runs, only the unmarked runs need to be expanded, thereby reducing unnecessary calculations and resource consumption. Therefore, by accurately judging the connectivity of candidate runs, unnecessary expansion of connected domains is avoided, making the connected domain marking process more efficient and stable.

[0075] In some embodiments, the target connected domain to which the seed run belongs is determined based on the run information, including: when the seed run is in a marked state, skipping the seed run and continuing to scan the current column; when the seed run is in an unmarked state, determining that the seed run belongs to a new connected domain, and taking the new connected domain as the target connected domain.

[0076] Specifically, if the current seed run is in a marked state, the computer device skips the run and continues to scan the current column; if the current seed run is in an unmarked state, the computer device determines the connected domain to which it belongs. At this time, the computer device sets the connected domain where the run is located as a new target connected domain.

[0077] In the above embodiment, the connected domain is determined by combining column scanning and step-by-step expansion, which reduces redundant calculations and enables more efficient processing of the connected domain in the image.

[0078] In some embodiments, after determining that the seed run belongs to the target connected domain, the method further includes: creating a connected domain container corresponding to the target connected domain, and adding the seed run to the connected domain container; updating the marking state of the seed run to a marked state.

[0079] After determining that a seed run belongs to the target connected domain, in order to organize and store all runs in the connected domain, the computer device first creates a new connected domain container, i.e., a blob container. This container will be used to store all runs related to the target connected domain, including all run information contained therein, and these containers can be used for subsequent analysis, such as shape extraction, regional statistics, etc. Subsequently, the computer device adds the current seed run to the connected domain container. After the current seed run is added to the connected domain container, the computer device updates its marking state to a marked state. This process ensures that the run will not be re-marked or repeatedly counted in other connected domains in subsequent processing, avoiding redundant calculations. Thus, after completing the marking of the seed run, the computer device expands the current connected domain in the manner of the above-mentioned embodiment, searches for other runs connected to the seed run, and incorporates these runs into the same target connected domain.

[0080] Exemplarily, a connected domain container may be defined as:

[0081] Vector <runinfo>vecBlobRunInfo;

[0082] vecBlobRunInfo is a dynamic array container, each element of which is a RunInfo structure, representing the information of a run. All RunInfo in vecBlobRunInfo describe the information of all runs in the connected domain.

[0083] In the above embodiment, by immediately marking the seed run as marked when creating a connected domain container, it is possible to avoid the run being repeatedly traversed and marked in the subsequent process, saving a lot of computing time; the creation and updating of the connected domain container enables the run information within each connected domain to be centrally stored, which is convenient for subsequent expansion and management; during the execution process, multiple traversals and markings of the same run are avoided, reducing the system's memory usage and computing resource consumption, and meeting the real-time requirements of large-scale image processing tasks.

[0084] In addition, since it is necessary to gradually expand from the seed run as the starting point and continuously spread to adjacent rows during the loop traversal, in order to facilitate the unified management of the connected domain, a temporary queue is also defined in the embodiment of the present application to temporarily store the runs contained in the connected domain before determining all the runs contained in the connected domain.

[0085] For example, a temporary queue can be defined as: Queue<RunInfo*> queRunInfoTemp is used to implement gradual expansion when marking connected domains and to effectively manage the order of run processing.

[0086] Specifically, when a new seed run (unmarked run) is found, the computer device puts it into the queRunInfoTemp queue as the starting point for expanding the connected domain. When expanding the connected domain, the runs in the queue will be taken out one by one as the current seed runs, and then the unmarked runs connected to them will be checked. If these connected runs belong to the same connected domain, they will be added to the current connected domain and continue to be added to the queue as new seed runs to expand the connected domain. Thus, the current runs to be expanded are managed by the queue to ensure that each run is processed only once, thereby avoiding repeated calculations and invalid traversals.

[0087] After explaining the principle of the method for determining the connected domain provided in the embodiment of the present application, it is also necessary to further explain the data storage and access methods to better explain why the present application can further reduce the consumption of computer resources.

[0088] As mentioned above, the run information of a run is stored in a run structure. The run structure can be defined as: RunInfo. The run structure RunInfo includes:

[0089] Long LineNum: the line number where the run is located;

[0090] Long RunBegin: The starting column number of the run, indicating the horizontal starting point of the run within the row;

[0091] Long RunEnd: The end column number of the run, indicating the horizontal end point of the run within the row;

[0092] BOOL Mark: Mark field, used to record whether the stroke has been processed or marked.

[0093] An image usually contains multiple runs, which can be stored in different vector containers according to the row number. For example, it can be defined as:

[0094] Vector <runinfo>[image height];

[0095] Among them, Vector <runinfo>[Image height] can be called the run information storage structure, which is an array, including multiple row containers vecRunInfo[i], i represents the row number. The row container vecRunInfo stores the information of all runs belonging to the row, and each run is represented by an independent RunInfo instance. That is, vecRunInfo[i] takes out Vector <runinfo>, which is a list of run information on the i-th line of the image. Each run is represented by a separate RunInfo instance.

[0096] That is to say, when the computer device scans any run, it uses the scanned run as a seed run and accesses the run structure corresponding to the seed run to extract the run information corresponding to the seed run.

[0097] In some embodiments, the run information storage structure also stores the following tag fields:

[0098] Int nRunSize[image height], also known as the total number of runs, is used to record the total number of runs in each row. For example, if there are three runs in the image data of row 1, then nRunSize[i] = 3.

[0099] Int nMarkSize[image height], also known as processed marks, is used to record the number of marked runs in each row, and quickly determine whether a row has been processed. For example, if 2 of the 3 runs in row 1 have been marked, then nMarkSize[1] is 2. This helps the algorithm avoid repeated marking when expanding the connected domain.

[0100] Int nValidLineIndex[image height], also known as a valid mark, is used to record the position of the unmarked strokes in each line to reduce the traversal range. For example, if the first two strokes of the first line have been marked, and the remaining strokes have not been marked, nValidLineIndex[1] will point to the position of the third stroke, indicating that starting from this position, the subsequent strokes need to be further checked.

[0101] In order to further reduce the consumption of computing resources, in the embodiment of the present application, the run position index is stored in the run position structure, which is used as an index to quickly access a run. The run position structure can be defined as RunPos. The run position structure RunPos includes:

[0102] Long LineNum: The row where the run is located, corresponding to the container number of the row container storing the run;

[0103] Long nPos: The position of the stroke in the container, that is, the sequential number.

[0104] Each column in the image corresponds to a RunPos, so the run position structure corresponding to the image can be defined as:

[0105] Vector <runpos>vecRunPos[image width];

[0106] Among them, Vector <runpos>Used to store the position information of all runs in the image. Each column corresponds to a vecRunPos[j], where j represents the column number.

[0107] Therefore, while extracting the stroke information, the stroke position information is also stored and stored in the column direction. In this way, when scanning, the stroke information is not scanned, but the stroke position index is scanned instead. According to the stroke position information, the stroke information can be obtained immediately, thereby reducing the number of scans.

[0108] In other words, in some embodiments, extracting the run information corresponding to the seed run in the run structure includes: accessing the run position structure corresponding to the seed run, and obtaining the run position index corresponding to the seed run stored in the run position structure; based on the run position index, accessing the position of the seed run in the run structure, and obtaining the run information corresponding to the seed run.

[0109] The computer device obtains the run position index corresponding to the current seed run by accessing the run position structure. The run position index includes the specific row and position of the run in the image. Furthermore, based on the run position index, the computer device can directly access the corresponding row container very quickly and directly locate the run and its run information in the row container without searching in the run information storage structure.

[0110] In the above embodiment, the run position is quickly located through the run position index of the run position structure, and relevant information can be quickly accessed only through the index information, which can reduce unnecessary calculations and memory accesses and improve the overall efficiency of the connected domain marking process.

[0111] Accordingly, in some embodiments, based on the run position index, the position of the seed run in the run structure is accessed to obtain the run information corresponding to the seed run, including: based on the container number, determining the row container corresponding to the seed run in the run structure; the row container stores the run information of all runs in the row where the seed run is located; based on the position of the seed run represented by the sequential number among all runs in the row, extracting the run information corresponding to the seed run.

[0112] The computer device can quickly determine the row container of the row where the seed run is located based on the container number in the run position structure. The row container contains the run information of all runs in the current row, which is convenient for the association operation between runs. Furthermore, the computer device can accurately find the specific position of the seed run in the row container based on the sequence number, so as to extract the corresponding run information. The extracted run information includes the row number, start column, end column and mark status of the run.

[0113] For example, the computer device determines the row container vecRunInfo where the run is located based on the Long LineNum field in the run position structure RunPos, and determines the index position of the run in the row container vecRunInfo based on the Long nPos field in the run position structure RunPos, thereby obtaining the run information.

[0114] For example, vecRunInfo[3] represents the run information of the third row, which contains the following runs:

[0115] The 0th run: RunInfo (LineNum = 3, RunBegin = 10, RunEnd = 15);

[0116] The first run: RunInfo (LineNum = 3, RunBegin = 20, RunEnd = 25);

[0117] …

[0118] The 5th run: RunInfo (LineNum=3, RunBegin=50, RunEnd=55).

[0119] An example of the run position structure RunPos is: RunPos(LineNum=3, nPos=5), which means that the current run is located at the 5th run in the 3rd line.

[0120] The search process is as follows: the computer device obtains vecRunInfo[3], i.e., all the run information of the 3rd row, according to RunPos.LineNum=3; then, according to RunPos.nPos=5, it accesses the 5th run of the container of the 3rd row, i.e., vecRunInfo[3][5], and obtains the corresponding RunInfo: RunInfo(LineNum=3, RunBegin=50, RunEnd=55). This search method utilizes the characteristics of row-by-row block storage and array random access, and can efficiently and quickly locate the specified run information from the huge image data.

[0121] In the above embodiment, through the dual indexing of container number and sequence number, the specific position of the seed run in the row container can be efficiently located, reducing redundant traversal and calculation. Compared with the traditional linked list structure, it avoids frequent dynamic memory allocation and release, effectively reduces memory usage, and improves processing efficiency.

[0122] The following is a specific example. Figure 7 As shown, the overall process includes:

[0123] Step 1: Scan the run by column, take out the run position index from the run position structure one by one, select the corresponding vecRunInfo container according to the container number of the LineNum run in the run position information, find the current run information RunInfo according to the position of the nPos run in the container, and regard the current run as the seed run.

[0124] Step 2: Determine whether the seed run has been marked. If so, execute Step 1 and continue to retrieve the next run information; if not, execute Step 3.

[0125] Step 3: Create a new blob container.

[0126] Step 4: Insert the current seed run into the blob container, add 1 to the image height in the nMarkSize field stored in the run information storage structure where the current seed run is located, and update the mark state of the run to the marked state. In addition, put the seed run into the temporary queue queRunInfoTemp.

[0127] Step 5: Loop to determine whether the temporary queue queRunInfoTemp is empty. If so, execute Step 1; if not, take out the first run in the queue and use it as the new seed run.

[0128] Step 6: According to the row number of the current run, get the row container of the previous and next row, and determine whether the number of runs marked in the row matches the total number of runs based on nRunSize and nMarkSize. If yes, execute Step 5; if no, execute Step 7.

[0129] Step 7: Traverse according to the unmarked starting position nValidLineIndex. If the run at the position nValidLineIndex has been marked, execute Step 8; otherwise, determine whether the run at the position nValidLineIndex belongs to the same connected domain as the seed run. If they belong to the same connected domain, go to Step 9.

[0130] Step8: nValidLineIndex adds 1 to the image height.

[0131] Step 9: Consider the current stroke as the seed stroke, and then execute Step 6 to determine the stroke of the next row. After the determination of the next row is completed, execute Step 4.

[0132] This application is based on the run length and introduces a vector container storage method to extract the connected domain area, which is used to solve the problem of excessive CPU usage caused by the linked list storage method. At the same time, an algorithm optimization method is proposed to further reduce the number of scans, so that the algorithm has higher efficiency and better robustness. The algorithm proposed in this application has been repeatedly verified by experiments, and images of various target shapes have been selected for testing. It can achieve fast, accurate and stable connected domain extraction and labeling. And the CPU usage of the algorithm proposed in this application is reduced by 50% compared with the linked list storage method, and the time consumption is also reduced by 30%.

[0133] The connected domain determination method provided in the embodiment of the present application may be executed by a connected domain determination device. In the embodiment of the present application, the connected domain determination device executing the connected domain determination method is taken as an example to illustrate the connected domain determination device provided in the embodiment of the present application.

[0134] The present application also provides a device for determining a connected domain, which is applied to a computer device. Figure 8 As shown, the connected domain determination device includes a scanning module 801, an extraction module 802, a determination module 803 and an expansion module 804. Among them:

[0135] The scanning module 801 is used to scan the runs in the image to be processed by columns.

[0136] The extraction module 802 is used to, when any run is scanned, use the scanned run as a seed run, and extract the run information corresponding to the seed run from the run structure.

[0137] The determination module 803 is used to determine the target connected domain to which the seed run belongs based on the run information.

[0138] The expansion module 804 is used to gradually expand the target connected domain starting from the seed run, until all the runs included in the target connected domain are obtained, return to the first step to continue execution, and after traversing all the columns in the image to be processed, obtain all the connected domains in the image to be processed.

[0139] According to the connected domain determination device provided by the embodiment of the present application, by scanning the runs in the image to be processed by columns, the number of traversals is reduced, and the repeated redundant operations existing in the row-by-row scanning method are avoided; when any run is scanned, the scanned run is used as a seed run, and the run information corresponding to the seed run is extracted from the run structure, and a Vector container is used instead of a linked list to store the run information, thereby avoiding frequent dynamic memory application and release, and improving memory management efficiency; thus, the target connected domain to which the seed run belongs is determined based on the run information, and the target connected domain is gradually expanded with the seed run as the starting point until all the runs included in the target connected domain are obtained, and the first step is returned to continue execution, and after traversing all the columns in the image to be processed, all the connected domains in the image to be processed are obtained, thereby gradually expanding the connected domain based on the seed run, and obtaining a complete connected domain at one time, without the need to repeatedly traverse other runs, reducing redundant calculations, and significantly improving processing efficiency.

[0140] In some embodiments, the run information corresponding to the seed run includes the row, starting column, and ending column where the seed run is located; the expansion module is also used to determine adjacent rows based on the row where the seed run is located, and search for target candidate runs associated with the seed run in the adjacent rows; determine that the target candidate run belongs to the target connected domain; use the target candidate run as a new seed run, and return to the step of determining adjacent rows based on the row where the seed run is located to continue executing until all runs included in the target connected domain are obtained.

[0141] In some embodiments, the run information corresponding to the seed run also includes a marking state, and the marking state includes a marked state and an unmarked state; the expansion module is also used to determine one or more candidate runs in an unmarked state in adjacent rows; for any candidate run, determine whether the targeted candidate run is connected with the seed run in at least one preset direction; when the targeted candidate run is connected with the seed run in at least one preset direction, determine the targeted candidate run as a target candidate run associated with the seed run.

[0142] In some embodiments, the expansion module is also used to obtain the total number of runs in adjacent rows; determine whether the number of runs in an unmarked state in an adjacent row is consistent with the total number of runs; if the number of runs in an unmarked state is consistent with the total number of runs, skip the adjacent row; if the number of runs in an unmarked state is inconsistent with the total number of runs, determine one or more candidate runs in an unmarked state.

[0143] In some embodiments, the determination module is also used to skip the seed run and continue scanning the current column when the seed run is in a marked state; when the seed run is in an unmarked state, determine that the seed run belongs to a new connected domain and use the new connected domain as the target connected domain.

[0144] In some embodiments, the determination module is further used to create a connected domain container corresponding to the target connected domain after determining that the seed run belongs to the target connected domain, and add the seed run to the connected domain container; update the marking state of the seed run to the marked state.

[0145] In some embodiments, the extraction module is also used to access the run position structure corresponding to the seed run, and obtain the run position index corresponding to the seed run stored in the run position structure; based on the run position index, access the position of the seed run in the run structure to obtain the run information corresponding to the seed run.

[0146] In some embodiments, the run position structure stores a container number and a sequence number; the extraction module is also used to determine the row container corresponding to the seed run in the run structure based on the container number; the row container stores the run information of all runs in the row where the seed run is located; based on the position of the seed run represented by the sequence number in all runs in the row, the run information corresponding to the seed run is extracted.

[0147] The determination device of the connected domain in the embodiment of the present application can be a computer device, or a component in the computer device, such as an integrated circuit or a chip. The computer device can be a terminal device or a server. Exemplarily, the computer device can be a mobile phone, a tablet computer, a laptop computer, a PDA, a vehicle-mounted computer device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (Augmented Reality, AR) / virtual reality (Virtual Reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (Ultra-mobile Personal Computer, UMPC), a netbook or a personal digital assistant (Personal Digital Assistant, PDA), etc., and can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (Personal Computer, PC), a television (Television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.

[0148] The device for determining the connected domain in the embodiment of the present application may be a device having an operating system. The operating system may be a Microsoft (Windows) operating system, an Android (Android) operating system, an IOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.

[0149] The connected domain determination device provided in the embodiment of the present application can achieve Figure 3 To avoid repetition, the various processes implemented by the method embodiment are not described here.

[0150] In some embodiments, Fig. 9 As shown, an embodiment of the present application also provides a computer device 900, including a processor 901, a memory 902, and a computer program stored in the memory 902 and executable on the processor 901. When the program is executed by the processor 901, each process of the above-mentioned method embodiments is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be described here.

[0151] It should be noted that the computer device in the embodiment of the present application includes the mobile computer device and the non-mobile computer device mentioned above.

[0152] An embodiment of the present application also provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, each process of the above-mentioned method for determining a connected domain is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.

[0153] The processor is the processor in the computer device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.

[0154] The embodiment of the present application also provides a computer program product, including a computer program, which implements the above-mentioned method for determining a connected domain when executed by a processor.

[0155] The processor is the processor in the computer device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.

[0156] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface is coupled to the processor, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned connected domain determination method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.

[0157] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.

[0158] It should be noted that, in this article, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved. For example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.

[0159] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the relevant technology, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0160] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.

[0161] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.

[0162] Unless otherwise specified, all embodiments and optional embodiments of the present application can be combined with each other to form a new technical solution.

[0163] Unless otherwise specified, all technical features and optional technical features of this application can be combined with each other to form a new technical solution.

[0164] If there is no special explanation, all steps of the present application can be performed sequentially or randomly, preferably sequentially. For example, the method includes steps (a) and (b), which means that the method may include steps (a) and (b) performed sequentially, or may include steps (b) and (a) performed sequentially. For example, it is mentioned that the method may also include step (c), which means that step (c) can be added to the method in any order. For example, the method may include steps (a), (b) and (c), or may include steps (a), (c) and (b), or may include steps (c), (a) and (b), etc.

[0165] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.< / runpos> < / runpos> < / runinfo> < / runinfo> < / runinfo> < / runinfo>

Claims

1. A method for determining a connected domain, characterized in that: The method comprises: Scanning the runs in the image to be processed by columns; When any run is scanned, the scanned run is used as a seed run, and the run information corresponding to the seed run is extracted from the run structure; Determine the target connected domain to which the seed run belongs based on the run information; Starting from the seed run, the target connected domain is gradually expanded until all runs included in the target connected domain are obtained, and then the process returns to the first step to continue, and after traversing all columns in the image to be processed, all connected domains in the image to be processed are obtained.

2. The method according to claim 1, characterized in that The run information corresponding to the seed run includes the row, starting column, and ending column of the seed run; the step of gradually expanding the target connected domain from the seed run as the starting point until all runs included in the target connected domain are obtained includes: Determine adjacent rows based on the row where the seed run is located, and search for a target candidate run associated with the seed run in the adjacent rows; Determining that the target candidate run belongs to the target connected domain; The target candidate run is used as a new seed run, and the step of determining adjacent rows based on the row where the seed run is located is returned to continue execution until all the runs included in the target connected domain are obtained.

3. The method according to claim 2, characterized in that The run information corresponding to the seed run also includes a marking state, and the marking state includes a marked state and an unmarked state; and searching for a target candidate run associated with the seed run in the adjacent rows includes: In the adjacent rows, determining one or more candidate runs in an unmarked state; For any candidate run, determining whether the candidate run is connected to the seed run in at least one preset direction; In the case that the targeted candidate run is connected to the seed run in at least one preset direction, the targeted candidate run is determined as a target candidate run associated with the seed run.

4. The method according to claim 3, characterized in that Determining one or more candidate runs in an unmarked state in the adjacent rows comprises: Get the total number of runs of adjacent rows; Determining whether the number of runs in the adjacent row that are in an unmarked state is consistent with the total number of runs; When the number of runs in an unmarked state is consistent with the total number of runs, skipping the adjacent row; In the case that the number of runs in the unmarked state is inconsistent with the total number of runs, one or more candidate runs in the unmarked state are determined.

5. The method according to any one of claims 1 to 4, characterized in that The step of determining the target connected domain to which the seed run belongs based on the run information includes: When the seed run is in the marked state, skip the seed run and continue scanning the current column; When the seed run is in an unmarked state, it is determined that the seed run belongs to a new connected domain, and the new connected domain is used as a target connected domain.

6. The method according to claim 5, characterized in that The method further comprises: After determining that the seed run belongs to the target connected domain, creating a connected domain container corresponding to the target connected domain, and adding the seed run to the connected domain container; Update the marking state of the seed run to the marked state.

7. The method according to claim 1, characterized in that The step of extracting the run information corresponding to the seed run from the run structure includes: Accessing a run position structure corresponding to the seed run, and obtaining a run position index corresponding to the seed run stored in the run position structure; Based on the run position index, the position of the seed run in the run structure is accessed to obtain the run information corresponding to the seed run.

8. The method according to claim 7, characterized in that The run position structure stores a container number and a sequence number; based on the run position index, accessing the position of the seed run in the run structure to obtain the run information corresponding to the seed run, including: Based on the container number, determining a row container corresponding to the seed run in the run structure; the row container stores the run information of all runs in the row where the seed run is located; Based on the position of the seed run represented by the sequence number in all runs in the row, the run information corresponding to the seed run is extracted.

9. A device for determining a connected domain, characterized in that: The device comprises: A scanning module, used for scanning the runs in the image to be processed by columns; An extraction module, used for, when any run is scanned, taking the scanned run as a seed run, and extracting the run information corresponding to the seed run from the run structure; A determination module, used for determining a target connected domain to which the seed run belongs based on the run information; An expansion module is used to gradually expand the target connected domain with the seed run as the starting point until all the runs included in the target connected domain are obtained, return to the first step to continue execution, and obtain all the connected domains in the image to be processed after traversing all the columns in the image to be processed.

10. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method for determining a connected domain according to any one of claims 1 to 8 is implemented.

Citation Information

Cited By

  • Image expansion method and device, electronic equipment and storage medium

    CN120655514A

  • Bab image pixel boundary tracking method and device based on run length coding

    CN120876523A