Method and apparatus for selecting representative color of picture

By determining the grayscale image and weight values ​​in the image and combining them with a hierarchical clustering algorithm to optimize the color system division, the problem of inaccurate selection of representative colors in existing technologies is solved, and a high degree of consistency between the color scheme style and the original image is achieved.

CN115496815BActive Publication Date: 2026-06-26HUAWEI TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HUAWEI TECH CO LTD
Filing Date
2021-06-18
Publication Date
2026-06-26

Smart Images

  • Figure CN115496815B_ABST
    Figure CN115496815B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a kind of selection method and device of picture representative color, the method comprises: determining the gray scale chart of target image;Determine the weight value of each pixel point in target image based on gray scale chart;The color corresponding to each pixel point in target image is color system division, obtain n color systems, each color system includes at least one color, n is greater than or equal to 1 positive integer;Determine the weight value of each color system in n color systems based on the weight value of the color included in each color system in n color systems, the weight value of the color included in each color system is obtained from the weight value of each pixel point in target image;Determine representative color based on the weight value of each color system in n color systems and the weight value of the color included in each color system in n color systems, representative color is used to represent the color of target image;Output representative color. Thus the color extracted from picture can represent original picture to the greatest extent, so that color matching style is consistent with original picture.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of terminal technology, and in particular to a method and apparatus for selecting the representative color of an image. Background Technology

[0002] In recent years, mobile operating systems have seen an increasing number of personalized scenarios, such as always-on display, lock screen, and themes. These scenarios inevitably require color matching for components. Some use default colors, others have selectable color palettes, and the most personalized scenarios use colors selected from user-chosen images. Therefore, the role of image color matching is becoming increasingly important, and the requirements for image color matching in business scenarios are also increasing. Summary of the Invention

[0003] To achieve the aforementioned technical objectives, this application provides a method, apparatus, computer-readable storage medium, and computer program product for selecting representative colors from an image, which enables the colors extracted from the image to represent the original image to the greatest extent possible, thereby ensuring that the color scheme remains consistent with the original image.

[0004] Firstly, a method for selecting a representative color for an image is provided. This method may include: determining a grayscale image of the target image; determining the weight value of each pixel in the target image based on the grayscale image; dividing the colors corresponding to each pixel in the target image into n color systems, each color system including at least one color, where n is a positive integer greater than or equal to 1; determining the weight value of each color system in the n color systems based on the weight values ​​of the colors contained in each color system, the weight values ​​of the colors contained in each color system being obtained from the weight values ​​of each pixel in the target image; determining a representative color based on the weight values ​​of each color system in the n color systems and the weight values ​​of the colors contained in each color system, the representative color being used to represent the colors of the target image; and outputting the representative color. In this way, the color extracted from the image can represent the original image to the greatest extent possible, thus ensuring that the color scheme is consistent with the original image.

[0005] According to the first aspect, based on the grayscale image, the weight value of each pixel in the target image is determined, specifically including: determining the brightness value of each pixel in the grayscale image; and determining the weight value of each pixel in the target image based on the brightness value of each pixel. In this way, the weight value of each pixel in the target image is determined based on the brightness value of each pixel in the grayscale image.

[0006] According to the first aspect, or any implementation of the first aspect above, before dividing the colors corresponding to each pixel in the target image into n color systems, the method further includes: merging identical colors among the colors corresponding to each pixel in the target image to obtain m different colors, where m is a positive integer greater than or equal to 1, and each of the m different colors corresponds to at least one pixel; merging the m different colors based on their color features to obtain p colors, where p is less than or equal to m. This merging of identical colors improves the efficiency of subsequent processing; and merging the m different colors based on their color features reduces the number of colors, facilitating subsequent color selection. For example, color features may include at least one of color system, saturation, and brightness.

[0007] According to the first aspect, or any implementation of the first aspect above, the weight value of any color among the m different colors is obtained by the weight value of the pixel corresponding to any color among the m different colors; and / or, the weight value of any color among the p colors is obtained by the weight values ​​corresponding to k different colors, wherein any color among the p colors is obtained by merging k different colors.

[0008] For example, the weight of any one of the m different colors is the sum of the weight values ​​of the pixels corresponding to that color. For instance, the weight of red is the sum of the weight values ​​of all pixels that are red. For example, the weight of any one of the p colors is the sum of the weight values ​​of the pixels corresponding to the k different colors.

[0009] According to the first aspect, or any implementation of the first aspect above, the color corresponding to each pixel in the target image is divided into n color systems. Specifically, this includes: determining a first feature of the color corresponding to each pixel in the target image; and based on the first feature, using a hierarchical clustering algorithm to divide the color corresponding to each pixel in the target image into n color systems. For example, the first feature is hue.

[0010] Based on the first aspect, or any implementation thereof, a representative color is determined based on the weight values ​​of each color system in the n color systems and the weight values ​​of the colors contained within each color system. Specifically, this includes: determining a primary color system based on the weight values ​​of each color system in the n color systems; reordering the remaining n-1 color systems (excluding the primary color system); and determining the representative color based on the primary color system, the reordered n-1 color systems, and the weight values ​​of the colors contained within each color system in the n color systems. This achieves the selection of several more representative colors from a holistic perspective. For example, the primary color system is the color system with the largest weight value among the weight values ​​of each color system in the n color systems.

[0011] Based on the first aspect, or any implementation of the first aspect above, the n-1 color systems other than the primary color system are reordered. Specifically, this includes: determining the ranking weight of each color system in the n-1 color systems; and reordering each color system in the n-1 color systems based on the ranking weight. This allows for the selection of several more representative colors from the overall composition.

[0012] According to the first aspect, or any implementation of the first aspect above, the ranking weight of each color system in the n-1 color systems is determined, specifically including: determining the deviation between the second feature of the color corresponding to the color system whose ranking weight is to be determined and the second feature of the color corresponding to each color system whose ranking weight has been determined; and determining the ranking weight of the color system whose ranking weight is to be determined based on the deviation and the weight values ​​of the colors contained in the color system whose ranking weight is to be determined.

[0013] According to the first aspect, or any implementation of the first aspect above, the required number of representative colors is j, where j is a positive integer greater than or equal to 1; based on the first color system, the reordered n-1 color systems, and the weight values ​​of the colors contained in each of the n color systems, the representative colors are determined, specifically including: if j is less than n, the first color in the j color systems is selected as the j representative colors, where the weight value of any color system in the j color systems is greater than the weight value of any color system in the nj color systems; if j is equal to n, the first color in the n color systems is selected as the j representative colors; if j is greater than n, the first color in the n color systems is selected as the n representative colors, and based on the weights of the remaining colors in each of the n color systems, jn representative colors are selected from the remaining colors in the n color systems.

[0014] In a second aspect, a device for selecting a representative color of an image is provided, comprising: at least one memory for storing a program; and at least one processor for executing the program stored in the memory. When the program stored in the memory is executed, the processor is used to execute the first aspect and any implementation thereof.

[0015] The second aspect and any implementation thereof correspond to the first aspect and any implementation thereof, respectively. The technical effects corresponding to the second aspect and any implementation thereof are similar to those corresponding to the first aspect and any implementation thereof, and will not be repeated here.

[0016] Thirdly, a computer-readable storage medium is provided, the computer-readable storage medium including a computer program that, when run on an electronic device, causes the electronic device to perform the method as described in the second aspect and any implementation thereof.

[0017] The third aspect and any implementation thereof correspond to the second aspect and any implementation thereof, respectively. The technical effects of the third aspect and any implementation thereof can be found in the technical effects of the second aspect and any implementation thereof, as described above, and will not be repeated here.

[0018] Fourthly, a computer program product is provided that, when run on an electronic device, causes the electronic device to perform the method as described in the second aspect and any implementation thereof.

[0019] The fourth aspect and any implementation thereof correspond to the second aspect and any implementation thereof, respectively. The technical effects of the fourth aspect and any implementation thereof can be found in the technical effects of the second aspect and any implementation thereof, as described above, and will not be repeated here. Attached Figure Description

[0020] Figure 1 A schematic diagram of the hardware structure of an electronic device is shown;

[0021] Figure 2 A flowchart illustrating a method for selecting a representative color for an image is shown.

[0022] Figure 3 A grayscale image of a picture is shown;

[0023] Figure 4 This diagram illustrates how saturation and brightness are divided under hue.

[0024] Figure 5 A schematic diagram illustrating the division of color systems is shown;

[0025] Figure 6 This diagram illustrates how a color system determines a representative color.

[0026] Figure 7 A flowchart illustrating the steps for sorting color systems is shown.

[0027] Figure 8 A flowchart illustrating a method for selecting a representative color for an image is shown.

[0028] Figure 9 A schematic diagram of a chip structure is shown. Detailed Implementation

[0029] The terminology used in the following embodiments is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to also include expressions such as “one or more,” unless the context clearly indicates otherwise. It should also be understood that in the following embodiments of this application, “at least one” and “one or more” refer to one or more (including two). The term “and / or” is used to describe the relationship between related objects, indicating that three relationships can exist; for example, A and / or B can indicate: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character “ / ” generally indicates that the preceding and following related objects are in an “or” relationship.

[0030] References to "one embodiment" or "some embodiments" as used in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized. The term "connection" includes both direct and indirect connections, unless otherwise stated.

[0031] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature.

[0032] In the embodiments of this application, the words "exemplarily" or "for example" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "exemplarily" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design solutions. Specifically, the use of the words "exemplarily" or "for example" is intended to present the relevant concepts in a specific manner.

[0033] For example, when using an electronic device, colors can be assigned to other pages or components based on images selected for the application scenario (such as wallpapers or photos). Generally, one can specify the number of colors to extract, then perform K-means clustering and select the colors of the cluster centers; alternatively, colors can be statistically merged and selected based on their proportions. However, in these methods, the specified number of colors may not match the original image. If the original image has a single color, the specified number of colors will be greater than the original image's color count; if the original image has a complex color scheme, the specified number of colors will be less than the original image's color count, making the extracted colors potentially unrepresentative of the original image. Furthermore, the method of statistically merging colors and selecting colors based on their proportions may extract too many colors, making the extracted colors potentially unrepresentative of the original image.

[0034] In order to ensure that the colors extracted from the image can represent the original image to the greatest extent possible, and thus maintain consistency with the color scheme of the original image, this application provides a method and electronic device for selecting representative colors of an image.

[0035] For example, Figure 1 A schematic diagram of the hardware structure of an electronic device is shown. (For example...) Figure 1 As shown, the electronic device 100 may include: a processor 110, a memory 120, a display screen 130, etc.

[0036] Processor 110 may include one or more processing units, such as application processors (APs), modem processors, graphics processing units (GPUs), image signal processors (ISPs), controllers, video codecs, digital signal processors (DSPs), and / or neural network processing units (NPUs). Different processing units may be independent devices or integrated into one or more processors. In some embodiments, electronic device 100 may also include one or more processors 110. For example, processor 110 may perform saliency detection, pixel weight mapping, hierarchical clustering color system partitioning, and representative color selection on an image.

[0037] The memory 120 can be used to store one or more computer programs, which include instructions. The processor 110 can execute the instructions stored in the memory 120, thereby causing the electronic device 100 to perform the image representative color selection method provided in this solution, etc. The memory 120 can also be used to store images, etc., in the electronic device 100.

[0038] Display screen 130 is used to display controls, information, images, videos, etc. Display screen 240 includes a display panel. The display panel may be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a Mini LED, a MicroLED, a Micro-OLED, a quantum dot light-emitting diode (QLED), etc.

[0039] It is understood that the structure illustrated in this application does not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0040] The following is combined with Figure 2 The technical solution provided in this application will be described in detail below. For example, Figure 2 This diagram illustrates a flowchart of a method for selecting a representative color of an image according to an embodiment of this application. It is understood that this method can be executed by any device, equipment, platform, or cluster of devices with computing and processing capabilities. Figure 2 As shown, the method may include the following steps:

[0041] S1. Select the target image.

[0042] Specifically, the target image can be a wallpaper on an electronic device, a picture in the image library on the electronic device, and so on.

[0043] S2. Perform saliency detection on the target image to obtain a grayscale image.

[0044] Specifically, after selecting the target image, a saliency algorithm can be used to process the target image to obtain at least one grayscale image. Saliency detection is an algorithm for identifying important regions in an image, and its results reflect the degree of importance the human eye places on different parts of the image. For example, saliency processing of the target image can be performed based on neural networks (such as convolutional neural networks, fully convolutional neural networks, etc.) to obtain at least one grayscale image.

[0045] S3. Based on the grayscale image, obtain the weight of each pixel in the target image.

[0046] Specifically, after obtaining the grayscale image, the weight of each pixel in the target image can be determined based on the grayscale image. For example, in the grayscale image, the whiter the pixel, the higher its weight, and the darker the pixel, the lower its weight; that is, the higher the brightness, the greater the weight, and the lower the brightness, the smaller the weight. For example, as... Figure 3 As shown, the weight of one pixel in this grayscale image can be 0.8, and the weight of another pixel can be 0.2.

[0047] For example, the red, green, and blue (RGB) values ​​of each pixel in the target image can be obtained first using a neural network (such as a convolutional neural network, a fully convolutional neural network, etc.). Then, the brightness value of each pixel is obtained using a pre-defined conversion formula between RGB values ​​and brightness values. For example, the conversion formula between RGB values ​​and brightness values ​​can be: Gray = R*0.3 + G*0.59 + B*0.11, or Gray = (R*30 + G*59 + B*11) / 100, or Gray = (R + G + B) / 3, etc.; where Gray is the brightness value, R is the red value, G is the green value, and B is the blue value.

[0048] Furthermore, a weighting formula can be pre-defined: W = a + b * light / 100, where light is the brightness of a pixel in the grayscale image (the brightness range is 0-100), the brightness of a black pixel can be 0, and the brightness of the whitest pixel is 100. After obtaining the grayscale image for saliency detection, the weight of each pixel can be determined according to this formula. For example, if the brightness of a black pixel is 0, then the weight of the black pixel is a; if the brightness of a gray pixel is 60, then the weight of the gray pixel is a + 0.6b.

[0049] S4. Merge pixels based on the weight of each pixel.

[0050] Specifically, firstly, pixels with the same color are counted, and the weights of these pixels are accumulated. For example, if 10 pixels are all of color A, and their weight is w1, then the total weight of these 10 pixels after counting is 10 * w1. After counting pixels of the same color, several different colors can be obtained, each with a weight (for example, the weight of color A is 10 * w1, and the weight of color B is 20 * w2).

[0051] After obtaining several colors, the large number of colors makes color selection difficult. Therefore, similar colors can be merged in the HSV (Hue, Saturation, Value) color space to reduce the number of colors. HSV is a color space used to define and describe colors: H represents hue (e.g., red and blue are different hues with different H values); S represents saturation (the vividness of the color; the higher the S value, the more vivid the color); and V represents value (the brightness; the higher the value, the brighter the color). Specifically, the hue H value range of 0-360 is divided into several segments (e.g., 36 segments, each 10 units long); then, within each segment of H, SV is divided into several blocks, where the colors in each block are similar. For example, ... Figure 4 As shown, when hue H is blue, SV can be divided into several blocks. The division for other hue cases is the same. Figure 4 The same applies to color saturation. Then, colors within the same block are merged to obtain the hue, saturation, brightness, and weight of the merged color. The weight of the merged color is the sum of the weights of the individual colors before merging. For example, if a block contains two colors, 2 and 3, with weights w2 and w3 respectively, the HSV components of the merged color 4 are: H4 = (H2*w2 + H3*w3) / (w2 + w3), and the weight of color 4 is w2 + w3. The same applies to S and V, which will not be elaborated further here.

[0052] For example, the color can be converted to the HSV color space using its RGB values. An example algorithm for RGB to HSV conversion could be:

[0053] max = max(R,G,B);

[0054] min = min(R,G,B);

[0055] V = max(R,G,B);

[0056] S = (max - min) / max;

[0057] if(R=max)H=(GB) / (max-min)*60;

[0058] if(G=max)H=120+(BR) / (max-min)*60;

[0059] if(B=max)H=240+(RG) / (max-min)*60;

[0060] if (H < 0) H = H + 360.

[0061] S5. Divide the merged pixels into color categories.

[0062] Specifically, after merging pixels, the hue of the color corresponding to the merged pixel can be obtained. Then, methods such as hierarchical clustering can be used to divide the color system so that colors with similar hues H can be grouped into the same color system.

[0063] It is understandable that common color system classification methods use fixed intervals. When the intervals are wide, this may result in very similar hues being classified into different color systems. Therefore, to avoid this situation, this application uses a hierarchical clustering algorithm to classify color systems. An example is shown below; clearly, the results obtained by hierarchical clustering are more reasonable.

[0064] For example, such as Figure 5 As shown in (A), a fixed interval division method is used, dividing the hue H value range of 0-360 into four segments, each with a value of 90. The hues of colors 1 and 2 are in the range of 0-90, colors 3 and 4 are in the range of 90-180, color 5 is in the range of 180-270, and colors 6 and 7 are in the range of 270-360. Therefore, colors 1 and 2 are classified into one color family, colors 3 and 4 into another, color 5 into another, and colors 6 and 7 into another. However, visually, colors 1, 2, and 3 are similar and should be classified into one color family, colors 4 and 5 are similar and should be classified into another, color 6 should be classified into a separate color family, and color 7 should be classified into a separate color family. It is evident that the fixed interval division method tends to classify similar hues into different color families.

[0065] like Figure 5As shown in (B), it employs a hierarchical clustering algorithm. The core logic of the hierarchical clustering algorithm is to cluster in layers sequentially: First, find the two colors with the closest hue H among all colors (e.g., colors 1 and 2) and merge them into one class. Then, calculate the mean hue of this class (e.g., the mean is H12 = (H1 + H2) / 2), which is the first layer of clustering. Then, place the merged class together with other colors (colors 3, 4, 5, 6, and 7), and select the two colors with the closest hue H (or classes, where the hue of a class is the mean of the hues of all colors in that class, e.g., H12) to merge. Therefore, color 3 is merged with colors 1 and 2 into one class, which is the second layer of clustering. This process continues until the hues of each class are no longer similar. Generally, a threshold is set, such as 40; if the hue difference exceeds 40, the colors cannot be merged into one class. Figure 5 In example (B), the final classification is into four categories: colors 1, 2, and 3 are the first category, colors 4 and 5 are the second category, color 6 is the third category, and color 7 is the fourth category.

[0066] After hierarchical clustering is completed, each cluster represents a color system, which can contain several colors with similar hues. Since gray is not sensitive to hue H, gray can be selected as the gray system before hierarchical clustering. For example, colors with a saturation S less than 7 can be considered gray.

[0067] For example, the hue of the divided color system can be obtained from the hues of the individual colors that make up the color system. For instance, the hue of the divided color system can be the average of the hues of the individual colors that make up the color system.

[0068] S6. Sort the colors in each of the determined color systems.

[0069] Specifically, each color system contains several colors with similar hues, and these colors can be ranked according to their weight within each system. For example, in descending order, the colors appearing earlier are considered more important; or in ascending order, the colors appearing later are considered more important.

[0070] S7. Sort the color schemes.

[0071] Specifically, we can first sum the weights of the colors within each color family to obtain the weights of each color family. Then, we select the color family with the highest weight as the first color family. Next, based on the hues of the unsorted and sorted color families, we determine the order of the remaining color families. Thus, we obtain the sorted hues.

[0072] S8. Based on the colors in each color system, obtain the representative color.

[0073] Specifically, a representative color refers to the color that best represents the target image (i.e., the original image). After the aforementioned steps are completed, several color schemes are obtained, each containing several colors. For a color scheme, the earlier color schemes are more important, meaning they are more representative; similarly, for each color within a color scheme, the earlier colors are more representative. For example, if only one color scheme is needed, a color from the first color scheme can be selected. If multiple color schemes are needed, the first color from all color schemes is obtained first, then the second color from all color schemes, and so on (if a color scheme lacks sufficient colors, such as a third color, it is skipped), until the required number of color schemes is obtained. If the required number of colors exceeds the number of representative colors, the representative colors can be used cyclically.

[0074] For example, such as Figure 6 As shown, the determined color schemes are: Color Scheme 1, Color Scheme 2, and Color Scheme 3. In descending order, Color Scheme 1 is first, Color Scheme 2 is second, and Color Scheme 3 is third. Color Scheme 1 includes 3 colors, arranged in descending order as: Color 1, Color 2, Color 3; Color Scheme 2 includes 2 colors, arranged in descending order as: Color 1, Color 2; Color Scheme 3 includes 4 colors, arranged in descending order as: Color 1, Color 2, Color 3, Color 4.

[0075] When only one representative color is required, the representative color is color 1 in color system 1.

[0076] When two representative colors are required, the representative colors are: color 1 in color scheme 1 and color 1 in color scheme 2.

[0077] When three representative colors are required, the representative colors are: color 1 in color system 1, color 1 in color system 2, and color 1 in color system 3.

[0078] When four representative colors are required, the representative colors are: color 1 in color system 1, color 1 in color system 2, color 1 in color system 3, and color 2 in color system 1.

[0079] When five representative colors are required, the representative colors are: color 1 in color system 1, color 1 in color system 2, color 1 in color system 3, color 2 in color system 1, and color 2 in color system 2.

[0080] When six representative colors are required, the representative colors are: color 1 in color system 1, color 1 in color system 2, color 1 in color system 3, color 2 in color system 1, color 2 in color system 2, and color 2 in color system 3.

[0081] When the required representative colors are 7, the representative colors are: color 1 in color system 1, color 1 in color system 2, color 1 in color system 3, color 2 in color system 1, color 2 in color system 2, color 2 in color system 3, and color 3 in color system 1.

[0082] When the required representative colors are 8, the representative colors are: color 1 in color system 1, color 1 in color system 2, color 1 in color system 3, color 2 in color system 1, color 2 in color system 2, color 2 in color system 3, color 3 in color system 1, and color 3 in color system 3.

[0083] When the required representative colors are 9, the representative colors are: color 1 in color system 1, color 1 in color system 2, color 1 in color system 3, color 2 in color system 1, color 2 in color system 2, color 2 in color system 3, color 3 in color system 1, color 3 in color system 3, and color 4 in color system 3.

[0084] When 10 representative colors are required, the representative colors are: color 1 in color system 1, color 1 in color system 2, color 1 in color system 3, color 2 in color system 1, color 2 in color system 2, color 2 in color system 3, color 3 in color system 1, color 3 in color system 3, color 4 in color system 3, and color 1 in color system 1.

[0085] When 11 representative colors are required, the representative colors are: color 1 in color system 1, color 1 in color system 2, color 1 in color system 3, color 2 in color system 1, color 2 in color system 2, color 2 in color system 3, color 3 in color system 1, color 3 in color system 3, color 4 in color system 3, color 1 in color system 1, and color 1 in color system 2.

[0086] Furthermore, after obtaining the representative color corresponding to the target image, this representative color can be used to match the color of the target icon (such as a user-defined icon), the target background (such as the display background of the application), the target text, etc.

[0087] Therefore, the colors extracted from the image can represent the original image to the greatest extent possible, thus ensuring that the color scheme is consistent with the original image.

[0088] It is understandable that the steps in S1-S8 above can be selected adaptively for execution, and no specific restrictions are imposed here; in addition, the execution order can also be selected adaptively, and no specific restrictions are imposed here.

[0089] The following is combined with Figure 7 This application provides a detailed explanation of the step of sorting color systems in the method for selecting representative colors of images provided in the embodiments of this application. For example, Figure 7 This is a flowchart illustrating the step of sorting color systems in the method for selecting representative colors of an image provided in an embodiment of this application. For example... Figure 7 As shown, the steps for sorting color schemes may include:

[0090] S71. Determine the weight of each color system.

[0091] Specifically, the weight of a color system can be obtained by performing mathematical operations on the weights of all colors in the system. For example, the weights of each color in the system can be summed to obtain the total weight of the system.

[0092] S72. Sort each color system according to its weight.

[0093] Specifically, color families can be sorted according to their respective weights. For example, they can be sorted in descending or ascending order. For instance, if there is a gray family, it can be placed last in descending order and first in ascending order.

[0094] S73. Select the color scheme with the highest weight as the first color scheme.

[0095] S74. Reorder the remaining colors to obtain the order of the remaining colors.

[0096] Specifically, the color systems to be sorted can be sorted based on the distance between the hues of the color systems to be sorted and the color systems in the determined order. For example, the color systems to be sorted can be sorted by multiplying the geometric mean of the distances between the hues of the color systems to be sorted and the color systems in the determined order by the weight of the color systems to be sorted determined in S71.

[0097] For example, sorting weights: Among them, sW x For ranking weights, H1 represents the hue corresponding to the color system with the highest weight, H2 represents the hue corresponding to the color system with the second highest weight, and H... n H represents the hue corresponding to the color system determined in the nth iteration. x For the hue corresponding to the color system to be determined this time, W x The weights are the color systems to be determined in S71.

[0098] For example, if we sort the color systems according to their weights as follows: Color System 1, Color System 2, Color System 3, Color System 4, where the hue of Color System 1 is H1, the hue of Color System 2 is H2, the hue of Color System 3 is H3, the weight of Color System 1 is W1, the weight of Color System 2 is W2, the weight of Color System 3 is W3, and the weight of Color System 4 is W4, then Color System 1 is the first color system. In this case, the color systems to be sorted are: Color System 2, Color System 3, Color System 4. The sorting weight corresponding to Color System 2 is: The sorting weight for color scheme 3 is: The sorting weights for color scheme 4 are:

[0099] Once the sorting weights of the remaining color systems are obtained, the remaining color systems can be reordered to obtain their order.

[0100] Next, based on the image representative color selection method described above, a method for selecting an image representative color provided in this application embodiment will be introduced. It is understood that this method is based on the content described above, and some or all of the content of this method can be found in the description above.

[0101] Please see Figure 8 , Figure 8 This is a flowchart illustrating a method for selecting a representative color of an image, as provided in an embodiment of this application. It is understood that this method can be executed by any device, equipment, platform, or cluster of devices with computing and processing capabilities.

[0102] This method can be applied to systems that include a first terminal and a second terminal, such as... Figure 8 As shown, the method may include:

[0103] S81. Determine the grayscale value of the target image.

[0104] Specifically, saliency detection can be performed on the target image to obtain a grayscale image.

[0105] S82. Based on the grayscale image, determine the weight value of each pixel in the target image.

[0106] Specifically, after obtaining the grayscale image, the weight of each pixel in the target image can be determined based on the grayscale image. For example, in the grayscale image, the whiter the pixel, the higher its weight, and the darker the pixel, the lower its weight; that is, the higher the brightness, the greater the weight, and the lower the brightness, the smaller the weight. For example, as... Figure 3 As shown, the weight of one pixel in this grayscale image can be 0.8, and the weight of another pixel can be 0.2.

[0107] For example, the brightness value of each pixel in the grayscale image can be determined first. Then, based on the brightness value of each pixel, the weight value of each pixel in the target image can be determined.

[0108] S83. Divide the colors corresponding to each pixel in the target image into n color systems. Each color system includes at least one color, and n is a positive integer greater than or equal to 1.

[0109] Specifically, the colors corresponding to each pixel in the target image can be divided into color systems, resulting in n color systems. Each color system includes at least one color, and n is a positive integer greater than or equal to 1.

[0110] For example, we can first determine the first feature (e.g., hue) of the color corresponding to each pixel in the target image. Then, based on the first feature, we use a hierarchical clustering algorithm to divide the color of each pixel in the target image into n color systems. The hierarchical clustering algorithm can be found in [link to relevant documentation]. Figure 5 The relevant descriptions in the document will not be repeated here.

[0111] For example, before this step, the colors corresponding to each pixel in the target image can be merged to obtain m different colors, thereby merging identical colors and improving the efficiency of subsequent processing; where m is a positive integer greater than or equal to 1, and each of the m different colors corresponds to at least one pixel. Then, based on the color features of the m different colors, the m different colors are merged to obtain p colors, thereby merging different colors and reducing the number of colors; where p is less than or equal to m. For example, it can be based on... Figure 4 The merging method described herein merges m different colors. For example, color features may include at least one of hue, saturation, and brightness.

[0112] Furthermore, the weight value of any one of the m different colors is obtained from the weight values ​​of the pixels corresponding to that color; and / or, the weight value of any one of the p colors is obtained from the weight values ​​corresponding to the k different colors, wherein any one of the p colors is obtained by merging the k different colors. For example, the weight value of any one of the m different colors is the sum of the weight values ​​of the pixels corresponding to that color. For instance, the weight value of red is the sum of the weight values ​​of all pixels that are red. For example, the weight value of any one of the p colors is the sum of the weight values ​​corresponding to the k different colors.

[0113] It should be understood that if the colors were merged before this step, then this step is to divide the color system based on the merged colors.

[0114] S84. Based on the weight values ​​of the colors contained in each of the n color systems, determine the weight values ​​of each color system in the n color systems. The weight values ​​of the colors contained in each color system are obtained from the weight values ​​of each pixel in the target image.

[0115] S85. Based on the weight values ​​of each color system in the n color systems and the weight values ​​of the colors contained in each color system in the n color systems, determine the representative color, which is used to represent the color of the target image.

[0116] Specifically, after determining the weight values ​​of each color system in the n color systems and the weight values ​​of the colors contained in each color system in the n color systems, the representative color can be determined based on the weight values ​​of each color system in the n color systems and the weight values ​​of the colors contained in each color system in the n color systems.

[0117] For example, a primary color system can be determined first based on the weight values ​​of each color system in the n color systems. Then, the remaining n-1 color systems (excluding the primary color system) are reordered. Finally, based on the primary color system, the reordered n-1 color systems, and the weight values ​​of the colors contained in each of the n color systems, a representative color is determined. This allows for the selection of several more representative colors from a holistic perspective. For example, the primary color system is the color system with the largest weight value among the weight values ​​of each color system in the n color systems.

[0118] For example, reordering the n-1 color systems excluding the primary color system involves: determining the ranking weight of each color system in the n-1 color systems; and reordering each color system in the n-1 color systems based on the ranking weight. This allows for the selection of several more representative colors from a holistic perspective.

[0119] Further, determining the ranking weight of each color system in the n-1 color systems specifically includes: determining the deviation between the second feature of the color corresponding to the color system whose ranking weight is to be determined and the second feature of the color corresponding to each color system whose ranking weight has been determined; and determining the ranking weight of the color system whose ranking weight is to be determined based on the deviation and the weight values ​​of the colors contained in the color system whose ranking weight is to be determined.

[0120] For example, if the required number of representative colors is j, where j is a positive integer greater than or equal to 1, then based on the first color system, the reordered n-1 color systems, and the weight values ​​of the colors contained in each of the n color systems, the representative colors are determined. Specifically, this includes: if j is less than n, selecting the first color in the j color systems as the j representative colors, where the weight value of any color system in the j color systems is greater than the weight value of any color system in the nj color systems; if j is equal to n, selecting the first color in the n color systems as the j representative colors; if j is greater than n, selecting the first color in the n color systems as the n representative colors; and based on the weights of the remaining colors in each of the n color systems, selecting jn representative colors from the remaining colors in the n color systems.

[0121] S86, output representative color.

[0122] Specifically, once a representative color is determined, it can be used to color-match target icons (such as user-defined icons), target backgrounds (such as application display backgrounds), target text, etc.

[0123] In this way, the colors extracted from the image can represent the original image to the greatest extent possible, thus ensuring that the color scheme is consistent with the original image.

[0124] Based on the methods described in the above embodiments, this application also provides a chip. Please refer to... Figure 9 , Figure 9 This is a schematic diagram of a chip structure provided in an embodiment of this application. Figure 9 As shown, chip 900 includes one or more processors 901 and interface circuitry 902. Optionally, chip 900 may also include a bus 903. Wherein:

[0125] The processor 901 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed through integrated logic circuits in the hardware of the processor 901 or through software instructions. The processor 901 may be a general-purpose processor, 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, or discrete hardware components. It can implement or execute the methods and steps disclosed in the embodiments of this application. The general-purpose processor may be a microprocessor or any conventional processor. The interface circuit 902 can be used to send or receive data, instructions, or information. The processor 901 can process the data, instructions, or other information received by the interface circuit 902 and send the processed information out through the interface circuit 902.

[0126] Optionally, the chip also includes memory, which may include read-only memory and random access memory, providing operation instructions and data to the processor. A portion of the memory may also include non-volatile random access memory (NVRAM). Optionally, the memory stores executable software modules or data structures, and the processor can perform corresponding operations by calling operation instructions stored in the memory (which may be stored in the operating system).

[0127] Optionally, the interface circuit 902 can be used to output the execution results of the processor 901.

[0128] It should be noted that the functions of the processor 901 and the interface circuit 902 can be implemented through hardware design, software design, or a combination of hardware and software; no restrictions are imposed here.

[0129] It should be understood that the steps of the above method embodiments can be implemented by hardware logic circuits or software instructions in a processor. The chip can be applied in the above-described electronic device 100 to implement the methods provided in the embodiments of this application.

[0130] It is understood that the processor in the embodiments of this application can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. A general-purpose processor can be a microprocessor or any conventional processor.

[0131] The method steps in the embodiments of this application can be implemented in hardware or by a processor executing software instructions. The software instructions can consist of corresponding software modules, which can be stored in random access memory (RAM), flash memory, read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, portable hard disks, CD-ROMs, or any other form of storage medium known in the art. One exemplary embodiment couples a storage medium to a processor, enabling the processor to read information from and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can reside in an ASIC.

[0132] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially 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, all or part of the processes or functions described in the embodiments of this application are generated. 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 through the computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. 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 integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk (SSD)).

[0133] It is understood that the various numerical designations used in the embodiments of this application are merely for descriptive convenience and are not intended to limit the scope of the embodiments of this application.

Claims

1. A method for selecting a representative color for an image, characterized in that, The method includes: Saliency detection is performed on the target image to obtain a grayscale image; Based on the grayscale image, determine the weight value of each pixel in the target image; The color corresponding to each pixel in the target image is divided into n color systems, each of which includes at least one color, where n is a positive integer greater than or equal to 1. Based on the weight values ​​of the colors contained in each of the n color systems, the weight values ​​of each color system in the n color systems are determined, and the weight values ​​of the colors contained in each color system are obtained from the weight values ​​of each pixel in the target image; Based on the weight values ​​of each color system in the n color systems and the weight values ​​of the colors contained in each color system in the n color systems, a representative color is determined, which is used to represent the color of the target image; Output the representative color.

2. The method according to claim 1, characterized in that, The step of determining the weight value of each pixel in the target image based on the grayscale image specifically includes: Determine the brightness value of each pixel in the grayscale image; Based on the brightness value of each pixel, the weight value of each pixel in the target image is determined.

3. The method according to claim 1, characterized in that, Before dividing the colors corresponding to each pixel in the target image into n color systems, the method further includes: Merge the same colors among the colors corresponding to each pixel in the target image to obtain m different colors, where m is a positive integer greater than or equal to 1, and each of the m different colors corresponds to at least one pixel. Based on the color features of the m different colors, the m different colors are merged to obtain p colors, where p is less than or equal to m.

4. The method according to claim 3, characterized in that, The weight value of any one of the m different colors is obtained from the weight value of the pixel corresponding to any one of the m different colors; and / or, The weight value of any one of the p colors is obtained by combining the weight values ​​of the k different colors.

5. The method according to any one of claims 1-4, characterized in that, The step of dividing the color of each pixel in the target image into n color systems specifically includes: Determine the first feature of the color corresponding to each pixel in the target image; Based on the first feature, a hierarchical clustering algorithm is used to divide the colors corresponding to each pixel in the target image into n color systems.

6. The method according to any one of claims 1-4, characterized in that, The process of determining a representative color based on the weight values ​​of each color system in the n color systems and the weight values ​​of the colors contained in each color system in the n color systems specifically includes: The primary color system is determined based on the weight values ​​of each color system among the n color systems. Reorder the n-1 color systems other than the primary color system; Based on the primary color system, the reordered n-1 color systems, and the weight values ​​of the colors contained in each of the n color systems, a representative color is determined.

7. The method according to claim 6, characterized in that, The reordering of the n-1 color systems other than the primary color system specifically includes: Determine the ranking weight of each color system in the n-1 color systems; Based on the sorting weights, each color system in the n-1 color systems is reordered.

8. The method according to claim 6, characterized in that, Determining the ranking weight of each color system among the n-1 color systems specifically includes: Determine the deviation between the second feature of the color corresponding to the color system whose sorting weight is to be determined and the second feature of the color corresponding to each color system whose sorting weight has been determined; The sorting weight of the color system to be sorted is determined based on the deviation and the weight values ​​of the colors contained in the color system to be sorted.

9. The method according to claim 6, characterized in that, The number of representative colors required is j, where j is a positive integer greater than or equal to 1; The process of determining a representative color based on the primary color system, the reordered n-1 color systems, and the weight values ​​of the colors contained in each of the n color systems specifically includes: If j is less than n, the first color in the j color systems is selected as the j representative colors, wherein the weight value of any color system in the j color systems is greater than the weight value of any color system in the nj color systems. If j equals n, select the first color from the n color systems as the j representative colors; If j is greater than n, select the first color in the n color systems as the n representative colors, and select jn representative colors from the remaining colors in the n color systems based on the weights of the remaining colors in each of the n color systems.

10. A device for selecting a representative color of an image, characterized in that, include: At least one memory for storing programs; At least one processor is configured to execute a program stored in the memory, wherein when the program stored in the memory is executed, the processor is configured to perform the method as described in any one of claims 1-9.

11. A computer-readable storage medium storing a computer program that, when run on an electronic device, causes the electronic device to perform the method as described in any one of claims 1-9.

12. A computer program product, characterized in that, When the computer program product is run on an electronic device, it causes the electronic device to perform the method as described in any one of claims 1-9.