A method, device and electronic device for cutting out a pure color background image
By performing pixel clustering and area detection on the target image, automatically filtering and extracting solid color background areas, the problem of low efficiency of solid color background images in the prior art is solved, and automatic image cutting is realized.
Patent Information
- Application Number
- CN202010383384.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-05-08
- Publication Date
- 2024-11-12
- Estimated Expiration
- 2040-05-08
AI Technical Summary
The cutting method of solid color background images in the prior art requires manual drawing of foreground edges, which is relatively inefficient.
By clustering the pixels of the target image, combining similar pixel categories, detecting the subject area, filtering pixel categories in non-subject areas, filtering solid color background categories using the number of pixels, and extracting the foreground area to achieve automatic cutout.
The foreground area edges are not required to manually draw the foreground area, which realizes automatic cutout of solid background images and improves cutout efficiency.
Smart Images

Figure CN113627453B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to a method, device and electronic equipment for cutting out a pure color background image. Background Art
[0002] When processing images, it is often necessary to perform cutout processing on pure color background images, that is, to cut out the foreground area from the pure color background image for subsequent image processing. The pure color background images that need to be cutout may include but are not limited to ID photos, film and television stills that need to be post-processed, etc.
[0003] In the prior art, the method for cutting out a pure color background image includes: the image processing client detects the foreground edge drawn manually by the user, thereby cutting out the foreground area from the pure color background. It can be seen that the prior method requires manual cutting out of the pure color background, and the cutting efficiency is low. Summary of the invention
[0004] The purpose of the embodiments of the present invention is to provide a method, device and electronic device for cutting out a pure color background image, so as to solve the problem of low cutting efficiency when cutting out a pure color background manually. The specific technical solution is as follows:
[0005] In a first aspect, an embodiment of the present invention provides a method for cutting out a pure color background image, the method comprising:
[0006] Acquire a target image, perform clustering processing on pixels of the target image, and obtain a plurality of clustered pixel categories, wherein each pixel category includes a plurality of pixels;
[0007] Determine a pixel category group from the multiple pixel categories, and merge the pixel categories in the determined pixel category group into one pixel category; wherein the pixel categories in the pixel category group belong to similar categories, and the pixels included in any two pixel categories belonging to the similar categories meet the predetermined pixel similarity condition;
[0008] Performing subject detection on the target image to obtain a subject area, and determining a non-subject area of the target image based on the subject area;
[0009] From the multiple pixel categories existing after the pixel category merging process, screening each candidate pixel category including pixels located in the non-subject area of the target image;
[0010] Filtering the target pixel category to which the pixels of the pure color background of the target image belong from the candidate pixel categories by using the number of the first category pixels respectively included in the candidate pixel categories; the first category pixels are pixels located in the non-subject area;
[0011] From the target image, a pixel region other than pixels included in the target pixel category is extracted as a foreground image of the target image.
[0012] Optionally, a method for determining whether pixels included in any two pixel categories meet a predetermined pixel similarity condition includes:
[0013] The color histogram distribution of each pixel category is determined, the similarity between the color histogram distributions of each pixel category is calculated, and two pixel categories with similarities greater than a predetermined threshold are determined as pixel categories that meet a predetermined pixel similarity condition.
[0014] Optionally, using the number of first-category pixels respectively included in each candidate pixel category, screening the target pixel category to which the pixels of the pure color background of the target image belong from each candidate pixel category includes:
[0015] From the candidate pixel categories, a pixel category including the largest number of first-category pixels is searched as the target pixel category to which the pixels of the pure color background of the target image belong.
[0016] Optionally, the using the number of first-category pixels respectively included in each candidate pixel category to filter, from each candidate pixel category, the target pixel category to which the pixels of the solid color background of the target image belong includes:
[0017] For each candidate pixel category, according to a predetermined correction rule, the number of first-category pixels included in the candidate pixel category and the number of second-category pixels included in the candidate pixel category are corrected, and the sum of the corrected number of first-category pixels and the corrected number of second-category pixels is calculated as the number of pixels corresponding to the candidate pixel category, wherein the second-category pixels are pixels located in the main body area, and the predetermined correction rule is such that the corrected number of the first-category pixels increases, and the corrected number of the second-category pixels decreases;
[0018] From the candidate pixel categories, a pixel category corresponding to the largest number of pixels is determined as the target pixel category to which the pixels of the pure color background of the target image belong.
[0019] Optionally, before determining the pixel category with the largest number of corresponding pixels from the candidate pixel categories as the pixel category to which the pixels of the pure color background of the target image belong, the method further comprises:
[0020] Determine whether the ratio of the maximum number of pixels among the numbers of pixels corresponding to each candidate pixel category to the total number of pixels is greater than a preset threshold, and if so, perform the step of determining the pixel category with the largest number of pixels from the candidate pixel categories as the pixel category to which the pixels of the pure color background of the target image belong;
[0021] The total number of pixels is the total number of pixels of the target image.
[0022] Optionally, extracting, from the target image, a pixel region other than pixels included in the target pixel category as a foreground image of the target image, includes:
[0023] Determine an area outside the pixels included in the target pixel category as a foreground area of the target image, and generate a mask image of the foreground area;
[0024] The foreground area of the target image is extracted using the mask image to obtain a foreground image of the target image.
[0025] Optionally, using the mask image to extract a foreground area of the target image to obtain a foreground image of the target image includes:
[0026] Optimizing the foreground edge of the mask image, and using the optimized mask image to extract the foreground area of the target image to obtain a foreground image of the target image;
[0027] The optimization processing includes at least one or more of deburring processing, filtering processing, and morphological processing.
[0028] In a second aspect, an embodiment of the present invention provides a pure color background image cutout device, the device comprising:
[0029] A clustering module, used to acquire a target image, perform clustering processing on pixels of the target image, and obtain a plurality of clustered pixel categories; each pixel category includes a plurality of pixels;
[0030] A merging processing module, used to determine a pixel category group from the multiple pixel categories, and merge each pixel category in the determined pixel category group into one pixel category; wherein each pixel category in the pixel category group belongs to a similar category, and pixels included in any two pixel categories belonging to the similar category meet a predetermined pixel similarity condition;
[0031] A region determination module, configured to perform subject detection on the target image to obtain a subject region, and determine a non-subject region of the target image based on the subject region;
[0032] A first screening module, used to screen, from the multiple pixel categories existing after the pixel category merging process, each candidate pixel category including pixels located in the non-main area of the target image;
[0033] A second screening module is used to screen the target pixel category to which the pixels of the solid color background of the target image belong from the candidate pixel categories by using the number of the first category pixels respectively included in the candidate pixel categories; the first category pixels are pixels located in the non-subject area;
[0034] The extraction module is used to extract a pixel area other than the pixels included in the target pixel category from the target image as a foreground image of the target image.
[0035] Optionally, a method for determining whether pixels included in any two pixel categories meet a predetermined pixel similarity condition includes:
[0036] The color histogram distribution of each pixel category is determined, the similarity between the color histogram distributions of each pixel category is calculated, and two pixel categories with similarities greater than a predetermined threshold are determined as pixel categories that meet a predetermined pixel similarity condition.
[0037] Optionally, the second screening module includes:
[0038] The search submodule is used to search, from the candidate pixel categories, a pixel category including the largest number of first-category pixels as the target pixel category to which the pixels of the pure color background of the target image belong.
[0039] Optionally, the second screening module includes:
[0040] a correction submodule, for correcting, for each candidate pixel category, the number of first-category pixels included in the candidate pixel category and the number of second-category pixels included in the candidate pixel category according to a predetermined correction rule, and calculating the sum of the corrected number of first-category pixels and the corrected number of second-category pixels as the number of pixels corresponding to the candidate pixel category, wherein the second-category pixels are pixels located in the main body area, and the predetermined correction rule is such that the corrected number of the first-category pixels increases, and the corrected number of the second-category pixels decreases;
[0041] The determination submodule is used to determine the pixel category with the largest number of corresponding pixels from the candidate pixel categories as the target pixel category to which the pixels of the pure color background of the target image belong.
[0042] Optionally, the device further comprises:
[0043] A judging module, used for determining, from among the candidate pixel categories, the pixel category with the largest number of corresponding pixels as the pixel category to which the pixels of the solid color background of the target image belong, whether the ratio of the maximum number of pixels among the numbers of pixels corresponding to the candidate pixel categories to the total number of pixels is greater than a preset threshold, and if so, executing the step of determining, from among the candidate pixel categories, the pixel category with the largest number of corresponding pixels as the target pixel category to which the pixels of the solid color background of the target image belong;
[0044] The total number of pixels is the total number of pixels of the target image.
[0045] Optionally, the extraction module includes:
[0046] A generating submodule, used for determining an area outside the pixels included in the target pixel category as a foreground area of the target image, and generating a mask image of the foreground area;
[0047] The extraction submodule is used to extract the foreground area of the target image to obtain the foreground image of the target image.
[0048] Optionally, the extraction submodule includes:
[0049] The optimization unit is used to optimize the foreground edge of the mask image, and use the optimized mask image to extract the foreground area of the target image to obtain the foreground image of the target image; wherein the optimization processing includes at least one or more of deburring processing, filtering processing, and morphological processing.
[0050] In a third aspect, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0051] Memory, used to store computer programs;
[0052] The processor is used to implement the steps of the solid color background image cutout method described in the embodiment of the present invention when executing the program stored in the memory.
[0053] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of the solid color background image cutout method described in the embodiment of the present invention are implemented.
[0054] In a fifth aspect, an embodiment of the present invention provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the steps of the solid color background image cutout method provided in the embodiment of the present invention.
[0055] Beneficial effects of the embodiments of the present invention:
[0056] In a method for cutting out a pure color background image provided by an embodiment of the present invention, clustering is performed on the pixels of the target image to obtain a plurality of pixel categories after clustering; a pixel category group is determined from the plurality of pixel categories, and each pixel category in the determined pixel category group is merged into a pixel category; subject detection is performed on the target image to obtain a subject area, and based on the subject area, a non-subject area of the target image is determined; from the plurality of pixel categories existing after the pixel category merging process, each candidate pixel category including pixels located in the non-subject area of the target image is screened; using the number of first-category pixels respectively included in each candidate pixel category, the target pixel category to which the pixels of the pure color background of the target image belong is screened from each candidate pixel category; and from the target image, a pixel area outside the pixels included in the target pixel category is extracted as the foreground image of the target image. It can be seen that the automatic cutting out of a pure color background image can be realized through this solution, without the need for the user to manually draw the edge of the foreground area to realize the cutting out, which solves the problem of low cutting out efficiency of manual cutting out of a pure color background.
[0057] Of course, it is not necessary to achieve all of the advantages described above at the same time to implement any product or method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0058] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0059] Figure 1 A flowchart of a method for cutting out a pure color background image provided in an embodiment of the present invention;
[0060] Figure 2 Another flow chart of a method for cutting out a pure color background image provided in an embodiment of the present invention;
[0061] Figure 3 A schematic diagram of a grayscale image of a target image provided in an embodiment of the present invention;
[0062] Figure 4 A schematic diagram of an image marked with pixel category numbers provided in an embodiment of the present invention;
[0063] Figure 5A schematic diagram of an image marked with pixel category numbers after similar pixel categories are merged according to an embodiment of the present invention;
[0064] Figure 6 A schematic diagram of a target image after subject detection provided in an embodiment of the present invention;
[0065] Figure 7 A mask image of a target image provided in an embodiment of the present invention;
[0066] Figure 8 To utilize the method provided by the embodiment of the present invention Figure 3 A schematic diagram of a grayscale image of an image obtained by performing cutout on the target image shown;
[0067] Fig. 9 A schematic structural diagram of a pure color background image cutout device provided in an embodiment of the present invention;
[0068] Fig.10 The present invention is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0069] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0070] In order to solve the problem of low efficiency in manually cutting out a pure color background, an embodiment of the present invention provides a method, device and electronic device for cutting out a pure color background image.
[0071] First, a method for cutting out a pure color background image provided by an embodiment of the present invention is introduced below.
[0072] Among them, a method for cutting out a pure color background image provided by an embodiment of the present invention is applied to an electronic device. In a specific application, the electronic device can be a server. Of course, the electronic device can also be a terminal device, such as a smart phone, a tablet computer, a laptop computer, a desktop computer, etc. When the electronic device is a server, the execution subject of the execution method can specifically be a server program running in the server and corresponding to a client with an image processing function. When the electronic device is a terminal device, the execution subject of the execution method can specifically be a client with an image processing function. In addition, it can be understood that the client can be a web page type client, or the client can be an APP (Application) type client, which is reasonable.
[0073] like Figure 1 As shown, a method for cutting out a pure color background image provided by an embodiment of the present invention may include the following steps:
[0074] S101, acquiring a target image, performing clustering processing on pixels of the target image, and obtaining a plurality of clustered pixel categories; each pixel category includes a plurality of pixels;
[0075] S102, determining a pixel category group from the multiple pixel categories, and merging each pixel category in the determined pixel category group into one pixel category;
[0076] Each pixel category in the pixel category group belongs to a similar category, and pixels included in any two pixel categories belonging to the similar category meet a predetermined pixel similarity condition.
[0077] S103, performing subject detection on the target image to obtain a subject area, and determining a non-subject area of the target image based on the subject area;
[0078] S104, screening each candidate pixel category including pixels located in the non-subject area of the target image from the multiple pixel categories existing after the pixel category merging process;
[0079] S105, using the number of first-category pixels included in each candidate pixel category, respectively, screening the target pixel category to which the pixels of the pure color background of the target image belong from each candidate pixel category; the first-category pixels are pixels located in the non-subject area;
[0080] S106: extracting, from the target image, a pixel region other than pixels included in the target pixel category as a foreground image of the target image.
[0081] In S101, clustering the pixels of the target image can be understood as classifying the same pixels or pixels with similar colors in the target image into one category, and each pixel category can correspond to a category identifier. Since the target image is an image with a pure color background, through clustering, each pixel included in the pure color background will be classified into one category, so as to determine the background area based on the category of the pure color background, and then extract the foreground image.
[0082] In addition, since each pixel category after clustering processing includes multiple pixels and each pixel has position information, the pixel category including pixels located in the non-subject area can be subsequently determined based on the position information of the pixels under each pixel category.
[0083] Furthermore, there are multiple ways to perform clustering processing on the pixels of the target image.
[0084] Exemplarily, in one implementation, pixel values of the target image may be acquired, and pixels with the same pixel value may be clustered together, that is, marked as the same class.
[0085] In another implementation, a clustering algorithm may be applied to perform clustering processing on the pixels of the target image. Exemplarily, the Meanshift clustering algorithm in the prior art may be used to perform clustering processing on the pixels of the target image. It is understandable that the application of the Meanshift clustering algorithm is not the only clustering algorithm. In the prior art, any algorithm for clustering the pixels of the target image may be applied to the embodiments of the present invention. For example, the application of spectral clustering and subspace clustering, etc., may all achieve clustering processing on the pixels of the target image.
[0086] In order to better understand S101, a detailed description is given in conjunction with the accompanying drawings. Figure 3 The target image is a grayscale image shown in FIG. In practical applications, the target image can be a grayscale image or a color image. The target image is clustered, and the image marked with pixel category numbers after clustering is as shown in FIG. Figure 4 As shown, after clustering, 0-4 5 pixel categories are obtained, each pixel category includes multiple pixels, wherein, in order to clearly show the pixel category, Figure 4 Only the outline of the main part is shown.
[0087] In S102, considering that it is necessary to determine the position of the pure color background area by screening the pixel category to which the pure color background area belongs in the future, in order to include more pixels of the pure color background area of the target image in the pixel category to which the pure color background area belongs, after clustering the pixels of the target image and obtaining multiple pixel categories after clustering, the pixel categories with similar pixel values in the pixel category can be merged into the same category. Specifically, a pixel category group is determined from the multiple pixel categories, and each pixel category in the determined pixel category group is merged into a pixel category; wherein each pixel category in the pixel category group belongs to a similar category, and the pixels included in any two pixel categories belonging to the similar category meet the predetermined pixel similarity condition.
[0088] There may be multiple predetermined pixel similarity conditions. For example, the predetermined pixel similarity condition may be that the difference in brightness value is less than a predetermined threshold; or, the predetermined pixel similarity condition may be that the similarity of color histogram distribution is greater than a predetermined threshold.
[0089] When the predetermined similarity condition is that the difference in brightness value is less than a predetermined threshold, correspondingly, the method for determining whether the pixels included in any two pixel categories meet the predetermined pixel similarity condition may include: determining the brightness values of the pixels included in each pixel category, calculating the difference in brightness values of the pixels included in each pixel category, and determining the pixel category whose difference is less than the predetermined threshold as the pixel category meeting the predetermined similarity condition. The predetermined threshold may be a reasonable value such as 10, 15, 20, etc.
[0090] Among them, for a pixel category that contains multiple pixels, the mean of the pixels in the pixel category can be calculated, and the brightness value corresponding to the mean can be used as the pixel value of the pixel category; for a pixel category that contains one pixel, the brightness value of the pixel can be directly used as the pixel value of the pixel category.
[0091] There are many ways to determine the brightness value of a pixel. For example, if the target image is an RGB image, the RGB (red, green, and blue) color value of the pixel can be determined, and the RGB color value can be converted into a YUV (brightness and chromaticity) color value, and the Y value is the brightness value of the pixel; or, if the target image is a YUV image, the YUV color value of the pixel can be directly obtained, and the Y value can be determined as the brightness value of the pixel. Of course, the method is not limited to this.
[0092] When the predetermined similarity condition is that the similarity of the color histogram distribution is greater than a predetermined threshold, correspondingly, a method for determining whether the pixels included in any two pixel categories meet the predetermined pixel similarity condition may include: determining the color histogram distribution of each pixel category, calculating the similarity between the color histogram distributions of each pixel category, and determining two pixel categories whose similarity is greater than the predetermined threshold as pixel categories that meet the predetermined pixel similarity condition.
[0093] Among them, the color histogram can be a grayscale histogram or an RGB histogram. The so-called RGB histogram is a color histogram that can reflect the three color dimensions of RGB. For any color histogram, the horizontal coordinate of the histogram is the pixel value of 0-255, and the vertical coordinate is the number of pixels. For each pixel category, based on the pixel values of the pixels included in the pixel category and the number of each pixel value, a color histogram of the pixel category is generated. In this way, the color histogram corresponding to the pixel category can be used to know the number of pixels corresponding to each pixel value in the pixels included in the pixel category.
[0094] There are many ways to calculate the similarity between the color histogram distributions of each pixel category. For example, for any two pixel categories, the pixel value distribution probability of each pixel category can be calculated based on the color histogram corresponding to the pixel category, and then the similarity of the two pixel categories is calculated using the pixel value distribution probability. Specifically, the number of pixels contained in each pixel value on the horizontal axis of the color histogram is calculated, and the obtained value is divided by the total number of pixels in the pixel category to obtain the probability of the pixel of the pixel category at each pixel value as the pixel value distribution probability. For the pixel value distribution probability of any two pixel categories, the probability of the same pixel value can be multiplied and then squared, and finally the obtained values are added together to obtain the similarity of the two images.
[0095] For example, taking the grayscale histogram as an example, for any two pixel categories, pixel category A and pixel category B, color histograms of pixel category A and pixel category B are generated. In the color histogram of pixel category A, there are 60 pixels with pixel values of 0, 100 pixels with pixel values of 1, and 40 pixels with pixel values of 2; in the color histogram of pixel category B, there are 6 pixels with pixel values of 0, 9 pixels with pixel values of 1, and 5 pixels with pixel values of 2.
[0096] Then calculate the pixel value distribution probability of each pixel category:
[0097] Then in pixel category A, the probability of the pixel value being 0 is: 60÷(60+100+40)=0.3; the probability of the pixel value being 1 is: 100÷(60+100+40)=0.5; the probability of the pixel value being 2 is: 40÷(60+100+40)=0.2;
[0098] Then in pixel category B, the probability of the pixel value being 0 is: 6÷(6+9+5)=0.3; the probability of the pixel value being 1 is: 9÷(6+9+5)=0.45; the probability of the pixel value being 2 is: 5÷(6+9+5)=0.25;
[0099] The pixel value distribution probability of pixel category A is: 0.3, 0.5, 0.2; the pixel value distribution probability of pixel category B is: 0.3, 0.45, 0.25;
[0100] Calculate similarity:
[0101] It can be understood that the similarity interval is [0, 1], the closer to 1, the greater the similarity, and the closer to 0, the smaller the similarity. Therefore, the predetermined threshold value can be 0.8, 0.9, etc.
[0102] It can be understood that for the RGB color histogram, for any two pixel categories, the similarity of the color histogram distribution of the two pixel categories in the R dimension, the similarity of the color histogram distribution in the G dimension, and the similarity of the color histogram distribution in the B dimension can be calculated respectively, and the similarity of the color histogram distribution of the two pixel categories can be calculated by using the similarity of the color histogram distribution in three dimensions.
[0103] It can be understood that the above two predetermined similarity conditions are merely examples of the embodiments of the present invention and do not constitute limitations of the embodiments of the present invention.
[0104] For ease of understanding, combined Figure 4 and Figure 5 Describes the content of merging pixel categories. Figure 4 From the five categories in , determine the pixel category group, and merge the pixel categories in the pixel category group into the same pixel category. Figure 4 In the figure, categories 0, 2, and 4 are one pixel category group, and categories 1 and 3 are another pixel category group. Then, categories 0, 2, and 4 are merged into category 0, and categories 1 and 3 are merged into category 1. The merged category distribution is as follows: Figure 5 shown.
[0105] In S103, the main area of the target image can be determined, and the area outside the main area of the target image is used as the non-main area, so as to filter the candidate pixel categories including pixels located in the non-main area of the target image. The main area is a rectangular frame area containing the main content of the target image, and the non-main area is an area determined based on the main area of the target image that does not contain the main content. Figure 6 As shown, Figure 6 The area inside the rectangular box is the main area, and the area outside the rectangular box is the non-main area.
[0106] There may be a variety of ways to determine the subject area and non-subject area of a target image. Exemplarily, in one implementation, the subject may be detected on the target image, and the subject area may be determined by identifying the subject content in the image, and then the non-subject area may be determined based on the subject area. Alternatively, in another implementation, the user may give a rectangular frame of the subject area, and the position of the rectangular frame may be detected. The area inside the rectangular frame is the subject area, and the area outside the rectangular frame is the non-subject area. Both of these are feasible.
[0107] In S104, the method of screening each candidate pixel category including pixels located in the non-subject area of the target image from the multiple pixel categories existing after the pixel category merging process may include: detecting whether each pixel category includes pixels in the non-subject area according to the pixel position information, and if so, selecting the pixel category to which the pixels in the non-subject area belong as the candidate pixel category. Of course, the method is not limited to this.
[0108] In S105, there are multiple ways to filter the target pixel category to which the pixels of the solid color background of the target image belong from the various candidate pixel categories by utilizing the number of the first-category pixels included in each of the candidate pixel categories. Exemplarily, in one implementation, the pixel category with the largest number of the first-category pixels included can be searched from the various candidate pixel categories as the target pixel category to which the pixels of the solid color background of the target image belong.
[0109] Among them, the method of finding the pixel category with the largest number of first-category pixels from each alternative pixel category can be: respectively counting the number of pixels in the non-main area of each alternative pixel category, that is, the number of first-category pixels, to find the pixel category with the largest number of first-category pixels; or, the area occupied by the first-category pixels in each alternative pixel category can be counted. Since the area of the unit pixel is the same, the pixel category with the largest area occupied by the first-category pixels is found, that is, the pixel category with the largest number of first-category pixels is found.
[0110] In another implementation, for each candidate pixel category, the number of first-category pixels included in the candidate pixel category and the number of second-category pixels included in the candidate pixel category may be corrected according to a predetermined correction rule, and the sum of the corrected number of first-category pixels and the corrected number of second-category pixels is calculated as the number of pixels corresponding to the candidate pixel category, wherein the second-category pixels are pixels located in the main body area, and the predetermined correction rule is such that the corrected number of the first-category pixels increases, and the corrected number of the second-category pixels decreases;
[0111] From the candidate pixel categories, a pixel category corresponding to the largest number of pixels is determined as the pixel category to which the pixels of the pure color background of the target image belong.
[0112] For the sake of clarity and detailed explanation, this method will be described in detail below in conjunction with a specific embodiment.
[0113] It can be understood that the above two methods of utilizing the number of first-category pixels respectively included in the various candidate pixel categories to filter the target pixel categories to which the pixels of the solid color background of the target image belong from the various candidate pixel categories are merely examples of the embodiments of the present invention and do not constitute a specific limitation. In the prior art, any method of utilizing the number of first-category pixels respectively included in the various candidate pixel categories to filter the target pixel categories to which the pixels of the solid color background of the target image belong from the various candidate pixel categories can be applied to the embodiments of the present invention.
[0114] In S106, there are multiple ways to extract a pixel area outside the pixels included in the target pixel category as the foreground image of the target image. Exemplarily, the area outside the pixels included in the target pixel category can be determined as the foreground area of the target image, and a mask image of the foreground area can be generated; the foreground area of the target image can be extracted using the mask image to obtain the foreground image of the target image.
[0115] The mask image is an image in which the pixel value of the foreground area is 255 and the pixel value of the background area is 0. That is, the foreground area of the mask image is white and the background area is black. Figure 7 In the mask image shown, the hand part is white and the background part is black.
[0116] For example, the mask image can be used as a mask and superimposed on the target image, and the superimposed image only displays the white part of the mask and does not display the black part of the mask, thereby extracting the foreground area of the target image and obtaining the foreground image of the target image, but the method is not limited to this.
[0117] In order to make the foreground image more accurate, the foreground edge of the mask image can be optimized, and the foreground area of the target image can be extracted using the optimized mask image to obtain the foreground image of the target image; wherein the optimization process includes at least one or more of deburring, filtering, and morphological processing. Deburring is to fill the part with concave points in the edge of the foreground area and remove the part with convex points to make the edge of the foreground area smoother; filtering is to eliminate noise points in the edge of the foreground area, such as isolated pixels; morphological processing is to expand or shrink the edge of the foreground area to make the edge of the foreground area more consistent with the foreground area of the target image.
[0118] In order to facilitate the understanding of the cutout effect, Figure 8 The method provided by the embodiment of the present invention is shown Figure 3 Schematic diagram of the grayscale image of the image obtained by matting the target image shown.
[0119] In a method for cutting out a pure color background image provided by an embodiment of the present invention, clustering is performed on the pixels of the target image to obtain a plurality of pixel categories after clustering; a pixel category group is determined from the plurality of pixel categories, and each pixel category in the determined pixel category group is merged into a pixel category; subject detection is performed on the target image to obtain a subject area, and based on the subject area, a non-subject area of the target image is determined, and from the plurality of pixel categories existing after the pixel category merging process, each candidate pixel category including pixels located in the non-subject area of the target image is screened; using the number of first-category pixels respectively included in each candidate pixel category, the target pixel category to which the pixels of the pure color background of the target image belong is screened from each candidate pixel category; and from the target image, a pixel area outside the pixels included in the target pixel category is extracted as the foreground image of the target image. It can be seen that the automatic cutting out of a pure color background image can be realized through this solution, without the need for the user to manually draw the edge of the foreground area to realize the cutting out, and the problem of low cutting out efficiency of manual cutting out of a pure color background is solved.
[0120] The embodiment of the present invention also provides a method for cutting out a pure color background image. Figure 2 As shown, the following steps may be included:
[0121] S201, acquiring a target image, performing clustering processing on pixels of the target image, and obtaining a plurality of clustered pixel categories; each pixel category includes a plurality of pixels;
[0122] S202, determining a pixel category group from the multiple pixel categories, and merging each pixel category in the determined pixel category group into one pixel category; wherein each pixel category in the pixel category group belongs to a similar category, and pixels included in any two pixel categories belonging to the similar category meet a predetermined pixel similarity condition;
[0123] S203, performing subject detection on the target image to obtain a subject area, and determining a non-subject area of the target image based on the subject area;
[0124] S204, screening each candidate pixel category including pixels located in the non-subject area of the target image from the multiple pixel categories existing after the pixel category merging process;
[0125] S205, for each candidate pixel category, according to a predetermined correction rule, correct the number of first-category pixels included in the candidate pixel category and the number of second-category pixels included in the candidate pixel category, and calculate the sum of the corrected number of first-category pixels and the corrected number of second-category pixels as the number of pixels corresponding to the candidate pixel category, wherein the second-category pixels are pixels located in the main body area, and the predetermined correction rule is such that the corrected number of the first-category pixels increases, and the corrected number of the second-category pixels decreases;
[0126] S206, determining, from the candidate pixel categories, a pixel category corresponding to the largest number of pixels as the target pixel category to which the pixels of the pure color background of the target image belong;
[0127] S207: extracting, from the target image, a pixel region other than pixels included in the target pixel category as a foreground image of the target image.
[0128] Among them, steps S201-S204 are the same as steps S101-S104, and steps S207 and S106 are the same, which will not be described in detail here.
[0129] In S205, for each candidate pixel category, the number of first-category pixels included in the candidate pixel category and the number of second-category pixels included in the candidate pixel category may be obtained. Specifically, the method of obtaining the number of first-category pixels included in the candidate pixel category and the number of second-category pixels included in the candidate pixel category may include:
[0130] For each candidate pixel category, according to the position information of the pixels included in the alternative pixel category, the number of pixels of the alternative pixel category in the non-subject area and the number of pixels in the subject area are counted respectively, and the number of pixels in the non-subject area is taken as the first category pixel number, and the number of pixels in the subject area is taken as the second category pixel number.
[0131] In order to prevent too many pixels belonging to the main content from being divided into the non-subject area due to inaccurate detection of the main area, thereby causing misjudgment of the target pixel category, for each alternative pixel category, the number of first-category pixels included in the alternative pixel category and the number of second-category pixels included in the alternative pixel category can be corrected according to a predetermined correction rule.
[0132] The predetermined correction rule is: the corrected number value of the number of pixels of the first category increases, and the corrected number value of the number of pixels of the second category decreases. Exemplarily, the first category of pixels may be multiplied by a first correction coefficient greater than 1, and the second category of pixels may be multiplied by a second correction coefficient less than 1. The sum of the corrected number of pixels of the first category and the corrected number of pixels of the second category is calculated as the number of pixels corresponding to the candidate pixel category.
[0133] For example, the following formula may be used to calculate the number of pixels corresponding to the candidate pixel category:
[0134] S i =αA in +βA out
[0135] In the formula, S i is the number of pixels in candidate pixel category i, A in is the number of first-class pixels of candidate pixel category i, A out is the number of second-category pixels of alternative pixel category i, α is the first correction coefficient, β is the second correction coefficient, wherein the first correction coefficient is less than 1, and the first correction coefficient is greater than 1. For example, α can be 0.7, 0.8, 0.9, etc., and β can be 1.2, 1.3, 1.5, etc.
[0136] In S206, the pixel category with the largest number of pixels obtained in S205 may be determined as the target pixel category to which the pixels of the pure color background of the target image belong.
[0137] Furthermore, the pixel category with the largest number of corresponding pixels can be determined in each candidate pixel category, and before the target pixel category to which the pixels of the pure color background of the target image belong, it is determined whether the target image is a pure color background, so that the non-pure color background image input by mistake can be screened out. The method for determining whether the target image is a pure color background can be:
[0138] Determine whether the ratio of the maximum number of pixels among the numbers of pixels corresponding to each candidate pixel category to the total number of pixels is greater than a preset threshold; if so, execute the step of determining the pixel category with the largest number of pixels from the various candidate pixel categories as the pixel category to which the target pixel of the solid color background of the target image belongs; if not, determine that the target image is not a solid color background image and do not process it; wherein the total number of pixels is the total number of pixels of the target image.
[0139] The preset threshold value may be a reasonable threshold value such as 0.6 or 0.7. The method for judging whether the ratio of the maximum number of pixels in the number of pixels corresponding to each candidate pixel category to the total number of pixels is greater than the preset threshold value may be: determining the maximum number of pixels in the number of pixels corresponding to each candidate pixel category, counting the total number of pixels of the target image, calculating the ratio of the maximum number of pixels in the number of pixels corresponding to each candidate pixel category to the total number of pixels, and judging whether the ratio is greater than the preset threshold value.
[0140] The formula for calculating the ratio of the maximum number of pixels among the numbers of pixels corresponding to each candidate pixel category to the total number of pixels can be:
[0141]
[0142] Where Smax is the maximum number of pixels among the numbers of pixels corresponding to each candidate pixel category, W is the number of pixels of the target image width, H is the number of pixels of the target image height, and δ is the ratio of the maximum number of pixels among the numbers of pixels corresponding to each candidate pixel category to the total number of pixels.
[0143] In a method for matting a pure color background image provided by an embodiment of the present invention, a target image is acquired, pixels of the target image are clustered to obtain a plurality of pixel categories after clustering; a pixel category group is determined from the plurality of pixel categories, and each pixel category in the determined pixel category group is merged into a pixel category; a subject detection is performed on the target image to obtain a subject area, and based on the subject area, a non-subject area of the target image is determined; from the plurality of pixel categories after the pixel category merging process, each candidate pixel category whose included pixels are located in the non-subject area of the target image is screened; for each candidate pixel category, the number of first-category pixels included in the candidate pixel category and the number of second-category pixels included in the candidate pixel category are corrected according to a predetermined correction rule, and the sum of the corrected number of first-category pixels and the corrected number of second-category pixels is calculated as the number of pixels corresponding to the candidate pixel category; from the plurality of candidate pixel categories, a pixel category with the largest corresponding number of pixels is determined as the pixel category to which the pixels of the pure color background of the target image belong; from the target image, a pixel area outside the pixels included in the target pixel category is extracted as the foreground image of the target image. It can be seen that this solution can realize automatic cutout of pure color background images without the need for users to manually draw the edge of the foreground area to achieve cutout, thus solving the problem of low cutout efficiency of manual cutout of pure color background images.
[0144] The embodiment of the present invention also provides a pure color background image cutout device, such as Fig. 9 As shown, a pure color background image cutout device provided by an embodiment of the present invention includes:
[0145] The clustering module 910 is used to obtain a target image, perform clustering processing on the pixels of the target image, and obtain a plurality of clustered pixel categories; each pixel category includes a plurality of pixels;
[0146] A merging processing module 920 is used to determine a pixel category group from the multiple pixel categories, and merge each pixel category in the determined pixel category group into one pixel category; wherein each pixel category in the pixel category group belongs to a similar category, and pixels included in any two pixel categories belonging to the similar category meet a predetermined pixel similarity condition;
[0147] The region determination module 930 is used to perform subject detection on the target image to obtain a subject region, and determine a non-subject region of the target image based on the subject region;
[0148] A first screening module 940 is used to screen, from the plurality of pixel categories, each candidate pixel category including pixels located in a non-subject area of the target image; the non-subject area is an area determined based on the subject area of the target image that does not contain subject content;
[0149] The second screening module 950 is used to screen the target pixel category to which the pixels of the solid color background of the target image belong from the candidate pixel categories by using the number of the first category pixels respectively included in the candidate pixel categories; the first category pixels are pixels located in the non-subject area;
[0150] The extraction module 960 is used to extract, from the target image, a pixel region other than the pixels included in the target pixel category as a foreground image of the target image.
[0151] In a pure color background image cutout device provided by an embodiment of the present invention, the pixels of the target image are clustered to obtain a plurality of pixel categories after clustering; a pixel category group is determined from the plurality of pixel categories, and each pixel category in the determined pixel category group is merged into a pixel category; a subject detection is performed on the target image to obtain a subject area, and based on the subject area, a non-subject area of the target image is determined; from the plurality of pixel categories existing after the pixel category merging process, each candidate pixel category including pixels located in the non-subject area of the target image is screened; using the number of first-category pixels respectively included in each candidate pixel category, the target pixel category to which the pixels of the pure color background of the target image belong is screened from each candidate pixel category; from the target image, a pixel area outside the pixels included in the target pixel category is extracted as the foreground image of the target image. It can be seen that the automatic cutout of the pure color background image can be realized through this solution, without the need for the user to manually draw the edge of the foreground area to realize the cutout, which solves the problem of low cutout efficiency of manual cutout of the pure color background.
[0152] Optionally, a method for determining whether pixels included in any two pixel categories meet a predetermined pixel similarity condition includes:
[0153] The color histogram distribution of each pixel category is determined, the similarity between the color histogram distributions of each pixel category is calculated, and two pixel categories with similarities greater than a predetermined threshold are determined as pixel categories that meet a predetermined pixel similarity condition.
[0154] Optionally, the second screening module 950 includes:
[0155] The search submodule is used to search, from the candidate pixel categories, a pixel category including the largest number of first-category pixels as the target pixel category to which the pixels of the pure color background of the target image belong.
[0156] Optionally, the second screening module 950 includes:
[0157] a correction submodule, for correcting, for each candidate pixel category, the number of first-category pixels included in the candidate pixel category and the number of second-category pixels included in the candidate pixel category according to a predetermined correction rule, and calculating the sum of the corrected number of first-category pixels and the corrected number of second-category pixels as the number of pixels corresponding to the candidate pixel category, wherein the second-category pixels are pixels located in the main body area, and the predetermined correction rule is such that the corrected number of the first-category pixels increases, and the corrected number of the second-category pixels decreases;
[0158] The determination submodule is used to determine the pixel category with the largest number of corresponding pixels from the candidate pixel categories as the pixel category to which the pixels of the pure color background of the target image belong.
[0159] Optionally, the device further comprises:
[0160] A judging module, used for determining, from among the candidate pixel categories, the pixel category with the largest number of corresponding pixels as the pixel category to which the pixels of the solid color background of the target image belong, whether the ratio of the maximum number of pixels among the numbers of pixels corresponding to the candidate pixel categories to the total number of pixels is greater than a preset threshold, and if so, executing the step of determining, from among the candidate pixel categories, the pixel category with the largest number of corresponding pixels as the pixel category to which the pixels of the solid color background of the target image belong;
[0161] The total number of pixels is the total number of pixels of the target image.
[0162] Optionally, the extraction module 960 includes:
[0163] A generating submodule, used for determining an area outside the pixels included in the target pixel category as a foreground area of the target image, and generating a mask image of the foreground area;
[0164] The extraction submodule is used to extract the foreground area of the target image to obtain the foreground image of the target image.
[0165] Optionally, extract submodules, including:
[0166] An optimization unit, configured to optimize the foreground edge of the mask image, extract the foreground area of the target image using the optimized mask image, and obtain a foreground image of the target image;
[0167] The optimization processing includes at least one or more of deburring processing, filtering processing, and morphological processing.
[0168] The embodiment of the present invention further provides an electronic device, such as Fig.10 As shown, it includes a processor 1001, a communication interface 1002, a memory 1003 and a communication bus 1004, wherein the processor 1001, the communication interface 1002, and the memory 1003 communicate with each other through a communication bus 1004.
[0169] Memory 1003, used for storing computer programs;
[0170] The processor 1001 is used to implement the steps of a pure color background image cutout method provided by an embodiment of the present invention when executing the program stored in the memory 1003.
[0171] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0172] The communication interface is used for communication between the above electronic device and other devices.
[0173] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0174] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0175] In another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned solid color background image cutout methods are implemented.
[0176] In another embodiment provided by the present invention, a computer program product including instructions is also provided, which, when executed on a computer, enables the computer to execute any of the solid color background image cutout methods in the above embodiments.
[0177] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0178] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0179] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0180] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A method for cutting out a pure color background image, characterized in that: The method comprises: Acquire a target image, perform clustering processing on pixels of the target image, and obtain a plurality of clustered pixel categories; each pixel category includes a plurality of pixels; Determine a pixel category group from the multiple pixel categories, and merge the pixel categories in the determined pixel category group into one pixel category; wherein the pixel categories in the pixel category group belong to similar categories, and the pixels included in any two pixel categories belonging to the similar categories meet the predetermined pixel similarity condition; Performing subject detection on the target image to obtain a subject area, and determining a non-subject area of the target image based on the subject area; From the plurality of pixel categories existing after the pixel category merging process, screening each candidate pixel category including pixels located in the non-subject area of the target image; Filtering the target pixel category to which the pixels of the pure color background of the target image belong from the candidate pixel categories by using the number of the first category pixels respectively included in the candidate pixel categories; the first category pixels are pixels located in the non-subject area; Extracting, from the target image, a pixel region other than pixels included in the target pixel category as a foreground image of the target image; The method of using the number of first-category pixels respectively included in each candidate pixel category to select a target pixel category to which pixels of the solid color background of the target image belong from each candidate pixel category includes: For each candidate pixel category, the number of first-category pixels included in the candidate pixel category and the number of second-category pixels included in the candidate pixel category are corrected according to a predetermined correction rule, and the sum of the corrected number of first-category pixels and the corrected number of second-category pixels is calculated as the number of pixels corresponding to the candidate pixel category, wherein the second-category pixels are pixels located in the main body area; From the candidate pixel categories, a pixel category corresponding to the largest number of pixels is determined as the target pixel category to which the pixels of the pure color background of the target image belong.
2. The method according to claim 1, characterized in that Methods for determining whether pixels included in any two pixel categories meet predetermined pixel similarity conditions include: The color histogram distribution of each pixel category is determined, the similarity between the color histogram distributions of each pixel category is calculated, and two pixel categories with similarities greater than a predetermined threshold are determined as pixel categories that meet a predetermined pixel similarity condition.
3. The method according to claim 1, characterized in that Using the number of first-category pixels respectively included in each candidate pixel category, screening the target pixel category to which the pixels of the pure color background of the target image belong from each candidate pixel category includes: From the candidate pixel categories, a pixel category including the largest number of first-category pixels is searched as the target pixel category to which the pixels of the pure color background of the target image belong.
4. The method according to claim 1, characterized in that: The predetermined correction rule is such that the number of pixels of the first category increases after correction, and the number of pixels of the second category decreases after correction.
5. The method according to claim 4, characterized in that Before determining the pixel category with the largest number of corresponding pixels from the candidate pixel categories as the pixel category to which the pixels of the pure color background of the target image belong, the method further includes: Determine whether the ratio of the maximum number of pixels among the numbers of pixels corresponding to each candidate pixel category to the total number of pixels is greater than a preset threshold, and if so, perform the step of determining the pixel category with the largest number of pixels from the candidate pixel categories as the pixel category to which the pixels of the pure color background of the target image belong; The total number of pixels is the total number of pixels of the target image.
6. The method according to claim 1, characterized in that Extracting, from the target image, a pixel region other than pixels included in the target pixel category as a foreground image of the target image, comprising: Determine an area outside the pixels included in the target pixel category as a foreground area of the target image, and generate a mask image of the foreground area; The foreground area of the target image is extracted using the mask image to obtain a foreground image of the target image.
7. The method according to claim 6, characterized in that Utilizing the mask image, extracting the foreground area of the target image to obtain the foreground image of the target image comprises: Optimizing the foreground edge of the mask image, and using the optimized mask image to extract the foreground area of the target image to obtain a foreground image of the target image; The optimization processing includes at least one or more of deburring processing, filtering processing, and morphological processing.
8. A pure color background image cutout device, characterized in that: The device comprises: A clustering module, used to acquire a target image, perform clustering processing on pixels of the target image, and obtain a plurality of clustered pixel categories; each pixel category includes a plurality of pixels; A merging processing module, used to determine a pixel category group from the multiple pixel categories, and merge each pixel category in the determined pixel category group into one pixel category; wherein each pixel category in the pixel category group belongs to a similar category, and pixels included in any two pixel categories belonging to the similar category meet a predetermined pixel similarity condition; A region determination module is used to perform subject detection on the target image to obtain a subject region, and determine a non-subject region of the target image based on the subject region; a first screening module is used to screen, from the multiple pixel categories existing after the pixel category merging process, each candidate pixel category including pixels located in the non-subject region of the target image; a second screening module is used to screen, from the candidate pixel categories, the target pixel category to which the pixels of the solid color background of the target image belong, using the number of first-category pixels respectively included in each candidate pixel category; the first-category pixels are pixels located in the non-subject region; An extraction module, used for extracting a pixel region other than pixels included in the target pixel category from the target image as a foreground image of the target image; The second screening module comprises: a correction submodule, configured to correct, for each candidate pixel category, the number of first-category pixels included in the candidate pixel category and the number of second-category pixels included in the candidate pixel category according to a predetermined correction rule, and calculate the sum of the corrected number of first-category pixels and the corrected number of second-category pixels as the number of pixels corresponding to the candidate pixel category, wherein the second-category pixels are pixels located in the main body area; The determination submodule is used to determine the pixel category with the largest number of corresponding pixels from the candidate pixel categories as the target pixel category to which the pixels of the pure color background of the target image belong.
9. The device according to claim 8, characterized in that Methods for determining whether pixels included in any two pixel categories meet predetermined pixel similarity conditions include: The color histogram distribution of each pixel category is determined, the similarity between the color histogram distributions of each pixel category is calculated, and two pixel categories with similarities greater than a predetermined threshold are determined as pixel categories that meet a predetermined pixel similarity condition.
10. The device according to claim 8, characterized in that The second screening module comprises: The search submodule is used to search, from among the candidate pixel categories, a pixel category including the largest number of first-category pixels as the target pixel category to which the pixels of the pure color background of the target image belong.
11. The device according to claim 8, characterized in that The predetermined correction rule is such that the number of pixels of the first category increases after correction, and the number of pixels of the second category decreases after correction.
12. The device according to claim 11, characterized in that The device also includes: A judging module, used for determining, from among the candidate pixel categories, the pixel category with the largest number of corresponding pixels as the pixel category to which the pixels of the solid color background of the target image belong, whether the ratio of the maximum number of pixels among the numbers of pixels corresponding to the candidate pixel categories to the total number of pixels is greater than a preset threshold, and if so, executing the step of determining, from among the candidate pixel categories, the pixel category with the largest number of corresponding pixels as the target pixel category to which the pixels of the solid color background of the target image belong; The total number of pixels is the total number of pixels of the target image.
13. The device according to claim 8, characterized in that The extraction module comprises: A generating submodule, used for determining an area outside the pixels included in the target pixel category as a foreground area of the target image, and generating a mask image of the foreground area; The extraction submodule is used to extract the foreground area of the target image to obtain the foreground image of the target image.
14. The device according to claim 13, characterized in that The extraction submodule comprises: The optimization unit is used to optimize the foreground edge of the mask image, and use the optimized mask image to extract the foreground area of the target image to obtain the foreground image of the target image; wherein the optimization processing includes at least one or more of deburring processing, filtering processing, and morphological processing.
15. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing any of the methods described in claims 1-7 when executing a program stored in a memory.
16. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
