Color distance determination method and device, equipment and storage medium
By obtaining the hue value, brightness value and saturation value of the color in the HSV color space, and calculating the hue distance and weight between colors, the problem of inaccurate color distance calculation in the prior art is solved, and a more accurate evaluation of the degree of color similarity is achieved.
Patent Information
- Application Number
- CN202411715738.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-03-07
AI Technical Summary
The prior art is difficult to accurately evaluate the degree of similarity between colors, resulting in inaccurate calculation of color distances.
By obtaining the hue value, brightness value and saturation value of the color in the HSV color space, calculate the hue distance and the weights of the brightness and saturation, and comprehensively calculate the color distance.
Improve the accuracy of color distance calculation, making the degree of similarity between colors more accurate.
Smart Images

Figure CN119579704A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method, device, equipment, and storage medium for determining a color distance. Background Art
[0002] Color refers to the visual attribute presented by the specific wavelength of light reflected or emitted by the surface of an object. It is the basis of vision-related fields and different colors can be described by different values in the color space.
[0003] In practical applications, the similarity between colors can be evaluated based on the color distance in the color space. Common applications are in the fields of image classification, interface design, image editing, etc. For example, the similarity between images can be evaluated based on color distance in order to screen similar images. Another example is to determine a more harmonious interface color based on color distance to assist designers in interface design and improve efficiency. For another example, when designing a film and television poster, the poster font color and poster image color that have both visual differences and overall coordination can be determined based on color distance to improve the efficiency of poster generation and visual effects.
[0004] It can be seen that how to determine the color distance is of great significance. However, the method for determining the color distance used in the related art is difficult to accurately evaluate the similarity between colors. Summary of the invention
[0005] In order to solve the above technical problems, the present application provides a method, device, equipment, and storage medium for determining color distance, which is conducive to determining a more accurate color distance, thereby more accurately evaluating the similarity between colors.
[0006] The embodiments of the present application disclose the following technical solutions:
[0007] On the one hand, an embodiment of the present application provides a method for determining a color distance, the method comprising:
[0008] Obtain a first hue value, a first brightness value, and a first saturation value corresponding to the first color, and obtain a second hue value, a second brightness value, and a second saturation value corresponding to the second color;
[0009] determining a first distance according to the first hue value and the second hue value;
[0010] Determine a first weight and a second weight according to the first brightness value, the first saturation value, the second brightness value, and the second saturation value, wherein the first weight is used to represent the influence of the brightness value on the first distance, and the second weight is used to represent the influence of the saturation value on the first distance;
[0011] A color distance between the first color and the second color is determined according to the first weight, the second weight, and the first distance.
[0012] On the other hand, an embodiment of the present application provides a device for determining a color distance, the device comprising an acquisition unit and a determination unit:
[0013] The acquisition unit is used to acquire a first hue value, a first brightness value, and a first saturation value corresponding to the first color, and to acquire a second hue value, a second brightness value, and a second saturation value corresponding to the second color;
[0014] The determining unit is configured to determine a first distance according to the first hue value and the second hue value;
[0015] The determining unit is further configured to determine a first weight and a second weight according to the first brightness value, the first saturation value, the second brightness value, and the second saturation value, wherein the first weight is used to represent the influence of the brightness value on the first distance, and the second weight is used to represent the influence of the saturation value on the first distance;
[0016] The determining unit is further configured to determine a color distance between the first color and the second color according to the first weight, the second weight, and the first distance.
[0017] In another aspect, an embodiment of the present application provides a computer device, the computer device comprising a processor and a memory:
[0018] The memory is used to store program code and transmit the program code to the processor;
[0019] The processor is used to execute the method for determining the color distance described in the above aspect according to the instructions in the program code.
[0020] On the other hand, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and the computer program is used to execute the method for determining the color distance described in the above aspects.
[0021] It can be seen from the above technical solution that for the first color and the second color, the first distance is determined according to the first hue value and the second hue value, and the first weight and the second weight are determined according to the first brightness, the first saturation value, the second brightness value and the second saturation value. Among them, the first weight is used to indicate the influence of the brightness value on the first distance, and the second weight is used to indicate the influence of the saturation value on the first distance. Since the change of hue is more likely to change the color as a whole, the first distance is first determined based on the hue value to reflect the similarity between the two colors from the hue dimension. At the same time, the values of the two dimensions of brightness and saturation can affect the effect of the change of hue on the overall change of the color. Under different brightness values and saturation values, the hue value produces the same change, and the effect of the overall change of the color is usually different. Therefore, the corresponding first weight and second weight can be determined based on the brightness value and saturation value of the two colors, so as to reflect the influence of the values of these two dimensions on the first distance, and also reflect the contribution of the values of these two dimensions to the similarity between the two colors. Finally, the color distance between the first color and the second color is determined based on the first weight, the second weight and the first distance. In the related art, the color distance is determined based on the distance formula between two three-dimensional coordinate points. The color distance determined in this way is a linear distance, and the colors do not have a linear change relationship in the color space. Therefore, compared with this, the use of the present application is conducive to determining a more accurate color distance, thereby more accurately evaluating the similarity between colors. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0023] Figure 1 A flowchart of a method for determining a color distance provided in an embodiment of the present application;
[0024] Figure 2 A schematic diagram of a method for determining a first distance provided in an embodiment of the present application;
[0025] Figure 3 A schematic diagram of a tolerance division area diagram provided in an embodiment of the present application;
[0026] Figure 4 A schematic diagram of a color distance determination process provided in an embodiment of the present application;
[0027] Figure 5A structural diagram of a device for determining color distance provided in an embodiment of the present application. DETAILED DESCRIPTION
[0028] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0029] Color is the basis of vision-related fields. By evaluating the similarity between colors, it can assist various tasks in vision-related fields. For example, image classification, poster design, interface design, etc. In practical applications, colors can be described by values in color space, so the color distance of colors in color space can be used to evaluate the similarity between colors. Among them, color spaces include RGB color space and HSV color space. The RGB color space is based on the three basic colors of R (Red), G (Green), and B (Blue), and is superimposed to varying degrees to produce rich and extensive colors, also known as the three-primary color model. The HSV color space describes colors with three components: H (Hue), S (Saturation), and V (Value). Hue represents the type or type of color, saturation represents the purity or vividness of the color, and brightness represents the brightness of the color.
[0030] Regarding how to determine the color distance, in the related art, each color is regarded as a three-dimensional coordinate, and the color distance is determined based on the distance formula between two three-dimensional coordinate points. For example, in the case of using RGB color space to describe the color, the color distance formula is as follows:
[0031]
[0032] In the above formula, (r1, g1, b1) represents color 1, corresponding to the values in the RGB color space respectively, (r2, g2, b2) represents color 2, and distance represents the color distance between color 1 and color 2.
[0033] It is understandable that, for color description methods using other color spaces, the color distance can also be directly calculated using the above method.
[0034] However, the color distance determined by this method used in the related art is a linear distance, and colors do not change linearly in the color space, especially the changes in human vision are not a simple linear relationship. Therefore, this method is difficult to accurately measure the similarity between colors.
[0035] To this end, the present application provides a method, device, equipment, and storage medium for determining color distance, which determines a first distance based on a hue value to reflect the similarity between two colors from the hue dimension. Also, based on the brightness value and saturation value of the two colors, the corresponding first weight and second weight are determined to reflect the degree of influence of the values of these two dimensions on the first distance, and also to reflect the contribution of the values of these two dimensions to the similarity between the two colors. Finally, based on the first weight, the second weight, and the first distance, the color distance between the first color and the second color is determined. It is no longer a simple linear distance, which is conducive to determining a more accurate color distance, thereby more accurately evaluating the similarity between colors.
[0036] The method for determining the color distance provided in the embodiment of the present application can be implemented by a computer device, which can be a terminal device or a server, wherein the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. The terminal device includes but is not limited to mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, etc. The terminal device and the server can be directly or indirectly connected via wired or wireless communication, and this application does not impose any restrictions on this.
[0037] The specific examples are as follows:
[0038] Figure 1 A flowchart of a method for determining a color distance provided in an embodiment of the present application is provided, and a server is used as the aforementioned computer device as an example for explanation. The method includes S101-S104:
[0039] S101: Acquire a first hue value, a first brightness value, and a first saturation value corresponding to a first color, and acquire a second hue value, a second brightness value, and a second saturation value corresponding to a second color.
[0040] The first hue value, the first brightness value and the first saturation value are used to describe the first color, and the second hue value, the second brightness value and the second saturation value are used to describe the second color. That is, in this application, the aforementioned HSV color space is used to describe the color.
[0041] It should be noted that the present application does not limit how to obtain the first hue value, the first brightness value, and the first saturation value corresponding to the first color, and how to obtain the second hue value, the second brightness value, and the second saturation value corresponding to the second color. For ease of understanding, the present application provides the following methods as examples:
[0042] Different colors can be considered to be produced by superimposing the three basic colors of red, green and blue to varying degrees, which makes the RGB color space a widely used method for describing colors. In order to make the determined color distance more accurately reflect the degree of similarity or difference of colors perceived by the human eye, this application uses the HSV color space to describe colors. Therefore, in one possible implementation, a color space conversion can be performed to convert the color description from the RGB color space to the HSV color space for subsequent processing.
[0043] In a specific implementation, the first channel value, the second channel value, and the third channel value corresponding to the first color in the RGB color space are obtained, and the first color is converted into a color space according to the first channel value, the second channel value, and the third channel value, so as to obtain the first hue value, the first brightness value, and the first saturation value corresponding to the first color in the HSV color space. Correspondingly, the fourth channel value, the fifth channel value, and the sixth channel value corresponding to the second color in the RGB color space are obtained, and the second color is converted into a color space according to the fourth channel value, the fifth channel value, and the sixth channel value, so as to obtain the second hue value, the second brightness value, and the second saturation value corresponding to the second color in the HSV color space.
[0044] The fourth channel value and the first channel value belong to the same channel, the fifth channel value and the second channel value belong to the same channel, and the sixth channel value and the third channel value belong to the same channel. For example, the fourth channel value and the first channel value correspond to the R channel in the RGB color space, the fifth channel value and the second channel value correspond to the G channel in the RGB color space, and the sixth channel value and the third channel value correspond to the B channel in the RGB color space.
[0045] Based on this, through color space conversion, the HSV color space is used to describe the color, so that through subsequent processing, the final color distance can more accurately reflect the similarity or difference between the colors perceived by the human eye.
[0046] In the HSV color space, there are three dimensions: hue H, saturation S, and brightness V. Specifically:
[0047] Hue H represents the basic properties of color, such as red, yellow, green, etc. Usually, 0 degrees (or 360 degrees) is used to represent red, 120 degrees to represent green, 240 degrees to represent blue, and other angles represent transition colors between these colors.
[0048] Saturation S indicates the vividness or purity of a color. The higher the saturation value, the more vivid the color. Conversely, the lower the saturation value, the closer the color is to gray. In the HSV color space, saturation values are usually expressed as a percentage, ranging from 0% (colorless, i.e. gray) to 100% (the most vivid color).
[0049] Brightness V indicates the lightness or darkness of a color. The higher the brightness value, the brighter the color, and vice versa. The lower the brightness value, the darker the color. In the HSV color space, brightness is also expressed as a percentage, ranging from 0% (black) to 100% (white).
[0050] S102: Determine a first distance according to the first hue value and the second hue value.
[0051] Since a change in hue is more likely to change the overall color, the first distance may be determined based on the hue value to preliminarily reflect the similarity between the two colors from the hue dimension.
[0052] It should be noted that this application does not impose any limitation on how to determine the first distance.
[0053] For ease of understanding, the present application provides the following examples as examples:
[0054] In a possible implementation, the first distance may be determined according to the difference between the first hue value and the second hue value, thereby simply and directly reflecting the difference between the two colors in the hue dimension.
[0055] In the HSV color space, the range of hue value is from 0 to 360 degrees, so it is also called the hue circle. The hue value is equivalent to a point on the circle. The first distance can refer to the distance between two points on the circle. For ease of understanding, the radius of the circle is set to r = 1. In specific implementation, the first distance can be determined by the following formula:
[0056] delta h =|h1-h2|
[0057] In the above formula, h1 is used to represent the first hue value, and h2 is used to represent the second hue value. In practical applications, if delta h If it is greater than 180 degrees, you can use delta h =360-delta h , to simplify the calculation.
[0058] dist h =2*1*sin(delta h / 2)
[0059] In the above formula, dist h It is used to represent the first distance, and sin is used to represent the sine function.
[0060] For example, see Figure 2 As shown, the first hue value and the second hue value can be represented by two points on the hue circle, and the angle between the two points and the center of the circle is delta h , the distance between two points is dist h .
[0061] S103: Determine a first weight and a second weight according to the first brightness value, the first saturation value, the second brightness value, and the second saturation value.
[0062] The values of brightness and saturation can affect the effect of the change of hue on the overall color change. Under different brightness and saturation values, the same change of hue value usually has different effects on the overall color change. Therefore, the corresponding first weight and second weight can be determined based on the brightness and saturation values of the two colors.
[0063] Among them, the first weight is used to represent the influence of the brightness value on the first distance, and the second weight is used to represent the influence of the saturation value on the first distance, thereby reflecting the influence of the values of these two dimensions on the first distance, and also reflecting the contribution of the values of these two dimensions to the similarity between the two colors.
[0064] It should be noted that the present application does not make any limitation on how to determine the first weight and the second weight. For ease of understanding, the present application embodiment provides the following method as an example:
[0065] In practical applications, the brightness values (same for saturation values) within the same value range have similar effects on the hue value. Therefore, in order to simplify the calculation, in a possible implementation, the first weight and the second weight may be determined based on the value range division method.
[0066] In specific implementation, first, a tolerance division area map determined according to the value range of the brightness value and the value range of the saturation value can be obtained. Among them, different areas in the tolerance division area map are used to identify different value ranges of brightness values and value ranges of saturation values. In different areas, the degree of influence of hue value changes on color changes is different. In other words, an area corresponds to a certain value range of brightness value and a certain value range of saturation value. In different areas, the hue value produces the same change, and the effect of the overall color change is different. Then, the first weight and the second weight can be determined according to the target area where the first brightness value, the first saturation value, the second brightness value and the second saturation value are located in the tolerance division area map. It can be understood that the first brightness value and the second brightness value both fall within the value range of the brightness value corresponding to the target area, and the first saturation value and the second saturation value both fall within the value range of the saturation value corresponding to the target area.
[0067] Based on this, the first weight and the second weight are determined by dividing the area by the value range and then evaluating the target area where the true values of the two colors with similarity are located. It can be understood that in different areas, the influence of hue value change on color change is different, so different areas have different first weights and different areas have different second weights.
[0068] It should be noted that the present application does not make any limitation on how to determine the first weight and the second weight according to the target area. For ease of understanding, the present application provides the following method as an example:
[0069] In a possible implementation, after the tolerance division area map is determined, for each area, the first weight and the second weight corresponding to the area can be preset directly according to the value range of the brightness value and the value range of the saturation value corresponding to the area and the influence of the hue value on the color change in the area. In this way, after determining the target area, the first weight and the second weight corresponding to the two colors currently needing to be evaluated can be quickly determined, which is conducive to improving efficiency.
[0070] In another possible implementation, considering that the specific values of brightness values are different, it will also affect the degree of influence of hue value on color change, and the same is true for saturation value. Therefore, after determining the tolerance division area map, for each area, the weight calculation method corresponding to each area can also be determined by simulation. In this way, after determining the target area, the first weight and second weight suitable for the first brightness value, the second brightness value, the first saturation value and the second saturation value can be calculated based on the target calculation method corresponding to the target area, which is conducive to improving accuracy.
[0071] In specific implementation, the target calculation method corresponding to the target area can be first obtained, wherein the target calculation method is determined by simulation based on the brightness value range and saturation value range identified by the target area. The target calculation method is used to calculate the brightness value and saturation value falling within the target area. The corresponding first weight and second weight are related to the specific values of the brightness value and the saturation value. Different areas have different corresponding calculation methods. Then, based on the target calculation method, the first weight and the second weight can be determined according to the first brightness value, the first saturation value, the second brightness value, and the second saturation value.
[0072] For ease of understanding, the present application also provides Figure 3 The tolerance division area diagram shown is as follows:
[0073] In the HSV color space, the range of brightness and saturation is [0, 100]%. In practical applications, the following situations can be distinguished according to the degree of influence of hue value on color change, that is, the following areas can be divided accordingly. For ease of understanding, the first saturation value is recorded as s1, the second saturation value is recorded as s2, the first brightness value is recorded as v1, and the second brightness value is recorded as v2.
[0074] (1) If s1<=20 and s2<=20 and v1>=80 and v2>=80, then both colors are biased towards white. In this area, no matter how the hue value changes, the color is still biased towards white, that is, the influence of the hue value change on the color change is relatively low. In the extreme case, s=0, v=100, and the colors are all white. For this case, simulation based on the saturation value range [0,20] and the brightness value range [80,100] can determine the calculation formula corresponding to this area as follows:
[0075] w1=w2=(s1+s2-v1-v2) / 80+5 / 2
[0076] In the above formula, w1 is used to represent the first weight, w2 is used to represent the second weight, s1 is used to represent the first saturation value, s2 is used to represent the second saturation value, v1 is used to represent the first brightness value, and v2 is used to represent the second brightness value.
[0077] (2) If s1<=20 and s2<=20 and the brightness value conditions specified in (1) are not met, both colors are gray. At this time, no matter how the hue value changes, the color is still gray visually, that is, the influence of the hue value change on the color change is relatively low. For example, in the extreme case, s=0, the color is gray. For this case, simulation based on the saturation value range [0,20] can determine the calculation formula corresponding to this area as follows:
[0078] w2=(s1+s2) / 40
[0079] In this case, the first weight w1 may be set to 1 by default.
[0080] (3) If v1<=20 and v2<=20, it means that the two colors are dark. In this case, no matter how the hue changes, the visually perceived color is black. In extreme cases, v=0, all colors are black. For this case, simulation based on the brightness value range [0,20] can determine the calculation formula corresponding to this area as follows:
[0081] w1=(v1+v2) / 40.
[0082] In this case, the second weight w2 may be set to 1 by default.
[0083] (4) If s1>=80 and s2>=80 and v1>=80 and v2>=80, then both colors are highly saturated and highly bright. In this case, a slight change in hue value will make the visually perceived color different, that is, the change in hue value has a greater impact on color change. For this situation, simulation based on the saturation value range [80,100] and the brightness value range [80,100] can determine the calculation formula corresponding to this area as follows:
[0084] w1=w2=-7*(s1+s2+v1+v2) / 40+(s1+s2)*(v1+v2) / 800+35.
[0085] (5) If the value range does not meet the above conditions, the first weight and the second weight can be defaulted to 1.
[0086] S104: Determine a color distance between the first color and the second color according to the first weight, the second weight, and the first distance.
[0087] The color distance between the two colors may be determined according to the first weight, the second weight, and the first distance, so as to evaluate the similarity or difference between the two colors.
[0088] It should be noted that the present application does not make any limitation on how to determine the color distance according to the first weight, the second weight and the first distance. For ease of understanding, the present application provides the following method as an example:
[0089] In a possible implementation, if the first weight is positively correlated with the degree of influence of the hue value change on the color change, and the second weight is positively correlated with the degree of influence of the hue value change on the color change, indicating that the greater the weight, the more significant the influence of the hue value change on the color change, and it can be considered that the visually perceived difference between the colors is more obvious. Therefore, when determining the color distance, the product of the first weight, the second weight and the first distance can be determined as the third distance, and the color distance between the first color and the second color can be determined based on the third distance.
[0090] Based on this, compared with the initial first distance, the third distance is optimized and adjusted by combining the values of the two dimensions of saturation and brightness, and can more accurately reflect the degree of visual difference between the two colors.
[0091] In yet another possible implementation, it is considered that the difference between the saturation values of two colors will also affect the visual perception of the colors, and the difference between the brightness values of two colors will also affect the visual perception of the colors.
[0092] Therefore, on the basis of determining the first distance based on the first hue value and the second hue value, the second distance can also be determined according to the first brightness value, the first saturation value, the second brightness value, and the second saturation value. The second distance reflects the similarity or difference between the two colors from the two dimensions of brightness and saturation. Accordingly, in the specific implementation of the aforementioned S104, the color distance between the first color and the second color can be determined according to the first weight, the second weight, the first distance, and the second distance.
[0093] Based on this, the three dimensions of hue, saturation, and brightness can be combined to more comprehensively evaluate the similarity or difference between two colors, so that the final color distance can more accurately reflect the similarity or difference between the two colors, which is conducive to improving accuracy.
[0094] In specific implementation, the product of the first weight, the second weight and the first distance may be determined as the third distance, and then the sum of the third distance and the second distance may be determined as the color distance between the first color and the second color.
[0095] Based on this, the final color distance can be determined through simple mathematical operations, which is conducive to improving efficiency.
[0096] In practical applications, the color distance can be determined by the following formula:
[0097] dist=w1*w2*dist h +dist sv
[0098] In the above formula, dist is used to represent the color distance, w1 is used to represent the first weight, and w2 is used to represent the second weight. h Used to indicate the first distance, dist sv Used to represent the second distance. And, w1*w2*dist h Used to indicate third distance.
[0099] The second distance can be determined by the following formula:
[0100]
[0101] In the above formula, dist sv It is used to represent the second distance, s1 is used to represent the first saturation value, s2 is used to represent the second saturation value, v1 is used to represent the first brightness value, and v2 is used to represent the second brightness value.
[0102] It can be seen from the above technical solution that for the first color and the second color, the first distance is determined according to the first hue value and the second hue value, and the first weight and the second weight are determined according to the first brightness, the first saturation value, the second brightness value and the second saturation value. Among them, the first weight is used to indicate the influence of the brightness value on the first distance, and the second weight is used to indicate the influence of the saturation value on the first distance. Since the change of hue is more likely to change the color as a whole, the first distance is first determined based on the hue value to reflect the similarity between the two colors from the hue dimension. At the same time, the values of the two dimensions of brightness and saturation can affect the effect of the change of hue on the overall change of the color. Under different brightness values and saturation values, the hue value produces the same change, and the effect of the overall change of the color is usually different. Therefore, the corresponding first weight and second weight can be determined based on the brightness value and saturation value of the two colors, so as to reflect the influence of the values of these two dimensions on the first distance, and also reflect the contribution of the values of these two dimensions to the similarity between the two colors. Finally, the color distance between the first color and the second color is determined based on the first weight, the second weight and the first distance. In the related art, the color distance is determined based on the distance formula between two three-dimensional coordinate points. The color distance determined in this way is a linear distance, and the colors do not have a linear change relationship in the color space. Therefore, compared with this, the use of the present application is conducive to determining a more accurate color distance, thereby more accurately evaluating the similarity between colors.
[0103] Through the above embodiments, the method for determining the color distance provided by the present application is described in detail. For better understanding, the present application embodiment also provides the following Figure 4 The schematic diagram of a color distance determination process shown in FIG. 1 mainly includes the following four parts:
[0104] Part 1: Color space conversion. Get the first color as RGB1, including [r1, g1, b1], and the second color as RGB2, including [r2, g2, b2]. Next, perform color space conversion, convert the first color from RGB color space to HSV color space, and you can get the first color as HSV1, including [h1, s1, v1], and the second color as HSV2, including [h2, s2, v2].
[0105] The second part is basic distance calculation. In the hue dimension, the hue distance (i.e. the first distance mentioned above) is calculated, and in the saturation and brightness dimensions, the saturation and brightness distance (i.e. the second distance mentioned above) is calculated.
[0106] The third part is tolerance calculation. That is, considering different values of brightness and different values of saturation, the tolerance of hue value is different, which is reflected in the different degrees of influence of hue value change on color change at the visual level. It can be understood that this part corresponds to the aforementioned determination of the first weight and the second weight, and the details can be referred to the specific description of the aforementioned related embodiments.
[0107] The fourth part, weighted distance, specifically determines the color distance between two colors according to the results of the second part and the third part. It can be understood that this part corresponds to the aforementioned determination of the color distance, and the details can be referred to the specific description of the aforementioned related embodiments.
[0108] It can be understood that it basically corresponds to the method embodiment, so the relevant parts can refer to the partial description of the method embodiment.
[0109] Through the above embodiments, the method for determining the color distance provided by the present application is described in detail. For better understanding, the embodiments of the present application also provide the following example description:
[0110] The color distance between the first color and the second color can reflect the similarity between the two colors, and can also reflect the visual perception when the two colors appear together. For example, when two relatively similar colors (such as light green and dark green) appear together, the visual perception is matched and harmonious. When two colors with large differences (such as bright red and bright green) appear together, the visual perception is relatively glaring, uncoordinated, and unmatched.
[0111] Therefore, in a possible implementation, the color distance between two colors can be used to determine whether the two colors can be used together. For ease of understanding, take the scenario of designing a poster image for video (such as a film or TV series) promotion as an example:
[0112] In one example, color distance can be calculated to guide users (such as designers) to select colors with better visual effects for use together, so as to design a poster image with better visual effects.
[0113] In another example, in order to improve the efficiency of generating poster images, poster images can also be automatically generated. Specifically, the aforementioned first color can be used to indicate the visual features of the theme logo of the video, and the second color can be used to indicate the visual features of the video frame image from the video. The video can be the aforementioned video of the film and television drama, etc., and correspondingly, the theme logo can be the logo of the title of the film and television drama, etc., and the video frame image can be an image captured from the video, such as a frame of an image including the protagonist of the film and television drama.
[0114] Correspondingly, if the color distance between the first color and the second color meets the color matching condition, it indicates that the visual effect of the two colors appearing at the same time is good, so the theme logo can be directly added to the video frame image to obtain a video frame image carrying the theme logo. On the contrary, if the color distance between the first color and the second color does not meet the color matching condition, it indicates that the visual effect of the two colors appearing at the same time is poor. At this time, the color of the theme logo can be adjusted until the color distance between the adjusted first color and the second color meets the color matching condition. Afterwards, the adjusted theme logo is added to the video frame image to obtain a video frame image carrying the adjusted theme logo.
[0115] Finally, the video frame image carrying the theme identifier, or the video frame image carrying the adjusted theme identifier, may be determined as the poster image of the video.
[0116] It can be seen that the color distance can be used to evaluate whether the theme logo and the video frame image match each other at the visual level. If they can match, the theme logo is directly added to the video frame image to quickly generate a poster image. Otherwise, the color of the theme logo is adjusted until they can match. Based on this, it can guide the generation of a poster image with better visual effects.
[0117] In practical applications, for example, for a certain TV series, the theme logo can be the show's name logo. In different episodes, due to different plots, the obtained video frame images are also quite different. For example, a video frame image is captured from each episode of the video, and multiple video frame images are obtained. After adopting the above method, by adjusting the color of the show's name logo, multiple poster images can be quickly generated. In this way, when playing each episode of the video, the corresponding poster image can be used for promotion.
[0118] It should also be noted that this application does not impose any limitation on the setting of color matching conditions.
[0119] For ease of understanding, this application provides the following examples:
[0120] In practical applications, the color distance between two colors can be a value between 0 and 1, which simply and intuitively reflects the similarity between the two colors. Accordingly, the interval [0.6, 0.8] can be set as the color matching condition. If the value of the color distance falls within this interval, it is determined that the color distance meets the color matching condition. Otherwise, it is determined that the color distance does not meet the color matching condition.
[0121] Based on this, it can be ensured that the two colors used in combination are relatively similar but not particularly similar, that is, they are similar but have a certain degree of distinction. In this way, when used in combination, the visual experience is harmonious, and at the same time, it can be seen that they are two colors. For example, in the aforementioned poster image, the color of the drama title logo matches the content of the video frame image, but at the same time, there is a certain degree of distinction from the content of the video frame image, thereby achieving a better publicity effect for the drama.
[0122] Figure 5 This is a structural diagram of a device for determining a color distance provided in an embodiment of the present application, wherein the device includes an acquisition unit 501 and a determination unit 502:
[0123] The acquisition unit 501 is used to acquire a first hue value, a first brightness value and a first saturation value corresponding to a first color, and to acquire a second hue value, a second brightness value and a second saturation value corresponding to a second color;
[0124] The determining unit 502 is configured to determine a first distance according to the first hue value and the second hue value;
[0125] The determining unit 502 is further configured to determine a first weight and a second weight according to the first brightness value, the first saturation value, the second brightness value, and the second saturation value, wherein the first weight is used to represent the influence of the brightness value on the first distance, and the second weight is used to represent the influence of the saturation value on the first distance;
[0126] The determining unit 502 is further configured to determine a color distance between the first color and the second color according to the first weight, the second weight, and the first distance.
[0127] In a possible implementation manner, the determining unit is further configured to:
[0128] Obtaining a tolerance division area map determined according to the value range of the brightness value and the value range of the saturation value, wherein different areas in the tolerance division area map are used to identify different value ranges of the brightness value and the value ranges of the saturation value, and in different areas, the degree of influence of hue value change on color change is different;
[0129] The first weight and the second weight are determined according to a target area where the first brightness value, the first saturation value, the second brightness value, and the second saturation value are located in the tolerance division area map.
[0130] In a possible implementation, if the first weight is positively correlated with the degree of influence of the hue value change on the color change, and the second weight is positively correlated with the degree of influence of the hue value change on the color change, the determining unit is further configured to:
[0131] Determine a third distance by multiplying the first weight, the second weight, and the first distance;
[0132] A color distance between the first color and the second color is determined according to the third distance.
[0133] In a possible implementation manner, the determining unit is further configured to:
[0134] Acquire a target calculation method corresponding to the target area, wherein the target calculation method is determined by simulation based on a brightness value range and a saturation value range identified by the target area;
[0135] Based on the target calculation method, the first weight and the second weight are determined according to the first brightness value, the first saturation value, the second brightness value, and the second saturation value.
[0136] In a possible implementation manner, the determining unit is further configured to:
[0137] determining a second distance according to the first brightness value, the first saturation value, the second brightness value, and the second saturation value;
[0138] A color distance between the first color and the second color is determined according to the first weight, the second weight, the first distance, and the second distance.
[0139] In a possible implementation manner, the determining unit is further configured to:
[0140] Determine a third distance by multiplying the first weight, the second weight, and the first distance;
[0141] The sum of the third distance and the second distance is determined as the color distance between the first color and the second color.
[0142] In a possible implementation manner, the acquiring unit is further configured to:
[0143] Obtain a first channel value, a second channel value, and a third channel value corresponding to the first color in the RGB color space;
[0144] Performing color space conversion on the first color according to the first channel value, the second channel value, and the third channel value to obtain the first hue value, the first brightness value, and the first saturation value corresponding to the first color in the HSV color space;
[0145] Obtain a fourth channel value, a fifth channel value, and a sixth channel value corresponding to the second color in the RGB color space, wherein the fourth channel value and the first channel value belong to the same channel, the fifth channel value and the second channel value belong to the same channel, and the sixth channel value and the third channel value belong to the same channel;
[0146] The second color is converted into a color space according to the fourth channel value, the fifth channel value, and the sixth channel value to obtain the second hue value, the second brightness value, and the second saturation value corresponding to the second color in the HSV color space.
[0147] In a possible implementation manner, if the first color is used to indicate a visual feature of a subject identifier of a video, and the second color is used to indicate a visual feature of a video frame image from the video, the determining unit is further used to:
[0148] If the color distance between the first color and the second color meets the color matching condition, adding the subject identifier to the video frame image to obtain the video frame image carrying the subject identifier;
[0149] If the color distance between the first color and the second color does not satisfy the color matching condition, adjusting the color of the theme logo until the color distance between the adjusted first color and the second color satisfies the color matching condition;
[0150] Adding the adjusted subject identifier to the video frame image to obtain the video frame image carrying the adjusted subject identifier;
[0151] The video frame image carrying the theme identifier, or the video frame image carrying the adjusted theme identifier, is determined as a poster image of the video.
[0152] It can be seen from the above technical solution that for the first color and the second color, the first distance is determined according to the first hue value and the second hue value, and the first weight and the second weight are determined according to the first brightness, the first saturation value, the second brightness value and the second saturation value. Among them, the first weight is used to indicate the influence of the brightness value on the first distance, and the second weight is used to indicate the influence of the saturation value on the first distance. Since the change of hue is more likely to change the color as a whole, the first distance is first determined based on the hue value to reflect the similarity between the two colors from the hue dimension. At the same time, the values of the two dimensions of brightness and saturation can affect the effect of the change of hue on the overall change of the color. Under different brightness values and saturation values, the hue value produces the same change, and the effect of the overall change of the color is usually different. Therefore, the corresponding first weight and second weight can be determined based on the brightness value and saturation value of the two colors, so as to reflect the influence of the values of these two dimensions on the first distance, and also reflect the contribution of the values of these two dimensions to the similarity between the two colors. Finally, the color distance between the first color and the second color is determined based on the first weight, the second weight and the first distance. In the related art, the color distance is determined based on the distance formula between two three-dimensional coordinate points. The color distance determined in this way is a linear distance, and the colors do not have a linear change relationship in the color space. Therefore, compared with this, the use of the present application is conducive to determining a more accurate color distance, thereby more accurately evaluating the similarity between colors.
[0153] In another aspect, an embodiment of the present application provides a computer device, the computer device comprising a processor and a memory:
[0154] The memory is used to store program code and transmit the program code to the processor;
[0155] The processor is used to execute the method for determining the color distance provided in the above embodiment according to the instructions in the program code.
[0156] The computer device may include a terminal device or a server, and the aforementioned color distance determination device may be configured in the computer device.
[0157] On the other hand, an embodiment of the present application further provides a storage medium, wherein the storage medium is used to store a computer program, and the computer program is used to execute the method for determining the color distance provided in the above embodiment.
[0158] In addition, an embodiment of the present application further provides a computer program product including instructions, which, when executed on a computer, enables the computer to execute the method for determining the color distance provided in the above embodiment.
[0159] A person of ordinary skill in the art can understand that: all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, the above program can be stored in a computer-readable storage medium, and when the program is executed, it executes the steps of the above method embodiment; and the above storage medium can be at least one of the following media: read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk, etc., various media that can store program codes.
[0160] For the device embodiment, since it basically corresponds to the method embodiment, the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative work.
[0161] It should be noted that, in this article, relational terms such as "first" and "second", etc. (if any) are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0162] The above is a detailed introduction to a method, device, equipment, and storage medium for determining a color distance provided by an embodiment of the present application. This article uses specific examples to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application. At the same time, for those skilled in the art, according to the method of the present application, there will be changes in the specific implementation method and application scope.
[0163] In summary, the content of this specification should not be understood as limiting the present application, and any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in this application should be included in the protection scope of this application. Moreover, based on the implementations provided in the above aspects, this application can also be further combined to provide more implementations.
Claims
1. A method for determining color distance, characterized in that: The method comprises: Obtain a first hue value, a first brightness value, and a first saturation value corresponding to the first color, and obtain a second hue value, a second brightness value, and a second saturation value corresponding to the second color; determining a first distance according to the first hue value and the second hue value; Determine a first weight and a second weight according to the first brightness value, the first saturation value, the second brightness value, and the second saturation value, wherein the first weight is used to represent the influence of the brightness value on the first distance, and the second weight is used to represent the influence of the saturation value on the first distance; A color distance between the first color and the second color is determined according to the first weight, the second weight, and the first distance.
2. The method according to claim 1, characterized in that The determining the first weight and the second weight according to the first brightness value, the first saturation value, the second brightness value, and the second saturation value includes: Obtaining a tolerance division area map determined according to the value range of the brightness value and the value range of the saturation value, wherein different areas in the tolerance division area map are used to identify different value ranges of the brightness value and the value ranges of the saturation value, and in different areas, the degree of influence of hue value change on color change is different; The first weight and the second weight are determined according to a target area where the first brightness value, the first saturation value, the second brightness value, and the second saturation value are located in the tolerance division area map.
3. The method according to claim 2, characterized in that If the first weight is positively correlated with the degree of influence of the hue value change on the color change, the second weight is positively correlated with the degree of influence of the hue value change on the color change; The determining the color distance between the first color and the second color according to the first weight, the second weight, and the first distance includes: Determine a third distance by multiplying the first weight, the second weight, and the first distance; A color distance between the first color and the second color is determined according to the third distance.
4. The method according to claim 2, characterized in that: The determining the first weight and the second weight according to the target area where the first brightness value, the first saturation value, the second brightness value, and the second saturation value are located in the tolerance division area map includes: Acquire a target calculation method corresponding to the target area, wherein the target calculation method is determined by simulation according to a brightness value range and a saturation value range identified by the target area; Based on the target calculation method, the first weight and the second weight are determined according to the first brightness value, the first saturation value, the second brightness value, and the second saturation value.
5. The method according to claim 1, characterized in that: The method further comprises: determining a second distance according to the first brightness value, the first saturation value, the second brightness value, and the second saturation value; The determining the color distance between the first color and the second color according to the first weight, the second weight, and the first distance includes: A color distance between the first color and the second color is determined according to the first weight, the second weight, the first distance, and the second distance.
6. The method according to claim 5, characterized in that The determining the color distance between the first color and the second color according to the first weight, the second weight, the first distance, and the second distance includes: Determine a third distance by multiplying the first weight, the second weight, and the first distance; The sum of the third distance and the second distance is determined as the color distance between the first color and the second color.
7. The method according to any one of claims 1 to 6, characterized in that: The obtaining of a first hue value, a first brightness value, and a first saturation value corresponding to the first color includes: Obtain a first channel value, a second channel value, and a third channel value corresponding to the first color in the RGB color space; Performing color space conversion on the first color according to the first channel value, the second channel value, and the third channel value to obtain the first hue value, the first brightness value, and the first saturation value corresponding to the first color in the HSV color space; The obtaining of a second hue value, a second brightness value, and a second saturation value corresponding to the second color includes: Obtain a fourth channel value, a fifth channel value, and a sixth channel value corresponding to the second color in the RGB color space, wherein the fourth channel value and the first channel value belong to the same channel, the fifth channel value and the second channel value belong to the same channel, and the sixth channel value and the third channel value belong to the same channel; The second color is converted into a color space according to the fourth channel value, the fifth channel value, and the sixth channel value to obtain the second hue value, the second brightness value, and the second saturation value corresponding to the second color in the HSV color space.
8. The method according to any one of claims 1 to 6, characterized in that: If the first color is used to indicate a visual feature of a subject identifier of a video, and the second color is used to indicate a visual feature of a video frame image from the video, the method further includes: If the color distance between the first color and the second color meets the color matching condition, adding the subject identifier to the video frame image to obtain the video frame image carrying the subject identifier; If the color distance between the first color and the second color does not satisfy the color matching condition, adjusting the color of the theme logo until the color distance between the adjusted first color and the second color satisfies the color matching condition; Adding the adjusted subject identifier to the video frame image to obtain the video frame image carrying the adjusted subject identifier; The video frame image carrying the theme identifier, or the video frame image carrying the adjusted theme identifier, is determined as a poster image of the video.
9. A device for determining color distance, characterized in that: The device comprises an acquisition unit and a determination unit: The acquisition unit is used to acquire a first hue value, a first brightness value, and a first saturation value corresponding to the first color, and to acquire a second hue value, a second brightness value, and a second saturation value corresponding to the second color; The determining unit is configured to determine a first distance according to the first hue value and the second hue value; The determining unit is further configured to determine a first weight and a second weight according to the first brightness value, the first saturation value, the second brightness value, and the second saturation value, wherein the first weight is used to represent the influence of the brightness value on the first distance, and the second weight is used to represent the influence of the saturation value on the first distance; The determining unit is further configured to determine a color distance between the first color and the second color according to the first weight, the second weight, and the first distance.
10. A computer device, characterized in that: The computer device comprises a processor and a memory: The memory is used to store program codes and transmit the program codes to the processor; The processor is configured to execute the method according to any one of claims 1 to 8 according to the instructions in the program code.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium is used to store a computer program, and the computer program is used to execute the method according to any one of claims 1 to 8.