Image color segmentation method, device, equipment and storage medium
By preprocessing and color segmentation of color images, determining and filling missing areas, the problems of missed segmentation and missing segmentation in the existing color segmentation methods are solved, and the accuracy and reliability of color recognition are improved.
Patent Information
- Application Number
- CN202311195195.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-16
- Publication Date
- 2025-02-11
- Estimated Expiration
- 2043-09-16
AI Technical Summary
The existing color segmentation methods have problems of missegment and missegment, resulting in low accuracy and reliability of color recognition results.
By obtaining the color image to be segmented, image preprocessing is performed to obtain the target color image, and then color segmentation of the target color image is determined to determine the missing area in the initial color area, and the gray value of the target average gray value and the gray value of the color area The missing areas are filled to get a perfect target color area.
It improves the accuracy and reliability of color recognition results, reduces the situation of missegment and missegment, and enhances the universality and stability of color segmentation.
Smart Images

Figure CN117218141B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of digital image processing, and in particular to an image color segmentation method, device, equipment and storage medium. Background Art
[0002] At present, color segmentation is a method to segment images or videos based on color information. In computer vision and image processing, color segmentation plays an important role. The purpose of color segmentation is to extract objects of interest from images, thereby achieving object detection and recognition. Color segmentation is a key step from image processing to image analysis. The quality of color segmentation largely determines the effect of subsequent image analysis.
[0003] Color segmentation is the process of dividing an image into several specific regions with unique properties. Through color segmentation, you can extract the color features of interest and enhance or repair the image. For example, color segmentation can be used to eliminate noise and background interference in an image, making the image clearer and easier to understand.
[0004] However, the image area determined by the color segmentation method still has large errors, and also has high requirements on the stability of the image acquisition system and the accuracy of the imaging system. Its versatility is not great. For example, the color segmentation method may have problems of mis-segmentation and missed segmentation, that is, the non-target area is misjudged as the target area or the target area is omitted, resulting in low accuracy and reliability of the color recognition results. This situation needs to be improved. Summary of the invention
[0005] In order to improve the accuracy and reliability of color recognition results, the present application provides an image color segmentation method, device, equipment and storage medium, which adopts the following technical solutions:
[0006] In a first aspect, the present application provides a method for segmenting image colors, comprising:
[0007] Obtain a color image to be segmented;
[0008] Performing image preprocessing on the color image to be segmented to obtain a target color image;
[0009] Performing color segmentation on the target color image to obtain an initial color region;
[0010] Determine a missing area in the initial color area, a target average grayscale value corresponding to the missing area, and a color area grayscale value corresponding to the initial color area;
[0011] The missing area is filled according to the target average grayscale value and the color area grayscale value to obtain a target color area.
[0012] By adopting the above technical scheme, a color image to be segmented is obtained through a camera or other means, and the color image is usually a digital image with color information; before color segmentation, the color image to be segmented can be preprocessed to obtain a target color image; then the target color image is color segmented to segment an initial color area containing only the extracted color; since color segmentation may omit the target area, resulting in low accuracy and reliability of color recognition results, the scheme in the present application first determines the missing area in the initial color area, wherein the missing area is the omitted target area; then determines the target average gray value corresponding to the missing area and the color area gray value corresponding to the initial color area, wherein the color area gray value is the average gray value of the initial color area; the missing area is filled according to the target average gray value and the color area gray value to obtain the target color area, and the present application fills the missing area omitted by color segmentation to obtain a complete target color area, which is beneficial to improving the accuracy and reliability of color recognition results.
[0013] Optionally, filling the missing area according to the target average grayscale value and the color area grayscale value to obtain a target color area includes:
[0014] Determining whether the grayscale value of the color area is within a first threshold range;
[0015] If the grayscale value of the color area is within the first threshold range, determining whether a first difference between the target average grayscale value and the grayscale value of the color area is less than a first preset threshold;
[0016] If the first difference is less than the first preset threshold, the missing area is filled to obtain the target color area.
[0017] By adopting the above technical solution, it is first determined whether the grayscale value of the color area is within the first threshold range. If the grayscale value of the color area is within the first threshold range, it means that the image noise of the color image to be segmented is small and the grayscale value of the color area is within the normal range. Under normal circumstances, there may be more than one missing area in the initial color area. It is determined whether the first difference between each target average grayscale value and the grayscale value of the color area is less than the first preset threshold. If the first difference is less than the first preset threshold, the missing area is filled. If the first difference is greater than the first preset threshold, the missing area is not filled, and finally the target color area is obtained.
[0018] Optionally, if the grayscale value of the color area is not within the first threshold range, the method further includes:
[0019] Determining whether the first difference is greater than a second preset threshold;
[0020] If the first difference is greater than the second preset threshold, the missing area is filled to obtain the target color area.
[0021] By adopting the above technical solution, if the grayscale value of the color area is not within the first threshold range, it means that the image noise of the color image to be segmented is large, and the grayscale value of the color area is too high or too low; then judge whether the first difference is greater than the second preset threshold. If the first difference is greater than the second preset threshold, it means that the target average grayscale value and the grayscale value of the color area are too different, then fill the missing area; if the first difference is less than the second preset threshold, then do not fill the missing area, and finally obtain the target color area.
[0022] Optionally, performing color segmentation on the target color image to obtain an initial color region includes:
[0023] Determine an initial threshold range corresponding to the target color image;
[0024] A pixel value region in the target color image that falls within the initial threshold range is determined as the initial color region.
[0025] By adopting the above technical solution, when the target color image is segmented, the initial threshold range corresponding to the target color image is first determined, and the pixel value area in the target color image that falls within the initial threshold range is determined as the initial color area. The color segmentation is specifically as follows: after determining the initial threshold range, the pixel value area that falls within the initial threshold range is determined as the foreground according to the initial threshold range, and the pixel value area that does not fall within the initial threshold range is determined as the background, the background is eliminated, and the foreground area is determined as the initial color area.
[0026] Optionally, filling the missing area to obtain the target color area includes:
[0027] Determine a color region in a target pixel value region corresponding to the missing region, wherein the target pixel value region is a pixel value region of the target color image that does not fall within the initial threshold range;
[0028] The color region is merged with the initial color region to obtain the target color region.
[0029] By adopting the above technical solution, the corresponding color area in the missing area in the pixel value area where the target color area does not fall within the initial threshold range is determined. The color area is the target area that is omitted after color segmentation. The color area and the initial color area are merged. Specifically, during color segmentation, the color area is divided into the background, which leads to the omission of the target area. Merging the color area with the initial color area is equivalent to dividing the color area from the background to the foreground.
[0030] Optionally, determining the missing area in the initial color area includes:
[0031] A morphological closing operation is performed on the initial color region to form a hole region:
[0032] Determine the hole area as the missing area;
[0033] and / or,
[0034] Expanding the initial color area according to preset pixel points to obtain an expanded area;
[0035] The expanded area is divided to determine the missing area.
[0036] By adopting the above technical scheme, the missing area in the initial color area is determined. The present application adopts two schemes; in the first scheme, a morphological closing operation is performed on the initial color area to form a hole area, and the hole area is determined as the missing area; in the second scheme, the initial color area is expanded according to preset pixels to obtain an expanded area, and the expanded area is divided to determine the missing area; the scheme in the present application can sequentially perform the first scheme and the second scheme, or sequentially perform the second scheme and the first scheme, or only use the first scheme, or only use the second scheme to determine the missing area in the initial color area.
[0037] Optionally, performing image preprocessing on the color image to be segmented to obtain a target color image includes:
[0038] Determining the neighborhood pixels corresponding to the color image to be segmented;
[0039] The neighborhood pixels corresponding to the color image to be segmented are weighted averaged to obtain the target color image.
[0040] By adopting the above technical solution, the color image to be segmented is preprocessed. First, the neighborhood pixels corresponding to the color image to be segmented are determined, and then the neighborhood pixels corresponding to the color image to be segmented are weighted averaged, so that the weight of the pixels closer to the center pixel is larger, and the weight of the pixels farther away is smaller, thereby achieving the purpose of smoothing the image and finally obtaining the target color image.
[0041] In a second aspect, the present application provides an image color segmentation device, comprising:
[0042] An image acquisition module, used for acquiring a color image to be segmented;
[0043] A preprocessing module, used for performing image preprocessing on the color image to be segmented to obtain a target color image;
[0044] An image segmentation module is used to perform color segmentation on the target color image to obtain an initial color region;
[0045] An image processing module, used to determine a missing area in the initial color area, a target average grayscale value corresponding to the missing area, and a color area grayscale value corresponding to the initial color area;
[0046] The image filling module is used to fill the missing area according to the target average gray value and the color area gray value to obtain a target color area.
[0047] By adopting the above technical solution, the image color segmentation device is composed of an image acquisition module, a preprocessing module, an image segmentation module, an image processing module and an image filling module; the image acquisition module acquires a color image to be segmented, and before color segmentation, the color image to be segmented is firstly subjected to image preprocessing by the preprocessing module to obtain a target color image, and then the target color image is subjected to color segmentation by the image segmentation module, thereby segmenting an initial color region containing only the extracted color; since color segmentation may result in the omission of the target region, resulting in low accuracy and reliability of the color recognition result, the color segmentation module in the present application The scheme first determines the missing area in the initial color area through an image processing module, wherein the missing area is the omitted target area; secondly, determines the target average grayscale value corresponding to the missing area and the color area grayscale value corresponding to the initial color area, wherein the color area grayscale value is the average grayscale value of the initial color area; finally, the target color area is obtained by filling the missing area according to the target average grayscale value and the color area grayscale value through an image filling module. The present application fills the missing area omitted by color segmentation to obtain a complete target color area, which is beneficial to improving the accuracy and reliability of color recognition results.
[0048] In a third aspect, the present application provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program that can be loaded by the processor and execute the image color segmentation method as described in the first aspect.
[0049] In a fourth aspect, the present application provides a computer-readable storage medium storing a computer program that can be loaded by a processor and execute the image color segmentation method as described in the first aspect.
[0050] In summary, it can be seen that in the embodiments provided by the present application, since color segmentation may result in the omission of the target area, resulting in low accuracy and reliability of the color recognition result, the scheme in the present application, after color segmentation of the target color image, first, determines the missing area in the initial color area, wherein the missing area is the omitted target area; secondly, determines the target average grayscale value corresponding to the missing area and the color area grayscale value corresponding to the initial color area, wherein the color area grayscale value is the average grayscale value of the initial color area; finally, fills the missing area according to the target average grayscale value and the color area grayscale value to obtain the target color area. The present application fills the missing area omitted by color segmentation to obtain a complete target color area, which is beneficial to improving the accuracy and reliability of the color recognition result. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 is a schematic diagram of image color segmentation provided by an embodiment of the present application;
[0052] Figure 2 It is a flowchart of an image color segmentation method according to an embodiment of the present application;
[0053] Figure 3 is a schematic diagram of image preprocessing provided in an embodiment of the present application;
[0054] Figure 4 It is a schematic diagram of an image color segmentation device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0055] The terms used in the following embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to be used as limitations to the present application. As used in the specification and appended claims of the present application, the singular expressions "one", "a kind of", "said", "above", "the" and "this" are intended to also include plural expressions, unless there is a clear indication to the contrary in the context. It should also be understood that the term "and / or" used in the present application refers to any or all possible combinations comprising one or more listed items.
[0056] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features, and in the description of the embodiments of the present application, unless otherwise specified, "plurality" means two or more.
[0057] The embodiment of the present application discloses a method for segmenting image colors.
[0058] Reference Figure 1 and Figure 2 , a method for segmenting image color includes the following steps:
[0059] S10, obtaining a color image to be segmented;
[0060] The color image to be segmented is obtained by a camera or other means, and the color image is usually a digital image with color information; Figure 1 As shown, Figure 1 A schematic diagram of image color segmentation provided in an embodiment of the present application, Figure 1 101 is the color image to be segmented in the embodiment of the present application.
[0061] S20, performing image preprocessing on the color image to be segmented to obtain a target color image;
[0062] Among them, since the color image to be segmented may be interfered by image noise, the main features of the image are blurred, which can easily affect the accuracy and reliability of color segmentation; in order to eliminate or reduce the noise in the image, before color segmentation, the color image to be segmented can be preprocessed to obtain the target color image.
[0063] It is worth noting that image noise refers to certain random or irregular pixels in the image. The appearance of these pixels will make the image look blurred, distorted or grainy.
[0064] In one embodiment, step S20 includes:
[0065] Determine the neighborhood pixels corresponding to the color image to be segmented;
[0066] The neighborhood pixels corresponding to the color image to be segmented are weighted averaged to obtain the target color image.
[0067] In this embodiment, the image preprocessing process first determines the neighborhood pixels corresponding to the color image to be segmented, and then performs weighted averaging on the neighborhood pixels corresponding to the color image to be segmented, so that the weight of the pixels closer to the center pixel is larger, and the weight of the pixels farther away is smaller, thereby achieving the purpose of smoothing the image and obtaining the target color image.
[0068] It is worth noting that if the color image to be segmented itself has large noise interference, such as Figure 3 As shown, Figure 3 The image preprocessing diagram provided in the embodiment of the present application, the image preprocessing can be to perform Gaussian filtering on the color image to be segmented, Figure 3 301 in the figure is the original image without noise interference. Figure 3 302 in the figure is the image interfered by noise. Figure 3 303 is the image after Gaussian filtering. Gaussian filtering effectively removes noise and details in the image while retaining the main features of the image to achieve the purpose of smoothing the image.
[0069] S30, performing color segmentation on the target color image to obtain an initial color region;
[0070] Among them, Figure 1 As shown, the target color image is segmented to obtain an initial color region containing only the extracted color. Figure 1 102 in the figure is the color image to be segmented in the embodiment of the present application, and specifically 102a in 102 is the initial color area in the embodiment of the present application.
[0071] In one embodiment, step S30 includes:
[0072] Determine the initial threshold range corresponding to the target color image;
[0073] The pixel value region in the target color image that falls within the initial threshold range is determined as the initial color region.
[0074] In the embodiment, when segmenting the target color image, the initial threshold range corresponding to the target color image is first determined, and the pixel value region in the target color image that falls within the initial threshold range is determined as the initial color region.
[0075] Specifically, first, the target color image is divided into a foreground area and a background according to the initial threshold range, and secondly, the background is removed, and the foreground area is determined as the initial color area. It is worth noting that the pixel value area that does not fall into the initial threshold range is determined as the background, and the pixel value area that falls into the initial threshold range is determined as the initial color area.
[0076] S40, determining a missing area in the initial color area, a target average grayscale value corresponding to the missing area, and a color area grayscale value corresponding to the initial color area;
[0077] Among them, the missing area in the initial color area is determined, specifically, the missing area is the target area omitted after color segmentation; the target average grayscale value and the color area grayscale value are determined, the target average grayscale value corresponds to the missing area, and the color area grayscale value corresponds to the initial color area. It is worth noting that the color area grayscale value is the average grayscale value of the initial color area.
[0078] In this application, the missing area in the initial color area can be determined in two different ways, which are described below:
[0079] Method 1: Determining the missing area in the initial color area includes the following steps:
[0080] Perform morphological closing operation on the initial color area to form a hole area;
[0081] The hole area is determined as the missing area.
[0082] In this embodiment, the initial color region is hole filled, and the initial color region is morphologically closed to form a hole region, such as Figure 1 As shown, the hole area refers to the area surrounded by the foreground pixel points or the initial color area, that is, the hole area is the pixel value area that does not fall into the initial threshold range. Specifically, 102b in 102 is the hole area in the embodiment of the present application; the hole area is determined as the missing area, and the hole area and the initial color area are merged. Figure 1 103 is the image in which the initial color area and the hole area are merged in the embodiment of the present application, that is, the hole area is divided from the background to the foreground.
[0083] Color segmentation may result in some small holes in the target area. The hole filling algorithm can automatically fill these holes, that is, merge the initial color area and the hole area to make the initial color area more complete and continuous.
[0084] Method 2: determining the missing area in the initial color area includes the following steps:
[0085] Expanding the initial color area according to preset pixel points to obtain an expanded area;
[0086] The dilated area is divided to determine the missing area.
[0087] In this embodiment, the boundary detection is performed on the initial color region, and the initial color region is expanded according to the preset pixel points to obtain an expanded region, specifically, 102c in 102 is the expanded region in the embodiment of the present application; the expanded region is determined as a missing region, and the expanded region and the initial color region are merged; Figure 1104 is the image of the initial color region and the dilated region combined in the embodiment of the present application, that is, the dilated region is divided from the background to the foreground, which is conducive to filling and perfecting the boundary of the initial color region.
[0088] Specifically, the expansion is an iterative expansion. For example, the initial color area is expanded outward by 5 pixels as a whole to obtain a first expanded area. The first expanded area is divided into 9 equally divided areas. The missing area is one or more of the 9 equally divided areas. When one of the equally divided areas is determined not to be a missing area, the expansion of the equally divided area is stopped. If one of the equally divided areas is determined to be a missing area, the equally divided area continues to expand outward to obtain a second expanded area. It is judged whether the second expanded area is a missing area, and the expansion is stopped until the expanded area is determined not to be a missing area.
[0089] Color segmentation may produce some unclear or inaccurate boundaries. Using boundary detection algorithms can extract the exact boundaries of the initial color region, making the segmentation results more accurate. Boundary detection can provide edge information of the initial color region, which is helpful for subsequent processing tasks.
[0090] In summary, hole filling and boundary detection can adjust and optimize the initial color region according to application requirements, thereby improving the accuracy, adaptability and robustness of color segmentation.
[0091] In the embodiments of the present application, Figure 1 As shown, determine the missing area in the initial color area. Solution 1: only fill the holes in the initial color area. Figure 1 103 in the figure is the image of the initial color area and the hole area combined in the embodiment of the present application; Solution 2: Only the boundary detection is performed on the initial color area. Figure 1 104 is the image of the initial color region and the dilated region combined in the embodiment of the present application; Solution 3: Hole filling and boundary detection are performed on the initial color region. The order of hole filling and boundary detection is not limited. Hole filling can be performed first, and then boundary detection can be performed; or boundary detection can be performed first, and then hole filling can be performed. Figure 1 105 is the image obtained by merging the initial color area, the dilated area and the hole area in the embodiment of the present application, that is, the target image.
[0092] In one embodiment, if color segmentation occurs by mistake, when performing hole filling and / or boundary detection on the initial color area, it is identified that there is a mis-segmented area in the initial color area, that is, the area originally belonging to the background is divided into the foreground, then the mis-segmented area is removed to improve the initial color area, thereby improving the accuracy and reliability of the color recognition result.
[0093] S50, filling the missing area according to the target average gray value and the color area gray value to obtain the target color area.
[0094] Among them, the target color area is obtained by filling the missing area according to the target average grayscale value and the color area grayscale value. This application fills the missing area omitted by color segmentation to obtain a complete target color area, which is conducive to improving the accuracy and reliability of color recognition results.
[0095] In one embodiment, step S50 includes:
[0096] Determine a color region in a target pixel value region corresponding to the missing region, the target pixel value region being a pixel value region of the target color image that does not fall within an initial threshold range;
[0097] The color region is merged with the initial color region to obtain the target color region.
[0098] In an embodiment, a pixel value region that does not fall within the initial threshold range is defined as a target pixel region, that is, a background image of a target color image, and a pixel value region that falls within the initial threshold range is a foreground image of a target color image; first, a color region in the target pixel value region corresponding to a missing region is determined, that is, a color region in the background image corresponding to a missing region is determined, and the color region is the target region that is omitted after color segmentation; specifically, when segmenting a color image, the color region is divided into the background, thereby omitting the target region, and the color region is merged with the initial color region, which is equivalent to dividing the color region from the background into the foreground.
[0099] In one embodiment, step S50 includes:
[0100] Step 1: determine whether the grayscale value of the color area is within a first threshold range;
[0101] Among them, a first threshold range is set. When the grayscale value of the color area is within the first threshold range, it means that the image noise of the color image to be segmented is small, or the color image to be segmented is less affected by lighting, that is, the grayscale value of the color area is within the normal range.
[0102] Step 2: If the grayscale value of the color area is within the first threshold range, determine whether a first difference between the target average grayscale value and the grayscale value of the color area is less than a first preset threshold;
[0103] Among them, when the grayscale value of the color area is within the first threshold range, that is, the grayscale value of the color area is within the normal range; generally, there may be more than one missing area in the initial color area, for example, the initial color area is the foreground, and the missing area is the background. By judging whether the first difference between each target average grayscale value and the color area grayscale value is less than the first preset threshold, it is judged whether the missing area needs to be divided from the background to the foreground, so as to achieve the purpose of optimizing the initial color area.
[0104] Step 3: If the first difference is less than a first preset threshold, fill the missing area to obtain a target color area.
[0105] Among them, when the first difference is less than the first preset threshold, it is determined that the missing area needs to be divided from the background to the foreground, that is, the missing area is filled; when the first difference is not less than the first preset threshold, the missing area is not filled; each identified missing area is judged one by one, if the condition that the first difference is less than the first preset threshold is met, it is filled; if the condition that the first difference is not less than the first preset threshold is not met, it is not filled, and finally the target color area is obtained.
[0106] After step 1, if the grayscale value of the color area is not within the first threshold range, the method further includes:
[0107] Determining whether the first difference is greater than a second preset threshold;
[0108] If the first difference is greater than the second preset threshold, the missing area is filled to obtain the target color area.
[0109] In an embodiment, if the grayscale value of the color region is not within the first threshold range, it means that the image noise of the color image to be segmented is large or the image noise is small, or the color image to be segmented is greatly affected by lighting. For example, the normal grayscale value is (128, 0, 0), the grayscale value of the larger noise is (150, 0, 0), and the grayscale value of the smaller noise is (80, 0, 0). According to the grayscale value of the color region, it can be judged whether the image noise of the color image to be segmented is within the normal range; in the case where the image noise of the segmented color image is large or the image noise is small, if the first difference is greater than the second preset threshold, it means that the target average grayscale value and the grayscale value of the color region are too different, then the missing area is filled, if the first difference is less than the second preset threshold, then the missing area is not filled, and finally the target color region is obtained.
[0110] The implementation principle of the image color segmentation method of the embodiment of the present application is as follows: since color segmentation may result in the omission of the target area, resulting in low accuracy and reliability of the color recognition result, the scheme in the present application segments the target color image to obtain the initial color area, first determine the missing area in the initial color area, it is worth noting that the missing area is the missing target area. Then determine the target average gray value and the color area gray value, wherein the target average gray value corresponds to the missing area, and the color area gray value corresponds to the initial color area. Then fill the missing area according to the target average gray value and the color area gray value to obtain the target color area. Specifically, when the color image is segmented, the color area is divided into the background, so that the target area is omitted, and the color area is merged with the initial color area, which is equivalent to dividing the color area from the background to the foreground. The present application fills the missing area omitted by the color segmentation to obtain a complete target color area, which is conducive to improving the accuracy and reliability of the color recognition result.
[0111] The above describes the embodiment of the present application from the perspective of the image color segmentation method. The following describes the embodiment of the present application from the perspective of the image color segmentation device. Figure 4 , Figure 4 This is a schematic diagram of an image color segmentation device provided in an embodiment of the present application. The image color segmentation device 400 includes:
[0112] An image acquisition module 401 is used to acquire a color image to be segmented;
[0113] A preprocessing module 402 is used to perform image preprocessing on the color image to be segmented to obtain a target color image;
[0114] The image segmentation module 403 is used to perform color segmentation on the target color image to obtain an initial color region;
[0115] An image processing module 404 is used to determine a missing area in the initial color area, a target average grayscale value corresponding to the missing area, and a color area grayscale value corresponding to the initial color area;
[0116] The image filling module 405 is used to fill the missing area according to the target average gray value and the color area gray value to obtain the target color area.
[0117] In a possible implementation manner, the image filling module 405 is specifically used for:
[0118] Determining whether the grayscale value of the color area is within a first threshold range;
[0119] If the grayscale value of the color area is within the first threshold range, determining whether a first difference between the target average grayscale value and the grayscale value of the color area is less than a first preset threshold;
[0120] If the first difference is less than the first preset threshold, the missing area is filled to obtain the target color area.
[0121] In a possible implementation manner, the image filling module 405 is further configured to, if the grayscale value of the color region is not within the first threshold range, determine whether the first difference is greater than a second preset threshold;
[0122] If the first difference is greater than the second preset threshold, the missing area is filled to obtain the target color area.
[0123] In a possible implementation manner, the image segmentation module 403 is specifically used for:
[0124] Determine an initial threshold range corresponding to the target color image;
[0125] A pixel value region in the target color image that falls within the initial threshold range is determined as the initial color region.
[0126] In a possible implementation manner, the image filling module 405:
[0127] Determine a color region in a target pixel value region corresponding to the missing region, wherein the target pixel value region is a pixel value region of the target color image that does not fall within the initial threshold range;
[0128] The color region is merged with the initial color region to obtain the target color region.
[0129] In a possible implementation manner, the image processing module 404 is specifically configured to:
[0130] A morphological closing operation is performed on the initial color region to form a hole region:
[0131] Determine the hole area as the missing area;
[0132] and / or,
[0133] Expanding the initial color area according to preset pixel points to obtain an expanded area;
[0134] The expanded area is divided to determine the missing area.
[0135] In one possible manner, the preprocessing module 402 is specifically used for:
[0136] Determining the neighborhood pixels corresponding to the color image to be segmented;
[0137] The neighborhood pixels corresponding to the color image to be segmented are weighted averaged to obtain the target color image.
[0138] In the embodiment of the present application, the image color segmentation device comprises an image acquisition module, a preprocessing module, an image segmentation module, an image processing module and an image filling module. First, the image acquisition module acquires the color image to be segmented, and before color segmentation, the preprocessing module performs image preprocessing on the color image to be segmented to obtain a target color image, and then the image segmentation module performs color segmentation on the target color image, thereby segmenting an initial color region containing only the extracted color. The missing area in the initial color area is then determined by the image processing module, and then the target average grayscale value corresponding to the missing area and the color area grayscale value corresponding to the initial color area are determined. Finally, the target color area is obtained by filling the missing area with the target average grayscale value and the color area grayscale value through the image filling module. Since color segmentation may omit the target area, resulting in low accuracy and reliability of the color recognition result, the solution in the present application fills the missing area with the target average grayscale value and the color area grayscale value to obtain the target color area by adding an image processing module and an image filling module. The solution of the present application can fill the missing area omitted by color segmentation to obtain a complete target color area, which is beneficial to improving the accuracy and reliability of the color recognition result.
[0139] In one embodiment, an electronic device is further provided, including a memory and a processor, wherein the memory stores a computer program that can be loaded and executed by the processor, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.
[0140] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the above-mentioned computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0141] In one embodiment, a computer-readable storage medium is also provided, storing a computer program that can be loaded and executed by a processor, and the computer program implements the steps of the above-mentioned image color segmentation method when executed by the processor.
[0142] The readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0143] The above are all preferred embodiments of the present application, and the protection scope of the present application is not limited thereto. Therefore, any equivalent changes made according to the structure, shape, and principle of the present application should be included in the protection scope of the present application.
Claims
1. A method for segmenting image color, characterized in that: include: Obtain a color image to be segmented; Performing image preprocessing on the color image to be segmented to obtain a target color image; Performing color segmentation on the target color image to obtain an initial color region; Determine a missing area in the initial color area, a target average grayscale value corresponding to the missing area, and a color area grayscale value corresponding to the initial color area; Filling the missing area according to the target average grayscale value and the color area grayscale value to obtain a target color area; The filling of the missing area according to the target average grayscale value and the color area grayscale value to obtain the target color area includes: Determining whether the grayscale value of the color area is within a first threshold range, wherein if the grayscale value of the color area is within the first threshold range, determining that the grayscale value of the color area is within a normal range; If the grayscale value of the color area is within the first threshold range, determining whether a first difference between the target average grayscale value and the grayscale value of the color area is less than a first preset threshold; If the first difference is less than the first preset threshold, filling the missing area to obtain the target color area; If the grayscale value of the color area is not within the first threshold range, the method further includes: Determining whether the first difference is greater than a second preset threshold; If the first difference is greater than the second preset threshold, the missing area is filled to obtain the target color area.
2. The method according to claim 1, characterized in that The color segmentation of the target color image to obtain the initial color region comprises: Determine an initial threshold range corresponding to the target color image; A pixel value region in the target color image that falls within the initial threshold range is determined as the initial color region.
3. The method according to claim 2, characterized in that The filling of the missing area to obtain the target color area includes: Determine a color region in a target pixel value region corresponding to the missing region, wherein the target pixel value region is a pixel value region of the target color image that does not fall within the initial threshold range; The color region is merged with the initial color region to obtain the target color region.
4. The method according to claim 1 or 3, characterized in that: Determining the missing area in the initial color area comprises: A morphological closing operation is performed on the initial color region to form a hole region: Determine the hole area as the missing area; and / or, Expanding the initial color area according to preset pixel points to obtain an expanded area; The expanded area is divided to determine the missing area.
5. The method according to claim 1 or 3, characterized in that: The step of performing image preprocessing on the color image to be segmented to obtain a target color image comprises: Determining the neighborhood pixels corresponding to the color image to be segmented; The neighborhood pixels corresponding to the color image to be segmented are weighted averaged to obtain the target color image.
6. A device for segmenting image color, characterized in that: include: An image acquisition module, used for acquiring a color image to be segmented; A preprocessing module, used for performing image preprocessing on the color image to be segmented to obtain a target color image; An image segmentation module is used to perform color segmentation on the target color image to obtain an initial color region; An image processing module, used to determine a missing area in the initial color area, a target average grayscale value corresponding to the missing area, and a color area grayscale value corresponding to the initial color area; An image filling module, used for filling the missing area according to the target average gray value and the color area gray value to obtain a target color area; The specific steps of the image processing module include: Determining whether the grayscale value of the color area is within a first threshold range, wherein if the grayscale value of the color area is within the first threshold range, determining that the grayscale value of the color area is within a normal range; If the grayscale value of the color area is within the first threshold range, determining whether a first difference between the target average grayscale value and the grayscale value of the color area is less than a first preset threshold; If the first difference is less than the first preset threshold, filling the missing area to obtain the target color area; If the grayscale value of the color area is not within the first threshold range, the specific steps of the image processing module further include: Determining whether the first difference is greater than a second preset threshold; If the first difference is greater than the second preset threshold, the missing area is filled to obtain the target color area.
7. An electronic device, characterized in that: include: A memory and a processor, wherein the memory stores a computer program that can be loaded by the processor and executes the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: A computer program is stored which can be loaded by a processor and execute the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Facial feature extraction method and device
CN110826418A