A method, device, equipment and medium for segmenting a gradual change image

By using two thresholds to divide the image into three regions in gradient-type images and then intersecting them using a dilation algorithm, the problem of segmentation difficulties when the object and background colors are similar in gradient-type images is solved, achieving accurate target region segmentation.

CN116091523BActive Publication Date: 2026-03-24HANGZHOU HUICUI INTELLIGENT TECH CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-22
Publication Date
2026-03-24

AI Technical Summary

Technical Problem

Existing technologies perform poor segmentation when processing gradient images, especially when the object and background colors are similar, making it difficult to effectively distinguish target regions.

Method used

The image is divided into three regions using two thresholds. The first deep region and the first shallow region are intersected by a dilation algorithm to achieve the segmentation of the target region.

Benefits of technology

It effectively segments the gradient target region and can distinguish areas where the target pixel value is similar to the background pixel value, thus improving the accuracy of image segmentation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116091523B_ABST
    Figure CN116091523B_ABST
Patent Text Reader

Abstract

The application discloses a segmentation method and device of a gradient image, equipment and a medium. The method comprises the following steps: acquiring a to-be-segmented image containing a gradient target region; recording a region with a pixel value less than a first threshold value as a first deep region and a region with a pixel value greater than a second threshold value as a first shallow region, wherein the first threshold value is less than the second threshold value; respectively dilating the first deep region to the first shallow region and / or dilating the first shallow region to the first deep region, so that the first shallow region and the first deep region intersect, and a segmented image is obtained. The image obtained by the application can well segment the required gradient target, and when the pixel value of a pixel point in a third region is similar to the background pixel value, the application can distinguish the region with the target pixel value similar to the background pixel value.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of image segmentation, in particular to a gradual change image segmentation method, device, equipment and medium. BACKGROUND

[0002] At present, there are many image segmentation methods such as threshold segmentation, contour segmentation, and special segmentation. However, when the color of an object is uneven and part of the region is similar to the background color, the segmentation effect is poor, such as the image containing a gradual change target region shown in the following figure: Figure 2 The human eye can see only one rectangle in the image, but due to visual errors, various segmentation methods cannot segment the rectangle. SUMMARY

[0003] The present application aims to provide a gradual change image segmentation method, device, equipment and medium, which solves the technical problem of poor segmentation effect when part of the region in the gradual change image is similar to the background color.

[0004] The first aspect of the present application further provides a gradual change image segmentation method, comprising:

[0005] Obtaining a to-be-segmented image containing a gradual change target region;

[0006] Regions with pixel values less than a first threshold are recorded as first deep regions, and regions with pixel values greater than a second threshold are recorded as first shallow regions, wherein the first threshold is less than the second threshold;

[0007] Respectively dilating the first deep region towards the first shallow region and / or dilating the first shallow region towards the first deep region, so that the first shallow region and the first deep region intersect, to obtain a segmented image.

[0008] Optionally, before the regions with pixel values less than a first threshold are recorded as first deep regions, and the regions with pixel values greater than a second threshold are recorded as first shallow regions, the method further comprises:

[0009] Identifying background region pixel points of the to-be-segmented image;

[0010] Determining the first threshold and the second threshold according to the pixel value of the background region pixel points.

[0011] Optionally, the identifying the background region pixel points of the to-be-segmented image comprises:

[0012] Counting the pixel values of each pixel point in the to-be-segmented image;

[0013] Taking the pixel points with a pixel value ratio exceeding a preset threshold as background region pixel points.

[0014] Optionally, the determining the first threshold value and the second threshold value according to the pixel values of the background region pixel points comprises:

[0015] calculating the first threshold value and the second threshold value according to a maximum value and a minimum value in the pixel values of the background region pixel points, the minimum value in the pixel values of the background region pixel points being greater than or equal to the first threshold value, and the maximum value in the pixel values of the background region pixel points being less than or equal to the second threshold value.

[0016] Optionally, the respectively dilating the first deep region to the first shallow region and / or dilating the first shallow region to the first deep region comprises:

[0017] selecting a region on the first deep region close to the first shallow region as a second deep region, and selecting a region on the first shallow region close to the first deep region as a second shallow region;

[0018] respectively calculating a first gradient direction vector from the first deep region to the second deep region, and calculating a second gradient direction vector from the first shallow region to the second shallow region;

[0019] dilating the first deep region in the direction of the first gradient direction vector, and / or dilating the first shallow region in the direction of the second gradient direction vector.

[0020] Optionally, the selecting a region on the first deep region close to the first shallow region as a second deep region, and selecting a region on the first shallow region close to the first deep region as a second shallow region comprises:

[0021] determining a third threshold value according to the first threshold value, and determining a fourth threshold value according to the second threshold value, the third threshold value being less than the first threshold value, and the fourth threshold value being greater than the second threshold value;

[0022] determining a second deep region according to the first threshold value and the third threshold value, and determining a second shallow region according to the second threshold value and the fourth threshold value, the second deep region belonging to the first deep region, and the second shallow region belonging to the first shallow region.

[0023] Optionally, the respectively calculating a first gradient direction vector from the first deep region to the second deep region, and calculating a second gradient direction vector from the first shallow region to the second shallow region; and dilating the first deep region in the direction of the first gradient direction vector, and / or dilating the first shallow region in the direction of the second gradient direction vector comprises:

[0024] respectively calculate a center point a of the first deep region, a center point b of the second deep region, a center point c of the first shallow region, and a center point d of the second shallow region;

[0025] dilate the first deep region in the direction of vector ab, and / or dilate the first shallow region in the direction of vector cd.

[0026] The second aspect of the present application further provides a segmentation device for a gradual change type image, the device comprising:

[0027] an acquisition unit configured to acquire a to-be-segmented image containing a gradual change target region;

[0028] a partition unit configured to record a region with a pixel value less than a first threshold value as a first deep region, and record a region with a pixel value greater than a second threshold value as a first shallow region, the first threshold value being less than the second threshold value;

[0029] a dilation unit configured to dilate the first deep region toward the first shallow region and / or dilate the first shallow region toward the first deep region, respectively, so that the first shallow region and the first deep region intersect, to obtain a segmented image.

[0030] The third aspect of the present application provides a segmentation device for a gradual change type image, the device comprising a processor and a memory:

[0031] the memory is configured to store program code and transmit the program code to the processor;

[0032] the processor is configured to execute steps of the segmentation method for a gradual change type image according to instructions in the program code.

[0033] The fourth aspect of the present application provides a computer readable storage medium, the computer readable storage medium is configured to store program code, the program code is configured to execute the segmentation method for a gradual change type image according to the first aspect.

[0034] As can be seen from the above technical solutions, the embodiments of the present application have the following advantages:

[0035] The application divides the image to be segmented into three regions by two thresholds, wherein the region with pixel value less than the first threshold is recorded as the first deep region, the region with pixel value greater than the second threshold is recorded as the first shallow region, since the first threshold is less than the second threshold, the region greater than the first threshold and less than the second threshold can be recorded as the third region, and since the pixel value of the gradual change region presents a gradual change trend, the first deep region and the first shallow region have a certain pixel value difference, and the algorithm can distinguish the first deep region and the first shallow region; then the first deep region is dilated to the second deep region, or the first deep region is dilated to the second deep region, or the first deep region is dilated to the second deep region and the first deep region is dilated to the second deep region at the same time, so that the first shallow region and the second shallow region intersect, and the segmented image is obtained. The image obtained in this way can well segment the required gradual change target, and when the pixel value of the pixel point in the third region is similar to the background pixel value, the scheme can distinguish the region with similar target pixel value and background pixel value.

[0036] Other features and advantages of the present application will be set forth in the following description, and in part will become apparent to those skilled in the art from the description, or can be learned by practice of the present application. The objects and other advantages of the present application can be realized and achieved by the structure particularly pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF DRAWINGS

[0037] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments of the present application. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.

[0038] Figure 1 The flow chart of the first embodiment of the gradual change image segmentation method provided by the embodiments of the present application;

[0039] Figure 2 A schematic diagram of a gradual change target region needed to be processed in the embodiments of the present application.

[0040] Figure 3 A schematic diagram of an embodiment of the present application after the image to be segmented is partitioned;

[0041] Figure 4 The flow chart of the second embodiment of the gradual change image segmentation method provided by the embodiments of the present application;

[0042] Figure 5 A schematic diagram of an embodiment of the present application after the image to be segmented is partitioned into multiple regions;

[0043] Figure 6 A flow chart of a third embodiment of the gradual change type image segmentation method provided by the embodiments of the present application;

[0044] Figure 7 A schematic diagram of an embodiment of the present application after the segmentation of the image to be segmented is completed;

[0045] Figure 8 A structural schematic diagram of an embodiment of the gradual change type image segmentation device provided by the embodiments of the present application;

[0046] Figure 9 A structural schematic diagram of the gradual change type image segmentation device provided by the embodiments of the present application. DETAILED DESCRIPTION

[0047] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments of the present application. The components of the embodiments of the present application described and shown in the accompanying drawings can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the claimed present application, but only represents selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present application.

[0048] It should be noted that similar reference numerals and letters represent similar items in the following drawings, and therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. Meanwhile, in the description of the present application, the terms "first", "second", etc. are only used to distinguish the description, and cannot be understood as indicating or implying relative importance.

[0049] Please refer to Figure 1 A flow chart of a first embodiment of the gradual change type image segmentation method provided by the present application. The gradual change type image segmentation method is used in a terminal device, such as a computer, a mobile phone terminal, etc. The gradual change type image segmentation method comprises the following steps:

[0050] 101, obtaining an image to be segmented containing a gradual change target region;

[0051] The present application is mainly applied to image segmentation of gradual change type images, such as Figure 2The gradient image shown gradually changes the pixel grayscale value of the target area from 0 or close to 0 to 255 or close to 255. Alternatively, it can start with a small grayscale value and gradually increase to a larger one. Since the background can have any grayscale value, if the background grayscale value is close to the grayscale value of a portion of the gradient area, image segmentation errors may occur, potentially resulting in the gradient area being segmented together with the background area.

[0052] 102. Regions with pixel values ​​less than a first threshold are designated as first deep regions, and regions with pixel values ​​greater than a second threshold are designated as first shallow regions, wherein the first threshold is less than the second threshold;

[0053] To distinguish between the background region and the gradient target region, at least two thresholds can be determined. Regions with pixel values ​​less than a first threshold are designated as the first deep region, and regions with pixel values ​​greater than a second threshold are designated as the first shallow region. The first threshold is less than the second threshold, effectively dividing the gradient target region into three regions. Alternatively, if the background region has pixel values ​​of 0 or 255, it can be segmented using existing image segmentation schemes. When the background region has pixel values ​​between 0 and 255, regions with pixel values ​​less than the first threshold are designated as the first deep region, which is a region with lower grayscale values. For example, grayscale values ​​between 0 and 50 or between 0 and 100 can be classified as the first deep region. Similarly, regions with pixel values ​​greater than the second threshold are designated as the first shallow region, with grayscale values ​​ranging from 150 to 255 or from 200 to 255. When the first threshold is 50, the second threshold can be 100 or any value greater than 50. Of course, the specific first and second thresholds can be set according to the background grayscale value. For example, if the background grayscale value is 100, or in the range of 100 to 120, then the first threshold can be set to a grayscale value less than 100, such as 80, and the second threshold can be set to a grayscale value greater than 120, such as 140, so that the first and second thresholds are not within the range of the background grayscale value.

[0054] 103. Expand the first deep region toward the first shallow region, and / or expand the first deep region toward the first shallow region, so that the first shallow region and the first deep region intersect, to obtain the segmented image.

[0055] In this embodiment, three regions are distinguished: the region between the first threshold value and the second threshold value, the first deep region and the first shallow region, and the first deep region can be expanded to the first shallow region; the first shallow region can also be expanded to the first deep region; or the first deep region can be expanded to the first shallow region and the first shallow region can be expanded to the first deep region at the same time. That is, the two regions can be expanded at the same time, or only one of the two regions can be expanded, so that the two regions after expansion can be spliced together to form a complete gradient target region. The specific expansion method can be to determine the center points of the first deep region and the first shallow region, and then expand the first deep region to the first shallow region and / or expand the first deep region to the first shallow region according to the vector formed by the two center points; or the two edges of the first deep region and the first shallow region are determined, and expansion is performed along the edge vector. Specifically, as shown in Figure 3 the first deep region is the region where mark 2 is located in the figure, the first shallow region is the region where mark 1 is located in the figure, the two edges of the first shallow region are mark 3 and mark 4, and the two edges of the first deep region are mark 5 and mark 6. Then, the first deep region can be expanded to the first shallow region along the two edges 5 and 6 of the first deep region, and / or the first deep region can be expanded to the first shallow region along the two edges 3 and 4 of the first shallow region, so that the two regions after expansion can be spliced together to form a complete gradient target region.

[0056] The present application divides the to-be-segmented image into three regions through two threshold values, wherein the region with a pixel value less than the first threshold value is recorded as the first deep region, and the region with a pixel value greater than the second threshold value is recorded as the first shallow region. Since the first threshold value is less than the second threshold value, the region greater than the first threshold value and less than the second threshold value can be recorded as the third region. Since the pixel values of the gradient region show a gradient trend, the first deep region and the first shallow region will have a certain pixel value difference, and the algorithm can distinguish the first deep region and the first shallow region. Then, the first deep region is expanded to the second deep region, or the first deep region is expanded to the second deep region, or the first deep region is expanded to the second deep region and the first deep region is expanded to the second deep region at the same time, so that the first shallow region and the second shallow region intersect, and the segmented image is obtained. The image obtained in this way can well segment the required gradient target, and when the pixel value of the pixel point in the third region is similar to the background pixel value, the present application can distinguish the region with a target pixel value similar to the background pixel value.

[0057] Figure 4 The flowchart of the second embodiment of the gradient image segmentation method provided by the present application; the gradient image segmentation method is used in a terminal device, such as a computer, a mobile phone terminal, etc. The gradient image segmentation method comprises the following steps:

[0058] 201, obtaining an image to be segmented containing a gradual change target region;

[0059] The present application is mainly applied to image segmentation of images with gradual changes, such as the gradual change image shown in Figure 2 The pixel gray value of the target region in the image gradually changes from 0 or a gray value close to 0 to 255 or a gray value close to 255, and of course, it can also gradually change from a small gray value to a large gray value. Since the background can be any gray value, when the background gray value is close to the gray value of part of the region in the gradual change region, the image segmentation of the region and the background region will be wrong, and the region with a gray value close to the background region in the gradual change region and the background region may be segmented together.

[0060] 202, identifying the background region pixel points of the image to be segmented;

[0061] The background region pixel points of the image to be segmented can be obtained by reading the image to be segmented to obtain the pixel value of each pixel point in the image. For example, when the proportion of each pixel value in the image exceeds 50%, the pixel value is determined to be a background pixel point, and of course, if the background is an interval, the interval with the largest proportion of multiple consecutive pixel values can be counted, for example, the interval of pixel values from 80 to 100 has the largest proportion, and the pixel points in the interval are determined to be background pixel points.

[0062] 203, determining the first threshold and the second threshold according to the pixel value of the background region pixel point.

[0063] After determining the background pixel points, the first threshold and the second threshold can be calculated according to the interval of the background pixel points, wherein the first threshold should be less than the pixel value of the background region pixel point, and the second threshold should be greater than the pixel value of the background region pixel point, so that the background region, the first deep region and the first shallow region can be distinguished.

[0064] 204, recording the region with a pixel value less than the first threshold as the first deep region, and recording the region with a pixel value greater than the second threshold as the first shallow region, wherein the first threshold is less than the second threshold;

[0065] In order to distinguish the background region and the gradual change target region, at least two thresholds can be determined, the region with pixel value less than the first threshold is recorded as the first deep region, and the region with pixel value greater than the second threshold is recorded as the first shallow region, wherein the first threshold is less than the second threshold, that is, the gradual change target region is divided into three regions. Of course, if the pixel value of the background region is 0 or 255, the existing image segmentation scheme can also be used for segmentation; and when the pixel value of the background region is between 0 and 255, the region with pixel value less than the first threshold can be recorded as the first deep region, wherein the first deep region is a region with lower gray value, for example, the gray value of 0-50 can be divided into the first deep region, or 0-100 can be divided into the first deep region; similarly, the region with pixel value greater than the second threshold is recorded as the first shallow region, and the gray value interval of the first shallow region can be 150-255 or 200-255; when the first threshold is 50, the second threshold can be 100 or any value greater than 50. Of course, the specific first threshold and second threshold can be set according to the background gray value, for example, the background gray value is 100 or in the interval of 100 to 120, then the first threshold can be set to a gray value less than 100, for example, it can be set to 80, and the second threshold can be set to a gray value greater than 120, for example, it can be set to 140, so that the first threshold and the second threshold are not in the range of the background gray value.

[0066] 205、selecting a region on the first deep region close to the first shallow region as a second deep region, and selecting a region on the first shallow region close to the first deep region as a second shallow region;

[0067] In the embodiment, the region on the first deep region close to the first shallow region can be selected as the second deep region, for example, when the pixel value interval of the first deep region is 0-100, the second deep region can be 80-100; similarly, the region on the first shallow region close to the first deep region can be selected as the second shallow region, for example, when the pixel value of the first shallow region is 150-255, the second shallow region can be 150-170. Specifically as shown in Figure 5 Figure 5 In the embodiment, the first shallow region is labeled as 1, the second shallow region is labeled as 7, the first deep region is labeled as 2, and the second deep region is labeled as 8.

[0068] 206、calculating a first gradual change direction vector of the first deep region to the second deep region, and calculating a second gradual change direction vector of the first shallow region to the second shallow region;

[0069] ​In this embodiment, the first gradient direction vector from the first deep region to the second deep region and the second gradient direction vector from the first shallow region to the second shallow region can be calculated separately. Specifically, after determining the center points of the first and second deep regions, the second deep region in the first deep region can be expanded towards the first shallow region along the vector formed by the two center points, and / or the second shallow region in the first shallow region can be expanded towards the first deep region along the vector formed by the center points. The vector pointing from the center point of the first deep region to the center point of the second deep region is the first gradient direction. A specific vector diagram can be found in [reference needed]. Figure 5 The arrow in the first deep region 2; the vector pointing from the center point of the first shallow region to the center point of the second shallow region is the second gradient direction. For a detailed vector diagram, please refer to... Figure 5 The arrow in the first shallow region 1.

[0070] 207. Expand the first deep region along the direction of the first gradient direction vector, and / or expand the first shallow region along the direction of the second gradient direction vector, so that the first shallow region and the first deep region intersect, to obtain the segmented image.

[0071] The first deep region can be expanded towards the first shallow region along the first gradient direction vector; alternatively, the first shallow region can be expanded towards the first deep region along the second gradient direction vector; or simultaneously, the first deep region can be expanded towards the first shallow region along the first gradient direction vector, and the first shallow region can be expanded towards the first deep region along the second gradient direction vector. In other words, both regions can be expanded simultaneously, or only one region can be expanded, allowing the two expanded regions to be joined together to form a complete gradient target region. The edges of the expanded region can be determined based on the edges of the first deep and first shallow regions. For example, if the two edges of the first shallow region are marked 3 and 4, and the two edges of the first deep region are marked 5 and 6, then the two edges 5 and 6 of the first deep region can be extended respectively, intersecting with the first shallow region, and / or along the two edges 3 and 4 of the first shallow region, intersecting with the first deep region. The region formed by these intersections is the gradient target region.

[0072] The application divides the to-be-segmented image into three regions through two thresholds, wherein a region with a pixel value less than a first threshold is recorded as a first deep region, and a region with a pixel value greater than a second threshold is recorded as a first shallow region. Since the first threshold is less than the pixel value of the background region, the pixel value of the background region is less than the second threshold, and the pixel value greater than the first threshold and less than the second threshold can be recorded as a third region. Since the pixel value of the gradual change region presents a gradual change trend, the first deep region and the first shallow region have a pixel difference with the pixel value of the background region, so that the algorithm can distinguish the first deep region and the first shallow region from the background region. Then, the first deep region is dilated to the second deep region, or the first deep region is dilated to the second deep region, or the first deep region is dilated to the second deep region and the first deep region is dilated to the second deep region at the same time, so that the first shallow region and the second shallow region intersect, and a segmented image is obtained. The image obtained in this way can well segment the required gradual change target region and is not affected by the pixel value of the background region. The scheme can distinguish the region with a similar target pixel value and background pixel value.

[0073] Figure 6 The flowchart of the second embodiment of the gradual change image segmentation method provided by the embodiment of the application; the gradual change image segmentation method is used in a terminal device, such as a computer, a mobile phone terminal, and the like. The gradual change image segmentation method comprises the following steps:

[0074] 301. Obtain a to-be-segmented image containing a gradual change target region;

[0075] 302. Count pixel values of each pixel point in the to-be-segmented image;

[0076] The pixel values of each pixel point in the to-be-segmented image can be obtained by reading the to-be-segmented image. For example, the proportion of each pixel value in the image can be obtained to determine the proportion of the number of pixel points of a single pixel value in all pixel points in the image, or the proportion of pixel points corresponding to a plurality of continuous pixel values in all pixel points in the image.

[0077] 303. Take the pixel points with a pixel value proportion exceeding a preset threshold as background region pixel points.

[0078] The pixel points with a pixel value proportion exceeding a preset threshold are taken as background region pixel points. For example, the proportion of each pixel value in the image can be obtained to determine, for example, when the proportion of the pixel value exceeds 50%, the pixel value is determined as a background pixel point. Of course, if the background is an interval, the interval with the largest proportion of a plurality of continuous pixel values can be counted, for example, the interval of pixel values in 80-100 has the largest proportion, and the pixel points in the interval of the pixel value are determined as background pixel points.

[0079] 304、calculating the first threshold value and the second threshold value according to the maximum value and the minimum value in the pixel values of the background region pixel points, the minimum value in the pixel values of the background region pixel points being greater than or equal to the first threshold value, and the maximum value in the pixel values of the background region pixel points being less than or equal to the second threshold value.

[0080] In the embodiment, the first threshold value and the second threshold value can be calculated according to the maximum value and the minimum value in the pixel values of the background region pixel points, the minimum value in the pixel values of the background region pixel points being greater than or equal to the first threshold value, and the maximum value in the pixel values of the background region pixel points being less than or equal to the second threshold value. For example, when the interval of the background pixel values is [a min , a max ], 0 < a < 255, the first threshold value k1≤a min , and the second threshold value k2≥a max .

[0081] 305、regarding a region with pixel values less than the first threshold value as a first deep region, and regarding a region with pixel values greater than the second threshold value as a first shallow region, the first threshold value being less than the second threshold value;

[0082] To distinguish the background region and the gradual change target region, at least two threshold values can be determined, a region with pixel values less than the first threshold value is regarded as a first deep region, and a region with pixel values greater than the second threshold value is regarded as a first shallow region, wherein the first threshold value is less than the second threshold value, that is, the gradual change target region is divided into three regions. Of course, if the pixel value of the background region is 0 or 255, the image can be segmented according to the existing image segmentation scheme; and when the pixel value of the background region is between 0 and 255, a region with pixel values less than the first threshold value can be regarded as a first deep region, wherein the first deep region is a region with a lower gray value, for example, a region with a gray value of 0-50 can be divided into the first deep region, or a region with a gray value of 0-100 can be divided into the first deep region; similarly, a region with pixel values greater than the second threshold value is regarded as a first shallow region, and the gray value interval of the first shallow region can be 150-255 or 200-255; when the first threshold value is 50, the second threshold value can be 100 or any value greater than 50. Of course, the specific first threshold value and the second threshold value can be set according to the background gray value, for example, when the background gray value is 100 or in the interval of 100-120, the first threshold value can be set to a gray value less than 100, for example, 80, and the second threshold value can be set to a gray value greater than 120, for example, 140, so that the first threshold value and the second threshold value are not in the range of the background gray value. Specifically, the to-be-segmented image can be processed as follows:

[0083]

[0084] where p1(x, y) = 1 is the first deep region, p1(x, y) = 2 is the first shallow region, and p(x, y) is the pixel value of the original image at (x, y). The results are as follows: Figure 2 The image is divided into three regions.

[0085] 306. A third threshold value is determined according to the first threshold value, and a fourth threshold value is determined according to the second threshold value, the third threshold value being less than the first threshold value, and the fourth threshold value being greater than the second threshold value;

[0086] In this embodiment, the region on the first deep region close to the first shallow region can be selected as the second deep region, for example, when the pixel value interval of the first deep region is 0-100, then the second deep region can be 80-100, that is, the third threshold value can be 80, of course, it can also be set to a value less than 100 according to needs; Similarly, the region on the first shallow region close to the first deep region can be selected as the second shallow region, for example, when the pixel value of the first shallow region is 150-255, then the second shallow region can be 150-170, that is, the fourth threshold value can be 170, of course, it can also be set to a value less than 100 according to needs.

[0087] 307. A second deep region is determined according to the first threshold value and the third threshold value, and a second shallow region is determined according to the second threshold value and the fourth threshold value, the second deep region belonging to the first deep region, and the second shallow region belonging to the first shallow region.

[0088] In this embodiment, the second deep region can be determined according to the first threshold value and the third threshold value, and the second shallow region can be determined according to the second threshold value and the fourth threshold value, the second deep region belonging to the first deep region, and the second shallow region belonging to the first shallow region. The specific calculation formula can be:

[0089] where p1(x, y) = 1 is the first deep region, p1(x, y) = 2 is the first shallow region, and p(x, y) is the pixel value of the original image at (x, y).

[0090] 308. The center point a of the first deep region, the center point b of the second deep region, the center point c of the first shallow region, and the center point d of the second shallow region are calculated respectively.

[0091] In this embodiment, the vector from the center point a of the first deep region to the center point b of the second deep region can be calculated, and the vector from the center point c of the first shallow region to the center point d of the second shallow region can be calculated. Specifically, after the center points of the first deep region and the second deep region are determined, the second deep region in the first deep region is expanded along the vector ab formed by the two center points to the first shallow region, and / or the second deep region in the first shallow region is expanded along the vector cd formed by the two center points to the first deep region. The specific vector diagram can refer to the arrow in the first deep region 2 and the arrow in the first shallow region 1 in FIG. 14. Figure 5

[0092] 309, expand the first deep region in the ab vector direction, and / or expand the first shallow region in the cd vector direction, so that the first shallow region and the first deep region intersect to obtain a segmented image.

[0093] The first deep region can be expanded to the first shallow region along the ab vector, the first shallow region can be expanded to the first deep region along the cd vector, or the first deep region can be expanded to the first shallow region along the ab vector and the first shallow region can be expanded to the first deep region along the cd vector. That is, the two regions can be expanded at the same time, or only one of the two regions can be expanded, so that the two expanded regions can be spliced together to form a complete gradient target region. The edge of the expanded region can be determined according to the edge of the first deep region and the edge of the first shallow region. For example, the two edges of the first shallow region are marked 3 and 4, and the two edges of the first deep region are marked 5 and 6. Then the two edges 5 and 6 of the first deep region can be extended, and the extended edges intersect the first shallow region, and / or the two edges 3 and 4 of the first shallow region can be extended, and the extended edges intersect the first deep region. The region formed after the intersection is the gradient target region.

[0094] ​This application divides the image to be segmented into three regions using two thresholds. Regions with pixel values ​​less than the first threshold are designated as the first deep region, and regions with pixel values ​​greater than the second threshold are designated as the first shallow region. Since the first threshold is less than the background region's pixel values, and the background region's pixel values ​​are less than the second threshold, regions with values ​​greater than the first threshold and less than the second threshold can be designated as the third region. Furthermore, because the pixel values ​​in the gradient region exhibit a gradual change, the first deep and first shallow regions will have pixel differences from the background region, allowing the algorithm to distinguish them from the background region. Then, by dilating the first deep region towards the second deep region, or by dilating both regions simultaneously, the first shallow region intersects with the second shallow region, resulting in the segmented image. This method can effectively segment the desired gradient target region without being affected by the background region's pixel values. This scheme can distinguish regions with similar target pixel values ​​to the background pixel values.

[0095] The second aspect of this application provides a segmentation apparatus for gradient-type images, such as... Figure 8 The above, Figure 8 Includes:

[0096] Acquisition unit 401 is used to acquire the image to be segmented containing the gradient target region;

[0097] This application is mainly applied to image segmentation of gradient-type images, such as... Figure 2 The gradient image shown gradually changes the pixel grayscale value of the target area from 0 or close to 0 to 255 or close to 255. Alternatively, it can start with a small grayscale value and gradually increase to a larger one. Since the background can have any grayscale value, if the background grayscale value is close to the grayscale value of a portion of the gradient area, image segmentation errors may occur, potentially resulting in the gradient area being segmented together with the background area.

[0098] The partitioning unit 402 is used to define regions with pixel values ​​less than a first threshold as first deep regions and regions with pixel values ​​greater than a second threshold as first shallow regions, wherein the first threshold is less than the second threshold.

[0099] In order to distinguish the background region and the gradual change target region, at least two threshold values can be determined, the region with pixel value less than the first threshold value is recorded as the first deep region, and the region with pixel value greater than the second threshold value is recorded as the first shallow region, wherein the first threshold value is less than the second threshold value, that is, the gradual change target region is divided into three regions. Of course, if the pixel value of the background region is 0 or 255, the existing image segmentation scheme can also be used for segmentation; and when the pixel value of the background region is between 0 and 255, the region with pixel value less than the first threshold value can be recorded as the first deep region, wherein the first deep region is a region with lower gray value, for example, the gray value of 0-50 can be divided into the first deep region, or 0-100 can be divided into the first deep region; similarly, the region with pixel value greater than the second threshold value is recorded as the first shallow region, and the gray value interval of the first shallow region can be 150-255 or 200-255; when the first threshold value is 50, the second threshold value can be 100 or any value greater than 50. Of course, the specific first threshold value and the second threshold value can be set according to the background gray value, for example, the background gray value is 100 or in the interval of 100 to 120, then the first threshold value can be set to a gray value less than 100, for example, it can be set to 80, and the second threshold value can be set to a gray value greater than 120, for example, it can be set to 140, so that the first threshold value and the second threshold value are not in the range of the background gray value.

[0100] The expansion unit 403 is configured to respectively expand the first deep region to the first shallow region and / or expand the first shallow region to the first deep region, so that the first shallow region and the first deep region intersect, and an image after segmentation is obtained.

[0101] In the embodiment, after the three regions are distinguished, that is, the region between the first threshold value and the second threshold value, the first deep region and the first shallow region, the first deep region can be expanded to the first shallow region; or the first shallow region can be expanded to the first deep region; or the first deep region can be expanded to the first shallow region and the first shallow region can be expanded to the first deep region. That is, the two regions can be expanded at the same time, or only one of the two regions can be expanded, so that the two regions after expansion can be spliced together to form a complete gradual change target region. The specific expansion mode can be that, after the center points of the first deep region and the first shallow region are determined, the first deep region is expanded to the first shallow region and / or the first deep region is expanded to the first shallow region according to the vector formed by the two center points; or after the two edges of the first deep region and the first shallow region are determined, the edges are expanded along the edge vector. Specifically, as shown in FIG. 4, the first deep region and the first shallow region are determined, and the center points of the two regions are determined, and then the first deep region is expanded to the first shallow region along the vector formed by the two center points, and / or the first shallow region is expanded to the first deep region along the vector formed by the two center points. Figure 3As shown in the figure, the first deep region is the region where mark 2 is located, the first shallow region is the region where mark 1 is located, two edges of the first shallow region are mark 3 and mark 4 respectively, and two edges of the first deep region are mark 5 and mark 6 respectively. The first deep region can be expanded to the first shallow region along the two edges 5 and 6 of the first deep region respectively, and / or the first shallow region can be expanded to the first deep region along the two edges 3 and 4 of the first shallow region respectively, so that the two regions after expansion can be spliced together to form a complete gradient target region.

[0102] The present application divides the image to be segmented into three regions by two thresholds, wherein the region with a pixel value less than the first threshold is recorded as the first deep region, and the region with a pixel value greater than the second threshold is recorded as the first shallow region. Since the first threshold is less than the second threshold, the region greater than the first threshold and less than the second threshold can be recorded as the third region. Since the pixel values of the gradient region show a gradient trend, the first deep region and the first shallow region will have a certain difference in pixel values, and the algorithm can distinguish the first deep region and the first shallow region. Then, the first deep region is expanded to the second deep region, or the first deep region is expanded to the second deep region, or the first deep region is expanded to the second deep region and the first deep region is expanded to the second deep region at the same time, so that the first shallow region and the second shallow region intersect, and the segmented image is obtained. The image obtained in this way can well segment the required gradient target, and when the pixel value of the pixel point in the third region is similar to the background pixel value, the present application can distinguish the region with a target pixel value similar to the background pixel value.

[0103] The third aspect of the present application provides a device for segmenting a gradient image, the device comprising a processor and a memory, wherein the memory is used to store program code and transmit the program code to the processor. Figure 9 As shown in the figure, the device comprises a processor and a memory, wherein the memory is used to store program code and transmit the program code to the processor.

[0104] The processor is used to execute the instructions in the program code to perform the segmentation method of the gradient image as described above.

[0105] The fourth aspect of the present application provides a readable storage medium, wherein the readable storage medium comprises a segmentation method of a gradient image program, and the segmentation method of the gradient image program is executed by a processor to implement the steps of the segmentation method of the gradient image as described in any one of the above aspects.

[0106] In the several embodiments provided in the present disclosure, it should be understood that the disclosed devices and methods can be implemented in other manners. The embodiments described above are merely exemplary, and the unit division is merely logical function division, and there can be other division manners in actual implementation. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed coupling, direct coupling, or communication connection between the components can be indirect coupling or communication connection through some interfaces, and can be electrical, mechanical, or in other forms.

[0107] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units; they can be located in one place, or distributed on a plurality of network units; and some or all of the units can be selected according to actual needs to achieve the purpose of the embodiments.

[0108] In addition, each functional unit in each embodiment of the present disclosure can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; and the integrated unit can be implemented in the form of hardware, or in the form of hardware plus software functional units.

[0109] Those skilled in the art can understand that all or part of the steps of the above-mentioned method embodiments can be completed by program instruction related hardware, and the foregoing program can be stored in a readable storage medium, and the program is executed to perform the steps of the above-mentioned method embodiments; and the foregoing storage medium includes: mobile storage equipment, read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk, and various storage program codes.

[0110] Alternatively, the integrated units of the present disclosure, if implemented in the form of software functional modules and sold or used as independent products, can also be stored in a readable storage medium. Based on such understanding, the technical solutions of the embodiments of the present disclosure can be embodied in the form of a software product, which is stored in a storage medium, and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the methods described in the embodiments of the present disclosure. The foregoing storage medium includes: mobile storage equipment, ROM, RAM, magnetic disk or optical disk, and various storage program codes.

Claims

1. A method for segmenting gradient-type images, characterized in that, The method includes: Obtain the image to be segmented, which contains the gradient target region; Regions with pixel values ​​less than a first threshold are designated as first deep regions, and regions with pixel values ​​greater than a second threshold are designated as first shallow regions, where the first threshold is less than the second threshold. The first deep region is expanded toward the first shallow region, and / or the first shallow region is expanded toward the first deep region, so that the first shallow region and the first deep region intersect, to obtain the segmented image; The step of expanding the first deep region toward the first shallow region and / or expanding the first shallow region toward the first deep region includes: The region on the first deep region that is close to the first shallow region is selected as the second deep region, and the region on the first shallow region that is close to the first deep region is selected as the second shallow region. Calculate the first gradient direction vector from the first deep region to the second deep region, and calculate the second gradient direction vector from the first shallow region to the second shallow region. Expand the first deep region along the direction of the first gradient direction vector, and / or expand the first shallow region along the direction of the second gradient direction vector.

2. The method for segmenting gradient-type images according to claim 1, characterized in that, Before defining regions with pixel values ​​less than a first threshold as first deep regions and regions with pixel values ​​greater than a second threshold as first shallow regions, the following steps are also included: Identify the background region pixels of the image to be segmented; The first threshold and the second threshold are determined based on the pixel values ​​of the pixels in the background region.

3. The method for segmenting gradient-type images according to claim 2, characterized in that, The process of identifying background region pixels in the image to be segmented includes: Calculate the pixel value of each pixel in the image to be segmented; Pixels whose pixel value percentage exceeds a preset threshold are designated as background area pixels.

4. The method for segmenting gradient-type images according to claim 2, characterized in that, Determining the first threshold and the second threshold based on the pixel values ​​of the background region pixels includes: The first threshold and the second threshold are calculated based on the maximum and minimum pixel values ​​of the background region pixels, wherein the minimum pixel value of the background region pixels is greater than or equal to the first threshold, and the maximum pixel value of the background region pixels is less than or equal to the second threshold.

5. The method for segmenting gradient-type images according to claim 1, characterized in that, The step of selecting a region on the first deep region that is close to the first shallow region as the second deep region, and selecting a region on the first shallow region that is close to the first deep region as the second shallow region, includes: A third threshold is determined based on the first threshold, and a fourth threshold is determined based on the second threshold, wherein the third threshold is less than the first threshold and the fourth threshold is greater than the second threshold; A second deep region is determined based on the first threshold and the third threshold, and a second shallow region is determined based on the second threshold and the fourth threshold. The second deep region belongs to the first deep region, and the second shallow region belongs to the first shallow region.

6. The method for segmenting gradient-type images according to claim 1, characterized in that, The step of calculating the first gradient direction vector from the first deep region to the second deep region, and calculating the second gradient direction vector from the first shallow region to the second shallow region; expanding the first deep region along the direction of the first gradient direction vector, and / or expanding the first shallow region along the direction of the second gradient direction vector includes: Calculate the center point a of the first deep region, the center point b of the second deep region, the center point c of the first shallow region, and the center point d of the second shallow region, respectively. Expand the first deep region along the direction of vector ab, and / or expand the first shallow region along the direction of vector cd.

7. A segmentation device for gradient-type images, characterized in that, include: The acquisition unit is used to acquire the image to be segmented, which contains the gradient target region; A partitioning unit is used to categorize regions with pixel values ​​less than a first threshold as first deep regions and regions with pixel values ​​greater than a second threshold as first shallow regions, wherein the first threshold is less than the second threshold. The dilation unit is used to dilate the first deep region toward the first shallow region and / or dilate the first shallow region toward the first deep region, so that the first shallow region and the first deep region intersect to obtain a segmented image. The step of expanding the first deep region toward the first shallow region and / or expanding the first shallow region toward the first deep region includes: The region on the first deep region that is close to the first shallow region is selected as the second deep region, and the region on the first shallow region that is close to the first deep region is selected as the second shallow region. Calculate the first gradient direction vector from the first deep region to the second deep region, and calculate the second gradient direction vector from the first shallow region to the second shallow region. Expand the first deep region along the direction of the first gradient direction vector, and / or expand the first shallow region along the direction of the second gradient direction vector.

8. A segmentation device for gradient-type images, characterized in that, The device includes a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is configured to execute the gradient image segmentation method according to any one of claims 1-6 according to the instructions in the program code.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store program code for performing the gradient image segmentation method according to any one of claims 1-6.

Citation Information

Patent Citations

  • Training method of image segmentation model, and image segmentation method and device

    CN115393377A