Image main color extraction method and device, terminal and computer readable storage medium
By mapping image color blocks to color space cells and filtering candidate colors, the problem of color difference erasing in the prior art is solved, and a more accurate image main color extraction is achieved.
Patent Information
- Application Number
- CN202210369138.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-08
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2042-04-08
AI Technical Summary
In the process of image color acquisition, the color difference will be erased in the center of the cluster, making it difficult to accurately extract colors that conform to the perception of the human eye, resulting in inaccurate color extraction.
By obtaining multiple color blocks of the input image, the preset color space model is divided into multiple cells, map the pixel values of each color block and count the points, filter out the cells with the previous points as candidate colors, according to Points and color difference values extract the main color from the candidate color.
It ensures that the extracted main color is more accurate, can effectively preserve color differences, and improves the visual similarity of image processing.
Smart Images

Figure CN114723834B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and more specifically, to an image main color extraction method, an image main color extraction device, a terminal and a non-volatile computer-readable storage medium. Background Art
[0002] Color has an important influence on people's psychological activities, especially it has a very close relationship with emotions. Red, yellow and orange are called "warm colors", while blue, green and cyan are called "cold colors". Warm colors give people a sense of intimacy and warmth, while cold colors give people a sense of distance and coolness. In computer graphics, color quantization or color image quantization is a quantization applied to color space, which is a process of reducing the number of different colors used in an image, usually to make the image as visually similar to the original image as possible. At present, when coloring an image, it is usually clustered to extract the color of the image, that is, after the cluster is located, the points in each cluster are averaged to obtain the representative color mapped to all the colors in the cluster. The disadvantage is that the cluster center will erase the color differences such as strong and weak saturation, high and low brightness, etc., which makes it difficult to accurately extract the color that meets the perception of the human eye. Summary of the invention
[0003] Embodiments of the present application provide an image main color extraction method, an image main color extraction device, a terminal, and a non-volatile computer-readable storage medium.
[0004] The main color extraction method of an image in an embodiment of the present application includes obtaining multiple color blocks of an input image; dividing a preset color space model into multiple cells; mapping the pixel value of each color block to the color space model, and counting the number of points of the color block mapped to each cell; screening out the cells whose points are ranked in the first i items as candidate colors, where i≥2; and extracting j items from the i items of candidate colors as the main color output of the input image according to the number of points and the color difference value of the cell, where j≤i.
[0005] The image main color extraction device of the embodiment of the present application includes an acquisition module, a division module, a mapping module, a screening module and an extraction module. The acquisition module is used to acquire multiple color blocks of the input image. The division module is used to divide the preset color space model into multiple cells. The mapping module is used to map the pixel value of each color block to the color space model, and count the number of points of the color block mapped to each cell. The screening module is used to screen out the cells whose points are ranked in the first i items as candidate colors, where i≥2. The extraction module is used to extract j items from the i items of the candidate colors as the main color output of the input image according to the number of points and the color value of the cell, where j≤i.
[0006] The terminal of the embodiment of the present application includes one or more processors, a memory and one or more programs. Among them, one or more of the programs are stored in the memory and executed by one or more of the processors. The program includes a method for executing the following image main color extraction method: obtaining multiple color blocks of the input image; dividing the preset color space model into multiple cells; mapping the pixel value of each color block to the color space model, and counting the number of points of the color block mapped to each cell; screening out the cells whose points are ranked in the first i items as candidate colors, where i≥2; and extracting j items from the i items of the candidate colors as the main color output of the input image according to the number of points and the color difference value of the cell, where j≤i.
[0007] The non-volatile computer-readable storage medium of the embodiment of the present application includes a computer program. When the computer program is executed by one or more processors, the processor executes the following image main color extraction method: obtain multiple color blocks of the input image; divide a preset color space model into multiple cells; map the pixel value of each of the color blocks to the color space model, and count the number of points of the color block mapped to each of the cells; filter out the cells whose points are ranked in the first i items as candidate colors, where i≥2; and extract j items from the i items of the candidate colors as the main color output of the input image according to the number of points and the color difference value of the cell, where j≤i.
[0008] In the image main color extraction method, image main color extraction device, terminal and non-volatile computer-readable storage medium of the embodiment of the present application, multiple color blocks of the input image are mapped to multiple cells of the preset color space model, and after counting the number of points of the color blocks in each cell, the mapping result, that is, the i-item cells with the first number of points are used as candidate colors. Finally, the candidate colors are re-screened by the color difference value of the number of points and the cell, so that the j-item candidate colors are output as the main color of the input image, wherein the number of points represents the number information of the color block mapped to the cell, and the candidate color represents the cell with a higher number of points, and by selecting the main color of the final output by re-screening, it can be ensured that the main color of the final output is relatively accurate.
[0009] Additional aspects and advantages of the embodiments of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the embodiments of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:
[0011] Figure 1 It is a flowchart of a method for extracting main color of an image in some embodiments of the present application;
[0012] Figure 2 is a schematic diagram of an image main color extraction device according to some embodiments of the present application;
[0013] Figure 3 is a schematic plan view of a terminal according to some embodiments of the present application;
[0014] Figures 4 to 6 It is a scene schematic diagram of the image main color extraction method in some embodiments of the present application;
[0015] Figure 7 and Figure 8 It is a flowchart of a method for extracting main color of an image in some embodiments of the present application;
[0016] Fig. 9 It is a scene schematic diagram of the image main color extraction method in some embodiments of the present application;
[0017] Figures 10 to 12 It is a flowchart of a method for extracting main color of an image in some embodiments of the present application;
[0018] Fig.13 It is a scene schematic diagram of the image main color extraction method in some embodiments of the present application;
[0019] Fig.14 It is a schematic diagram of the connection status of a non-volatile computer-readable storage medium and a processor in certain embodiments of the present application. DETAILED DESCRIPTION
[0020] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals represent the same or similar elements or elements having the same or similar functions from beginning to end. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the embodiments of the present application, and cannot be understood as limiting the embodiments of the present application.
[0021] See also Figure 1 The present application embodiment provides a method for extracting the main color of an image. The method for extracting the main color of an image comprises the steps of:
[0022] 01: Get multiple color blocks of the input image;
[0023] 03: Divide the preset color space model into multiple cells;
[0024] 05: Map the pixel value of each color block to the color space model, and count the number of points mapped to the color block in each cell;
[0025] 07: Filter out the cells with the first i points as candidate colors, where i ≥ 2; and
[0026] 09: Extract j items from i candidate colors as the main color output of the input image according to the number of points and the color difference value of the cell, where j≤i.
[0027] See also Figure 2 , the embodiment of the present application provides an image main color extraction device 10. The image main color extraction device 10 includes an acquisition module 11, a division module 13, a mapping module 15, a screening module 17 and an extraction module 19. The image main color extraction method of the embodiment of the present application can be applied to the image main color extraction device 10. Among them, the acquisition module 11, the division module 13, the mapping module 15, the screening module 17 and the extraction module 19 are used to execute step 01, step 03, step 05, step 07 and step 09 respectively. That is, the acquisition module 11 is used to acquire multiple color blocks of the input image; the division module 13 is used to divide the preset color space model into multiple cells. The mapping module 15 is used to map the pixel value of each color block to the color space model, and count the number of points of the color block mapped to each cell. The screening module 17 is used to filter out the cells with the number of points arranged in the first i items as candidate colors, where i≥2. The extraction module 19 is used to extract j items from the i items of candidate colors as the main color output of the input image according to the number of points and the color difference value of the cell, where j≤i.
[0028] See also Figure 3 , the embodiment of the present application also provides a terminal 100. The main color extraction method of the image of the embodiment of the present application can be applied to the terminal 100. The terminal 100 includes one or more processors 20, a memory 30 and one or more programs. The one or more programs are stored in the memory 30 and executed by one or more processors 20. The one or more programs include methods for executing steps 01, 03, 05, 07 and 09. That is, when the processor 20 executes one or more programs, it can: be used to obtain multiple color blocks of the input image; divide the preset color space model into multiple cells; map the pixel value of each color block to the color space model, and count the number of points mapped to the color block in each cell; filter out the cells with the number of points ranked in the first i items as candidate colors, where i≥2; and extract j items from the i candidate colors according to the number of points and the color difference value of the cell as the main color output of the input image, where j≤i.
[0029] The terminal 100 may further include a housing 40. The housing 40 is used to install the functional modules of the terminal 100, such as a display device, an imaging device, a power supply device, and a communication device, so that the housing 40 provides protection for the functional modules, such as dustproof, drop-proof, and waterproof. The terminal 100 may be a mobile phone, a tablet computer, a digital camera, a laptop computer, a smart watch, a head-mounted display device, a game console, etc. The embodiment of the present application is described by taking the terminal 100 as a mobile phone as an example. It can be understood that the specific form of the terminal 100 is not limited to a mobile phone.
[0030] Specifically, see Figure 4 and Figure 5 After obtaining the input image P, the processor 20 can obtain multiple color blocks Q1 of the input image P. The processor 20 can divide the input image P into multiple pixel units P1 with sizes of 4*4, 8*8, 16*16, and 32*32. For example, if the processor 20 divides the input image P into multiple pixel units P1 with a size of 16*16, each pixel unit P1 contains 16*16 pixels P10. The specific size of each pixel unit P1 is positively correlated with the size of the input image P, that is, the larger the size of the input image P, the larger the size of each pixel unit P1.
[0031] Next, if Figure 6 , the processor 20 divides the color space model into a plurality of cells. The color space model may be a Hue, Saturation, Value (HSV) color space model or a Hue, Lighting, Saturation (HLS) color space model. This application takes the HSV color space model as an example, and it can be understood that the color space model is not limited to the HSV color space model.
[0032] More specifically, please combine Figure 6 , it can be seen that the HSV color space model has a cone structure, in which the hue H is measured by angle, ranging from 0 to 360 degrees, and is calculated counterclockwise from red. For example, red is 0 degrees, green is 120 degrees, blue is 240 degrees, yellow is 160 degrees, cyan is 180 degrees, magenta is 300 degrees, etc. The saturation S ranges from 0 to 1. The closer to the edge of the HSV color space model, the higher the saturation S, that is, the saturation S increases from the center to the edge of the HSV color space model. The lightness V ranges from 0 (black) to 1 (white), and the closer to the top of the HSV color space model ( Figure 6 The apex of the cone in the middle), the smaller the lightness V is, that is, the lightness V moves from the top to the bottom of the HSV color space model ( Figure 6 The base of the middle cone) increases successively.
[0033] When the processor 20 divides the HSV color space model into a plurality of cells, the brightness V may be divided into 10 disks according to the height by taking each 0.1 as an interval, such as Figure 6 As shown, taking a disk C as an example, the processor 20 takes the saturation S as an interval of 0.1 to divide the disk C into multiple rings C1 (two adjacent concentric circles in the figure form a ring C1). In this way, the processor 20 finally takes the hue H as an interval of 5 degrees, that is, divides a ring C1 into multiple small blocks every 5 degrees, thereby obtaining multiple cells C2. By analogy, the processor 20 can obtain the entire HSV color space model for division to obtain all cells C2.
[0034] After the processor 20 obtains the multiple color blocks Q1 and the multiple cells C2 of the input image P, the processor 20 may map the pixel value of each color block to the HSV color space model, and count the number of points of the color block mapped to each cell.
[0035] The specific mapping relationship is: the processor 20 maps the pixel value of each color block to the cell of the corresponding color according to the color represented by each color block. For example, if the color of a color block is red, the processor 20 maps the color block of red to the cell of the corresponding red area. According to the above, the value ranges of H, S, and V of each cell are different. In this way, the processor 20 can count the number of points of the color block in each cell. The number of points can be understood as the number of color blocks corresponding to each cell.
[0036] like Figure 6 As shown, if the processor 20 maps the pixel values of 10 color blocks to the cell C21, it means that the number of points in the cell C21 is 10, and if the processor 20 maps the pixel values of 20 color blocks to the cell C22, it means that the number of points in the cell C22 is 20. It can be understood that after the processor 20 maps the pixel values of each color block to the HSV color space model, the number of points information of multiple cells C2 can be obtained.
[0037] It should be noted that before the processor 20 maps the pixel value of the color block Q1 to the cell C2, the processor 20 may also extract a number of pixels P10 in each pixel unit P1 and use the pixel average of the pixels P10 as the pixel value of the entire color block Q1.
[0038] Please combine again Figure 4 and Figure 5In one embodiment, each pixel unit P1 contains 16*16 pixels, and the processor 20 can select the average value of the sum of the pixel values of all pixels P10 in the 4*4 central area P2 of each pixel unit P1 as the pixel value of the corresponding color block Q1, so that the amount of calculation can be reduced while eliminating the influence of discrete noise. The size of the central area P2 is positively correlated with the size of the pixel unit P1. For example, when the size of the pixel unit P1 is 16*16, the size of the central area P2 is 4*4. For example, when the size of the pixel unit P1 is 8*8, the size of the central area P2 is 2*2.
[0039] In another embodiment, the processor 20 may also select a pixel P10 by interval sampling, such as selecting one pixel P10 every interval of one pixel P10 in rows and columns, thereby selecting 64 pixels P10, and taking the average value of the sum of the pixel values of the 64 pixels P10 as the pixel value of the corresponding color block Q1. In this way, the accuracy of the pixel value of the color block Q1 can be ensured while reducing the amount of calculation because pixels of various parts of the entire pixel unit P1 are selected.
[0040] Next, the processor 20 can select cells with the first i points as candidate colors according to the point information of the plurality of cells C2, where i is an integer greater than or equal to 2.
[0041] For example, the processor 20 maps multiple color blocks to 10 cells, and the number of dots in these 10 cells are 100, 150, 200, 130, 20, 80, 70, 60, 110 and 90 respectively. If i is 6, the processor 20 uses the colors of the first 6 cells with the number of dots as candidate colors, that is, the number of dots in these 6 cells are 200, 150, 130, 110, 100 and 90 respectively.
[0042] Finally, the processor 20 can extract j items from i items (pieces) of candidate colors as the main color output of the input image according to the number of points and the color difference value of the cell. Wherein, j is less than or equal to i. For example, when i is 6, the value of j is [1, 6]. Preferably, the value of i is twice that of j, such as when i is 6, j is 3. In the main color extraction method of the image in the embodiment of the present application, i is 8 items and j is 4 items.
[0043] Specifically, when the processor 20 extracts j from i candidate colors as the main color of the input image, the processor 20 may first select the candidate color of the cell with the largest number of points as the first main color. Taking the above six cells with points of 200, 150, 130, 110, 100 and 90 as an example, the candidate color of the cell with a point of 200 is the first main color.
[0044] When the number of cells is 6, that is, when there are 6 candidate colors, 3 main colors need to be extracted. Then, after obtaining the first main color, the processor 20 will calculate the color difference between the other 5 candidate colors and the first main color in turn, and select the color with the largest color difference as the second main color. After the second main color is determined, the processor 20 calculates the first color difference between the other 4 candidate colors and the first main color, and the second color difference between the other 4 candidate colors and the second main color, thereby obtaining the sum of the first color difference and the second color difference corresponding to the other 4 candidate colors, and thus selecting the candidate color with the largest sum of the first color difference and the second color difference among the other 4 candidate colors as the third main color. In this way, the processor 20 can extract 3 of the 6 candidate colors and output these 3 as the main colors.
[0045] In the method for extracting the main color of an image, the device for extracting the main color of an image 10 and the terminal 100 of the embodiment of the present application, multiple color blocks of the input image are mapped to multiple cells of a preset color space model, and after counting the number of points of the color blocks in each cell, the mapping result, i.e., the i-th cell with the highest number of points, is used as a candidate color. Finally, the candidate colors are screened again by the color difference value of the number of points and the cell, so that the j-th candidate color is output as the main color of the input image, wherein the number of points represents the number of information of the color block mapped to the cell, and the candidate color represents the cell with a higher number of points, and by selecting the main color of the final output by the method of screening again, it can be ensured that the main color of the final output is relatively accurate.
[0046] See also Figure 2 , Figure 3 , Figure 7 and Figure 8 In some embodiments, step 01: obtaining a plurality of color blocks of an input image comprises the steps of:
[0047] 011: Get multiple color blocks of the input image using a mosaic filter.
[0048] Specifically, step 011: obtaining multiple color blocks of the input image in a mosaic filter manner, including the steps of:
[0049] 0111: Divide the input image into a plurality of pixel units, each pixel unit includes M*M pixels, where M=4*N (N is a natural number); and
[0050] 0113: Perform mosaic filter processing on each pixel unit to obtain a mosaic image, where the mosaic image includes multiple color blocks, each color block corresponds to a pixel unit, and the pixel value of each color block is associated with the pixel value of the pixel in the predetermined area of the corresponding pixel unit.
[0051] In some embodiments, the acquisition module 11 is used to perform step 011, step 0111, and step 0113. That is, the acquisition module 11 is used to acquire multiple color blocks of the input image in a mosaic filter manner; divide the input image into multiple pixel units, each pixel unit includes M*M pixels, where M=4*N (N is a natural number); and perform mosaic filter processing on each pixel unit to acquire a mosaic image, the mosaic image includes multiple color blocks, each color block corresponds to a pixel unit, and the pixel value of each color block is associated with the pixel value of the pixel in the predetermined area of the corresponding pixel unit.
[0052] In some embodiments, one or more programs correspond to executing step 011, step 0111, and step 0113. When the processor 20 executes one or more programs, steps 011, step 0111, and step 0113 may be executed. That is, the processor 20 is used to obtain multiple color blocks of the input image in a mosaic filter manner; divide the input image into multiple pixel units, each pixel unit includes M*M pixels, where M=4*N (N is a natural number); and perform mosaic filter processing on each pixel unit to obtain a mosaic image, the mosaic image includes multiple color blocks, each color block corresponds to a pixel unit, and the pixel value of each color block is associated with the pixel value of the pixel in the corresponding pixel unit predetermined area.
[0053] Specifically, the processor 20 may perform mosaic processing on the input image by using a mosaic filter, such as Fig. 9 As shown, the left picture is the input image, and the right picture is the mosaic image processed by the mosaic filter. The processor 20 can use multiple adjacent pixels, such as 4*4, 8*8, 16*16, 32*32 pixels as a pixel area, and use the pixel area as a color block, so as to obtain multiple color blocks.
[0054] More specifically, please combine Figure 4 and Figure 5 The processor 20 may also first divide the input image P into a plurality of pixel units P1, each pixel unit P1 including M*M pixels, where M=4*N, N is a natural number, that is, M is an integer multiple of 4, such as 4*4, 8*8, 16*16, 32*32, etc.
[0055] Next, the processor 20 may perform mosaic filter processing on each pixel unit P1 to obtain a mosaic image Q of the input image P. In this way, the mosaic image Q of the input image P may include a plurality of color blocks Q1, and each color block Q1 corresponds to the above-mentioned pixel unit P1 one by one.
[0056] According to the above, each pixel unit P1 includes M*M pixels, and the pixel value of each color block Q1 is associated with the pixel value of the pixel P10 in the predetermined area P2 of the corresponding pixel unit P1. The predetermined area P2 is an N*N matrix centered on the center of the pixel unit P1, and the pixel value of each color block Q1 is the average pixel value of the pixels in the N*N matrix in the corresponding pixel unit P1. For example, each pixel unit P1 corresponds to a color block Q1, and each pixel unit P1 includes 16*16 pixels, that is, M is 16, N is 4, and the matrix Q2 includes 4*4 pixels. In this way, the pixel value of each pixel block Q1 is the average pixel value of the 16 pixels in the corresponding matrix Q2.
[0057] In this way, the processor 20 can obtain multiple color blocks Q1 of the input image P, and in this process, by taking the average pixel value of the pixels of the matrix Q2 in each pixel unit P1 as the average pixel value of the corresponding color block Q1, it is possible to reduce the amount of calculation while avoiding obtaining the pixel values of discrete noise points in the pixel unit P1, thereby ensuring that the pixel value of each color block Q1 is more accurate.
[0058] See also Figure 2 , Figure 3 and Fig.10 In some implementations, step 03: dividing the preset color space model into a plurality of cells comprises the steps of:
[0059] 031: Divide the color space model into multiple disks in the height direction;
[0060] 033: Divide each disk into multiple rings; and
[0061] 035: Each circular ring is divided into multiple sector rings, and the three-dimensional structure corresponding to each sector ring is a unit cell.
[0062] In some embodiments, the division module 13 is used to perform step 031, step 033 and step 035. That is, the division module 13 is used to divide the color space model into multiple disks in the height direction; divide each disk into multiple rings; and divide each ring into multiple sector rings, and the three-dimensional structure corresponding to each sector ring is a unit cell.
[0063] In some embodiments, one or more programs are used to execute step 031, step 033, and step 035. When the processor 20 executes one or more programs, it can be used to execute step 031, step 033, and step 035. That is, the processor 20 is used to divide the color space model into multiple disks in the height direction; divide each disk into multiple rings; and: divide each ring into multiple sector rings, and the three-dimensional structure corresponding to each sector ring is a unit cell.
[0064] Specifically, when the processor 20 divides the preset color space model into a plurality of cells, the color space model may be first divided into a plurality of disks in the height direction. Figure 6 As shown, it can be known that in the HSV color space model, the height direction is brightness V, that is, the processor 20 can divide the color space model into multiple disks according to the value range of brightness.
[0065] According to the above, the value range of brightness V is 0 to 1, and the processor 20 can divide the value range of brightness V into multiple intervals, such as taking every 0.1 as an interval, so as to divide the color space model into 10 disks.
[0066] Next, the processor 20 may further divide each disk into a plurality of rings, such as Figure 6 As shown, it can be seen that the disk C is divided into a plurality of concentric rings C1, that is, each ring C1 is obtained by dividing the disk C in the radial direction. Figure 5 As can be seen from the left figure, this direction represents the saturation S in the HSV color space model, and its value range is 0 to 1. That is, the processor 20 can divide the value range of the saturation S into multiple intervals, such as every 0.1 as an interval, so as to divide the disk C into 10 rings C1.
[0067] Finally, if Figure 6 As shown, the processor 20 can divide each circular ring C1 into multiple sector rings C2 in the circumferential direction of each circular ring C1, and the circumferential direction represents the hue H in the HSV color space model, and its value range is 0 degrees to 360 degrees. That is, the processor 20 can divide the value range of the hue H into multiple intervals, such as every 5 degrees as an interval, to divide the circular ring C1 into 72 sector rings C2. Among them, the division of the lightness V, saturation S and hue H by the processor 20 is not limited to 0.1, 0.1 and 5 degrees. The processor 20 can take any value and divide the lightness V, saturation S and hue H equally.
[0068] Thus, the three-dimensional structure corresponding to the fan ring C2 is finally obtained (such as Figure 6 The processor 20 can obtain multiple cells by dividing the color space model in three directions.
[0069] See also Figure 2 , Figure 3 and Fig.11 In some implementations, step 05: mapping the pixel value of each color block to a color space model further includes the steps of:
[0070] 051: Convert the RGB pixel value of each color block into the values of three dimensions in the color space model; and
[0071] 053: According to the values of the three dimensions and the value ranges of the three dimensions of each cell, find out the cell that each color block falls into.
[0072] In some embodiments, the mapping module 15 is used to perform step 051 and step 053. That is, the mapping module 15 is used to convert the RGB pixel value of each color block into the values of three dimensions in the color space model; and find the cell where each color block falls according to the values of the three dimensions and the value ranges of the three dimensions of each cell.
[0073] In some embodiments, one or more programs are used to execute step 051 and step 053. When the processor 20 executes one or more programs, it can be used to execute step 051 and step 053. That is, the processor 20 is used to convert the RGB pixel value of each color block into the value of three dimensions in the color space model; and according to the value of the three dimensions and the value range of the three dimensions of each cell, find the cell where each color block falls.
[0074] Specifically, after the processor 20 obtains multiple color blocks and multiple cells, the processor 20 can convert the RGB pixel value of each color block into the values of three dimensions in the color space model. For the HSV color space model, the three dimensions are hue H, saturation S, and lightness V. For the HLS color space model, the three dimensions are hue H, lightness L, and saturation S.
[0075] For example, the processor 20 converts the RGB pixel value of a color block into three dimensions of the HSV color space model, with values of H121, S0.25 and V0.12. As can be seen from the above, each cell divided by the processor 20 corresponds to a value range of the three dimensions of hue H, saturation S and lightness V. In this way, the processor 20 can find the cell including the value according to H121, S0.25 and V0.12. At this time, the number of points of the cell can be increased by 1.
[0076] By analogy, the processor 20 can find the corresponding cells of the RGB pixel values of all color blocks after they are converted into the three dimensions of the HSV color space model, thereby determining the number of points of all cells. It can be understood that the number of points represents the number of color blocks contained in the cell.
[0077] See also Figure 2 , Figure 3 and Fig.12 In some embodiments, step 09: extracting j items from i items of candidate colors as the main color output of the input image according to the number of points and the color difference value of the cell, comprising the steps of:
[0078] 091: Step 1: Take the one with the most points among the i candidate colors as the first result color;
[0079] 093: Step 2: Calculate the color difference between the other i-1 candidate colors and the first result color in turn, and take the candidate color with the largest absolute value of the color difference as the second result color;
[0080] 095: Step 3: Calculate the first color difference between the other i-2 candidate colors and the first result color, and the second color difference between the other i-2 candidate colors and the second result color, and take the candidate color with the largest sum of the absolute value of the first color difference and the absolute value of the second color difference as the third result color;
[0081] 097: Step 4: sequentially calculate the first color difference between the other i-3 candidate colors and the first result color, the second color difference between the other i-3 candidate colors and the second result color, and the third color difference between the other i-3 candidate colors and the third result color, and take the candidate color with the largest sum of the absolute value of the first color difference value, the absolute value of the second color difference value, and the absolute value of the third color difference value as the fourth result color; and
[0082] 099: Steps 5 to j, continue to execute the calculation steps in sequence according to step 4, and extract the 5th result color to the jth result color, wherein, when j=1, 2, 3, or 4, terminate at step 1, step 2, step 3, step 4 in sequence, and when j≥5, terminate at step j, and output the 1st result color to the jth result color as the main color of the input image.
[0083] In some embodiments, the extraction module 19 is further used to execute step 091, step 093, step 095, step 097, and step 099. That is, the extraction module 19 is used to execute step 1: taking the one with the most points among the i candidate colors as the first result color; step 2: sequentially calculating the color difference values between the other i-1 candidate colors and the first result color, and taking the candidate color with the largest absolute value of the color difference value as the second result color; step 3: sequentially calculating the first color difference value between the other i-2 candidate colors and the first result color, and the second color difference value between the other i-2 candidate colors and the second result color, and taking the candidate color with the largest sum of the absolute value of the first color difference value and the absolute value of the second color difference value as the third result color; step 4: sequentially calculating the first color difference value between the other i-3 candidate colors and the first result color The absolute value of the first color difference, the absolute value of the second color difference and the absolute value of the third color difference are taken as the candidate color with the largest sum as the fourth result color; and steps 5 to j, continue to perform the steps of calculation in sequence according to step 4, and extract the fifth result color to the jth result color, wherein, when j=1, 2, 3, or 4, terminate at step 1, step 2, step 3, and step 4 in sequence, and when j≥5, terminate at step j, and output the first result color to the jth result color as the main color of the input image.
[0084] In some embodiments, one or more programs are used to execute step 091, step 093, step 095, step 097, and step 099. When the processor 20 executes one or more programs, it can be used to execute step 091, step 093, step 095, step 097, and step 099. That is, the processor 20 is used to execute step 1: taking the one with the largest number of points among the i candidate colors as the first result color; step 2: sequentially calculating the color difference values between the other i-1 candidate colors and the first result color, and taking the candidate color with the largest absolute value of the color difference value as the second result color; step 3: sequentially calculating the first color difference value between the other i-2 candidate colors and the first result color, and the second color difference value between the other i-2 candidate colors and the second result color, and taking the candidate color with the largest sum of the absolute value of the first color difference value and the absolute value of the second color difference value as the third result color; step 4: sequentially calculating the first color difference value between the other i-3 candidate colors and the first result color The absolute value of the first color difference, the absolute value of the second color difference and the absolute value of the third color difference are taken as the candidate color with the largest sum as the fourth result color; and steps 5 to j, continue to perform the steps of calculation in sequence according to step 4, and extract the fifth result color to the jth result color, wherein, when j=1, 2, 3, or 4, terminate at step 1, step 2, step 3, and step 4 in sequence, and when j≥5, terminate at step j, and output the first result color to the jth result color as the main color of the input image.
[0085] Specifically, the processor 20 selects cells with the top i points according to the points of each cell, that is, after the candidate colors are determined, the processor 20 can further select j items according to the i candidate colors as the main color output of the input image.
[0086] More specifically, Fig.13 For example, the processor 20 determines 6 candidate colors, and the corresponding points of each candidate color are i1=20, i2=40, i3=50, i4=60, i5=80 and i6=100, respectively, and the color values corresponding to the candidate colors i1 to i6 are 10, 15, 30, 40, 80 and 20, respectively. According to the above, preferably, when i=6, j=3.
[0087] Thus, when the processor 20 executes step 1, the processor 20 takes the candidate color i6 as the first result color. Next, the processor 20 starts to execute step 2, and the processor 20 starts to calculate the color difference values between the other i-1 items, that is, the other 5 candidate colors and the first result color, and records the candidate color with the largest absolute value of the color difference value as the second result color. Through calculation, it can be known that the absolute value of the color difference value of i1-i6 is 10, the absolute value of the color difference value of i2 and i6 is 5, the absolute value of the color difference value of i3 and i6 is 10, the absolute value of the color difference value of i4 and i6 is 20, and the absolute value of the color difference value of i5 and i6 is 60, so the second result color is the candidate color i5.
[0088] After obtaining the second result color, the processor 20 calculates the other i-2 items, namely, the first color difference between the other four candidate colors and the first result color, and the second color difference between the other four candidate colors and the second result color, and takes the candidate color with the largest sum of the absolute value of the first color difference and the absolute value of the second color difference, and records the corresponding candidate color as the third result color. Fig.13 , it can be seen that the third result color is candidate color i1.
[0089] According to the above, j=3, when the processor 20 obtains the third result color, it will stop at step 3 and output the first result color, the second result color and the third result color as the main colors of the input image.
[0090] If i is 8 and j is 4, after obtaining the third result color, the processor 20 needs to execute step 4, that is, the processor 20 calculates the first color difference value between the other 5 candidate colors and the first result color, the second color difference value between the other 5 candidate colors and the second result color, and the third color difference value between the other 5 candidate colors and the third result color in turn, and the candidate color with the largest sum of the absolute value of the first color difference value, the absolute value of the second color difference value, and the absolute value of the third color difference value is recorded as the fourth result color.
[0091] By analogy, if i is 10 and j is 5, after the processor 20 obtains the fourth result color, the processor 20 will recalculate according to step 4 the first color difference value between the other 6 candidate colors and the first result color, the second color difference value between the other 6 candidate colors and the second result color, the third color difference value between the other 6 candidate colors and the third result color, and the fourth color difference value between the other 6 candidate colors and the fourth result color, and record the candidate color corresponding to the maximum sum of the absolute values of the first color difference value, the second color difference value, the third color difference value and the fourth color difference value as the fifth result color.
[0092] It can be understood that when j is X, the processor 20 needs to perform X steps in sequence to obtain X result colors. Therefore, when j is greater than or equal to 5, the processor 20 will terminate at step j to obtain j result colors, and output the first result color to the jth result color as the main color of the input image.
[0093] See also Fig.14 The present application also provides a non-volatile computer-readable storage medium 300 including a computer program 301. When the computer program 301 is executed by one or more processors 20, the one or more processors 20 execute the method for extracting the main color of an image in any of the above embodiments.
[0094] For example, when the computer program 301 is executed by one or more processors 20, the processor 20 performs the following image main color extraction method:
[0095] 01: Get multiple color blocks of the input image;
[0096] 03: Divide the preset color space model into multiple cells;
[0097] 05: Map the pixel value of each color block to the color space model, and count the number of points mapped to the color block in each cell;
[0098] 07: Filter out the cells with the first i points as candidate colors, where i ≥ 2; and
[0099] 09: Extract j items from i candidate colors as the main color output of the input image according to the number of points and the color difference value of the cell, where j≤i.
[0100] For another example, when the computer program 301 is executed by one or more processors 20, the processor 20 performs the following image main color extraction method:
[0101] 011: Get multiple color blocks of the input image using a mosaic filter.
[0102] In the description of this specification, the descriptions with reference to the terms "certain embodiments", "in an example", "exemplarily", etc., mean that the specific features, structures, materials or characteristics described in conjunction with the embodiments or examples are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, unless they are contradictory.
[0103] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.
[0104] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.
Claims
1. A method for extracting main color of an image, characterized in that: include: Get multiple color blocks of the input image; Divide the preset color space model into multiple cells; Mapping the pixel value of each color block into the color space model, and counting the number of points mapped to the color block in each cell; Filter out the cells whose points are ranked in the first i items as candidate colors, where i≥2; and Extracting j items from i items of the candidate colors as the main color output of the input image according to the number of points and the color difference value of the cell, where j≤I; The step of obtaining a plurality of color blocks of an input image comprises: Acquire the plurality of color blocks of the input image in a mosaic filter manner; The step of obtaining the plurality of color blocks of the input image in a mosaic filter manner includes: Divide the input image into a plurality of pixel units, each of which includes M*M pixels, where M=4*N, and N is a natural number; Performing mosaic filter processing on each of the pixel units to obtain a mosaic image, wherein the mosaic image includes a plurality of color blocks, each of the color blocks corresponds to one of the pixel units, and a pixel value of each of the color blocks is associated with a pixel value of a pixel in a predetermined area of the corresponding pixel unit; The predetermined area is an N*N matrix centered at the center of the pixel unit, and the pixel value of each color block is the average pixel value of the pixels in the N*N matrix in the corresponding pixel unit.
2. The method for extracting main color of an image according to claim 1, characterized in that: The step of dividing the preset color space model into a plurality of cells comprises: Dividing the color space model into a plurality of disks in the height direction; Dividing each of the disks into a plurality of rings; and Each of the circular rings is divided into a plurality of sector rings, and the three-dimensional structure corresponding to each of the sector rings is a unit cell.
3. The method for extracting main color of an image according to claim 1, characterized in that: Each of the cells has a value range of three dimensions, and mapping the pixel value of each of the color blocks to the color space model includes: Converting the RGB pixel value of each color block into values of three dimensions in the color space model; and According to the values of the three dimensions and the value ranges of the three dimensions of each cell, the cell into which each color block falls is found.
4. The method for extracting main color of an image according to claim 1, characterized in that: The step of extracting j items from i items of candidate colors as the main color output of the input image according to the number of points and the color value of the cell comprises: Step 1: The candidate color with the largest number of points in item i is taken as the first result color; Step 2: Calculate the color difference between the other i-1 candidate colors and the first result color in turn, and take the candidate color with the largest absolute value of the color difference as the second result color; Step 3: Calculate the first color difference between the other i-2 candidate colors and the first result color, and the second color difference between the other i-2 candidate colors and the second result color, and take the candidate color with the largest sum of the absolute values of the first color difference and the second color difference as the third result color; Step 4: sequentially calculating the first color difference between the other i-3 candidate colors and the first result color, the second color difference between the other i-3 candidate colors and the second result color, and the third color difference between the other i-3 candidate colors and the third result color, and taking the candidate color with the largest sum of the absolute values of the first color difference, the second color difference, and the third color difference as the fourth result color; and Steps 5 to j, continue to execute the calculation steps in sequence according to step 4, and extract the 5th result color to the jth result color, wherein the steps 1 to j are executed in sequence, and when j=1, 2, 3, or 4, terminate at step 1, step 2, step 3, and step 4 in sequence, and when j≥5, terminate at step j, and output the 1st result color to the jth result color as the main color of the input image.
5. An image main color extraction device, characterized in that: include: An acquisition module, used for acquiring multiple color blocks of an input image; A division module, used for dividing a preset color space model into a plurality of cells; A mapping module, used for mapping the pixel value of each color block into the color space model, and counting the number of points mapped to the color block in each cell; A screening module, used for screening out the cells whose points are ranked in the first i items as candidate colors, where i≥2; and An extraction module, used for extracting j items from i items of candidate colors as the main color output of the input image according to the number of points and the color value of the cell, where j≤i; The acquisition module is used to acquire the plurality of color blocks of the input image in a mosaic filter manner; The acquisition module is further used to divide the input image into a plurality of pixel units, each of which includes M*M pixels, where M=4*N, and N is a natural number; Performing mosaic filter processing on each of the pixel units to obtain a mosaic image, wherein the mosaic image includes a plurality of color blocks, each of the color blocks corresponds to one of the pixel units, and a pixel value of each of the color blocks is associated with a pixel value of a pixel in a predetermined area of the corresponding pixel unit; The predetermined area is an N*N matrix centered at the center of the pixel unit, and the pixel value of each color block is the average pixel value of the pixels in the N*N matrix in the corresponding pixel unit.
6. A terminal, characterized in that: include: One or more processors, memory; and One or more programs, wherein one or more of the programs are stored in the memory and executed by one or more of the processors, and the programs include instructions for executing the image main color extraction method according to any one of claims 1 to 4.
7. A non-volatile computer-readable storage medium storing a computer program, wherein when the computer program is executed by one or more processors, the processors implement the image main color extraction method according to any one of claims 1 to 4.
