A method for marking connected regions of a binary image
By processing binary images using Euclidean distance transformation and threshold segmentation, the problem of difficulty in identifying small discontinuous connected regions in traditional methods is solved, achieving efficient connected region labeling, which is suitable for labeling binary images.
Patent Information
- Application Number
- CN202310170082.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-27
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2043-02-27
AI Technical Summary
Traditional connected component labeling methods cannot effectively identify small discontinuous regions in binary images, leading to difficulties in subsequent processing.
Binary images are processed using Euclidean distance transformation and threshold segmentation. By setting a discontinuity threshold, pixels smaller than the threshold are set to 1, and pixels larger than the threshold are set to 0, thus marking connected regions. The zero-pixel positions corresponding to the zero-pixel points in the marked image are then set to zero. Combined with the allocation and sorting of temporary label numbers, the final labeling result is obtained.
It can accurately identify and label small discontinuous connected regions in binary images, improve labeling efficiency, simplify processing steps, and is applicable to binary images with small discontinuities.
Smart Images

Figure CN116309677B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the technical field of image processing, and particularly relates to a method for marking a connected region of a binary image. BACKGROUND
[0002] Marking a connected region in a binary image is one of the basic operations in image processing. In the processing procedure in the fields of image analysis, image understanding, pattern recognition and computer vision, an image is usually converted into a corresponding binary image, in which the pixels belonging to the object to be recognized are converted into foreground pixels (object pixels) and the other pixels are converted into background pixels. In order to distinguish different objects in the binary image, a connected region marking method is used to assign a unique label to all the pixels of each object in the image. Through the connected region marking operation, a binary image is converted into a marked image, in which all the pixels belonging to one connected region are assigned a unique label. Whenever the system needs to recognize the connected regions in a binary image, it needs to be marked. The marking of a binary image is applied in many scenarios, such as fingerprint recognition, character recognition, automatic inspection, target recognition, face recognition, medical image analysis and computer-aided diagnosis, etc. However, due to the complexity of the environment or various conditions when the image is acquired, the connected regions in the obtained binary image may appear discontinuous, and the original connected region is divided into two or more sub-connected regions. If the traditional connected region marking method is used, these sub-connected regions are marked as different and independent connected regions, which brings difficulties to the subsequent processing.
[0003] Therefore, for the image with discontinuous connected regions, a method for marking the connected regions under the condition of discontinuity is needed. SUMMARY
[0004] The present application aims to overcome the shortcoming of the traditional connected region marking method that cannot recognize the connected regions with small discontinuity in a binary image, and to provide a new connected region marking method.
[0005] In order to achieve the above-mentioned purpose, the present application adopts the following technical solution:
[0006] A method for marking a connected region of a binary image, comprising:
[0007] Step 1: performing Euclidean distance transformation on the original binary image I to obtain a Euclidean distance transformed image D;
[0008] Step 2: setting a discontinuity threshold, in the Euclidean distance transformed image D, setting the pixels smaller than the threshold to 1, and setting the pixels larger than the threshold to 0 to obtain a new binary image T;
[0009] Step 3: performing connected region marking on the new binary image T to obtain a marked image L;
[0010] Step 4: In the marking image L, set the pixels corresponding to the positions of zero pixel points in the original binary image I to zero, to obtain the final marking result.
[0011] Further, the formula of the Euclidean distance transformation in step 1 is:
[0012]
[0013] wherein D(i,j) represents the value of the pixel point in the i-th row and the j-th column of the Euclidean distance transformation image, min{} represents the minimum value from all elements in the set; the size of the original binary image I is M rows and N columns, M and N are both natural numbers greater than 1, and the set of all pixel points with a pixel value of 1 in the image I is P={(x,y) I(x,y)=1}, I(x,y) represents the value of the pixel point in the x-th row and the y-th column of the original binary image.
[0014] Further, step 3 includes the following steps:
[0015] Step 3-1: scan the new binary image T row by row;
[0016] Step 3-2: mark the row-connected blocks in the first row from left to right, and assign a temporary label number to each row-connected block, the temporary label number starts from 1 and is an increasing natural number, and then set the pixel value corresponding to the row-connected block in the marking image to the corresponding temporary label number;
[0017] Step 3-3: from the second row, mark each row-connected block in each row in turn, including the following three cases:
[0018] 1) if there is no row-connected block in the previous row connected to the current row-connected block, assign a new temporary label number to the current row-connected block;
[0019] 2) if the number of row-connected blocks connected to the current row-connected block in the previous row is 1, assign the temporary label number of the connected row-connected block in the previous row to the temporary label number of the current row-connected block;
[0020] 3) if the number of row-connected blocks connected to the current row-connected block in the previous row is greater than 1, assign the temporary label numbers of all connected row-connected blocks to the minimum temporary label number of the connected row-connected blocks in the previous row;
[0021] Step 3-4: after marking all row-connected blocks in all rows, sort all existing temporary label numbers according to their values, and correspond the temporary label number with the sorted sequence number, and use the sorted sequence number as the final label number corresponding to the temporary label number;
[0022] Step 3-5: Set the pixel value corresponding to each row connected block in the new binary image T to the corresponding final label number, to obtain a label image L.
[0023] Further, in the step 3-1, if the left adjacent pixel value of a non-0 pixel is 0, the non-0 pixel position is the starting position of a row connected block, and if the right adjacent pixel value of a non-0 pixel is 0, the non-0 pixel position is the termination position of the current row connected block.
[0024] Further, in the step 3-3, record the starting position and the termination position of the current row connected block, and when the starting position of the current row connected block is less than or equal to the termination position of the row connected block in the previous row plus 1, and the termination position of the current row connected block is greater than or equal to the starting position of the row connected block in the previous row minus 1, the current row connected block is connected with the row connected block in the previous row.
[0025] A computer readable storage medium, storing a computer program, the computer program causes a computer to execute the binary image connected region labeling method according to any one of claims 1-6.
[0026] An electronic device, comprising: a memory, a processor, and a computer program stored on the memory and executable on the processor, when the processor executes the computer program, the binary image connected region labeling method is realized.
[0027] Beneficial effects: the present application can accurately identify the connected regions with small discontinuities in the binary image, and assign the same label to them, so that the labeling efficiency is high, so as to achieve the effect of being suitable for the binary image connected region labeling with small discontinuities, and the algorithm is simple, and more convenient for users to use. BRIEF DESCRIPTION OF DRAWINGS
[0028] Figure 1 The flowchart of the method of the present application;
[0029] Figure 2 The original binary image in the embodiment;
[0030] Figure 3 The new binary image after distance transformation and threshold segmentation in the embodiment;
[0031] Figure 4 The label image in the embodiment;
[0032] Figure 5 The final label result image in the embodiment. DETAILED DESCRIPTION
[0033] The present application will be further explained in conjunction with the accompanying drawings.
[0034] As Figure 1 shown in the figure, the embodiment of the present application provides a binary image connected region marking method, comprising the following steps:
[0035] Step 1: Perform Euclidean distance transformation on the original binary image I to obtain a Euclidean distance transformed image D;
[0036] Step 2: Set an interruption threshold, in the Euclidean distance transformed image D, set the pixels less than the threshold to 1, and otherwise set the pixels greater than the threshold to 0, to obtain a new binary image T;
[0037] Step 3: Perform connected region marking on the new binary image T to obtain a marking image L;
[0038] Step 4: In the marking image L, set the pixels corresponding to the zero pixel point positions in the original binary image I to zero to obtain the final marking result.
[0039] In step 1, the method of performing Euclidean distance transformation on the original binary image I is that, assuming that the size of the original binary image I is M rows and N columns, M and N are both natural numbers greater than 1, I(i,j) represents the value of the pixel point in the i-th row and the j-th column of the image I, wherein 1≤i≤M, 1≤j≤N; let the set of all pixel points with a value of 1 in the image I be P={(x,y)I(x,y)=1}, I(x,y) represents the value of the pixel point in the x-th row and the y-th column of the image I, calculate the value of each pixel point D(i,j) in the image after Euclidean distance transformation on the original binary image on the image processor according to the Euclidean distance transformation formula, thereby obtaining the original binary image D after distance transformation, wherein the min{} operation means taking the minimum value from all elements in the set, and the Euclidean distance transformation formula is:
[0040]
[0041] Then in step 2, select an interruption threshold G, according to the tolerance of interruption, G is generally set to a real number greater than 0 and less than 5, and obtain the new binary image T according to the following formula:
[0042]
[0043] Wherein, T(i,j) is the value of each pixel point in the image T.
[0044] In the embodiment, as Figure 2 shown in the figure, the original binary image I contains two numbers "1" and "2", wherein there are some interruptions in the two digital binary images, let the size of the image be M rows and N columns, M=13, N=13, set the interruption threshold G=2, and process the pixel value in the original binary image I through Euclidean distance transformation, and the obtained new binary image T is as followsFigure 3 The Euclidean distance transformation is shown to simplify the data of the image D, thereby facilitating the subsequent threshold segmentation processing, and the selection of the discontinuous threshold G eliminates the intervals in the original binary image I, thereby facilitating the subsequent labeling of the connected regions, and simplifying the labeling difficulty and steps.
[0045] Step 3 comprises the following steps:
[0046] Step 3-1: scan the new binary image T row by row:
[0047] If the left adjacent pixel value of a non-0 pixel is 0, the non-0 pixel position is the starting position of a row-connected block, and if the right adjacent pixel value of a non-0 pixel is 0, the non-0 pixel position is the termination position of the current row-connected block.
[0048] Step 3-2: label the row-connected blocks in the first row from left to right, and assign a temporary label number to each row-connected block, the temporary label number starts from 1 and is a natural number that is sequentially incremented, and then set the pixel value corresponding to the row-connected block in the label image to the corresponding temporary label number.
[0049] Step 3-3: from the second row, label each row-connected block in each row in turn.
[0050] Record the starting position and termination position of the current row-connected block. For each row-connected block in the previous row, if the starting position of the current row-connected block is less than or equal to the termination position of the row-connected block in the previous row plus 1, and the termination position of the current row-connected block is greater than or equal to the starting position of the row-connected block in the previous row minus 1, then the current row-connected block is connected to the row-connected block in the previous row, and therefore includes the following three cases:
[0051] 1) If there is no row-connected block in the previous row that is connected to the current row-connected block, assign a new temporary label number to the current row-connected block;
[0052] 2) If the number of row-connected blocks in the previous row that are connected to the current row-connected block is 1, assign the temporary label number of the connected row-connected block in the previous row to the temporary label number of the current row-connected block;
[0053] 3) If the number of row-connected blocks in the previous row that are connected to the current row-connected block is greater than 1, assign all the temporary label numbers of the connected row-connected blocks to the minimum temporary label number of the connected row-connected blocks in the previous row.
[0054] Step 3-4: after completing the labeling of the row-connected blocks in all rows, sort all existing temporary label numbers by their numerical values, and correspond the temporary label numbers to the sorted sequence numbers, and use the sorted sequence numbers as the final label numbers corresponding to the temporary label numbers.
[0055] Step 3-5: Set the pixel values corresponding to each row of connected blocks in the new binary image T to the corresponding final label number to obtain the labeled image L.
[0056] In this embodiment, the connected regions in the image T are accurately and quickly labeled by the above-mentioned connected region labeling step, and the above-mentioned connected region labeling step is more convenient to process and calculate, thereby further improving the labeling rate. The labeled image L obtained in this embodiment is shown in FIG. 3. Figure 4
[0057] Finally, the original connected regions are restored by using the original binary image I. Specifically, in the labeled image L, the pixel corresponding to the zero pixel point in the original binary image is set to zero according to the following formula, and the final labeling result is shown in FIG. 4. Figure 5
[0058]
[0059] Wherein, L(i,j) represents the value of the pixel at the i-th row and the j-th column in the image L.
[0060] The method overcomes the shortcoming of the traditional connected region labeling method that cannot identify the connected regions with small discontinuities in the binary image, and can accurately identify the connected regions with small discontinuities in the binary image and assign the same label to them. The method can be used for labeling the connected regions with small discontinuities in the image caused by small signal-to-noise ratio or interference.
[0061] In another embodiment, the present application further provides a computer readable storage medium storing a computer program, wherein the computer program enables a computer to execute the binary image connected region labeling method as described in the above-mentioned embodiments.
[0062] In another embodiment, the present application further provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the binary image connected region labeling method as described in the above-mentioned embodiments.
[0063] The above-mentioned is only the preferred embodiment of the present application, and it should be noted that for those skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, and these improvements and refinements should also be considered as the protection scope of the present application.
Claims
1. A method for labeling connected components in a binary image, characterized in that, include: Step 1: Convert the original binary image Perform Euclidean distance transformation to obtain the Euclidean distance transformed image. ; Step 2: Set a discontinuity threshold and transform the image using Euclidean distance. In this process, pixels smaller than the threshold are set to 1, and pixels larger than the threshold are set to 0, resulting in a new binary image. ; Step 3: For the new binary image Connected component labeling is performed to obtain the labeled image L; Step 3 includes the following steps: Step 3-1: Process the new binary image row by row. Perform a scan; Step 3-2: Mark the connected components in the first row from left to right, and assign a temporary label number to each connected component. The temporary label number starts from 1 and is a natural number that increases sequentially. Then, set the pixel value of the corresponding connected component in the marked image to the corresponding temporary label number. Step 3-3: Starting from the second row, mark each connected component in each row sequentially, including the following three cases: 1) If there is no connected row in the previous row that is connected to the current row, then assign a new temporary label to the current row. 2) If the number of connected row components in the previous row that are connected to the current row component is 1, then assign the temporary label number of the connected row component in the previous row to the temporary label number of the current row component. 3) If the number of connected row components in the previous row that are connected to the current row is greater than 1, then assign the temporary label number of all connected row components to the minimum temporary label number of the connected row components in the previous row. Steps 3-4: After marking all row-to-row connected components, sort all existing temporary labels by their numerical values, associate each temporary label with a sorted number, and use the sorted number as the final label corresponding to that temporary label. Steps 3-5: Convert the new binary image The pixel values of each row of connected components are set to the corresponding final label numbers to obtain the labeled image L; Step 4: In the labeled image L, the image corresponding to the original binary image... The pixels at the zero pixel position are set to zero to obtain the final marking result.
2. The binary image connected component labeling method according to claim 1, characterized in that, The formula for the Euclidean distance transformation in step 1 is: in, Represents the first Euclidean distance in the image. Line number The values of the pixels in the column, min{} represents taking the minimum value from all elements in the set; the original binary image. The image has a size of M rows and N columns, where M and N are both natural numbers greater than 1. The set of all pixels with a value of 1 is , Represents the first element in the original binary image. Line number The value of the pixel in the column.
3. The binary image connected component labeling method according to claim 1, characterized in that, In step 3-1, if a non-zero pixel is scanned and its left adjacent pixel value is 0, then the position of the non-zero pixel is the starting position of a row connected component. If a non-zero pixel is scanned and its right adjacent pixel value is 0, then the position of the non-zero pixel is the ending position of the current row connected component.
4. The binary image connected component labeling method according to claim 1, characterized in that, In step 3-3, the start and end positions of the current row connected component are recorded. For each row connected component in the previous row, if the start position of the current row connected component is less than or equal to the end position of the previous row connected component plus 1, and the end position of the current row connected component is greater than or equal to the start position of the previous row connected component minus 1, then the current row connected component is connected to the previous row connected component.
5. A computer-readable storage medium storing a computer program, characterized in that, The computer program causes the computer to execute the binary image connected region labeling method as described in any one of claims 1-4.
6. An electronic device, characterized in that, include: The memory, the processor, and the computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, it implements the binary image connected region labeling method as described in any one of claims 1-4.
Citation Information
Patent Citations
Data clustering method based on adjacent point connection
CN111209926A
Techniques for restoring content from a torn document
US20170308745A1