A color extraction method, a lighting control method, a medium, and a device
By dividing and weighting the color range using RGB sampling and HSV quantization standards, the primary color range is selected, solving the problem that electronic devices cannot accurately count the primary color. This achieves the creation of an environmental atmosphere that is synchronized with the screen display content and conforms to human visual perception.
Patent Information
- Application Number
- CN202310159456.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-23
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2043-02-23
AI Technical Summary
Existing electronic devices cannot accurately determine the dominant color that matches the human eye's sensory experience, resulting in ambient lighting that does not meet expectations.
By adopting RGB sampling and HSV quantization standards, the main color range is selected through color range division and weighted processing. The lighting equipment is then controlled according to the RGB values within the main color range to achieve a synchronized atmosphere creation with the screen display content.
It can quickly and effectively determine the main color that conforms to human visual perception, reduce computer resource consumption, has low hardware requirements, and creates an environment atmosphere that meets expectations.
Smart Images

Figure CN116343710B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of lighting control, and more particularly to a color extraction method, a lighting control method, a medium, and a device. Background Technology
[0002] With the continuous development of smart lighting devices and IoT technology, the demand for ambient lighting that synchronously creates ambiance based on screen display content is becoming increasingly strong in e-sports or audio-visual entertainment scenarios. Based on this need for ambient lighting, we need to determine the dominant color within a specified display area of the computer and display it in RGB ambient lighting.
[0003] Because warm colors are more visually appealing than cool colors, in image and video compositions, the background is typically a large area of gray, black, and white, while the specific people or objects are often depicted in bright warm colors to highlight the content. However, in mathematical statistics, this approach usually results in a higher proportion of background color and a lower proportion of color for the specific people or objects, leading to a calculated dominant color that doesn't align with human visual perception. Summary of the Invention
[0004] In view of this, the present invention discloses a color extraction method, an illumination control method, a medium, and an illumination device to solve the problem that existing electronic devices cannot statistically determine the dominant color that conforms to the sensory experience of the human eye.
[0005] To achieve the above objectives, the technical solution adopted by this invention is as follows:
[0006] The first aspect of this invention discloses a color extraction method for a display screen of an electronic device, the method comprising:
[0007] Acquire the image within a defined area on the display screen;
[0008] Perform RGB sampling on the image to obtain the RGB values of all sampled points;
[0009] The RGB values are categorized and statistically analyzed to determine multiple color ranges;
[0010] Select at least one primary color range from multiple color ranges;
[0011] The target RGB value is determined based on all RGB values within at least one primary color zone.
[0012] Further, optionally, the color range includes a color value range and a non-color value range. RGB values are categorized and statistically analyzed to determine multiple color ranges, including:
[0013] Convert the RGB value of each sampling point to the corresponding HSV value;
[0014] The brightness value V of the HSV value is compared with the first threshold, and the saturation value S of the HSV value is compared with the second threshold.
[0015] When the brightness value V is less than the first threshold and / or the saturation value S is less than the second threshold, the corresponding RGB value will be classified into the non-color value range.
[0016] When the brightness value V is greater than or equal to the first threshold and the saturation value S is greater than or equal to the second threshold, the corresponding RGB value is assigned to its respective color value range.
[0017] Further, optionally, selecting at least one primary color range from multiple color ranges includes:
[0018] The sum of the R, G, and B values of all RGB values in each color range and the number of samples are weighted to obtain the weighted RGB statistics and weighted number of samples for the corresponding color range.
[0019] Select the intervals whose weighted sampling number meets the set requirements as the main color intervals.
[0020] Optionally, color ranges whose weighted sampling number meets the set requirements can be selected as the primary color range, including:
[0021] For each color value range, calculate the maximum weighted number of samples among all color value ranges;
[0022] Select the intervals where the weighted sample number is greater than the maximum weighted sample number by a certain percentage as the main color interval;
[0023] For non-color value ranges, calculate the total weighted number of samples for all color ranges;
[0024] Select the intervals where the weighted sample count reaches a certain percentage of the total weighted sample count as the main color interval.
[0025] Further, optionally, weighting is performed on the sum of the R, G, and B values and the number of samples for all RGB values in each color range, including:
[0026] Count the number of sampling points in color interval i to obtain the number of samples count(i), and calculate the sum of R values red(i), the sum of G values green(i), and the sum of B values blue(i) based on all RGB values in color interval i.
[0027] Based on the interval weight coefficient w(i), the number of samples count(i) in color interval i, the sum of R values red(i), the sum of G values green(i), and the sum of B values blue(i) are weighted respectively.
[0028] Further optionally, the weighted sums of R, G, and B values for color interval i are set to red(i)′, green(i)′, and blue(i)′, respectively, and the weighted sample count for color interval i is set to count(i)′, then:
[0029] count(i)′=count(i)×w(i);
[0030] red(i)′=red(i)×w(i);
[0031] green(i)′=green(i)×w(i);
[0032] blue(i)′=blue(i)×w(i).
[0033] Alternatively, the weight coefficient w(i) of color interval i is linearly related to the hue value H of the corresponding interval, and the interval weight coefficient w(i) decreases linearly from warm colors to cool colors.
[0034] Alternatively, the weighting coefficient w(i) can be calculated using the following formula:
[0035] w(i)=abs(h(i)﹣180) / 180·(w(max)﹣w(min))﹢w(min);
[0036] Where h(i) represents the reference hue value H of interval i, w(max) represents the preset maximum weight coefficient, and w(min) represents the preset minimum weight coefficient.
[0037] Further, optionally, the target color data is determined based on all color data within at least one primary color interval, including:
[0038] Mix all weighted RGB statistical values within at least one primary color range in a certain proportion to obtain the target RGB value.
[0039] Preferably, the target RGB value is obtained by summing all weighted RGB statistical values within at least one primary color interval and dividing by the sum of all weighted sample numbers within at least one primary color interval.
[0040] Suppose that a total of m primary color statistical intervals are selected: {i1,i2,...,im}.
[0041] The weighted sum of the sample numbers is calculated as follows:
[0042] count(sum)=count(i1)+count(i2)+…+count(im);
[0043] Calculate the weighted sum of the R, G, and B values respectively:
[0044] red(sum)=red(i1)+red(i2)+…+red(im);
[0045] green(sum)=green(i1)+green(i2)+…+green(im);
[0046] blue(sum)=blue(i1)+blue(i2)+…+blue(im);
[0047] Then, process the statistical interval data of gray, black and white values.
[0048] Assuming the percentage threshold for the gray-black-white interval is t(g)%, and the number of samples in the gray-black-white interval is:
[0049] count(g) is the total weighted number of samples across all color value statistical intervals, which is count(total).
[0050] If count(g) > count(total) × t(g)%, then:
[0051] The weighted sum of the sampled values increases the number of samples in the gray-black and white value intervals:
[0052] count(sum)=count(sum)+count(g);
[0053] The weighted sum of R, G, and B values is also included in the statistical values for the gray-black value interval:
[0054] red(sum) = red(sum) + red(g);
[0055] green(sum)=green(sum)+green(g);
[0056] blue(sum)=blue(sum)+blue(g);
[0057] Finally, the weighted average of the weighted sums of the R, G, and B values is taken to obtain the final result:
[0058] red(final)=red(sum) / count(sum);
[0059] green(final)=green(sum) / count(sum);
[0060] blue(final)=blue(sum) / count(sum);
[0061] The target RGB value is obtained.
[0062] The second aspect of the present invention discloses a lighting control method, which uses the target RGB value obtained by any of the color extraction methods in the first aspect to control the lighting device, so that the screen display content of the electronic device and the lighting device are synchronized to create an environmental atmosphere.
[0063] A third aspect of the present invention discloses a non-transitory computer-readable storage medium having program instructions stored thereon, which, when executed by one or more processors, enable the one or more processors to implement the method provided in either the first or second aspect.
[0064] The fourth aspect of the present invention discloses an electronic device that employs the method of either the first aspect or the second aspect, or includes the medium of the third aspect.
[0065] Beneficial effects: This method can quickly and effectively determine the dominant color within a computer display area, and the created RGB environment atmosphere conforms to the visual expectations of the human eye. Furthermore, this method has low computer resource consumption and a low hardware barrier for users. Attached Figure Description
[0066] The above and other objects, features, and advantages of the present invention will become more apparent from the detailed description of exemplary embodiments with reference to the accompanying drawings. The drawings described below are merely some embodiments disclosed in the present invention; those skilled in the art can obtain other drawings based on these drawings without any inventive effort.
[0067] Figure 1 One of the schematic flowcharts of a color extraction method according to an embodiment of the present invention is shown as an example.
[0068] Figure 2 A second schematic flowchart of a color extraction method according to an embodiment of the present invention is shown as an example.
[0069] Figure 3 An example of an HSV color system hue wheel according to an embodiment of the present invention is shown.
[0070] Figure 4 An exemplary illustration shows the linear relationship between the HUE value and the statistical interval weighting coefficient according to an embodiment of the present invention.
[0071] Figure 5 An image within a defined area on a display screen is shown as an example according to an embodiment of the present invention. Detailed Implementation
[0072] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0073] The terminology used in the embodiments of this invention is for the purpose of describing particular embodiments only and is not intended to limit the invention. The singular forms “a,” “the,” and “the” used in the embodiments of this invention and the appended claims are also intended to include the plural forms, unless the context clearly indicates otherwise. “Multiple” generally includes at least two, but does not exclude the inclusion of at least one.
[0074] It should be understood that the term "and / or" used in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this article generally indicates that the preceding and following related objects have an "or" relationship.
[0075] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a product or system comprising a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a product or system. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the product or system that includes said element.
[0076] To further illustrate the technical solution of the present invention, the technical terms involved in this embodiment will first be explained.
[0077] The RGB color model is an industry-standard color system that uses variations in the red (R), green (G), and blue (B) color channels and their interactions to create a wide variety of colors. It is one of the most widely used color systems and is also the color system adopted by computer display systems. However, because the red (R), green (G), and blue (B) components are highly correlated, the RGB color space makes it difficult to perform mathematical statistics on the dominant color.
[0078] The HSV color system is a representation of points in the RGB color model in a cylindrical coordinate system. This representation attempts to be more intuitive than the Cartesian coordinate system-based geometry of RGB, making it easier to compare colors.
[0079] Statistical interval division method based on HSV color system:
[0080] In the HSV color system, Hue values are used as a quantification method to classify and statistically analyze color data across computer screen areas. Hue is measured in angles, ranging from 0 to 360°. Dividing the hue wheel into equal sections using these angles results in a set of color statistical intervals. Each interval contains a starting and ending Hue angle; sampled values with Hue values between these angles are assigned to that interval. Lower Saturation and Value indicate lower color intensity, resulting in a color closer to black, gray, and white to the naked eye. Using saturation and value as quantification methods, gray, black, and white color data are grouped into separate intervals for statistical processing. Thresholds are set for saturation and value; if either is below the threshold, the sampled value is uniformly assigned to the gray / black / white statistical interval. Other samples are assigned to their corresponding color statistical intervals based on their Hue values. Assuming the hue wheel is divided into n equal parts, there are n color value statistical intervals and one gray / black / white value statistical interval.
[0081] The first aspect of this embodiment discloses a color extraction method for an electronic device display screen, combined with... Figure 1 The methods include S1 to S5, wherein:
[0082] S1, acquire the image within the set area on the display screen;
[0083] S2, perform RGB sampling on the image to obtain the RGB values of all sampling points;
[0084] S3, classifies and statistically analyzes RGB values to determine multiple color ranges;
[0085] S4, select at least one primary color range from multiple color ranges;
[0086] S5, determine the target RGB value based on all RGB values within at least one primary color interval.
[0087] The color extraction method provided in this embodiment is mainly based on sampling RGB values, statistically classifying the RGB values using HSV as the quantization standard, then selecting at least one primary color range according to its color family, and finally mixing these primary colors in proportion to output the target RGB value. This method can quickly and effectively obtain the primary color values in the computer display area that conform to human visual perception. Based on the needs of creating ambient lighting, it is preferable to output the target RGB value to the lighting device, thereby creating an environmental atmosphere that conforms to human visual sensory experience.
[0088] Further optionally, the color range includes a color value range and a non-color value range, and step S3 includes S31 to S34, wherein:
[0089] S31, convert the RGB value of each sampling point into the corresponding HSV value;
[0090] S32, compare the brightness value V of the HSV value with the first threshold, and compare the saturation value S of the HSV value with the second threshold;
[0091] S33, when the brightness value V is less than the first threshold and / or the saturation value S is less than the second threshold, the corresponding RGB value is classified into the non-color value range.
[0092] S34. When the brightness value V is greater than or equal to the first threshold and the saturation value S is greater than or equal to the second threshold, the corresponding RGB value is assigned to the corresponding color value range.
[0093] Specifically, the current screen content can be captured using the computer operating system API to generate a bitmap. Based on a defined area, the RGB values of all sampling coordinates within this area are captured as sample values. Preferably, an interval method is used to select the sampling coordinates to reduce the number of samples, thereby reducing the consumption of computer hardware resources and improving efficiency. For each sampling coordinate's RGB value, it is first converted to its corresponding HSV value. Then, it is determined whether the lightness (V) and saturation (S) values of the HSV value are less than the corresponding thresholds.
[0094] If either the lightness value (V) or the saturation value (S) is less than the corresponding threshold, the RGB value of the sampled point is inserted into the non-color value (gray, black, and white value) range.
[0095] If both the lightness value (V) and saturation value (S) are greater than the corresponding threshold, the sampled RGB data value is inserted into the corresponding color value range based on the hue value (H).
[0096] Further optionally, step S4 includes the following steps:
[0097] A1, weight the sum of R, G, and B values and the number of samples of all RGB values in each color interval to obtain the weighted RGB statistics and weighted number of samples for the corresponding color interval;
[0098] A2, select the intervals whose weighted sampling number meets the set requirements as the main color intervals.
[0099] Specifically, for each statistical interval (color interval), the sum of R, G, and B values is calculated based on all RGB values within the interval. Let the sums of R, G, and B values for statistical interval i be red(i), green(i), and blue(i), respectively, and let count(i) be the number of samples in the statistical interval.
[0100] Further optionally, step A1 includes steps A11 to A12, wherein:
[0101] A11, for each color interval i, count the number of sampling points in the interval to obtain the number of samples count(i), and calculate the sum of R values red(i), the sum of G values green(i) and the sum of B values blue(i) based on all RGB values in the interval.
[0102] A12, based on the interval weight coefficient w(i), the number of samples count(i) in the interval, the sum of R values red(i), the sum of G values green(i), and the sum of B values blue(i) are weighted respectively.
[0103] Among them, the interval weight coefficient w(i) of color interval i is linearly related to the hue value H of the corresponding interval, and the interval weight coefficient w(i) decreases linearly from warm color system to cool color system.
[0104] Figure 3 The hue wheel provided in this embodiment, Figure 4 This diagram illustrates the linear relationship between the hue value (Hue) of each statistical interval and the corresponding weighting coefficient in this embodiment. From... Figure 3 , 4 It can be seen that the weight coefficients decrease linearly from red (Hue=0°) counterclockwise to blue-green (Hue=180°) in each statistical interval; and the weight coefficients increase linearly from blue-green (Hue=180°) counterclockwise to red (Hue=0°) in each statistical interval.
[0105] Alternatively, the interval weight coefficient w(i) can be calculated using the following formula, with the interval containing red (Hue = 0°) having the highest weight and the interval containing blue-green (Hue = 180°) having the lowest weight:
[0106] w(i)=abs(h(i)﹣180) / 180·(w(max)﹣w(min))﹢w(min);
[0107] Where h(i) represents the reference hue value H of interval i, the reference hue value H is the middle hue value of the hue value range of the color value statistical interval, assuming that there are a total of n color value statistical intervals, h(1)=0 (red Hue=0°), h(i)=360 / n·(i-1), the hue value range of interval i is [h(i)-360 / 2n,h(i)+360 / 2n]; w(max) represents the maximum weight coefficient in each statistical interval; w(min) represents the minimum weight coefficient in each statistical interval.
[0108] After obtaining the interval weight coefficients w(i), the number of samples and the sum of R, G, and B values for each interval are weighted separately:
[0109] Let the weighted sums of R, G, and B values in statistical interval i be red(i)′, green(i)′, and blue(i)′, respectively, and let the weighted sample size for statistical interval i be count(i)′, then:
[0110] count(i)′=count(i)×w(i);
[0111] red(i)′=red(i)×w(i);
[0112] green(i)′=green(i)×w(i);
[0113] blue(i)′=blue(i)×w(i).
[0114] Further optionally, step A2 includes steps A21 to A24, wherein:
[0115] A21, for a color value range, calculate the maximum weighted number of samples among all color value ranges;
[0116] A22, select the intervals with a weighted sample number greater than the maximum weighted sample number by a certain percentage as the main color interval;
[0117] For situations where multiple color value statistical intervals have similar weighted sampling numbers, this method filters out statistical intervals whose weighted sampling numbers exceed the maximum sampling number by a certain percentage and adds them to the main color interval set. The RGB weighted statistical data of all intervals in the main color interval set are then averaged to make the output results more consistent with expectations.
[0118] A23, For non-color value intervals, calculate the total weighted number of samples for all color intervals;
[0119] A24, select the intervals where the weighted sample count reaches a certain percentage of the total weighted sample count as the main color interval.
[0120] For non-color value ranges, taking the gray-black-white range as an example, a separate threshold percentage is set. Only when the weighted sampling number of the gray-black-white range reaches a certain proportion of the total weighted sampling number will the gray-black-white range be added to the main color range set.
[0121] The specific method is as follows: First, process the color value statistical interval data. Assume the maximum weighted sampling number in the color value statistical interval is count(max), and the threshold percentage is t%.
[0122] Iterate through all color value statistical intervals. For statistical interval i, if the weighted sample count (i) of the interval is greater than count (max) × t%, then add the interval to the main color interval set.
[0123] Assume a total of m primary color statistical intervals are selected: {i1,i2,...,i...} m}
[0124] The weighted sum of the sample numbers is calculated as follows:
[0125] count(sum)=count(i1)+count(i2)+…+count(i m );
[0126] Calculate the weighted sum of the R, G, and B values respectively:
[0127] red(sum)=red(i1)+red(i2)+…+red(i m );
[0128] green(sum)=green(i1)+green(i2)+…+green(i m );
[0129] blue(sum)=blue(i1)+blue(i2)+…+blue(i m );
[0130] Then, process the statistical interval data of gray, black and white values.
[0131] Assume the percentage threshold for the gray-black-white interval is t(g)%, the weighted number of samples for the gray-black-white interval is count(g), and the total weighted number of samples for all color statistical intervals is count(total).
[0132] If count(g) > count(total) × t(g)%, then:
[0133] The weighted sum of the sampled numbers increases the number of samples in the gray-black and white intervals:
[0134] count(sum)′=count(sum)+count(g);
[0135] The weighted sum of R, G, and B values is also included in the statistical values for the gray-black value interval:
[0136] red(sum)′=red(sum)+red(g);
[0137] green(sum)′=green(sum)+green(g);
[0138] blue(sum)′=blue(sum)+blue(g);
[0139] Finally, the weighted average of the weighted sums of the R, G, and B values is taken to obtain the final result:
[0140] red(final)′=red(sum) / count(sum);
[0141] green(final)′=green(sum) / count(sum);
[0142] blue(final)′=blue(sum) / count(sum).
[0143] A second aspect of the present invention provides a lighting control method, which uses the target RGB value obtained by the color extraction method provided in the first aspect to control a lighting device, so that the screen display content of the electronic device and the lighting device are synchronized to create an environmental atmosphere.
[0144] To make the technical solution and beneficial effects of this embodiment clearer, the following will be combined with... Figure 2 , Figure 3 , Figure 4 The color extraction method and lighting method provided in this embodiment will be described in detail.
[0145] Statistical interval division method based on HSV color system:
[0146] In the HSV color system, Hue is measured in degrees, with a value range of 0 to 360°. Starting from red and rotating counterclockwise, Hue = 0° represents red, Hue = 120° represents green, and Hue = 240° represents blue.
[0147] The color values were divided into 12 statistical intervals, each covering a 30° hue angle.
[0148] Meanwhile, the saturation threshold for the gray-black-white statistical interval is set to 20, and the brightness threshold is set to 20.
[0149] In summary, there are a total of 13 color statistical intervals, including 12 color value statistical intervals and 1 gray-black-white statistical interval, as detailed in Table 1:
[0150] Table 1
[0151] Serial Number Color scheme HUE starting angle HUE endpoint angle Saturation Brightness 1 red 346°(-14°) 15° >20 >20 2 Orange-red 16° 45° >20 >20 3 orange 46° 75° >20 >20 4 yellow 76° 105° >20 >20 5 yellow-green 106° 135° >20 >20 6 green 136° 165° >20 >20 7 Blue-green 166° 195° >20 >20 8 blue 196° 225° >20 >20 9 blue 226° 255° >20 >20 10 blue-purple 256° 285° >20 >20 11 Purple 286° 315° >20 >20 12 purplish-red 316° 345° >20 >20 13 gray, black and white — — ≤20 ≤20
[0152] Based on the above statistical interval division scheme and in conjunction with the technical solution and flowchart, the specific calculation process is illustrated with an example.
[0153] 1. RGB data sampling and sample value classification statistics
[0154] Assume the computer display area has a resolution of 1920×1080, and the starting coordinates of the area are (0,0). The currently displayed content is as follows: Figure 4 As shown.
[0155] Capture the displayed content of this area and generate a bitmap.
[0156] Starting from the initial coordinate (0,0), both column and row intervals are set to 3, and RGB data values at specified coordinates are sampled, with a total of 230,400 samples.
[0157] For each sampled coordinate's RGB data value, the RGB value is first converted to HSV value. Then, it is determined whether the saturation (S) value or the lightness (V) value is less than the corresponding threshold. In this embodiment, both the first and second thresholds are 20. If either the saturation (S) value or the lightness (V) value is less than the threshold of 20, the RGB value is added to the gray-black-white statistical interval. Items with both saturation (S) value and lightness (V) value greater than the threshold are classified and added to the corresponding color value statistical interval according to their hue (H) value.
[0158] A number of representative sample values are selected for detailed explanation:
[0159] Suppose that the sums of the R, G, and B values of the statistical interval (indication i) are red(i), green(i), and blue(i), respectively, and let count(i) be the number of samples in the statistical interval.
[0160] 1) Sampling coordinates (3,12), RGB value is RGB(3,7,6), converted to HSV value (H:210, S:67, V:4). Since the brightness is 4, which is less than the threshold of 20, this RGB value is added to the gray-black-white statistical interval. The gray-black-white statistical interval number is 13, then:
[0161] count(13) = count(13) + 1;
[0162] red(13) = red(13) + 3;
[0163] green(13) = green(13) + 7;
[0164] blue(13) = blue(13) + 6.
[0165] In the gray-black-white statistical interval with serial number 13, for each new sample value, taking the above sample value RGB(3,7,6) as an example, the number of samples in the interval count(13) is increased by 1, the sum of R values in the interval red(13) is increased by 3, the sum of G values in the interval green(13) is increased by 7, the sum of B values in the interval blue(13) is increased by 6, and so on, to calculate the sum of R values, G values, B values and the number of samples of all RGB values in the interval.
[0166] 2) Sampling coordinates (1200, 60), RGB value RGB(155, 12, 13), converted to HSV value (H: 359, S: 92, V: 61), saturation and brightness values are both greater than the threshold of 20. Based on the Hue value of 359, it is added to the red statistical interval. The red statistical interval number is 1, then:
[0167] count(1) = count(1) + 1;
[0168] red(1) = red(1) + 155;
[0169] green(1) = green(1) + 12;
[0170] blue(1) = blue(1) + 13.
[0171] That is, in the red statistical interval with serial number 1, for each new sample value, taking the above sample value RGB(155,12,13) as an example, the number of samples in the interval count(1) is increased by 1, the sum of R values in the interval red(1) is increased by 155, the sum of G values in the interval green(1) is increased by 12, the sum of B values in the interval blue(1) is increased by 13, and so on, to calculate the sum of R values, G values, B values and the number of samples of all RGB values in the interval.
[0172] 3) Sampling coordinates (909, 750), RGB value RGB(45, 69, 10), converted to HSV value (H: 85, S: 86, V: 27), both saturation and brightness values are greater than the threshold of 20. Based on the Hue value of 85, it is added to the yellow statistical interval. The yellow statistical interval number is 4, therefore:
[0173] count(4) = count(4) + 1;
[0174] red(4) = red(4) + 45;
[0175] green(4) = green(4) + 69;
[0176] blue(4) = blue(4) + 10.
[0177] That is, in the yellow statistical interval with serial number 4, for each new sample value, taking the above sample value RGB(45,69,10) as an example, the number of samples in the interval count(4) is increased by 1, the sum of R values in the interval red(4) is increased by 45, the sum of G values in the interval green(4) is increased by 69, the sum of B values in the interval blue(4) is increased by 10, and so on, to calculate the sum of R values, G values, B values and the number of samples of all RGB values in the interval.
[0178] The above statistical method involves accumulating the data after each sample. This reduces the amount of computer memory used. Alternatively, all samples can be accumulated together after sampling is complete, which can also achieve the goal of calculating the sum of the R, G, and B values of all RGB values in each color range, as well as the number of samples.
[0179] Figure 5 An image within a defined area on a display screen, as provided in this embodiment of the invention, is processed according to the color extraction method of this embodiment. Figure 5 The statistical partitioning and interval statistical results are detailed in Table 2:
[0180] Table 2
[0181] Serial Number Color scheme Number of samples R-value and G value and B value and 1 red 122645 16085169 3185743 2556422 2 Orange-red 49235 8626408 5926658 3947393 3 orange 6802 1122332 1116269 633079 4 yellow 5172 565190 689137 369912 5 yellow-green 183 16135 21002 15343 6 green 26 954 1198 1078.67 7 Blue-green 33 1984 2299 2338 8 blue 388 10396.67 13400.7 16956 9 blue 178 5118 5230 7220 10 blue-purple 85 3112.8 2662.8 3584 11 Purple 137 5954 4597 5945 12 purplish-red 3903 193836 131937 153768 13 gray, black and white 41613 2114599 2018418 1995798
[0182] 2. Weighted processing of interval statistics:
[0183] Assuming the baseline Hue value of statistical interval i is h(i), then the weight of statistical interval i is:
[0184] w(i)=abs(h(i)-180) / 180·(w(max)-w(min))+w(min)
[0185] The steps for calculating weighting coefficients are illustrated using examples of the green and blue-purple regions:
[0186] Set the highest weight to 4 and the lowest weight to 1.
[0187] The green section, numbered 6, has a baseline Hue value of 150:
[0188] w(6)=abs(h(6)-180) / 180·(w(max)-w(min))+w(min)
[0189] =abs(150-180) / 180·(4-1)+1=30 / 180·3+1=1.5
[0190] The blue-purple interval, numbered 10, has a baseline Hue value of 270.
[0191] w(10)=abs(h(10)-180) / 180·(w(max)-w(min))+w(min)
[0192] =abs(270-180) / 180·(4-1)+1=90 / 180·3+1=2.5
[0193] After obtaining the interval weight coefficients, the number of samples and the sum of R, G, and B values for each interval are weighted and processed:
[0194] count(i)′=count(i)×w(i);
[0195] red(i)′=red(i)×w(i);
[0196] green(i)′=green(i)×w(i);
[0197] blue(i)′=blue(i)×w(i);
[0198] The calculated weights and weighted statistical results for each interval in Table 2 are shown in Table 3:
[0199] Table 3
[0200] Serial Number Color scheme Weight Weighted sample number R-value weighted sum Weighted sum of G values B-value weighted sum 1 red 4 490580 64340676 12742972 10225688 2 Orange-red 3.5 172322 30192428 20743303 13815875 3 orange 3 20406 3366996 3348807 1899237 4 yellow 2.5 12930 1412975 1722842 924780 5 yellow-green 2 366 32270 42004 30686 6 green 1.5 39 1431 1797 1618 7 Blue-green 1 33 1984 2299 2338 8 blue 1.5 582 15595 20101 25434 9 blue 2 356 10236 10460 14440 10 blue-purple 2.5 212 7782 6657 8960 11 Purple 3 411 17862 13791 17835 12 purplish-red 3.5 13660 678426 461779 538188 13 gray, black and white 1 41613 2114599 2018418 1995798
[0201] 3. Main color range filtering and statistical result calculation
[0202] Based on the weighted statistical results, the maximum weighted sample size is 490,580.
[0203] If the threshold percentage is set to 80%, the interval with a weighted sample number greater than 392464 can be used as the main color interval. Then the main color intervals selected are: interval 1 (red).
[0204] The calculated total number of weighted samples in the main color range is 490,580, and the weighted sums of R, G, and B values are 64,340,676, 12,742,972, and 10,225,688, respectively.
[0205] If the threshold percentage for the gray-black-white interval is set to 50% and the number of samples in the gray-black-white interval is 41613, which is less than 753510 × 50%, then the gray-black-white interval samples are insufficient to be classified into the main color interval.
[0206] Finally, the weighted sum of the R, G, and B values is divided by the weighted sample sum to obtain the final result:
[0207] red(final)=64340676 / 490580=131;
[0208] green(final)=12742972 / 490580=26;
[0209] blue(final)=10225688 / 490580=21;
[0210] The final output RGB value is RGB(131,26,21);
[0211] RGB value data is sent to ambient lighting devices via a local area network communication protocol.
[0212] The atmospheric photos are presented in a way that meets the expectations of human visual perception.
[0213] The third aspect of this embodiment discloses a non-transitory computer-readable storage medium having program instructions stored thereon, which, when executed by one or more processors, are used to implement the method provided in either the first or second aspect.
[0214] The fourth aspect of this embodiment discloses an electronic device that employs the method provided in either the first or second aspect, or includes the medium provided in the third aspect.
[0215] In the different embodiments provided by this invention, the same parameters, terms, logic, etc. should be understood to have the same meaning, and this application does not intentionally repeat the description in each embodiment.
[0216] Exemplary embodiments of the present disclosure have been specifically shown and described above. It should be understood that the present disclosure is not limited to the detailed structures, arrangements, or implementation methods described herein; rather, the present disclosure is intended to cover various modifications and equivalent arrangements contained within the spirit and scope of the appended claims.
Claims
1. A color extraction method for an electronic device display screen, characterized in that, The method includes: Acquire the image within a defined area on the display screen; Perform RGB sampling on the image to obtain the RGB values of all sampling points; The RGB values are categorized and statistically analyzed to determine multiple color ranges; Select at least one primary color range from the plurality of color ranges; The target RGB value is determined based on all RGB values within the at least one primary color interval; The color range includes a color value range and a non-color value range, and the step of classifying and statistically analyzing the RGB values to determine multiple color ranges includes: Convert the RGB value of each sampling point to the corresponding HSV value; The brightness value V of the HSV value is compared with a first threshold, and the saturation value S of the HSV value is compared with a second threshold. When the brightness value V is less than the first threshold and / or the saturation value S is less than the second threshold, the corresponding RGB value is classified into the non-color value range. When the brightness value V is greater than or equal to the first threshold and the saturation value S is greater than or equal to the second threshold, the corresponding RGB value is assigned to the corresponding color value range based on the hue value H.
2. The method as described in claim 1, characterized in that, The step of selecting at least one primary color range from the plurality of color ranges includes: The sum of the R, G, and B values of all RGB values in each color interval and the number of samples are weighted to obtain the weighted RGB statistics and weighted number of samples for the corresponding color interval. The color range that meets the set requirements for weighted sampling number is selected as the main color range.
3. The method as described in claim 2, characterized in that, The selection of color ranges whose weighted sampling number meets the set requirements as the main color range includes: For the given color value range, the maximum weighted sampling number among all color value ranges is calculated; The range with a weighted sample number greater than the maximum weighted sample number by a certain percentage is selected as the main color range; For the non-color value range, calculate the total weighted sample count for all color ranges; The range where the weighted sample count reaches a certain percentage of the total weighted sample count is selected as the main color range.
4. The method as described in claim 3, characterized in that, The weighted processing of the sum of the R, G, and B values and the number of samples of all RGB values in each color range includes: Count the number of sampling points in color interval i to obtain the number of samples count(i), and calculate the sum of R values red(i), the sum of G values green(i), and the sum of B values blue(i) based on all RGB values in color interval i. Based on the interval weight coefficient w(i), the number of samples count(i) in color interval i, the sum of R values red(i), the sum of G values green(i), and the sum of B values blue(i) are weighted respectively.
5. The method as described in claim 4, characterized in that, Let the weighted sums of R, G, and B values for color interval i be red(i)', green(i)', and blue(i)', respectively, and let the weighted sample count for color interval i be count(i)', then: count(i) ´= count(i)×w(i); red(i) ´ = red(i)×w(i); green(i) ´ = green(i)×w(i); blue(i) ´ = blue(i)×w(i).
6. The method as described in claim 4, characterized in that, The weight coefficient w(i) of color interval i is linearly related to the hue value H of the corresponding interval, and the interval weight coefficient w(i) decreases linearly from warm colors to cool colors.
7. The method as described in claim 4, characterized in that, The interval weight coefficient w(i) is calculated using the following formula: w(i) = abs(h(i)﹣180) / 180·(w(max)﹣w(min))﹢w(min); Where h(i) represents the reference hue value H of interval i, w(max) represents the preset maximum weight coefficient, and w(min) represents the preset minimum weight coefficient.
8. The method as described in claim 4, characterized in that, Determining the target RGB value based on all RGB values within the at least one primary color interval includes: All weighted RGB statistical values within the at least one primary color range are mixed in a certain proportion to form the target RGB value.
9. A lighting control method, characterized in that, It uses the target RGB value obtained by the color extraction method according to any one of claims 1-8 to control the lighting device, so that the screen display content of the electronic device is synchronized with the lighting device to create an environmental atmosphere.
10. A non-transitory computer-readable storage medium having stored thereon program instructions that, when executed by one or more processors, enable the one or more processors to implement the color extraction method of any one of claims 1-8 or the lighting control method of claim 9.
11. An electronic device, characterized in that, It employs the color extraction method of any one of claims 1-8 or the lighting control method of claim 9, or includes the non-transitory computer-readable storage medium of claim 10.
Citation Information
Patent Citations
Image data processing method and device, electronic equipment and storage medium
CN114266838A