Image processing method, image processing device, terminal and readable storage medium
By converting the image to LAB color space and for clustering, it solves the problem of the theme color that is difficult to generate in the existing technology, and realizes the theme color with clear color and distinct features.
Patent Information
- Application Number
- CN202210369140.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-08
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2042-04-08
Smart Images

Figure CN114723602B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image processing method, an image processing device, a terminal and a non-volatile computer-readable storage medium. Background Art
[0002] Image theme colors are multiple colors extracted from an image that best represent the main color of the image. That is to say, in a colorful image, the number of different colors corresponds to the proportion of the color in the image. The theme color is calculated by counting the number of pixels of different colors in the image. The main color of the color watermark (palette) is often not simply the RGB value that appears most frequently. It should conform to the habits of the human eye and be the visual focus. Summary of the invention
[0003] Embodiments of the present application provide an image processing method, an image processing device, a terminal, and a non-volatile computer-readable storage medium for generating a theme color that conforms to human eye perception.
[0004] The image processing method of the embodiment of the present application includes: converting the image to be processed into the LAB color space to obtain a first image; clustering the first image to obtain multiple clustering results; and obtaining a theme color based on the multiple clustering results and the sum of the color differences corresponding to each clustering result.
[0005] The image processing device of the embodiment of the present application includes: a first acquisition module, used to convert the image to be processed into the LAB color space to obtain a first image; a clustering module, used to cluster the first image to obtain multiple clustering results; and a color acquisition module, used to obtain a theme color based on the multiple clustering results and the sum of the color differences corresponding to each clustering result.
[0006] The terminal of the embodiment of the present application includes: one or more processors, a memory; and one or more programs, wherein the one or more programs are stored in the memory and executed by the one or more processors, and the program includes instructions for the image processing method of the embodiment of the present application. The image processing method of the embodiment of the present application includes: converting the image to be processed into the LAB color space to obtain a first image; clustering the first image to obtain multiple clustering results; and obtaining the theme color according to the multiple clustering results and the sum of the color differences corresponding to each clustering result. .
[0007] The non-volatile computer-readable storage medium containing a computer program according to an embodiment of the present application, when the computer program is executed by one or more processors, enables the processors to implement instructions of the image processing method according to the embodiment of the present application. The image processing method includes: converting the image to be processed into the LAB color space to obtain a first image; performing clustering processing on the first image to obtain a plurality of clustering results; and obtaining a theme color according to the plurality of clustering results and the sum of the color differences corresponding to each of the clustering results.
[0008] The image processing method, image processing device, terminal and non-volatile computer-readable storage medium of the embodiment of the present application perform clustering processing by converting the image to be processed into the LAB color space, and obtain the theme color according to the sum of the color differences corresponding to the clustering results. The LAB color space is the color space that best fits the visual perception of the human eye. Clustering processing in the LAB color space can make the colors corresponding to the clustering results conform to the perception of the human eye, so as to generate a theme color that conforms to the perception of the human eye.
[0009] Additional aspects and advantages of the embodiments of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:
[0011] Figure 1 is a flowchart of an image processing method of certain embodiments of the present application;
[0012] Figure 2 is a schematic diagram of the structure of an image processing device in some embodiments of the present application;
[0013] Figure 3 is a schematic diagram of the structure of a terminal in some implementation modes of the present application;
[0014] Figure 4 is a flowchart of an image processing method of certain embodiments of the present application;
[0015] Figure 5 is a flowchart of an image processing method of certain embodiments of the present application;
[0016] Figure 6 is a flowchart of an image processing method of certain embodiments of the present application;
[0017] Figure 7 is a schematic diagram of the center point position of the image processing method in certain embodiments of the present application;
[0018] Figure 8is a schematic diagram of a clustering scene of an image processing method in certain embodiments of the present application;
[0019] Fig. 9 is a flowchart of an image processing method of certain embodiments of the present application;
[0020] Fig.10 is a schematic diagram of a clustering scene of an image processing method in certain embodiments of the present application;
[0021] Fig.11 is a schematic diagram of a clustering scene of an image processing method in certain embodiments of the present application;
[0022] Fig.12 is a schematic diagram of a clustering scene of an image processing method in certain embodiments of the present application;
[0023] Fig.13 is a flowchart of an image processing method of certain embodiments of the present application;
[0024] Fig.14 is a schematic diagram of a clustering scene of an image processing method in certain embodiments of the present application;
[0025] Fig.15 is a flowchart of an image processing method of certain embodiments of the present application;
[0026] Fig.16 is a flowchart of an image processing method of certain embodiments of the present application;
[0027] Fig.17 is a schematic diagram of a YUV image and a corresponding color watermark in certain embodiments of the present application;
[0028] Fig.18 It is a schematic diagram of the connection relationship between the computer-readable storage medium and the processor in certain embodiments of the present application. DETAILED DESCRIPTION
[0029] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals represent the same or similar elements or elements having the same or similar functions from beginning to end. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the embodiments of the present application, and cannot be understood as limiting the embodiments of the present application.
[0030] See also Figure 1 , the embodiment of the present application provides an image processing method. The image processing method includes:
[0031] 02: Convert the image to be processed into the LAB color space to obtain a first image;
[0032] 03: performing clustering processing on the first image to obtain multiple clustering results; and
[0033] 04: Get the theme color based on multiple clustering results and the sum of the color differences corresponding to each clustering result.
[0034] See also Figure 2 , the embodiment of the present application also provides an image processing device 10. The image processing device 10 includes a first acquisition module 11, a clustering module 13 and a color acquisition module 14. The first acquisition module 11 is used to implement the method in 02. The clustering module 13 is used to implement the method in 03. The color acquisition module 14 is used to implement the method in 04. That is, the first acquisition module 10 is used to convert the image to be processed into the LAB color space to obtain a first image. The clustering module 13 is used to perform clustering processing on the first image to obtain multiple clustering results. The color acquisition module 14 is used to obtain the theme color according to multiple clustering results and the sum of the color differences corresponding to each clustering result.
[0035] See also Figure 3 The present application also provides a terminal 100. The terminal 100 may be a mobile phone, a desktop computer, a laptop computer, a server, a smart home appliance, a smart wearable device, a game console, a digital camera, etc., which are not listed here one by one. The terminal 100 includes one or more processors 80, a memory 90 and one or more programs. One or more programs are stored in the memory 90 and executed by one or more processors 80. Figure 1 The program includes instructions for executing the image processing method of the embodiment of the present application. That is, the program includes instructions for executing the methods in 02, 03 and 04.
[0036] The image theme color is a plurality of colors extracted from an image that best represent the main color tone of the image. In the embodiment of the present application, the image to be processed and the first image are the representations of the same frame image in different color spaces. The image processing method, image processing device 10 and terminal 100 of the embodiment of the present application perform clustering processing by converting the image to be processed into the LAB color space, and obtain the theme color according to the sum of the color differences corresponding to the clustering results.
[0037] LAB color space is a color-opposition space, including three components: L, a, and b. , where dimension L represents brightness, a and b represent color opposition dimensions, a represents the component from green to red, and b represents the component from blue to yellow. LAB is designed based on people's perception of color. When the human eye is stimulated by light, it will produce three color sensations: the feeling of white to black, the feeling of red to green, and the feeling of yellow to blue. The three components of LAB color space, L, a, and b, are the color channels designed for these three visual sensations. If the amplitude of the changes in the three parameters L, a, and b are similar, then the amplitude of the visual changes it brings to people is also similar. Therefore, LAB color space is the color space that best fits the visual perception of the human eye. Clustering in LAB color space can make the colors corresponding to the clustering results conform to the perception of the human eye. Obtaining the theme color according to the sum of the color differences corresponding to the clustering results can reduce the gradient color in the theme color and obtain a theme color with distinct hue, distinct features, and visual focus.
[0038] The following is a further description with reference to the accompanying drawings.
[0039] The image to be processed may include images of various formats. In one embodiment, the image to be processed is an image in the LAB color space, and the image to be processed is used as the first image for subsequent processing.
[0040] See also Figure 4 In some embodiments, the image to be processed is an image in an XYZ color space, and pixels of the image to be processed include a first XYZ component, a second XYZ component, and a third XYZ component. 02: Converting the image to be processed into a LAB color space to obtain a first image, including:
[0041] 021: Obtain LAB three-channel values of pixels of the image to be processed according to the first XYZ component, the second XYZ component, the third XYZ component, the preset mapping relationship and the preset hyperparameters of the pixels of the image to be processed; and
[0042] 022: Obtain a first image according to the LAB three-channel value of each pixel of the image to be processed.
[0043] Please combine Figure 2 In some implementations, the first acquisition module 11 can also be used to implement the methods in 021 and 022, that is, the first acquisition module 11 can also be used to: acquire the LAB three-channel values of the pixels of the image to be processed according to the first XYZ component, the second XYZ component, the third XYZ component, the preset mapping relationship and the preset hyperparameters of the pixels of the image to be processed; and 022: acquire the first image according to the LAB three-channel values of each pixel of the image to be processed.
[0044] Please combine Figure 3In some implementations, the program also includes instructions for executing the methods in 021 and 022.
[0045] The XYZ color space is based on the RGB color system, using three ideal primary colors instead of the actual RGB primary colors. The XYZ color space includes X-axis, Y-axis, and Z-axis coordinate axes. The coordinate of a color on the X-axis represents the proportion of its red, the coordinate on the Y-axis represents the proportion of its green, and the coordinate on the Z-axis represents the proportion of its blue. The image pixel in the XYZ color space includes the first XYZ component, the second XYZ component, and the third XYZ component, which respectively represent the proportions of red, green, and blue of the pixel. The following explanation assumes that the first XYZ component is X, the second XYZ component is Y, and the third XYZ component is Z.
[0046] Assuming that the channel values of the three channels L, A, and B of the LAB color space are L*, a*, and b* respectively, the image to be processed in the XYZ color space can be converted into the first image in the LAB color space using the following formulas 1, 2, and 3.
[0047] Formula 1:
[0048] Formula 2:
[0049] Formula 3:
[0050] in, X n , Y n , Z n is a hyperparameter. In one embodiment, X n The value of Y is 95.047. n The value of Z is 100.000. n The value of is 108.883 to accurately obtain the mapping from XYZ color space to LAB color space.
[0051] As shown in Formula 1, L* in the LAB color space represents brightness, while brightness in the XYZ color space is represented by the value of the Y component. Formula 1 links the brightness relationship between the LAB color space and the XYZ color space to obtain the L* channel value in the LAB color space.
[0052] As shown in Formula 2, a* in LAB color space represents the component from green to red, while the X component in XYZ color space represents the proportion of red and the Y component represents the proportion of green. Formula 2 links the red-green relationship of LAB color space and XYZ color space to obtain the a* channel value in LAB color space.
[0053] As shown in Formula 3, b* in the LAB color space represents the component from blue to yellow, while the Z component in the XYZ color space represents the proportion of blue and the Y component represents the proportion of green, and green is close to yellow. Formula 3 links the blue-green relationship of the LAB color space and the XYZ color space to obtain the b* channel value in the LAB color space.
[0054] See also Figure 1 In some embodiments, the image to be processed is an image in the RGB color space, which is a color space based on the three primary colors of red, green, and blue. Converting the image in the RGB color space to the LAB color space requires the use of the XYZ color space as a medium. Assuming that the pixel value ranges of the three color channels of the image to be processed in R, G, and B are all [0, 255], and the value range is set to range, the following formula 4 can be used to obtain the first image in the XYZ color space according to the image to be processed in the RGB color space.
[0055] Formula 4:
[0056] in,
[0057] After finishing, we can get:
[0058] In this way, the corresponding X, Y, and Z component values in the XYZ color space can be determined according to the pixel values of the three color channels of the image to be processed, R, G, and B, so as to obtain the corresponding first image.
[0059] In some embodiments, since the conversion relationship between the XYZ color space and the LAB color space is relatively clear, an image to be processed in any color space can be converted into an image in the XYZ color space, and then converted into the LAB color space to obtain a first image.
[0060] See also Figure 5 In some embodiments, the image processing method further comprises:
[0061] 05: Get YUV image;
[0062] 06: Downsample the YUV image to obtain a second image;
[0063] 07: Convert the second image into an RGB color space to obtain a third image; and
[0064] 08: Convert the third image into an XYZ color space to obtain an image to be processed.
[0065] Please combine Figure 2In some embodiments, the image processing device 10 further includes a second acquisition module 12, a third acquisition module 15, a downsampling module 16 and a fourth acquisition module 17. The second processing module 12 is used to implement the method in 05. The downsampling module 16 is used to implement the method in 06. The third acquisition module 15 is used to implement the method in 07. The fourth acquisition module 17 is used to implement the method in 08. That is, the second processing module 12 is used to acquire a YUV image. The downsampling module 16 is used to downsample the YUV image to acquire a second image. The third acquisition module 15 is used to convert the second image into an RGB color space to acquire a third image. The fourth acquisition module 17 is used to convert the third image into an XYZ color space to acquire an image to be processed. Please refer to Figure 3 In some implementations, the program also includes instructions for executing the methods in 05, 06, 07 and 08.
[0066] Usually, the image captured by a mobile phone or camera is a YUV image. According to the methods in 05, 06, 07, and 08, the YUV image can be converted into an image in the RGB color space for subsequent image processing. Downsampling the YUV image can increase the speed of subsequent image processing and reduce the time the user waits for the theme color to be generated. In one embodiment, the YUV image is reduced by 16 times to obtain the third image. In other embodiments, it can also be reduced by 8 times, 4 times, 2 times, 32 times, etc., which are not listed here one by one.
[0067] In some embodiments, the second image may be converted into an RGB color space according to the following formula 5 to obtain a third image.
[0068] Formula 5:
[0069] Among them, Y, C b , C γ are components of three channels of the third image in the YUV color space, and R, G, and B are components of three channels corresponding to the third image after conversion to the RGB color space.
[0070] The third image is an image in the RGB color space. Please combine Formula 4 to convert the third image in the RGB color space into the image to be processed in the XYZ color space. Combine Formula 1, Formula 2, and Formula 3 to convert the image to be processed in the XYZ color space into the first image in the LAB color space for processing.
[0071] See also Figure 6 In some embodiments, 03: performing clustering processing on the first image to obtain a plurality of clustering results, including:
[0072] 031: Determine a plurality of center points in the first image according to the number of color categories, each center point corresponding to a color category;
[0073] 032: Obtain the first color value of each color category and the second color value of each pixel in the first image;
[0074] 033: classify the pixel into a corresponding color category according to a difference between the second color value of each pixel and the first color value of each color category;
[0075] 034: Obtain the average value of the second color value of each pixel in each color category; and
[0076] 035: Update the center point and the first color value corresponding to each color category according to the average value corresponding to each color category.
[0077] Please combine Figure 2 In some implementations, the clustering module 13 can also be used to implement the methods in 031, 032, 033, 034 and 035, that is, the clustering module 13 can also be used to: obtain the first color value of each color category and the second color value of each pixel in the first image; divide the pixel into the corresponding color category according to the difference between the second color value of each pixel and the first color value of each color category; obtain the average value of the second color value of each pixel in each color category; and update the center point and the first color value corresponding to each color category according to the average value corresponding to each color category. Please combine Figure 3 In some implementations, the program also includes instructions for executing the methods in 031, 032, 033, 034 and 035.
[0078] In some embodiments, the number of color categories is twice the target number of theme colors. The target number of theme colors is a preset value, which indicates how many colors are used to reflect the main color tone of an image. For example, if the number of theme colors is 5, it means that 5 different colors are used to reflect the main color tone of an image. The number of clustering results is the same as the number of color categories, that is, the number of clustering results can be obtained as many as the number of color categories. Figure 1, the number of color categories is twice the number of theme colors, that is, the number of clustering results is twice the number of theme colors. In this way, when obtaining theme colors based on multiple clustering results and the sum of color differences corresponding to each clustering result, suitable colors can be screened out from the colors corresponding to the multiple clustering results as theme colors. For example, colors with similar color differences in multiple clustering results are screened out so that there are obvious differences between the theme colors finally obtained, and a bright theme color is obtained. In other embodiments, the number of color categories is not limited to twice the target number of theme colors, and can be any number greater than the target number of theme colors. For example, the number of color categories is 1, 2, 3, etc. more than the target number of theme colors. For another example, the number of color categories is 3, 4, 5, etc. times the target number of theme colors, which are not listed here one by one.
[0079] Please combine Figure 7 , the center point is a position point selected in the first image, and the image can be an image to be processed in the RGB color space, or an initial image in other color spaces, which is not limited here. Figure 5 In the illustrated embodiment, the target number of theme colors is 5, the number of color categories is 10, and the number of center points is 10. When determining the center point, the image is divided into 4 parts horizontally by 3 dividing lines, and the image is divided into 4 parts vertically by another 3 dividing lines. Among the intersections D1, D2, D3, D4, D5, D6, D7, D8, and D9 formed by the above 6 dividing lines, the intersections D1, D2, D3, D4, D5, D7, D8, and D9 are set as center points, and the midpoint D10 between the intersection D4 and the intersection D5, and the midpoint D11 between the intersection D6 and the intersection D5 are set as center points, so as to obtain 10 center points. In other embodiments, the distribution of the center points may not be limited to Figure 5 The illustrated distribution method is not limited here. For example, in another embodiment, the center points are evenly distributed in the image.
[0080] The clustering process is to divide each pixel in the first image into the color classification with the closest color according to color. Among them, the first color value is the color corresponding to the position where the center point is located, and the first color value is reflected by the L*, A*, and B* channel values. For example, let the first color value corresponding to the center point Ai be Yai = (Li*, Ai*, Bi*). The second color value is the color corresponding to the position where the pixel is located, and the second color value is reflected by the L*, A*, and B* channel values. For example, let the second color value corresponding to the pixel point Pj be Ypj = (Lj*, Aj*, Bj*). The difference value reflects the color difference between the first color value Yai and the second color value Ypj. The smaller the difference value, the closer the color corresponding to the first color value Yai and the color corresponding to the second color value Ypj are. In the clustering process, each pixel point Pj is divided into the color classification where the center point Ai with the closest color is located.
[0081] Taking pixel P1 as an example, obtain the difference value between pixel P1 and each center point Ai to determine the cluster closest to the color of pixel P1. Assume that the difference value between the color corresponding to pixel P1 and center point A2 is the smallest, and center point A2 corresponds to color category S2, then pixel P1 is classified into color category S2. Similarly, obtain the difference value between each pixel Pj and each center point Ai to determine the color category Sk corresponding to each pixel Pj, k∈[1,i].
[0082] See also Figure 8 As an example, the first image has a central point A1 and a central point A2 that have been determined, corresponding to color category S1 and color category S2 respectively. Figure 6 In the example of , other pixels in the first image are omitted, and the clustering of pixels P1, P2, P3, P4, P5, and P6 is described. Assuming that the pixels with the smallest difference between the colors corresponding to the center point A1 are P1, P2, and P3, and the pixels with the smallest difference between the colors corresponding to the center point A2 are P4, P5, and P6, then P1, P2, and P3 are classified into color category S1, and P4, P5, and P6 are classified into color category S2. Figure 6 In the figure, the upper side of the dividing line O1 is the color category S1, and the lower side of the dividing line O1 is the color category S2.
[0083] After a division, the average value of the second color value Ypj of each pixel point Pj in each color classification Sk is obtained, and the center point Ai and the first color value Yai corresponding to each color classification Sk are updated according to the average value corresponding to each color classification Sk. In this way, the average value of the second color value Ypj of the pixel point Pj contained in the color classification Sk after division is used as the first color value Yai corresponding to the color classification Sk, which can more accurately represent the overall color characteristics of the color classification Sk after division. The updated center point Ai is the position point corresponding to the updated first color value Yai in the LAB color space.
[0084] See also Figure 8 As an example, assume that the average value of the second color value Ypj of each pixel point Pj in each color classification Sk is Ydk. After one division, the average value of the second color values Yp1, Yp2, and Yp3 of the pixel points P1, P2, and P3 in the color classification S1 is Yd1, and Yd1 is used as the value of the first color value Ya1 of the updated color classification S1, and the center point corresponding to the updated color classification S1 is A3; the average value of the second color values Yp4, Yp5, and Yp6 of the pixel points P4, P5, and P6 in the color classification S2 is Yd2, and Yd2 is used as the value of the first color value Ya2 of the updated color classification S2, and the center point corresponding to the updated color classification S1 is A4.
[0085] See also Fig. 9 In some embodiments, 03: performing clustering processing on the first image to obtain a plurality of clustering results, further comprising:
[0086] 036: classify the pixel into a corresponding color category according to a difference between the second color value of each pixel and the updated first color value of each color category;
[0087] 037: When the number of updates of the center point corresponding to the color classification reaches a preset number threshold, the clustering process is terminated, and the first color value corresponding to the center point is output as the clustering result; or
[0088] 038: When the center point corresponding to the color classification remains unchanged before and after the update, the clustering process is terminated, and the first color value corresponding to the center point is output as the clustering result.
[0089] Please combine Figure 2In some implementations, the clustering module 13 can also be used to implement the method in 036, 037 or 038, that is, the clustering module 13 can also be used to: classify the pixels into corresponding color categories according to the difference between the second color value of each pixel and the first color value of each color category after update; terminate the clustering process when the update times of the center point corresponding to the color category reaches a preset times threshold, and output the first color value corresponding to the center point as the clustering result; or terminate the clustering process when the center point corresponding to the color category remains unchanged before and after the update, and output the first color value corresponding to the center point as the clustering result. Please combine Figure 3 In some implementations, the program also includes instructions for executing the method in 026, 027 or 028.
[0090] Please combine Figure 8 , Fig.10 ,and Fig.11 After completing the update of the center point Ai and the first color value Yai, the second color value Ypj of each pixel point Pi is clustered again according to the updated first color value Yai of each color classification Sk, until the number of updates of the center point Ai reaches the preset number threshold, or the clustering is terminated when the updated first color value Yai is the same as the first color value Yai before the update. Ending clustering means accepting the first color value Yai corresponding to the color classification Sk as the clustering result, that is, accepting the first color value Yai as the representative color representing the color classification Sk.
[0091] See also Figure 8 , Fig.10 and Fig.11 , Fig.10 is Figure 8 The next clustering is based on the clustering of . Assume that in this clustering: the pixels with the smallest color difference values corresponding to the center point A3 are P1, P2, and P4, and the pixels with the smallest color difference values corresponding to the center point A2 are P3, P5, and P6, then P1, P2, and P4 are classified into color category S1, and P3, P5, and P6 are classified into color category S2. Fig.10 In the figure, the color category S1 is on the left side of the dividing line O1, and the color category S2 is on the right side of the dividing line O1. Fig.11 As shown, after dividing and updating the center point, the center point of color classification S1 is A5, and the corresponding value Yd1 of the first color value Ya1 is the average value of the second color values Yp1, Yp2, and Yp4 of the pixel points P1, P2, and P4; the center point of color classification S2 is A6, and the corresponding value Yd2 of the first color value Ya2 is the average value of the second color values Yp3, Yp5, and Yp6 of the pixel points P3, P5, and P6.
[0092] Please combine Fig.12, Fig.12 is Fig.11 The next clustering is performed based on the clustering of . Assume that after this clustering, the center point of color classification S1 is updated to A7, and the center point of color classification S2 is updated to A8. In one embodiment, the position of A7 in the LAB color space is the same as the position of A5 in the color space, and the position of A8 in the LAB color space is the same as the position of A6 in the color space, then the clustering is terminated, and the first color value Ya1 corresponding to color classification S1 and the first color value Ya2 corresponding to color classification S2 after this clustering are output as clustering results. In another embodiment, the position of A7 in the LAB color space is different from the position of A5 in the color space, and the position of A8 in the LAB color space is different from the position of A6 in the color space, but the number of updates of the center point has reached the preset number threshold, then the clustering is terminated, and the first color value Ya1 corresponding to color classification S1 and the first color value Ya2 corresponding to color classification S2 after this clustering are output as clustering results.
[0093] See also Fig.13 In some embodiments, 033: classifying the pixel points into corresponding color categories according to the difference between the second color value of each pixel point and the first color value of each color category, including:
[0094] 0331: Get the first LAB component of the first color value and the second LAB component of the second color value;
[0095] 0332: Obtain a hue rotation item, a brightness compensation value, a chroma compensation value and a hue compensation value according to the first LAB component and the second LAB component;
[0096] 0333: Obtain a difference value according to the first LAB component, the second LAB component, the hue rotation item, the brightness compensation value, the chroma compensation value and the hue compensation value; and
[0097] 0334: Select a minimum difference value from a plurality of difference values between the second color value of the pixel point and a plurality of first color values, and classify the pixel point into a color category corresponding to the minimum difference value.
[0098] Please combine Figure 2In some implementations, the clustering module 13 can also be used to implement the methods in 0331, 0332, 0333 and 0334, that is, the clustering module 13 can also be used to: obtain the first LAB component of the first color value and the second LAB component of the second color value; obtain the hue rotation item, the brightness compensation value, the chromaticity compensation value and the hue compensation value according to the first LAB component and the second LAB component; obtain the difference value according to the first LAB component, the second LAB component, the hue rotation item, the brightness compensation value, the chromaticity compensation value and the hue compensation value; and select the minimum difference value among the multiple difference values between the second color value of the pixel point and the multiple first color values, and classify the pixel point into the color category corresponding to the minimum difference value. Please combine Figure 3 In some implementations, the program also includes instructions for executing the methods in 0231, 0232, 0233, and 0234.
[0099] Please combine Fig.14 , let the first color value of the center point A1 be Ya1=(L1, a1, b1), the first color value of the center point A2 be Ya2=(L2, a2, b2), the second color value of the pixel point P1 be Yp1=(L1 * , a1 * , b1 * ), the difference between the center point A1 and the pixel point P1 is E1, and the difference between the center point A2 and the pixel point P1 is E2. The difference value E1 can be calculated by the following formula 6:
[0100] Formula 6:
[0101] Among them, K L , K C , K H are all preset values. In one embodiment, K L , K C , K H The value of is 1.
[0102] △L=L1-L1 * , △C=C1-C2,
[0103]
[0104]
[0105]
[0106] h1=atan2(b1,a1)mod360°,h2=atan2(b1 * , a1 * )mod360°;
[0107]
[0108]
[0109]
[0110]
[0111] Among them, R T As the hue rotation term, the hue rotation term R is introduced T The difference value E1 can better adapt to the blue area near the hue angle 275° to avoid inaccurate differences in the blue area. L S is the brightness compensation value, so that the difference value E1 can accurately reflect the brightness difference. C S is the chromaticity compensation value, so that the difference value E1 can accurately reflect the chromaticity difference. H is the hue compensation value, so that the difference value E1 can accurately reflect the hue difference. Similar to the method of calculating the difference value E1, the components L1, a1, b1 in formula five are replaced by L2, a2, b2 to calculate the calculated difference value E2. After calculating the difference value E1 and the difference value E2 respectively, the pixel point P1 is divided into the color category corresponding to the smallest difference value between the difference value E1 and the difference value E2. For example, if E1<E2, the pixel point P1 is divided into the color category S1. Similarly, when the number of center points is i, the difference value Ek between the second color value Yp1 of the pixel point P1 and each first color value Yai is calculated respectively, and the pixel point P1 is divided into the color category Skmin corresponding to the minimum difference value Ekmin. Wherein, k∈[1, i]. By analogy, each pixel point Pj can be divided into the corresponding color category Sk.
[0112] After obtaining the clustering results, n clustering results with the largest sum of color differences with other clustering results are selected from the clustering results to generate n theme colors, so as to ensure that the multiple theme colors are distinct and representative, and avoid selecting gradient colors with similar colors as theme colors.
[0113] See also Fig.15 In some embodiments, 04: obtaining a theme color according to a plurality of clustering results and the sum of color differences corresponding to each clustering result, including:
[0114] 041: Obtain the sum of color differences corresponding to each clustering result respectively; and
[0115] 042: Obtain the first n clustering results in descending order of the total color difference and generate n theme colors respectively, where the value of n is the target number of theme colors.
[0116] Please combine Figure 2In some implementations, the color acquisition module 14 can also be used to implement the methods in 041 and 042, that is, the clustering module 13 can also be used to: respectively obtain the color difference sum corresponding to each clustering result; and obtain the first n clustering results in descending order of the color difference sum to generate n theme colors respectively, where n is the target number of theme colors. Figure 3 In some implementations, the program also includes instructions for executing the methods in 041 and 042.
[0117] In some embodiments, let the clustering result be Jm, the color difference sum corresponding to the clustering result Jm be Zm, let m=6, that is, 6 clustering results are obtained after clustering, n=3, that is, 3 theme colors are generated. First, the clustering result Jm is mapped back to the RGB color space to obtain the RGB color value Um corresponding to the clustering result Jm, and the color difference sum Zm of the color value Um is the sum of each color difference between the color value Um and other color values. For example, please refer to the following table:
[0118]
[0119]
[0120] The numbers where the horizontal and vertical coordinates intersect represent the color difference between the color value on the horizontal axis and the color value on the vertical axis. For example, the color difference between color value U1 and color value U1 is 0, and the color difference between color value U1 and color value U2 is 1. The final statistics Z1, Z2, Z3, Z4, Z5, and Z6 are the sum of the color differences corresponding to color values U1, U2, U3, U4, U5, and U6, respectively. The color difference sum Z6 is the largest, indicating that the color difference between color value U6 corresponding to cluster result J6 and the color value corresponding to each other cluster result is the largest; the color difference sum Z1 is the smallest, indicating that the color difference between color value U1 corresponding to cluster result J1 and the color value corresponding to each other cluster result is the smallest. When n=3, the first three clustering results with the largest sum of color differences are taken to generate the theme color. In this example, the first three clustering results with the largest sum of color differences are clustering result J6, clustering result J5, and clustering result J4, respectively. The color values U6, U5, and U4 corresponding to clustering result J6, clustering result J5, and clustering result J4, respectively, are used as the theme colors. In other embodiments, after obtaining the first n clustering results with the largest sum of color differences, it is not limited to using the color values in the RGB color space corresponding to the clustering results as the theme color, and it can also be color values in other color spaces, such as color values in the HSV color space, color values in the LAB color space, color values in the YUV space, etc., which are not limited here.
[0121] See also Fig.16 In some embodiments, the image processing method further comprises:
[0122] 09: Convert the third color value corresponding to the theme color into the YUV color space to generate a color watermark; and
[0123] 010: Sort the color watermarks according to the brightness value of the third color value and display them together with the YUV image.
[0124] Please combine Figure 2 In some embodiments, the image processing device 10 further includes a watermark generation module 18 and a sorting module 19. The watermark generation module 18 is used to implement the method in 09. The sorting module 19 is used to implement the method in 010. That is, the watermark generation module 18 is used to convert the third color value corresponding to the theme color into the YUV color space to generate a color watermark. The sorting module 19 is used to sort the color watermarks according to the brightness value of the third color value and display them together with the YUV image. Please combine Figure 3 In some implementations, the program also includes instructions for executing the methods in 09 and 010.
[0125] The third color value is the color value corresponding to the theme color in the RGB color space. The color watermark is usually displayed on a display screen of a terminal 100 such as a mobile phone, a camera, or a computer. The image obtained by photographing an object by such a terminal 100 is usually a YUV image. Therefore, generating a color watermark in a YUV format can facilitate the use of the color watermark to edit the YUV image stored in the terminal 100.
[0126] In one embodiment, according to the above formulas 1 to 5, the YUV image of the terminal device is converted into an RGB color space image, an XYZ color space image, and a LAB color space image in sequence for corresponding processing. The theme color can be generated according to the LAB color space image corresponding to the YUV image, and then the third color value corresponding to the theme color is converted back to the YUV color space to generate a color watermark corresponding to the YUV color space and sort it.
[0127] Please combine Fig.17 The sorted color watermarks are displayed together with the YUV image, so that the user can intuitively see the color watermarks that match the color theme of the YUV image. In some embodiments, the user can use the color watermark to create a personal homepage, filter the color tones of the picture, and enhance the immersive interactive experience of the user when browsing pictures.
[0128] In one embodiment, in order to meet the visual effect of the human eye, after the color watermark is generated, the color watermark is sorted according to the brightness value of the third color value, so that the color watermark seen by the user is arranged from light to dark or from dark to light, with a beautiful visual effect.
[0129] See also Fig.17The embodiment of the present application further provides a non-volatile computer-readable storage medium 800 containing a computer program 801. When the computer program 801 is executed by one or more processors 80, the processor 80 can execute the adjustment method of any of the above embodiments, for example, implement one or more steps of steps 01, 02, and 03.
[0130] For example, when the computer program 801 is executed by one or more processors 80, the processor 80 performs the following steps:
[0131] 02: Convert the image to be processed into the LAB color space to obtain a first image;
[0132] 03: performing clustering processing on the first image to obtain multiple clustering results; and
[0133] 04: Get the theme color based on multiple clustering results and the sum of the color differences corresponding to each clustering result.
[0134] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples" or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiments or examples are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, a technician in the field may combine and combine different embodiments or examples described in this specification and features of different embodiments or examples, unless they are contradictory.
[0135] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in the reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.
[0136] Although the embodiments of the present application have been shown and described above, it is to be understood that the above embodiments are exemplary and cannot be construed as limitations on the present application. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present application.
Claims
1. An image processing method, characterized in that: include: Converting the image to be processed into the LAB color space to obtain a first image; Performing clustering processing on the first image to obtain multiple clustering results; and Obtaining a theme color according to the plurality of clustering results and the sum of the color differences corresponding to each clustering result; The image processing method further comprises: Get YUV image; Downsampling the YUV image to obtain a second image; converting the second image into an RGB color space to obtain a third image; and The third image is converted into an XYZ color space to obtain the image to be processed.
2. The image processing method according to claim 1, characterized in that: The pixels of the image to be processed include a first XYZ component, a second XYZ component, and a third XYZ component. The step of converting the image to be processed into a LAB color space to obtain a first image includes: Acquire LAB three-channel values of pixels of the image to be processed according to the first XYZ component, the second XYZ component, the third XYZ component, a preset mapping relationship, and a preset hyperparameter of the pixels of the image to be processed; and The first image is acquired according to the LAB three-channel value of each pixel of the image to be processed.
3. The image processing method according to claim 1, characterized in that: The clustering process is performed on the first image to obtain a plurality of clustering results, including: Determining a plurality of center points in the first image according to the number of color categories, each center point corresponding to one color category; Obtaining a first color value of each color category and a second color value of each pixel in the first image; Classifying the pixel points into the corresponding color classification according to the difference between the second color value of each pixel point and the first color value of each color classification; Obtaining an average value of the second color values of each of the pixels in each color category; and The center point and the first color value corresponding to each color category are updated according to the average value corresponding to each color category.
4. The image processing method according to claim 3, characterized in that: The clustering process of the first image to obtain a plurality of clustering results further includes: Classifying the pixel points into the corresponding color classification according to the difference between the second color value of each pixel point and the first color value updated for each color classification; When the number of updates of the center point corresponding to the color classification reaches a preset number threshold, the clustering process is terminated, and the first color value corresponding to the center point is output as the clustering result; or The clustering process is terminated when the center point corresponding to the color classification remains unchanged before and after the updating, and the first color value corresponding to the center point is output as the clustering result.
5. The image processing method according to claim 3, characterized in that: The number of color categories is twice the target number of theme colors.
6. The image processing method according to claim 3, characterized in that: The step of classifying the pixel points into the corresponding color classification according to the difference between the second color value of each pixel point and the first color value of each color classification includes: Obtain a first LAB component of the first color value and a second LAB component of the second color value; Acquire a hue rotation item, a brightness compensation value, a chroma compensation value, and a hue compensation value according to the first LAB component and the second LAB component; Acquire the difference value according to the first LAB component, the second LAB component, the hue rotation item, the brightness compensation value, the chromaticity compensation value, and the hue compensation value; and A minimum difference value among the plurality of difference values between the second color value of the pixel and the plurality of the first color values is selected, and the pixel is classified into the color category corresponding to the minimum difference value.
7. The image processing method according to claim 1, characterized in that: The obtaining of the theme color according to the plurality of clustering results and the sum of the color differences corresponding to each clustering result includes: Respectively obtain the color difference sum corresponding to each clustering result; and The first n clustering results are obtained in descending order of the sum of the color differences to generate n theme colors respectively, and the value of n is the target number of the theme colors.
8. The image processing method according to claim 1, characterized in that: The image processing method further comprises: Converting the third color value corresponding to the theme color into a YUV color space to generate a color watermark; and The color watermarks are sorted according to the brightness values of the third color values and displayed together with the YUV image.
9. An image processing device, characterized in that: include: A first acquisition module, used for converting the image to be processed into a LAB color space to acquire a first image; A clustering module, used for performing clustering processing on the first image to obtain multiple clustering results; and A color acquisition module, used for acquiring a theme color according to the plurality of clustering results and the sum of the color differences corresponding to each clustering result; The second acquisition module is used to acquire the YUV image; A downsampling module, used for downsampling the YUV image to obtain a second image; A third acquisition module, used for converting the second image into an RGB color space to acquire a third image; and The fourth acquisition module is used to convert the third image into an XYZ color space to acquire the image to be processed.
10. A terminal, characterized in that: The terminal comprises: one or more processors, memory; and One or more programs, wherein the one or more programs are stored in the memory and executed by the one or more processors, and the programs include instructions for executing the image processing method according to any one of claims 1 to 8.
11. A non-volatile computer-readable storage medium containing a computer program, which, when executed by one or more processors, enables the processors to implement instructions of the image processing method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Image main color recognition method and device, electronic equipment and storage medium
CN112509068A
Image processing method and device
CN114219733A