Block analysis method, system, and medium based on stroke code binarization
By introducing the run-length code binarization method, the problem of frequent data storage and memory operations in the block counting algorithm is solved, realizing efficient block analysis and improving the efficiency and practicality of industrial applications.
Patent Information
- Application Number
- CN202510990247.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-18
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2045-07-18
AI Technical Summary
Existing technologies for binarization processing of block counting algorithms suffer from problems such as large data storage burden, frequent memory operations, and low efficiency, especially for large-size images, making it difficult to meet the requirements for efficient processing.
A method based on run-length code binarization is adopted. By acquiring pixel block sequences, run-length code sequences are generated using a run-length coding structure. Then, connected regions are dynamically merged using a disjoint-set data structure to calculate block features and output them for visualization, thus replacing traditional binary image processing.
It significantly improves the efficiency of block analysis, reduces memory usage, and lowers execution time from 100 milliseconds to about 10 milliseconds, while providing rich block attribute information to meet the needs of industrial applications.
Smart Images

Figure CN120495384B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of machine vision and image processing, and more particularly, to a block analysis method, system and medium based on run-length coding binarization. BACKGROUND
[0002] In the field of machine vision, block counting algorithm as a basic and key technology is widely used in various scenes. However, the current algorithm has certain limitations in the binarization processing link.
[0003] Specifically, the binarization process often directly generates a new binary image, which not only increases unnecessary data storage burden, but also involves frequent memory allocation and release operations, greatly affecting the overall running efficiency of the algorithm, so that its performance in practical application still has a lot of room for improvement. The specific shortcomings are as follows:
[0004] 1. Large data storage burden, the binary image data generated by the traditional method is large, and there is a lot of redundant data;
[0005] 2. Frequent memory operations, among which, frequent memory allocation and release operations reduce the running efficiency of the algorithm;
[0006] 3. Low efficiency, especially for large size images (such as 10000x10000), the execution time of the traditional method is long (about 100 milliseconds), which is difficult to meet the demand of efficient processing. SUMMARY
[0007] The purpose of the present application is to provide a block analysis method, system and medium based on run-length coding binarization, which is used to solve the shortcomings of the prior art described above.
[0008] The first aspect of the present application provides a block analysis method based on run-length coding binarization, comprising the following steps:
[0009] Obtaining a pixel block sequence from an original image;
[0010] Processing the pixel block sequence based on a preset run-length coding structure to obtain a run-length code sequence;
[0011] Based on the run-length code sequence, using union-find set to dynamically merge connected regions to obtain a connected domain set;
[0012] Based on the connected domain set, block feature calculation is performed to obtain an analysis result, and the analysis result is visualized and output, wherein the block feature calculation includes calculating geometric features, and the geometric features at least include minimum circumscribed rectangle, target diameter, circularity and rectangularity.
[0013] In the scheme, the original image is obtained to obtain the pixel block sequence, specifically comprising:
[0014] An original image is obtained, the original image comprising an HxW matrix, H being the image height and W being the image length;
[0015] The pixel block is divided based on the original image, wherein the fixed length of the division is W;
[0016] The pixel block sequence P is obtained by extracting the pixel block after the block processing.
[0017] In the scheme, the pixel block sequence is processed based on the preset run-length encoding structure to obtain a run-length code sequence, specifically comprising:
[0018] The bit mask is generated based on the pixel block sequence, wherein the generated bit mask specifically comprises a binary sequence with a length of W;
[0019] The run-length code is generated based on the bit mask, and the run-length code sequence is obtained by globally merging all rows of run-length codes.
[0020] In the scheme, the run-length code is generated based on the bit mask, and the run-length code sequence is obtained by globally merging all rows of run-length codes, specifically comprising:
[0021] The state machine is maintained based on the bit mask and the position data of the current pixel block in the image, and the state variables include the current run-length start column and the current run-length end column, wherein,
[0022] The mask is processed based on the pixel block type, if the bit mask is all background blocks, the current run is closed; if the bit mask is all foreground blocks, a new run is started; if the bit mask is mixed blocks, the mask is scanned bit by bit, and the run is dynamically adjusted according to the current mask state.
[0023] The run-length code sequence is obtained by globally merging after the run at the end of the row is forced to close.
[0024] In the scheme, the connected domain set is obtained by using the union-find set to dynamically merge the connected regions based on the run-length code sequence, specifically comprising:
[0025] Each run-length code in the run-length code sequence is initialized as an independent node of the union-find set, wherein the region attribute of the independent node includes the boundary coordinates, the zero-order moment, the first-order moment and the run-length code endpoint set;
[0026] Adjacent run-length codes are detected based on a preset connected rule, wherein the root nodes of adjacent run-length codes are compared, if the root nodes are different, the merging is performed, wherein the merging content includes updating the boundary coordinates, accumulating the moment value and merging the endpoint set.
[0027] After detecting all the run codes, the connected domain set is obtained by merging, compressing and searching the tree structure.
[0028] In the present scheme, the block feature calculation based on the connected domain set obtains an analysis result, and the analysis result is visualized and output, specifically including:
[0029] The area, centroid, minimum circumscribed rectangle, target radius, circularity and rectangularity of the block are calculated based on the connected domain set.
[0030] The calculated analysis result is used as a feature set corresponding to each connected domain.
[0031] The feature set is visualized and output, including drawing boundaries, centroids and minimum circumscribed rectangles on the original image, and generating a structured report.
[0032] The second aspect of the present application also provides a block analysis system based on run code binarization, including a memory and a processor, the memory includes a block analysis method based on run code binarization program, and the block analysis method based on run code binarization program is executed by the processor to realize the following steps:
[0033] An original image is obtained to obtain a pixel block sequence.
[0034] The pixel block sequence is processed based on a preset run code structure to obtain a run code sequence.
[0035] The connected regions are dynamically merged based on the run code sequence using a union-find set to obtain a connected domain set.
[0036] The block feature calculation based on the connected domain set obtains an analysis result, and the analysis result is visualized and output, wherein the block feature calculation includes calculating geometric features, and the geometric features at least include a minimum circumscribed rectangle, a target diameter, a circularity and a rectangularity.
[0037] In the present scheme, the original image is obtained to obtain a pixel block sequence, specifically including:
[0038] An original image is obtained, and the original image includes an HxW matrix, H is the image height, and W is the image length.
[0039] The pixel blocks are divided based on the original image, and the fixed length of the division is W.
[0040] The pixel block sequence P is obtained by extracting the pixel blocks processed by the block division.
[0041] In the scheme, the pixel block sequence is processed based on the preset run encoding structure to obtain a run code sequence, specifically including:
[0042] A bit mask is generated based on the pixel block sequence, and the generated bit mask specifically includes a binary sequence with a length of W;
[0043] The run code is generated based on the bit mask, and the run code sequence is obtained by globally merging all rows of run codes.
[0044] In the scheme, the run code is generated based on the bit mask, and the run code sequence is obtained by globally merging all rows of run codes, specifically including:
[0045] The state machine is maintained based on the bit mask and the position data of the current pixel block in the image, and the state variables include the current run start column and the current run end column, wherein,
[0046] The mask is processed based on the pixel block type, if the bit mask is all background blocks, the current run is closed; if the bit mask is all foreground blocks, a new run is opened; if the bit mask is mixed blocks, the mask is scanned bit by bit, and the run opening or closing is dynamically adjusted according to the current mask state;
[0047] The run code sequence is obtained by globally merging after forcibly closing the unfinished run at the end of the row.
[0048] In the scheme, the connected domain set is obtained by using the union-find set to dynamically merge the connected regions based on the run code sequence, specifically including:
[0049] Each run code in the run code sequence is initialized as an independent node of the union-find set, wherein the region attribute of the independent node includes the boundary coordinates, the zero-order moment, the first-order moment and the run code endpoint set;
[0050] Adjacent run codes are detected based on a preset connected rule, wherein the root nodes of adjacent run codes are compared, and if the root nodes are different, the adjacent run codes are merged, wherein the merging content includes updating the boundary coordinates, accumulating the moment value and merging the endpoint set.
[0051] After detecting all run codes, the union-find set structure tree is compressed after merging to obtain the connected domain set.
[0052] In the scheme, the block feature calculation is performed based on the connected domain set to obtain an analysis result, and the analysis result is visualized and output, specifically including:
[0053] The area, centroid, minimum circumscribed rectangle, target radius, circularity and rectangularity of the block are calculated based on the connected domain set.
[0054] based on the calculated analysis results as a feature set corresponding to each connected domain;
[0055] based on the feature set, visual output is performed, including drawing boundaries, centroids and minimum circumscribed rectangles on the original image, and generating a structured report.
[0056] The third aspect of the present application provides a computer-readable storage medium, which comprises a machine-based block analysis method program based on run-length coding, and the program is executed by a processor to implement the steps of the block analysis method based on run-length coding according to any one of the above aspects.
[0057] The block analysis method, system and medium based on run-length coding disclosed by the present application optimize the binarization process by introducing run-length code and parallel computing, significantly improve the efficiency and practicability of block analysis, and provide rich block information, which is suitable for various application scenarios in the industrial field, and has the following specific beneficial effects:
[0058] 1. Efficiency is significantly improved. For a 10000x10000 image, the execution time is reduced from 100 milliseconds to about 10 milliseconds, and the efficiency is improved by 10 times.
[0059] 2. Memory usage is reduced. The run-length code structure is used to replace the traditional binary image, reducing data redundancy and memory operations.
[0060] 3. Rich functions, providing various block properties (such as area, circumscribed rectangle, roundness, etc.), meeting the needs of industrial applications.
[0061] 4. High flexibility, supporting ROI and shielding ROI functions, and can frame or exclude specific areas according to needs. BRIEF DESCRIPTION OF DRAWINGS
[0062] Figure 1 A step diagram of the block analysis method based on run-length coding is shown;
[0063] Figure 2 A flowchart of the block analysis method based on run-length coding is shown;
[0064] Figure 3 An original image of the block analysis method based on run-length coding is shown;
[0065] Figure 4 An output image of the block analysis method based on run-length coding is shown;
[0066] Figure 5A block diagram of a block analysis system based on run-length code binarization according to the present invention is shown. Detailed Implementation
[0067] To better understand the above-mentioned objectives, features, and advantages of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.
[0068] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and therefore the scope of protection of the invention is not limited to the specific embodiments disclosed below.
[0069] Figure 1 The diagram illustrates the steps of a block analysis method based on run-code binarization according to this application.
[0070] like Figure 1 As shown, this application discloses a block analysis method based on run-length code binarization, including the following steps:
[0071] S102, Obtain the pixel block sequence from the original image;
[0072] S104, The pixel block sequence is processed based on a preset run-length coding structure to obtain a run-length code sequence;
[0073] S106, Based on the run-code sequence, use disjoint-set data structure to dynamically merge connected regions to obtain a set of connected components;
[0074] S108, based on the set of connected components, the block features are calculated to obtain the analysis results, and the analysis results are visualized and output.
[0075] It should be noted that, in this embodiment, as Figure 2 The diagram shows a flowchart of a block analysis method based on run-length code binarization. Specifically, the original image to be processed is loaded and subjected to fast binarization. The binarization process includes parallelization and instruction set acceleration using a preset run-length code structure. A fixed length of pixel block is loaded each time, and run-length codes are generated through bitmasks and state variables to obtain a run-length code sequence. The process efficiently obtains a full background block, a full foreground block, and a mixed block, while simultaneously performing boundary processing, i.e., processing the tail pixels point by point to ensure run-length code closure.
[0076] Further, after obtaining the run code sequence, a connected domain analysis is performed based on the union-find set, including storing node and region attributes (such as coordinates, a matrix, and run code endpoints), processing region nodes corresponding to the run code line by line, updating region attributes to obtain a connected domain set through dynamic merging of adjacent run codes, and finally performing block information calculation based on the connected domain set, including specific calculation contents such as area, centroid, minimum circumscribed rectangle, target radius, circularity, and rectangularity, so that after obtaining the calculated analysis result, a visual display is performed, and the ROI (Region of Interest) and shielding ROI functions are supported when displaying the block information, so as to output the detection result, wherein the ROI is set to improve the algorithm efficiency and accuracy, and avoid invalid calculation, and the target radius is the Feret radius, which is used to describe the maximum projection length of the block, and is defined as the farthest Euclidean distance between any two points on the boundary of the block, and is used to quantify the maximum size or extension direction of the object (such as judging the long axis direction in particle analysis), and in this embodiment, the farthest point pair is directly calculated by using the run code endpoint set of the connected domain, avoiding scanning all pixels.
[0077] According to the embodiment of the present application, the original image is obtained to obtain a pixel block sequence, specifically including:
[0078] An original image is obtained, and the original image includes an HxW matrix, H is the image height, and W is the image length;
[0079] The pixel block is divided based on the original image, and the fixed length of the division is W;
[0080] The pixel block sequence P is obtained by extracting the pixel block processed.
[0081] It should be noted that, in this embodiment, as shown in Figure 3 , for the obtained original image, an efficient conversion from the gray original image to the binary run length encoding RLE is realized, and in this embodiment, a parallel computing and instruction set block data processing strategy is adopted, and each row of the image is processed by using parallelization, wherein for each row of the original image, an instruction set is used for acceleration, a fixed length W of pixel blocks is loaded each time, W is the maximum number of data that can be processed by the instruction set at a time, the pixel block sequence P is obtained by reading the pixel block processed by the instruction set at a time, and the specific representation is as follows: , is the first pixel block, is the second pixel block, is the pixel block.
[0082] According to the embodiment of the present application, the pixel block sequence is processed based on the preset run length encoding structure to obtain a run code sequence, specifically including:
[0083] generating a bit mask based on the pixel block sequence, wherein the generated bit mask specifically comprises a binary sequence with length W;
[0084] processing based on the bit mask to generate a run code, and globally merging all the run codes of the rows to obtain the run code sequence.
[0085] It should be noted that in the embodiment, the pixel block sequence In terms of generating a bit mask according to the comparison result of the pixel and the threshold value: , wherein or According to the binarization requirement, for example The condition defines the image foreground as the part with gray value less than or equal to a certain threshold , thereby obtaining a binary sequence with length W corresponding to the bit mask B, and generating a run code based on the bit mask B and the block position (r, c), wherein r is the row number and c is the starting column of the block.
[0086] According to the embodiment of the application, the processing based on the bit mask to generate a run code, and globally merging all the run codes of the rows to obtain the run code sequence, specifically comprises:
[0087] maintaining a state machine based on the bit mask and the position data of the current pixel block in the image, and the state variables include the current run starting column and the current run ending column, wherein
[0088] processing the mask based on the pixel block type, if the bit mask is all background blocks, closing the current run; if the bit mask is all foreground blocks, opening a new run; if the bit mask is mixed blocks, scanning the mask bit by bit, and dynamically adjusting the run opening or closing according to the current mask state;
[0089] globally merging to obtain the run code sequence after forcibly closing the run at the end of the row which is not completed.
[0090] It should be noted that in the embodiment, the state variable s is defined to represent the current run starting position, and the block information is processed into a run code according to the mask result:
[0091] ①: all background blocks ( );
[0092] If , that is, there is an ongoing run, generating a run segment [s, e] and resetting s = -1, wherein e is the position of the previous block;
[0093] ②: all foreground blocks ( );
[0094] If , set s as the block start position and continue to process the next block;
[0095] III: mixed block (1) );
[0096] For each index i in the block, handle it in two cases:
[0097] i: when and : set s as the image x coordinate corresponding to index i;
[0098] ii: when and : set e as the image x coordinate corresponding to index i, generate the run segment and reset ;
[0099] So far, the processing efficiency of the mask on the data in this embodiment is high, because only bit operations are required for B to obtain any , and ① and ② do not need to compare pixels point by point as in the general method, and the tail pixels that are not long enough are processed point by point, and the unfinished run segment is forced to close at the end of the line.
[0100] Correspondingly, after the line is determined, the run code list of the current line is , , and the run codes of all lines are merged to obtain the global column to obtain the run code sequence of the original image , specifically, the run code is a horizontal line segment, which can be represented as follows:
[0101] ;
[0102] Wherein, r is the number of the line where the run code is located, s and e represent the start and end columns of the run code, represents the first run code of the starting column of the current line, represents the second run code of the starting column of the current line, represents the first run code of the ending column of the current line, represents the second run code of the ending column of the current line, and the area covered by a plurality of non-overlapping run codes can correspond to the area of the foreground of the binary image one by one, avoiding a large amount of redundant data generated in the process of generating a binary image and the burden of frequent memory allocation and release operations, and improving the efficiency of data searching and storage.
[0103] According to the embodiment of the application, the connected region set is obtained by using the union-find set to dynamically merge the connected regions based on the run code sequence, specifically including:
[0104] each of the stroke codes in the stroke code sequence is initialized as an independent node of the union-find set, wherein the region attribute of the independent node comprises boundary coordinates, zeroth moment, first moment, and a set of stroke code endpoints;
[0105] adjacent stroke codes are detected based on a preset connectivity rule, wherein the root nodes of the adjacent stroke codes are compared, and if the root nodes are different, the adjacent stroke codes are merged, wherein the merging content comprises updating the boundary coordinates, accumulating the moment values, and merging the endpoint sets;
[0106] after the detection of all the stroke codes is completed, the union-find set structure tree is compressed after merging to obtain the set of connected domains.
[0107] It should be noted that in the embodiment, specifically, each stroke code {r, s, e} is initialized as an independent node, and the region attribute (boundary, moment, endpoint, etc.) is stored, wherein each node stores the parent node index and the region attribute, and the path compression is used to optimize the lookup efficiency, wherein the region attribute comprises: ① minimum / maximum row and column coordinates ; ② zeroth moment and first moment , ; ③ left and right endpoint coordinates of all stroke codes in the region ; ④ record the index of the last merged stroke code.
[0108] Further, the stroke codes are traversed row by row, and for each stroke code on a row, an independent node is created and the region attribute is initialized:
[0109] For any stroke code , if it is represented as , that is, the stroke code on the rth row, the starting column is s, and the ending column is r, then:
[0110] ;
[0111] ;
[0112] ;
[0113] ;
[0114] wherein r is the row number of the stroke code, s and e represent the starting and ending columns of the stroke code, is the minimum row coordinate, is the maximum row coordinate, is the minimum column coordinate, is the maximum column coordinate, is the zeroth moment, and For the first moment, the left and right endpoint coordinates of all the run codes in the region and the last merged run code index are all referenced by themselves.
[0115] Further, the run codes are traversed row by row and the region nodes corresponding to the run codes are initialized, and only whether the run code i is adjacent to the last row run code j (8-connected) is detected, that is, whether there is:
[0116] ;
[0117] If adjacent, the root nodes of the two run codes are merged: the region node where the run code is located updates the root node of the run code to the root node of the run code , and the region attribute of the root node where the run code is located is updated:
[0118] , ;
[0119] , ;
[0120] ;
[0121] ;
[0122] ;
[0123] wherein, is the root node of the node where the run code is located, is the root node of the run code , and the left and right endpoint coordinates of all the run codes in the region are directly merged; the last merged run code index is updated according to the newly traversed run code, and finally the connected domain set is obtained, each Blob contains: the merged run code list and the region attribute (area, boundary, centroid, endpoint set, etc.).
[0124] According to the embodiment of the application, the block feature calculation based on the connected domain set obtains an analysis result, and the analysis result is visualized and output, specifically including:
[0125] The area, centroid, minimum circumscribed rectangle, target radius, circularity and rectangularity of the block are calculated based on the connected domain set;
[0126] The calculated analysis result is taken as a feature set corresponding to each connected domain;
[0127] The visualization output is performed based on the feature set, including drawing the boundary, the center of mass and the minimum circumscribed rectangle on the original image, and generating a structured report.
[0128] It should be noted that in this embodiment, the various information of the block is calculated during / after the connected domain process, including:
[0129] Area:
[0130] ;
[0131] Center of mass:
[0132] , ;
[0133] wherein, is the center of mass coordinate of the block, is the area of the pixel block, is the zeroth moment, and is the first moment, is the zeroth moment of the entire block, equal to the sum of the zeroth moments of all the stroke codes contained therein, , is the first moment of the entire block with respect to x and y, respectively, equal to the sum of the corresponding first moments of all the stroke codes contained therein.
[0134] Minimum circumscribed rectangle:
[0135] Equivalent to the minimum circumscribed rectangle containing all the endpoints of the stroke codes:
[0136] ;
[0137] wherein is the connected domain, is the endpoint set of the connected domain corresponding to the stroke code, in actual application, it is calculated by calling, i.e. recording the endpoint set of the stroke code, and calling the “cv: minAreaRect” interface of opencv to calculate.
[0138] Target radius (Feret radius):
[0139] Defined as the distance between the two farthest points inside the block, equal to the distance between the two farthest points in the endpoint set of the stroke code:
[0140] ;
[0141] Circularity:
[0142] The circumscribed circle of the block is defined as the smallest circle containing the block with the center of the block as the center of the circle, and the radius is only the farthest distance from the center of the mass to the end of the stroke code, which avoids the high time consumption in the process of fitting a circle in the embodiment, and is defined as follows:
[0143] ;
[0144] When the block converges to a standard circle, the roundness will converge to "1", which meets the requirement of using roundness as a judgment of whether the block is close to a circle in various scenarios, wherein, represents the area of the block, represents the area of the smallest circle containing the stroke code with the center of the mass as the center of the circle, and the radius is equal to the farthest distance from the center of the mass to the end of the stroke code, which is convenient for calculation.
[0145] Rectangularity:
[0146] ;
[0147] When the block converges to a standard rectangle, the rectangularity will converge to "1", which meets the requirement of using rectangularity as a judgment of whether the block is close to a rectangle in various scenarios, wherein, represents the area of the block, represents the area of the smallest circumscribed rectangle of the block.
[0148] Further, when visualizing output based on the feature set, as shown in Figure 4 , the block information is displayed on the graphical interface, and ROI / ROI shielding is supported, that is, the function of framing the region of interest as needed and excluding irrelevant areas, and the detection result will only include the area inside the ROI and the area outside the shielding ROI, wherein, as shown in Figure 4 , only the upper left quarter of the block is output in the embodiment due to the existence of ROI and shielding area.
[0149] Figure 5 A block diagram of a block analysis system based on stroke code binarization is shown.
[0150] As shown in Figure 5 , the application discloses a block analysis system based on stroke code binarization, which comprises a memory and a processor, the memory comprises a block analysis method program based on stroke code binarization, and the block analysis method program based on stroke code binarization is executed by the processor to realize the following steps:
[0151] Obtaining a pixel block sequence from an original image;
[0152] Processing the pixel block sequence based on a preset stroke coding structure to obtain a stroke code sequence;
[0153] obtaining a connected domain set by using a union-find dynamic merging of the connected regions based on the stroke code sequence;
[0154] performing block feature calculation based on the connected domain set to obtain an analysis result, and visualizing and outputting the analysis result, wherein the block feature calculation comprises calculating geometric features, and the geometric features at least include a minimum circumscribed rectangle, a target diameter, a circularity, and a rectangularity.
[0155] It should be noted that, in the present embodiment, the specific implementation manner of the present embodiment corresponds to the foregoing method embodiment, and therefore the same details will not be repeated here. The third aspect of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium comprises a stroke code binarization-based block analysis method program, and the stroke code binarization-based block analysis method program is executed by a processor to implement the steps of the stroke code binarization-based block analysis method according to any one of the foregoing method embodiments.
[0156] The stroke code binarization-based block analysis method, system, and medium disclosed in the present application innovatively introduce a run-length encoding (RLE) structure, and combine an instruction set acceleration and other optimization schemes to deeply optimize the binarization process. By using a run-length encoding code with a smaller data amount and a compact structure to replace a traditional original binarization method with a large data amount and a large amount of redundancy, the present application significantly reduces the calculation complexity and memory occupation of the algorithm. Figure Two For an image with a size of 10000x10000, the present application is reduced from 100 milliseconds to about 10 milliseconds, the efficiency is improved by 10 times, the running efficiency and practicability of the block counting algorithm are greatly improved, and rich block information is provided as output, including area, circumscribed rectangle, circularity, ellipticity, and the like, thereby providing convenience for industrial applications.
[0157] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic, for example, the division of the units is only a logical function division, and actual implementation can have another division manner, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed components can be through some interfaces, indirect coupling or communication connection between devices or units, which can be electrical, mechanical or other forms.
[0158] The units described as separate components above can or can not be physically separate, and the components shown as units can or can not be physical units; they can be located in one place or distributed on multiple network units; and part or all of the units can be selected according to actual needs to achieve the purposes of the embodiments.
[0159] In addition, each functional unit in each embodiment of the present application can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in the form of hardware or in the form of hardware plus software functional units.
[0160] Those of ordinary skill in the art can understand that all or part of the steps of the above method embodiments can be completed by relevant hardware instructed by programs, and the foregoing programs can be stored in a computer readable storage medium, and when the programs are executed, steps including the above method embodiments are executed; and the foregoing storage medium includes mobile storage devices, read-only memories (ROMs), random access memories (RAMs), magnetic discs or optical discs, and various media that can store program codes.
[0161] Alternatively, the integrated units of the present application, if implemented in the form of software functional modules and sold or used as independent products, can also be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the embodiments of the present application can be embodied in the form of software products, and the computer software products are stored in a storage medium, including a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the methods described in the embodiments of the present application. The foregoing storage medium includes mobile storage devices, ROMs, RAMs, magnetic discs or optical discs, and various media that can store program codes.
Claims
1. A block analysis method based on run-length code binarization, characterized in that, Includes the following steps: Obtain the pixel block sequence from the original image; The pixel block sequence is processed based on a preset run-length encoding structure to obtain a run-length code sequence; Based on the travel code sequence, a set of connected components is obtained by dynamically merging connected regions using a disjoint-set data structure. The block feature calculation is performed based on the connected component set to obtain the analysis results, and the analysis results are visualized and output. The block feature calculation includes calculating geometric features, which include at least the minimum bounding rectangle, the target diameter, the roundness, and the rectangularity. The step of processing the pixel block sequence based on a preset run-length encoding structure to obtain a run-length code sequence specifically includes: A bitmask is generated based on the pixel block sequence, wherein the generated bitmask specifically includes a binary sequence of length W; The process involves generating a travel code based on the bitmask, and then globally merging the travel codes from all rows to obtain the travel code sequence. Specifically, this includes: The state machine is maintained based on the bitmask and the position data of the current pixel block in the image. The state variables include the current travel start column and the current travel end column, wherein... The mask is processed based on the pixel block type. If the bitmask is all background blocks, the current travel is closed; if the bitmask is all foreground blocks, a new travel is started; if the bitmask is a mixed block, the mask is scanned bit by bit, and the travel is dynamically adjusted to open or close according to the current mask state. The incomplete travel at the end of the line is forcibly closed and then globally merged to obtain the travel code sequence.
2. The block analysis method based on run-length code binarization according to claim 1, characterized in that, The process of obtaining the pixel block sequence from the original image specifically includes: Obtain the original image, which includes an H×W matrix, where H is the image height and W is the image length; The original image is divided into pixel blocks, wherein the fixed length of the block is W. The pixel block sequence P is obtained by extracting the pixel blocks after block processing.
3. The block analysis method based on run-length code binarization according to claim 2, characterized in that, The process of dynamically merging connected regions using a disjoint-set data structure based on the run-length code sequence to obtain a set of connected components specifically includes: Each travel code in the travel code sequence is initialized as a disjoint-set independent node, wherein the regional attributes of the independent node include boundary coordinates, zeroth moment, first moment and travel code endpoint set; Adjacent travel codes are detected based on preset connectivity rules. The root nodes of adjacent travel codes are compared. If the root nodes are different, they are merged. The merging process includes updating the boundary coordinates, accumulating moment values, and merging the endpoint set. After all travel codes have been detected, the connected component set is obtained by merging and compressing the disjoint-set data structure tree.
4. The block analysis method based on run-length code binarization according to claim 3, characterized in that, The step of calculating block features based on the connected component set to obtain analysis results, and then visualizing the analysis results, specifically includes: The area, centroid, minimum bounding rectangle, target radius, roundness, and rectangularity of the block are calculated based on the set of connected components. The calculated analysis results are used as the feature set corresponding to each connected component; Visualization output is performed based on the feature set, including drawing the boundary, centroid, and minimum bounding rectangle on the original image, and generating a structured report.
5. A block analysis system based on run-length code binarization, characterized in that, The system includes a memory and a processor. The memory contains a block analysis method program based on run-code binarization. When the processor executes the block analysis method program based on run-code binarization, it performs the following steps: Obtain the pixel block sequence from the original image; The pixel block sequence is processed based on a preset run-length encoding structure to obtain a run-length code sequence; Based on the travel code sequence, a set of connected components is obtained by dynamically merging connected regions using a disjoint-set data structure. The block feature calculation is performed based on the connected component set to obtain the analysis results, and the analysis results are visualized and output. The block feature calculation includes calculating geometric features, which include at least the minimum bounding rectangle, the target diameter, the roundness, and the rectangularity. The step of processing the pixel block sequence based on a preset run-length encoding structure to obtain a run-length code sequence specifically includes: A bitmask is generated based on the pixel block sequence, wherein the generated bitmask specifically includes a binary sequence of length W; The process involves generating a travel code based on the bitmask, and then globally merging the travel codes from all rows to obtain the travel code sequence. Specifically, this includes: The state machine is maintained based on the bitmask and the position data of the current pixel block in the image. The state variables include the current travel start column and the current travel end column, wherein... The mask is processed based on the pixel block type. If the bitmask is all background blocks, the current travel is closed; if the bitmask is all foreground blocks, a new travel is started; if the bitmask is a mixed block, the mask is scanned bit by bit, and the travel is dynamically adjusted to open or close according to the current mask state. The incomplete travel at the end of the line is forcibly closed and then globally merged to obtain the travel code sequence.
6. A block analysis system based on run-length code binarization according to claim 5, characterized in that, The process of obtaining the pixel block sequence from the original image specifically includes: Obtain the original image, which includes an H×W matrix, where H is the image height and W is the image length; The original image is divided into pixel blocks, wherein the fixed length of the block is W. The pixel block sequence P is obtained by extracting the pixel blocks after block processing.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a block analysis method program based on run-code binarization, which, when executed by a processor, implements the steps of a block analysis method based on run-code binarization as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Algorithm and device for obtaining maximal horizontally inscribed rectangle for any connected domain based on run length encoding
CN106651944A
Block information determination method and system and storage medium
CN119205788A