Binary image hole filling method, device, equipment and readable storage medium
Through the construction and inverse matrix filling methods, the problem of long-term hole filling processing of binary graphs is solved, and efficient hole filling processing is achieved, avoiding the problem of excessive system resource occupation.
Patent Information
- Application Number
- CN202510123156.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-26
- Publication Date
- 2025-05-09
- Estimated Expiration
- 2045-01-26
AI Technical Summary
In the prior art, the process of filling a binary graph hole in the hole takes a long time and occupies a large amount of computing resources, which may cause the system to fail to work normally.
By obtaining the hole area in the binary graph, constructing the block matrix on the finite domain gf(2), determining its inverse matrix, and backfilling the matrix elements in the inverse matrix into the hole area, realizing hole filling in the binary graph.
Using the binary operation rules of the finite domain gf(2) and the bit width of the central processor, the matrix is compressed columnically and converted serial processing into parallel processing, greatly improving the efficiency of binary graph hole processing.
Smart Images

Figure CN119559295B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a method, device, equipment and readable storage medium for filling holes in binary images. Background Art
[0002] Image binarization refers to the process of converting an image into a grayscale image with only two gray levels. Filling holes in binary images during the image binarization process can simplify image features and reduce noise, thereby simplifying the image processing process, improving image contrast, and facilitating image segmentation. Thanks to the advantages of binary image hole filling in image processing, this technical means has been widely used in industrial inspection, biomedical image processing and other fields. The process of filling holes in binary images involves matrix inversion operations, and the serial operation characteristics of matrix inversion operations limit the operation speed. As a result, the process of filling holes in binary images for images with large data scales is time-consuming and long, and even because the binary image hole filling process occupies a large amount of computing resources, there is a hidden danger that the system cannot work properly. Therefore, it is urgent to improve the efficiency of binary image hole filling. Summary of the invention
[0003] In order to solve the problem that the binary image hole filling process takes a long time, this application provides the following technical solutions:
[0004] In a first aspect, a binary image hole filling method is provided, comprising:
[0005] Obtain a binary image and detect the hole area in the binary image;
[0006] Constructing at least one input matrix corresponding to the pixel points in the hole region according to the pixel values of the pixel points in the hole region, wherein the at least one input matrix is a block matrix on gf(2), and gf(2) is a finite field;
[0007] determining at least one inverse matrix corresponding to at least one input matrix;
[0008] Backfill the values of the matrix elements in at least one inverse matrix to the pixel points in the hole area whose positions correspond to the matrix elements in at least one inverse matrix, to obtain an image after the binary image hole is filled;
[0009] Wherein, determining at least one inverse matrix corresponding to at least one input matrix comprises:
[0010] Traverse any of the input matrices in at least one input matrix and execute:
[0011] In response to the input matrix being invertible, determining an augmented matrix corresponding to the input matrix according to the input matrix;
[0012] Obtaining a bit width of a central processing unit, and determining a compression matrix according to the bit width and the augmented matrix, wherein the central processing unit is used to perform hole filling on the binary image;
[0013] Based on the compressed matrix, an inverse matrix corresponding to the input matrix is determined.
[0014] Furthermore, according to the bit width and the augmented matrix, a compression matrix is determined, including:
[0015] The number of rows of the augmented matrix is used as the number of rows of the compressed matrix, wherein the number of bits of any matrix element in the compressed matrix is the bit width, and the compressed matrix has a compressed matrix first part and a compressed matrix second part;
[0016] The quotient of the number of columns and the bit width of the augmented matrix is used as the number of columns of the compressed matrix;
[0017] Fill the matrix elements in any row of the input matrix with a number of the bit width from high to low in the order of increasing values of the column index of the input matrix, to obtain an input compressed number corresponding to any row of the input matrix, and determine the matrix elements in the first part of the compressed matrix according to the corresponding relationship between the input compressed number and the row of the input matrix, wherein any row in the first part of the compressed matrix has one matrix element, and the matrix element in any row of the first part of the compressed matrix is the input compressed number corresponding to the row index and the row index of the input matrix;
[0018] Fill any row of matrix elements in the unit matrix of the same size as the input matrix with a word length equal to the bit width from high to low in the order of increasing values of the unit matrix column index, to obtain a unit compression number corresponding to any row of the unit matrix, and determine the matrix elements in the second part of the compressed matrix according to the corresponding relationship between the unit compression number and the row of the unit matrix, wherein any row in the second part of the compressed matrix has one matrix element, and the matrix element of any row in the second part of the unit matrix is the unit compression number corresponding to the row index and the row index of the unit matrix;
[0019] The compressed matrix is obtained by adding the second part of the compressed matrix to the right side of the first part of the compressed matrix.
[0020] Further, based on the compression matrix, determining an inverse matrix corresponding to the input matrix includes:
[0021] Diagonalizing the digital array composed of the digital elements of the compressed matrix in the first part of the compressed matrix, wherein the row index of the digital array is the same as the row index of the compressed matrix, and the ascending order of the numerical value of the column index of the digital array corresponds to the descending order of the digital elements of any row of the digital array;
[0022] Extract the second part of the compressed matrix when the first part of the compressed matrix is diagonalized;
[0023] An inverse matrix of the input matrix is determined based on the extracted second portion of the compressed matrix.
[0024] Further, the digital array composed of the matrix element digital numbers of the compressed matrix in the first part of the compressed matrix is diagonalized, including:
[0025] Initialize the current index value to the minimum value of the compressed matrix row index, wherein the current index value is used to indicate the element of the digital array to be operated;
[0026] In response to the current index value not being greater than the maximum value of the compressed matrix row index, executing:
[0027] Update the current row index value and the current column index value of the digital array with the current index value;
[0028] In any row whose row index value is greater than the current row index value, get any row whose current column index value corresponds to 1, and swap it with the row corresponding to the current row index value;
[0029] Update the row by adding the row whose corresponding value is 1 to the row whose corresponding value is 1.
[0030] Increase the current index value by 1.
[0031] Further, according to the extracted second part of the compressed matrix, an inverse matrix of the input matrix is determined, including:
[0032] Get the matrix element of any row of the second part of the compressed matrix;
[0033] The matrix elements of any row of the second part of the compressed matrix are split in the order of high digits to low digits, and the splits are used as the matrix elements in the corresponding row of the inverse matrix with the column indexes arranged in ascending order.
[0034] Furthermore, the bit width of the central processing unit is obtained, including:
[0035] Get the actual number of bytes of a variable in any computer language environment;
[0036] The product of the actual number of bytes and the preset number of bits is used as the bit width of the CPU.
[0037] Furthermore, before obtaining the binary image and detecting the hole area in the binary image, the method further includes:
[0038] An original image is obtained, and a binary image corresponding to the original image is determined according to the original image.
[0039] In a second aspect, a binary image hole filling device is provided, comprising:
[0040] A hole detection module is used to obtain a binary image and detect hole areas in the binary image;
[0041] An input matrix determination module, used to construct at least one input matrix corresponding to the pixel points in the hole area according to the pixel values of the pixel points in the hole area, wherein the at least one input matrix is a block matrix on gf(2), and gf(2) is a finite field;
[0042] an inverse matrix determination module, configured to determine at least one inverse matrix corresponding to at least one input matrix;
[0043] A hole backfilling module, used to backfill the values of the matrix elements in at least one inverse matrix to the pixel points in the hole area whose positions correspond to the matrix elements in at least one inverse matrix, so as to obtain an image after the binary image holes are filled;
[0044] Wherein, determining at least one inverse matrix corresponding to at least one input matrix comprises:
[0045] Traverse any of the input matrices in at least one input matrix and execute:
[0046] In response to the input matrix being invertible, determining an augmented matrix corresponding to the input matrix according to the input matrix;
[0047] Obtaining a bit width of a central processing unit, and determining a compression matrix according to the bit width and the augmented matrix, wherein the central processing unit is used to perform hole filling on the binary image;
[0048] Based on the compressed matrix, an inverse matrix corresponding to the input matrix is determined.
[0049] In a third aspect, a computer device is provided, comprising a memory, a processor, and a binary image hole filling program stored in the memory and executable on the processor. When the processor executes the binary image hole filling program, the binary image hole filling method described in the first aspect is implemented.
[0050] In a fourth aspect, a computer-readable storage medium is provided, on which a binary image hole filling program is stored. When the binary image hole filling program is executed by a processor, the binary image hole filling method recorded in the first aspect is implemented.
[0051] In a fifth aspect, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the binary image hole filling method described in the first aspect.
[0052] The technical solution provided in the embodiment of the present application has the following beneficial effects: based on the pixel characteristics of the binary image, a matrix on the finite field gf(2) is used to perform binary image filling processing on the image corresponding to the binary image pixels, which can make full use of the computer's binary operation rules and improve the efficiency of binary image hole processing; the bit width of the central processing unit is used to perform column compression on the original matrix on the finite field gf(2), and the original multiple data are compressed into a data with the same bit width as the central processing unit, so that the serial processing process of the matrix operation is converted into a parallel processing process, which greatly improves the efficiency of binary image hole processing using a computer. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0054] Figure 1 It is a schematic diagram of a binary image hole filling method provided in an embodiment of the present application;
[0055] Figure 2 It is a schematic diagram of matrix compression provided by an embodiment of the present application;
[0056] Figure 3 It is a schematic diagram of a binary image hole filling device provided in an embodiment of the present application;
[0057] Figure 4 It is a schematic diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0058] In order to make the purpose, technical solutions and advantages of this application clearer, the technical solutions in the implementation mode of this application will be clearly and completely described below in conjunction with the drawings in the implementation mode of this application. Obviously, the described implementation mode is only a part of the embodiments of this application, not all embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0059] Unless otherwise defined, the technical terms or scientific terms used in the present disclosure shall have the usual meanings understood by persons with ordinary skills in the field to which the present disclosure belongs. The words "first", "second" and similar words used in the present disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, words such as "one", "one" or "the" do not indicate a quantity limitation, but indicate that there is at least one. The numbers in the drawings of the specification only indicate the distinction between various functional components or modules, and do not indicate the logical relationship between components or modules. Words such as "include" or "comprise" and similar words mean that the elements or objects appearing before the word include the elements or objects listed after the word and their equivalents, without excluding other elements or objects. Words such as "connect" or "connected" and similar words are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0060] Hereinafter, various embodiments according to the present disclosure will be described in detail with reference to the accompanying drawings. It should be noted that in the accompanying drawings, the same reference numerals are given to components having substantially the same or similar structures and functions, and repeated descriptions thereof will be omitted.
[0061] To solve the problem that the process of filling holes in binary images takes a long time, this application provides the following technical solutions:
[0062] In some embodiments, Figure 1 As shown, the binary image hole filling method includes:
[0063] S100: Obtain a binary image and detect hole areas in the binary image.
[0064] A binary image refers to an image in which each pixel has only two possible values or grayscale levels. It is usually represented by a black and white monochrome image. It is customary to use "0" to represent a black background and "1" to represent a white foreground when using a computer to express pixel points. A hole in a binary image refers to a background area surrounded by a boundary connected to foreground pixels. Simply put, it is a black area surrounded by a white area. Holes in a binary image are generated when some areas are mistakenly identified as background or noise during the processing of the original image. The existence of holes will affect the processing efficiency of the binary image. In order to improve the processing efficiency of binary images, the image is usually preprocessed to fill the hole area. The common binary image hole filling method identifies holes through connected component analysis, constructs a linear equation system for each pixel in the hole, and reconstructs the image after solving the equation system to fill the hole area.
[0065] S200: Construct at least one input matrix corresponding to the pixel points in the hole area according to the pixel values of the pixel points in the hole area, wherein at least one input matrix is a block matrix on gf(2), and gf(2) is a finite field.
[0066] A finite field is a field that contains only a finite number of elements. Schematically, the finite field gf(2) contains only two elements: 0 and 1.
[0067] Constructing at least one input matrix corresponding to the pixels in the hole area is based on the known pixel values around each pixel in the hole and the modulus of 2. This article does not go into detail on how to construct the input matrix based on the pixel values, but only focuses on the matrix equation obtained after constructing the input matrix, which has the following form:
[0068] ,
[0069] in, A is the coefficient matrix, that is, the input matrix mentioned above, x is the unknown pixel vector, b is the right side vector. For unknown pixel vector x Solve it to get the unknown pixel vector x The pixel value of each pixel in the hole area is then determined. That is:
[0070] ,
[0071] in, A -1 The input matrix A The inverse matrix of . It should be noted that the constructed input matrix is a block matrix, and the matrix size of the input matrix is "bit width" × "bit width". The bit width is the bit width of the central processing unit that performs the binary image hole filling task. Schematically, the bit width of the central processing unit is 32 bits, and the matrix size of the input matrix is 32×32.
[0072] Therefore, when constructing at least one input matrix based on the pixel points in the hole area, the scale of the input matrix needs to meet the above conditions. If the pixel points cannot fill the matrix elements in the input matrix, the values of the matrix elements in the unfilled part can be set to preset values. Schematically, the preset value is 1 or 0. Specifically:
[0073] S210: Obtaining a pixel value corresponding to any pixel point in the hole area;
[0074] S220: Dividing the pixel point range in the hole area according to the input matrix scale so that the number of pixels in the hole area is not greater than the number of matrix elements of the input matrix;
[0075] S230: setting pixel values within the pixel point range to corresponding matrix element values in the input matrix;
[0076] S240: In response to the presence of unset matrix elements in the input matrix, setting the matrix elements with preset values, wherein the preset values are 1 or 0.
[0077] S300: Determine at least one inverse matrix corresponding to at least one input matrix.
[0078] S400: Backfill the values of matrix elements in at least one inverse matrix to the pixel points in the hole area whose positions correspond to the matrix elements in at least one inverse matrix, so as to obtain an image after the binary image holes are filled.
[0079] Wherein, S300: determining at least one inverse matrix corresponding to at least one input matrix includes:
[0080] Traverse any of the input matrices in at least one input matrix and execute:
[0081] S310: In response to the input matrix being reversible, determining an augmented matrix corresponding to the input matrix according to the input matrix.
[0082] The judgment of whether the input matrix is reversible is to judge whether the matrix elements in the first column of the input matrix are all "0". If the first column of the input matrix is not all "0", it means that the input matrix is reversible; if the first column of the input matrix is all "0", the input matrix is not reversible.
[0083] S310ʹ: In response to the input matrix being not invertible, a prompt indicating that the input matrix is not invertible is returned.
[0084] The method of constructing an augmented matrix is to concatenate a unit matrix with the same matrix size as the input matrix to the right side of the input matrix to obtain an augmented matrix corresponding to the input matrix.
[0085] S320: Obtain the bit width of the central processing unit, and determine the compression matrix according to the bit width and the augmented matrix, wherein the central processing unit is used to perform hole filling on the binary image.
[0086] The bit width of a CPU is the data bandwidth of the CPU to execute an instruction, such as 16 bits, 32 bits, 64 bits, etc. The larger the bit width, the more data the CPU can process in a single clock cycle, thereby improving the overall computing speed and efficiency.
[0087] The obtained bit width of the CPU can be stored in a preset register, and the bit width of the CPU can be called by accessing the register, thereby simplifying the method of obtaining the bit width of the CPU in the case where the bit width of the CPU needs to be called multiple times.
[0088] The compressed matrix is the matrix obtained by compressing the augmented matrix. The compression process is to compress the matrix elements in the original matrix and the unit matrix into two columns of data with a bit width equal to the bit width of the central processing unit. Since the scale of the input matrix and the unit matrix are the same as the bit width; and because the input matrix is a matrix over the finite field gf(2), the matrix elements of the unit matrix have only two values, "0" and "1", and it is also a matrix over the finite field gf(2). Therefore, any row of matrix elements in the input matrix and the unit matrix can correspond to a data with a corresponding bit width arranged in descending order of the number of bits according to the ascending column index.
[0089] Figure 2 A schematic diagram showing how to compress the original matrix of 32 columns into 1 column.
[0090] S330: Based on the compressed matrix, determine an inverse matrix corresponding to the input matrix.
[0091] Due to the above correspondence between the bit width and the matrix size of the original matrix and the matrix size of the unit matrix, the compressed matrix contains only two columns. The original serial operation on the matrix elements of each row of the original matrix is converted into a digital parallel operation on the elements of each row of the compressed matrix.
[0092] According to the operation rules of gf(2) finite field:
[0093] a+b=ab=a^b, which means that the addition and subtraction operations of numbers can be converted into XOR operations, where a and b are two numbers respectively; a×b=a&b, which means that the penalty operation of numbers can be converted into AND operations. Under the premise that each digit is operated independently and no carry is performed, the operation of a digit in any matrix element of the compressed matrix represents the operation of the corresponding matrix element in the input matrix or unit matrix. This greatly improves the efficiency of filling holes in binary images.
[0094] Specifically, according to the bit width and the augmented matrix, the compression matrix is determined, including:
[0095] S325: Using the number of rows of the augmented matrix as the number of rows of the compressed matrix, wherein the number of bits of any matrix element in the compressed matrix is the bit width, and the compressed matrix includes a compressed matrix first part and a compressed matrix second part.
[0096] S326: Taking the quotient of the number of columns of the augmented matrix and the bit width as the number of columns of the compressed matrix.
[0097] S327: Fill the matrix elements in any row of the input matrix with a number whose word length is the bit width from high to low in the order of increasing numerical values of the column index of the input matrix, and obtain the input compressed number corresponding to any row of the input matrix, and determine the matrix elements in the first part of the compressed matrix according to the corresponding relationship between the input compressed number and the row of the input matrix, wherein any row in the first part of the compressed matrix has a matrix element, and the matrix element of any row in the first part of the compressed matrix is the input compressed number whose row index corresponds to the row index of the input matrix.
[0098] S328: Fill the matrix elements of any row in the unit matrix whose matrix size is equal to that of the input matrix with a word length equal to the bit width from high to low in the order of increasing values of the column index of the unit matrix, and obtain the unit compression number corresponding to any row of the unit matrix, and determine the matrix elements in the second part of the compressed matrix according to the corresponding relationship between the unit compression number and the row of the unit matrix, wherein any row in the second part of the compressed matrix has a matrix element, and the matrix element of any row in the second part of the unit matrix is the unit compression number corresponding to the row index and the row index of the unit matrix.
[0099] S329: Add the second part of the compressed matrix to the right of the first part of the compressed matrix to obtain the compressed matrix.
[0100] Specifically, based on the compression matrix, determining the inverse matrix corresponding to the input matrix includes:
[0101] S331: Diagonalize the digital array composed of the matrix element digits of the compressed matrix in the first part of the compressed matrix, wherein the row index of the digital array is the same as the row index of the compressed matrix, and the ascending order of the numerical value of the column index of the digital array corresponds to the descending order of the digits of any row element of the digital array.
[0102] Diagonalizing the digital array composed of matrix element digits of the compressed matrix in the first part of the compressed matrix is based on elementary matrix transformation, operating the compressed matrix so that the digital array composed of matrix element digits of the first part of the compressed matrix presents a diagonal form.
[0103] S332: Extracting the second part of the compressed matrix when the first part of the compressed matrix is diagonalized.
[0104] When the first part of the digits of the compressed matrix is in a diagonal form, the matrix form corresponding to the second part of the digits of the compressed matrix is the inverse matrix of the input matrix. Therefore, when the first part of the digits of the compressed matrix is in a diagonal form, the digits of the second part of the compressed matrix are extracted and restored to the matrix form to obtain the inverse matrix corresponding to the input matrix.
[0105] S333: Determine the inverse matrix of the input matrix according to the extracted second part of the compressed matrix.
[0106] Specifically, the bit array composed of the matrix element bits of the compressed matrix in the first part of the compressed matrix is diagonalized, including:
[0107] S3311: Initialize the current index value to the minimum value of the compressed matrix row index, where the current index value is used to indicate the element of the digital array to be operated.
[0108] In response to the current index value not being greater than the maximum value of the compressed matrix row index, executing:
[0109] S3312: Update the current row index value and the current column index value of the digital array with the current index value.
[0110] S3313: In any row whose row index value is greater than the current row index value, obtain any row whose current column index value corresponds to a value of 1, and swap the row with the row corresponding to the current row index value.
[0111] S3314: Update the row by adding the row whose corresponding value is 1 of the current column index value and the row whose corresponding value is the current row index value.
[0112] S3315: Add 1 to the current index value.
[0113] Optionally, a row traversal method is used to find a row whose corresponding column index is 1.
[0114] Preferably, the first row corresponding to the column index of 1 is obtained and the row indicated by the current index value is exchanged with the matrix row.
[0115] Specifically, according to the extracted second part of the compressed matrix, the inverse matrix of the input matrix is determined, including:
[0116] S3331: Obtain the matrix element of any row of the second part of the compressed matrix;
[0117] S3332: Split the matrix elements of any row of the second part of the compressed matrix in order of digits from high to low, and use them as the matrix elements in the corresponding row of the inverse matrix with column indices arranged in ascending order.
[0118] Specifically, obtaining the bit width of the CPU includes:
[0119] S321: Get the actual number of bytes of the variable in any computer language environment;
[0120] S322: The product of the actual number of bytes and the preset number of bits is used as the bit width of the central processing unit.
[0121] In different computer language environments, different commands are usually used to obtain the actual bytes of a variable. Schematically, in C language, the sizeof keyword is used to obtain the actual number of bytes of a variable; for example, in Java language, since Java does not directly provide a built-in method to calculate the number of bytes of a variable, it is necessary to determine the actual number of bytes of the variable based on the variable type and the number of bytes corresponding to the variable type. For example: use getclass() to obtain the type of a variable, and then determine the corresponding actual number of bytes of the variable based on the obtained variable type. For example: an int integer variable occupies 4 bytes in Java.
[0122] Usually, according to the conversion relationship of 1 byte = 8 bits, the preset number of bits is 8.
[0123] Furthermore, before obtaining the binary image and detecting the hole area in the binary image, the method further includes:
[0124] S000: Acquire an original image, and determine a binary image corresponding to the original image based on the original image.
[0125] Under the condition of obtaining the original image, the original image can be converted into a binary image by using methods such as fixed threshold method, adaptive threshold method, bimodal method, P parameter method, iteration method and OTSU method. The present application does not limit the specific method of converting the original image into a binary image.
[0126] It should be understood that although Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0127] In other embodiments, Figure 3 As shown, a binary image hole filling device comprises:
[0128] A hole detection module is used to obtain a binary image and detect hole areas in the binary image;
[0129] An input matrix determination module, used to construct at least one input matrix corresponding to the pixel points in the hole area according to the pixel values of the pixel points in the hole area, wherein the at least one input matrix is a block matrix on gf(2), and gf(2) is a finite field;
[0130] an inverse matrix determination module, configured to determine at least one inverse matrix corresponding to at least one input matrix;
[0131] A hole backfilling module, used to backfill the values of the matrix elements in at least one inverse matrix to the pixel points in the hole area whose positions correspond to the matrix elements in at least one inverse matrix, so as to obtain an image after the binary image holes are filled;
[0132] Wherein, determining at least one inverse matrix corresponding to at least one input matrix comprises:
[0133] Traverse any of the input matrices in at least one input matrix and execute:
[0134] In response to the input matrix being invertible, determining an augmented matrix corresponding to the input matrix according to the input matrix;
[0135] Obtaining a bit width of a central processing unit, and determining a compression matrix according to the bit width and the augmented matrix, wherein the central processing unit is used to perform hole filling on the binary image;
[0136] Based on the compressed matrix, an inverse matrix corresponding to the input matrix is determined.
[0137] For the specific limitations of the binary image hole filling device described above, please refer to the limitations of the binary image hole filling method described above, which will not be repeated here. Each module in the above-mentioned binary image hole filling device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0138] In other embodiments, Figure 4 As shown, a computer device includes a memory, a processor, and a binary image hole filling program stored in the memory and executable on the processor. When the processor executes the binary image hole filling program, the binary image hole filling method described above is implemented. The binary image hole filling method is not described in detail here.
[0139] In some other embodiments, a computer-readable storage medium stores a binary image hole filling program, and when the binary image hole filling program is executed by a processor, the binary image hole filling method described above is implemented. The binary image hole filling method is not described in detail here.
[0140] In some other embodiments, a computer program product includes a computer program, and when the computer program is executed by a processor, the binary image hole filling method described above is implemented. The binary image hole filling method is not described in detail here.
[0141] The technical solution provided in the embodiment of the present application has the following beneficial effects: based on the pixel characteristics of the binary image, a matrix on the finite field gf(2) is used to perform binary image filling processing on the image corresponding to the binary image pixels, which can make full use of the computer's binary operation rules and improve the efficiency of binary image hole processing; the bit width of the central processing unit is used to perform column compression on the input matrix on the finite field gf(2), and the original multiple data are compressed into a data with the same bit width as the central processing unit, so that the serial processing process of the matrix operation is converted into a parallel processing process, which greatly improves the efficiency of binary image hole processing using a computer.
[0142] Example
[0143] Determine the CPU (central processing unit) bit width, recorded as size_bint; you can use the sizeof keyword to measure the actual number of bytes of the variable, and multiply it by 8 to get the actual bit width.
[0144] Construct an augmented matrix consisting of the input matrix and the identity matrix concatenated to the right of the input matrix, with the same size as the input matrix E The number of rows in this augmented matrix is n, and the number of columns is The augmented matrix is divided into two parts: the input matrix A The number of columns is n, and the input matrix A Each size_bint column of is compressed into 1 column as the first part of the compressed matrix; the identity matrix E Each size_bint column of is compressed into 1 column, forming the second part of the compressed matrix.
[0145] Use i, j as input matrix A The row index and column index of the compressed matrix (aug_mat) are used as i, floor(j / size_bint) as the row index and column index of the compressed matrix (aug_mat). A The corresponding elements in are shifted left by j and become the corresponding elements in the compressed matrix;
[0146] Start processing the first column of the compressed matrix: check if the first bit of the first row is 1. If not, look for other rows, find the row with the first bit 1, and swap it with the first row. If the first bit of all rows is 0, the matrix is not invertible.
[0147] Check the rows of the compressed matrix except the first row. If the first bit of this row is not 0, add the first row of the current compressed matrix to this row. At this time, the first bit of this row is 0. After completing the operation of all rows, the first bits of all rows except the first row are 0. At this time, the first column of the digital array of the first part of the compressed matrix has been diagonalized.
[0148] Continue to calculate the second column according to the above steps. You need to change the second bit of the second row to 1, and change the second bits of all rows except the second row to 0;
[0149] Continue to calculate other columns until the digital array of the first part of the compressed matrix becomes the unit matrix. At this time, the second part of the compressed matrix is the compressed inverse matrix.
[0150] When performing column calculations, each step follows the order of column search and row calculation. The first step is to find whether the bit corresponding to the mth column and the mth row is 1. If it is not 1, then search down to find the row with the mth column as 1 and swap it with the mth row. The second step is to find the bit that is 1 in the mth column except for the mth row, and add the mth row to this row. After the execution is completed, the mth row can be diagonalized.
[0151] In a compressed matrix, the column search operation can use the AND operation to find the corresponding bit. When selecting the mth bit of each row, mb and mr can be used to select. The calculation formula of mb and mr is as follows:
[0152] mb = m / size_bint;
[0153] mr = 1<<(size_bint-m%size_bint-1);
[0154] Among them, % represents the remainder operation. Therefore, the calculation formula for the mth bit of the nth row of the compressed matrix to be 1 is as follows:
[0155] aug_mat[m][mb]&mr != 0;
[0156] The reason why we use "not equal to 0" to judge is that in the judgment logic, it is either 0 or 1, which corresponds to the finite field gf(2).
[0157] The columns of the compressed matrix are compressed, but its rows are not. Among all row calculations, there are only two types: row swap and row addition. Row swap does not generate carry, and row addition can be replaced by XOR operation, which also does not generate carry. Therefore, row calculation can be done in the same way as ordinary matrix row calculation, except that the number of columns in each row is less than that of ordinary matrix.
[0158] The second part of the compressed matrix is extracted and expanded to an n×n matrix, which is the obtained inverse matrix.
[0159] Extraction of the second part of the compressed matrix and compression of the compressed matrix are inverse operations. You can use i and j as the index of the inverse matrix. Correspondingly, use i and (j+n) / size_bint as the index of the compressed matrix. Shift the corresponding element in the compressed matrix right by size_bint-j%size_bint-1, and take the last bit, that is, do an AND operation with 1 to get the result.
[0160] In this embodiment, 32 data in a row are divided into a group, and each group of data is compressed into a data processed by one instruction of the central processing unit. The amount of calculation completed by one bit operation of the processor is equivalent to the calculation of 32 data in the matrix on the finite field gf(2), so the processor resources are fully utilized and the calculation performance is greatly improved.
[0161] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present application, which will not be described one by one here.
[0162] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program loaded on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device, or installed from a memory, or installed from a ROM. When the computer program is executed by an external processor, the above-mentioned functions defined in the method of the embodiment of the present application are executed.
[0163] It should be noted that the computer-readable medium of the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In an embodiment of the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In an embodiment of the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0164] The computer-readable medium may be included in the server; or it may exist independently without being installed in the server. The computer-readable medium carries one or more programs. When the one or more programs are executed by the server, the server: in response to detecting that the peripheral mode of the terminal is not activated, obtains the frame rate of the application on the terminal; when the frame rate meets the screen-off condition, determines whether the user is obtaining the screen information of the terminal; in response to the judgment result that the user is not obtaining the screen information of the terminal, controls the screen to enter the immediate dimming mode.
[0165] Computer program code for performing the operation of the embodiments of the present application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer, partially on the remote computer, or completely on the remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., using an Internet service provider to connect through the Internet).
[0166] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.
[0167] The technical solution provided by the present application is described in detail above. The principle and implementation method of the present application are described in detail using specific examples. The description of the above embodiments is only used to help understand the method and core idea of the present application. At the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as limiting the present application.
[0168] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. A binary image hole filling method, characterized in that: include: Acquire a binary image, and detect a hole area in the binary image; Constructing at least one input matrix corresponding to the pixel points in the hole area according to the pixel values of the pixel points in the hole area, wherein the at least one input matrix is a block matrix on gf(2), and gf(2) is a finite field; determining at least one inverse matrix corresponding to the at least one input matrix; Filling back the values of the matrix elements in the at least one inverse matrix to the pixel points in the hole area whose positions correspond to the matrix elements in the at least one inverse matrix, to obtain an image after the binary image hole is filled; Wherein, determining at least one inverse matrix corresponding to the at least one input matrix comprises: Traverse any input matrix of the at least one input matrix and execute: In response to the input matrix being invertible, determining an augmented matrix corresponding to the input matrix according to the input matrix; Acquire a bit width of a central processing unit, and determine a compression matrix according to the bit width and the augmented matrix, wherein the central processing unit is used to perform hole filling on the binary image; Based on the compressed matrix, an inverse matrix corresponding to the input matrix is determined.
2. The binary image hole filling method according to claim 1, characterized in that: The step of determining a compression matrix according to the bit width and the augmented matrix includes: The number of rows of the augmented matrix is used as the number of rows of the compressed matrix, wherein the number of bits of any matrix element in the compressed matrix is the bit width, and the compressed matrix has a compressed matrix first part and a compressed matrix second part; Taking the quotient of the number of columns of the augmented matrix and the bit width as the number of columns of the compressed matrix; Fill the matrix elements in any row of the input matrix with a number having a word length of the bit width from high to low in the order of increasing values of the column index of the input matrix, to obtain an input compressed number corresponding to any row of the input matrix, and determine the matrix elements in the first part of the compressed matrix according to the corresponding relationship between the input compressed number and the row of the input matrix, wherein any row in the first part of the compressed matrix has a matrix element, and the matrix element in any row of the first part of the compressed matrix is the input compressed number corresponding to the row index and the row index of the input matrix; Fill any row of matrix elements in a unit matrix having the same matrix size as the input matrix with a word length of the bit width from high to low in the order of increasing values of the column index of the unit matrix, to obtain a unit compression number corresponding to any row of the unit matrix, and determine the matrix elements in the second part of the compressed matrix according to the corresponding relationship between the unit compression number and the row of the unit matrix, wherein any row in the second part of the compressed matrix has one matrix element, and the matrix element of any row in the second part of the unit matrix is a unit compression number corresponding to the row index and the row index of the unit matrix; The compressed matrix is obtained by adding the second part of the compressed matrix to the right side of the first part of the compressed matrix.
3. The binary image hole filling method according to claim 1, characterized in that: The step of determining an inverse matrix corresponding to the input matrix based on the compressed matrix comprises: Diagonalizing a digital array composed of matrix element digits of the compressed matrix in the first part of the compressed matrix, wherein the row index of the digital array is the same as the row index of the compressed matrix, and the ascending order of the column index of the digital array corresponds to the descending order of the digits of any row element of the digital array; extracting a second portion of the compressed matrix when the first portion of the compressed matrix is diagonalized; An inverse matrix of the input matrix is determined based on the extracted second portion of the compressed matrix.
4. The binary image hole filling method according to claim 3, characterized in that: The step of diagonalizing the bit array composed of the matrix element bits of the compressed matrix in the first part of the compressed matrix comprises: Initialize a current index value to the minimum value of the compressed matrix row index, wherein the current index value is used to indicate the element of the digital array to be operated; In response to the current index value being not greater than the maximum value of the compressed matrix row index, executing: Update the current row index value and the current column index value of the digital array with the current index value; In any row whose row index value is greater than the current row index value, obtain any row whose current column index value corresponds to a value of 1, and swap the row with the row corresponding to the current row index value; Update the row by adding the row whose corresponding value is 1 to the row whose corresponding value is 1. The current index value is incremented by 1.
5. The binary image hole filling method according to claim 3, characterized in that: Determining the inverse matrix of the input matrix according to the extracted second part of the compressed matrix comprises: Obtaining a matrix element of any row of the second part of the compressed matrix; The matrix elements of any row of the second part of the compressed matrix are split in the order of digits from high to low, and used as the matrix elements with increasing column indices in the corresponding row of the inverse matrix.
6. The binary image hole filling method according to claim 1, characterized in that: The obtaining of the bit width of the central processing unit comprises: Get the actual number of bytes of a variable in any computer language environment; The product of the actual number of bytes and the preset number of bits is used as the bit width of the central processing unit.
7. The binary image hole filling method according to claim 1, characterized in that: Before acquiring the binary image and detecting the hole area in the binary image, the method further includes: An original image is acquired, and a binary image corresponding to the original image is determined according to the original image.
8. A binary image hole filling device, characterized in that: include: A hole detection module, used to obtain a binary image and detect a hole area in the binary image; An input matrix determination module, used for constructing at least one input matrix corresponding to the pixel points in the hole area according to the pixel values of the pixel points in the hole area, wherein the at least one input matrix is a block matrix on gf(2), and gf(2) is a finite field; an inverse matrix determination module, configured to determine at least one inverse matrix corresponding to the at least one input matrix; A hole backfilling module, used to backfill the values of the matrix elements in the at least one inverse matrix to the pixel points in the hole area whose positions correspond to the matrix elements in the at least one inverse matrix, so as to obtain an image after the binary image holes are filled; Wherein, determining at least one inverse matrix corresponding to the at least one input matrix comprises: Traverse any input matrix of the at least one input matrix and execute: In response to the input matrix being invertible, determining an augmented matrix corresponding to the input matrix according to the input matrix; Acquire a bit width of a central processing unit, and determine a compression matrix according to the bit width and the augmented matrix, wherein the central processing unit is used to perform hole filling on the binary image; Based on the compressed matrix, an inverse matrix corresponding to the input matrix is determined.
9. Computer device, characterized in that The invention comprises a memory, a processor and a binary image hole filling program stored in the memory and executable on the processor. When the processor executes the binary image hole filling program, the binary image hole filling method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that A binary image hole filling program is stored thereon, and when the binary image hole filling program is executed by a processor, the binary image hole filling method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Hole filling equipment control method, device and equipment and computer readable medium
CN114782450A
Electronic device and display control method thereof
CN119025694A