An image segmentation method and system based on local adaptive threshold and symmetric constraint morphology
Patent Information
- Application Number
- CN202610668888.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-15
- Publication Date
- 2026-09-01
AI Technical Summary
[0006]为了解决传统形态学操作在图像分割中存在的边缘过度扩张和对光照不均敏感的问题,本发明提供了一种基于局部自适应阈值与对称约束形态学的图像分割方法及系统,通过改进二值化算法和重构形态学膨胀机制,可以有效地提高分割精度和减少计算复杂度,保持图像拓扑结构的前提下实现精准的孔洞填充和边缘保护
本发明采用改进的Bernsen局部自适应阈值算法将处理后的图像转换为二值图像,有效解决光照不均导致的分割失效问题;构建 3×3 对称约束膨胀结构元,定义四组对称点对检测通道,仅当任意一对对称邻域像素同时为目标像素时,中心点才被置为目标像素,实现精准向内孔洞填充并严格约束边界外扩;同时,对膨胀后图像执行选择性腐蚀操作,仅对膨胀过程中新修改的像素进行腐蚀,最大限度保留原始边缘特征。
Smart Images

Figure CN122675889A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of digital image processing and computer vision technology, and in particular to an image segmentation method and system based on local adaptive thresholding and symmetry constraint morphology. Background Technology
[0002] Morphological operations are a mathematical theory based on set theory, primarily studying morphological operations and morphological reconstruction on sets. In digital image processing, morphological operations are mainly applied to binary and grayscale image processing, achieving morphological transformations and feature extraction of images by analyzing and processing the neighborhood around each pixel.
[0003] Due to differences in imaging equipment, environmental characteristics, and application scenarios, acquired images often suffer from problems such as uneven illumination, large local contrast differences, and noise interference. For example, Chinese patent document CN102819841 discloses a global thresholding segmentation method for target image segmentation; Chinese patent document CN110276761A discloses a liver tissue pathology image segmentation method based on the Otsu threshold. However, traditional global thresholding segmentation methods (such as the Otsu algorithm) use a single threshold for the entire image, which often results in severe oversegmentation or undersegmentation when processing such images, leading to distortion of target boundaries.
[0004] Morphological post-processing after binarization (such as closing operations) is often used to fill tiny holes inside a target and connect broken contours. However, traditional dilation operations are based on "OR" logic, which causes the target boundary to expand outward. Although subsequent erosion operations can shrink the boundary, they cannot accurately restore the fine structure of the original edge and are prone to changing the true size and shape of the target, which has an adverse effect on the accuracy of image processing.
[0005] Therefore, there is an urgent need for an image segmentation method that can effectively adapt to local image features to achieve accurate binarization, and can strictly maintain the original boundary shape of the target in morphological post-processing. Summary of the Invention
[0006] To address the issues of excessive edge expansion and sensitivity to uneven illumination in traditional morphological operations for image segmentation, this invention provides an image segmentation method and system based on local adaptive thresholding and symmetry-constrained morphology. By improving the binarization algorithm and reconstructing the morphological dilation mechanism, the method can effectively improve segmentation accuracy and reduce computational complexity, while maintaining the image topology and achieving accurate hole filling and edge protection.
[0007] An image segmentation method based on local adaptive thresholding and symmetry-constrained morphology includes the following steps: (1) Convert the original color image to a grayscale image; (2) The grayscale image is binarized using the improved Bernsen local adaptive thresholding algorithm to generate a binary image. ; (3) Construct a 3×3 symmetric constrained expansion structural element, set a marker symbol at the center point of the structural element, and number the 8 pixels in the neighborhood of the marker symbol from 0 to 7 in a clockwise direction to form four sets of symmetric point pairs: ; (4) Perform symmetric constraint dilation operation: traverse the binary image Each pixel If there exists any pair of symmetrical points satisfy and The output image will be... Corresponding center point The pixel value is set to 255; otherwise, the original pixel value remains unchanged; at the same time, the set M of all pixels that have been dilated and modified is recorded. (5) Perform selective erosion operation: Using a 3×3 all-1 rectangular structuring element, the erosion operation is performed only on the pixels in the pixel set M to obtain the final segmented image. .
[0008] Furthermore, in step (2), the improved Bernsen local adaptive thresholding algorithm specifically includes: (2-1) For each pixel in the grayscale image Take a point as the center and a size of The neighborhood window; (2-2) Calculate the maximum gray value within the neighborhood window and minimum gray value ; (2-3) Calculate local contrast ; (2-4) Set the contrast threshold ,like The binarization threshold for the current pixel is then... ;like Then the binarization threshold Use the preset default threshold ; (2-5) Based on the binarization threshold Binarize the current pixel; if the pixel grayscale value is greater than or equal to... If it is true, then set it to the first value 255; otherwise, set it to the second value 0.
[0009] Preferably, in step (2-1), It is an odd number, and its value range is: 5≤ ≤15.
[0010] Preferably, in steps (2-4), the contrast threshold is... The range of values for is: 5≤ ≤30.
[0011] Preferably, in steps (2-5), the default threshold is... The range of values for is: 120≤ ≤135.
[0012] Preferably, in step (4), the detection priority order of symmetrical point pairs is as follows: When any pair meets the conditions, the subsequent detection will be terminated immediately.
[0013] Furthermore, in step (5), the mathematical expression for the selective corrosion operation is: ; in, It is a 3×3 all-rectangular structure element. .
[0014] An image segmentation system based on local adaptive thresholding and symmetry constraint morphology includes a memory and one or more processors. The memory stores executable code, and when the one or more processors execute the executable code, they implement the image segmentation method described above.
[0015] Compared with the prior art, the present invention has the following beneficial effects: This invention employs an improved Bernsen local adaptive thresholding algorithm to convert the processed image into a binary image, effectively solving the segmentation failure problem caused by uneven illumination. It constructs a 3×3 symmetric constrained dilation structuring element, defining four sets of symmetric point pairs for detection channels. The center point is set as the target pixel only when any pair of symmetric neighboring pixels are simultaneously the target pixel, achieving precise inward hole filling and strictly constraining boundary expansion. Simultaneously, a selective erosion operation is performed on the dilated image, eroding only newly modified pixels during the dilation process to preserve the original edge features to the maximum extent. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a flowchart of an image segmentation method based on local adaptive thresholding and symmetry constraint morphology according to an embodiment of the present invention.
[0018] Figure 2 This is a schematic diagram of a multi-origin structural element with a symmetrical numbering rule in an embodiment of the present invention.
[0019] Figure 3 This is a comparison diagram showing the effects of using the method of the present invention with existing technical methods. Detailed Implementation
[0020] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] It should be noted that, unless otherwise specified, the features in the following embodiments and implementation methods can be combined with each other.
[0022] like Figure 1 As shown, an image segmentation method based on local adaptive thresholding and symmetry-constrained morphology includes the following steps: S1. Image preprocessing.
[0023] Convert the original color image to grayscale; for DICOM format medical images, first convert to HU values, then set the window width according to the type of tissue to be segmented. and window position The HU value is linearly mapped to the grayscale range of 0-255 to obtain a grayscale image. The mapping formula is: ; in, Indicates the value Limited to the range Internally. For abdominal soft tissue windows, the following are usually taken: For lung windows, take .
[0024] S2, Improved Bernsen Local Adaptive Threshold Binarization.
[0025] For grayscale images Each pixel in Take its size as neighborhood window, For odd numbers, a value range of 5-15 is recommended. Calculate the maximum grayscale value within the window. and minimum gray value This yields local contrast: ; Set contrast threshold Recommended value range: 15-30. Then the binarization threshold for the current pixel is: ; like This indicates that the area is a low-contrast, uniform region, and the preset default threshold is used. The recommended value range is 120-135 to avoid artifacts caused by noise. The binarized output is: .
[0026] S3. Construct symmetrical numbered structural elements.
[0027] Definition as follows Figure 2 shown The structural element is centered at the origin (marked with a "+"), and its eight neighboring pixels are numbered sequentially from 0 to 7, starting from the top left corner, in a clockwise direction. This numbering rule ensures that the two pixels whose sums to 7 are centrally symmetrical about the center point, thus establishing four pairs of symmetrical points: main diagonal pairs: Vertical pair: Secondary diagonal pair: ; Horizontal pair: .
[0028] S4. Perform symmetric constraint expansion operation.
[0029] Traversing a binary image For each internal pixel (ignoring image boundaries), using the structuring element described in step three as the center, extract the values of 8 neighboring pixels. These are then processed in priority order. Detect symmetrical point pairs. If any pair of symmetrical neighboring pixels has a value of 255, set the output value of the center pixel to 255 and mark it as a changed pixel; otherwise, keep the original binarization result unchanged. The mathematical definition of the dilation operation is: ; in, The set of changing pixels is denoted as: .
[0030] S5. Selective corrosion post-treatment.
[0031] use Rectangular structural elements (All-1 matrix), only for the changing pixel set The pixels in the array undergo a standard erosion operation to smoothly fill the region edges. The erosion operation is defined as follows: ; For pixels that have not changed Its output value remains constant.
[0032] S6. Output the segmented target image.
[0033] The final processed binary image Output as the segmentation result.
[0034] This embodiment uses an abdominal CT DICOM image from a publicly available dataset as the processing object. The image size is [missing information]. Pixel.
[0035] Experimental environment: Python 3.10, scikit-image 0.26.0, OpenCV 4.10.0; Comparison method: Traditional Otsu global threshold + closing operation.
[0036] Dataset: The test images used in this invention are from public data datasets.
[0037] Step 1: Read the DICOM and convert it to grayscale.
[0038] Use the `pydicom` library to read the DICOM file and extract the pixel array. Convert the pixel values to HU values based on `RescaleSlope` (usually 1) and `RescaleIntercept` (usually -1024) from the header file. Set the abdominal soft tissue window parameters: window width. Window position Truncate the HU value to Interval, and according to the formula Linear mapping to the 0-255 range yields a grayscale image. ,like Figure 3 As shown in (a).
[0039] Step 2: Improve Bernsen binarization.
[0040] For grayscale images Execute the improved Bernsen algorithm. Parameter settings: neighborhood window size. Contrast threshold Default threshold Iterate through each pixel and calculate... The maximum and minimum grayscale values within the window are used to determine local contrast and calculate a threshold. A binary image is then generated. The target area (soft tissue) has a pixel value of 255, and the background has a value of 0. Figure 3 As shown in (b).
[0041] Step 3: Symmetrical constraint expansion.
[0042] Build as Figure 2 The symmetrically numbered structural elements are shown. Traversing the binary image. Internal pixels, by priority Detect symmetrical point pairs. If any pair of symmetrical neighboring pixels is detected with a value of 255, the center pixel is set to 255. This step fills the tiny pores inside the soft tissue region without causing outward expansion of the outer boundary, such as... Figure 3 As shown in (d).
[0043] Step 4: Selective corrosion.
[0044] Record the set of pixels that changed in step 3. .use Rectangular structural elements, only applicable to The pixels in the array undergo a standard erosion operation. This operation smooths the newly formed boundaries of the filled region without altering the original outer contour, such as... Figure 3 As shown in (e).
[0045] To verify the advantages of the method of this invention, Otsu's global thresholding method is used for binarization, such as... Figure 3 As shown in (c), and performs a closing operation on the disk structuring element with a radius of 1, as follows. Figure 3 As shown in (g), the target contours under the three methods are extracted and overlaid, as shown in the figure. Figure 3 As shown in Figure (h), the red line represents the original Bernsen binarization boundary, the green dashed line represents the boundary of the method of this invention, and the blue dotted line represents the boundary of the traditional closing operation. It can be clearly seen that the boundary of the method of this invention almost completely coincides with the original boundary, while the boundary of the traditional closing operation has significantly expanded.
[0046] The relevant quantitative indicators are shown in Table 1 below: Table 1 Experimental data show that the method of the present invention maintains a high pore filling rate (91.5%) while controlling the area change rate at 3.2% (slight expansion) and the boundary similarity is as high as 98.7%, which is significantly better than the traditional closing operation method.
[0047] The embodiments described above provide a detailed explanation of the technical solutions and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the present invention. Any modifications, additions, and equivalent substitutions made within the scope of the principles of the present invention should be included within the protection scope of the present invention.
Claims
1. An image segmentation method based on local adaptive thresholding and symmetry-constrained morphology, characterized in that, Includes the following steps: (1) Convert the original color image to a grayscale image; (2) The grayscale image is binarized using the improved Bernsen local adaptive thresholding algorithm to generate a binary image. ; (3) Construct a 3×3 symmetric constrained expansion structural element, set a marker symbol at the center point of the structural element, and number the 8 pixels in the neighborhood of the marker symbol from 0 to 7 in a clockwise direction to form four sets of symmetric point pairs: ; (4) Perform symmetric constraint dilation operation: traverse the binary image Each pixel If there exists any pair of symmetrical points satisfy and The output image will be... Corresponding center point The pixel value is set to 255; otherwise, the original pixel value remains unchanged; at the same time, the set M of all pixels that have been dilated and modified is recorded. (5) Perform selective erosion operation: Using a 3×3 all-1 rectangular structuring element, the erosion operation is performed only on the pixels in the pixel set M to obtain the final segmented image. .
2. The image segmentation method based on local adaptive thresholding and symmetry-constrained morphology according to claim 1, characterized in that, In step (2), the improved Bernsen local adaptive thresholding algorithm specifically includes: (2-1) For each pixel in the grayscale image Take a point as the center and a size of neighborhood window, (2-2) Calculate the maximum gray value within the neighborhood window and minimum gray value ; (2-3) Calculate local contrast ; (2-4) Set the contrast threshold ,like The binarization threshold for the current pixel is then... ;like Then the binarization threshold Use the preset default threshold ; (2-5) Based on the binarization threshold Binarize the current pixel; if the pixel grayscale value is greater than or equal to... If it is true, then set it to the first value 255; otherwise, set it to the second value 0.
3. The image segmentation method based on local adaptive thresholding and symmetry-constrained morphology according to claim 1, characterized in that, In step (2-1), It is an odd number, and its value range is: 5≤ ≤15.
4. The image segmentation method based on local adaptive thresholding and symmetry-constrained morphology according to claim 1, characterized in that, In steps (2-4), the contrast threshold The range of values for is: 5≤ ≤30.
5. The image segmentation method based on local adaptive thresholding and symmetry-constrained morphology according to claim 1, characterized in that, In steps (2-5), the default threshold The range of values for is: 120≤ ≤135.
6. The image segmentation method based on local adaptive thresholding and symmetry-constrained morphology according to claim 1, characterized in that, In step (4), the detection priority order of symmetrical point pairs is as follows: When any pair meets the conditions, the subsequent detection will be terminated immediately.
7. The image segmentation method based on local adaptive thresholding and symmetry-constrained morphology according to claim 1, characterized in that, In step (5), the mathematical expression for the selective etching operation is: ; in, It is a 3×3 all-rectangular structure element. .
8. An image segmentation system based on local adaptive thresholding and symmetry-constrained morphology, characterized in that, The device includes a memory and one or more processors, wherein the memory stores executable code, and the one or more processors execute the executable code to implement the image segmentation method according to any one of claims 1-7.
Citation Information
Patent Citations
Liver tissue pathological image segmentation method based on OTSU threshold value
CN110276761A