Method and terminal for analyzing color relation in image

By analyzing and replacing the subject color of the image to be tested, real-time analysis and display of image colors is achieved, and the problem of difficult real-time display of color changes in the existing technology is solved, which improves students' understanding and experience of color application.

CN120147439APending Publication Date: 2025-06-13FUJIAN TQ ONLINE INTERACTIVE INC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510171040.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-17
Publication Date
2025-06-13

AI Technical Summary

Technical Problem

Existing art teaching methods are difficult to show the impact of color changes on the overall atmosphere and emotional expression of the painting in real time, and digital teaching tools lack interactivity and real-timeness, making it difficult for students to intuitively understand the impact of color selection and matching on the rendering results of the painting.

Method used

By receiving the image to be tested, obtaining the subject color and its corresponding pixel points, performing harmony analysis and contrast analysis, displaying the analysis results, and allowing users to receive color replacement requests, replacing the subject color, and re-analyzing the changed image to realize real-time analysis and display of image colors.

Benefits of technology

Real-time analysis and display of colors in the image to be tested is realized, allowing users to experience the changes brought by different colors to the picture in real time, and improving their understanding and application ability of color expression.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120147439A_ABST
    Figure CN120147439A_ABST
Patent Text Reader

Abstract

The invention provides a method and terminal for analyzing a color relationship in an image, and the method comprises the steps: receiving a to-be-detected image, and obtaining at least two main body colors and pixel points corresponding to each main body color in the to-be-detected image; performing harmony analysis and contrast analysis on the to-be-detected image according to the main body color and the corresponding pixel point to obtain a first analysis result; receiving a color replacement request including a target subject color and a conversion color; replacing a target pixel point corresponding to the target main body color with the converted color to obtain a changed image; according to the unconverted main body color, the pixel point corresponding to the unconverted main body color, the conversion color and the pixel point corresponding to the conversion color, carrying out harmony degree analysis and contrast analysis on the change image to obtain a second analysis result; and displaying the first analysis result and the second analysis result. According to the invention, the main body color in the to-be-detected image can be replaced in real time, the change of the replaced image can be experienced, and the harmony and contrast after replacement can be analyzed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing, and particularly to a method and a terminal for analyzing color relationships in an image. Background Art

[0002] In the process of art teaching, color application is a very important part. Existing art teaching methods mainly rely on traditional classroom lectures and physical object displays, and students learn color application by observing and copying. However, this method has certain limitations, and it is difficult for teachers to display in real time the impact of color changes on the overall atmosphere and emotional expression of a painting. In addition, although some existing digital teaching tools can display colors, they lack interactivity and real-time nature, and it is difficult for students to intuitively understand the impact of color selection and matching on the presentation result of a painting through operations. Summary of the Invention

[0003] The technical problem to be solved by the present invention is: to provide a method and a terminal for analyzing color relationships in an image, and to realize real-time analysis and display of image colors.

[0004] A method for analyzing color relationships in an image, the method comprising: Receiving a to-be-tested image, and obtaining at least two main colors in the to-be-tested image and pixel points corresponding to each of the main colors; Performing harmony analysis and contrast analysis on the to-be-tested image according to the main colors and the pixel points corresponding to the main colors to obtain a first analysis result; Receiving a color replacement request, where the color replacement request includes a target main color and a conversion color; Replacing the target pixel points corresponding to the target main color with the conversion color to obtain a changed image; Performing harmony analysis and contrast analysis on the changed image according to the non-converted main colors, the pixel points corresponding to the non-converted main colors, the conversion color, and the pixel points corresponding to the conversion color to obtain a second analysis result; Displaying the first analysis result and the second analysis result.

[0005] To solve the above technical problem, another technical solution adopted by the present invention is: A terminal for analyzing color relationships in an image, comprising a memory, a processor, and a computer program stored on the memory and running on the processor, where when the processor executes the computer program, the following steps are implemented: Receiving a to-be-tested image, and obtaining at least two main colors in the to-be-tested image and pixel points corresponding to each of the main colors; Perform harmony analysis and contrast analysis on the image to be tested based on the main color and the pixel points corresponding to the main color to obtain a first analysis result; Receive a color replacement request, where the color replacement request includes a target main color and a conversion color; Replace the target pixel points corresponding to the target main color with the conversion color to obtain a changed image; Perform harmony analysis and contrast analysis on the changed image based on the un-converted main color, the pixel points corresponding to the un-converted main color, the conversion color, and the pixel points corresponding to the conversion color to obtain a second analysis result; Display the first analysis result and the second analysis result.

[0006] The beneficial effects of the present invention are as follows: For the received image to be tested, obtain the main color and the pixel points corresponding to the main color therein, and perform harmony analysis and contrast analysis on the main color and its corresponding pixel points to obtain a first analysis result, which can intuitively present the color application mode in the image to be tested; at the same time, it is allowed to receive a color replacement request, and after replacing the main color with the conversion color according to the color replacement request to obtain a changed image, re-analyze the harmony and contrast of the changed image. Then, on the basis of real-time displaying and analyzing the color usage of the image to be tested itself, it is also possible to replace the main color in the image to be tested in real time, experience the changes in the replaced image, and analyze the harmony and contrast after replacement, so as to be able to experience the changes brought by different colors to the picture in real time and achieve real-time analysis and display of the image color. Description of the Drawings

[0007] Figure 1 It is a flowchart of the steps of a method for analyzing color relationships in an image provided by an embodiment of the present invention; Figure 2 It is an implementation architecture diagram of a method for analyzing color relationships in an image provided by an embodiment of the present invention in an actual scenario; Figure 3 It is a schematic diagram of the implementation process of a method for analyzing color relationships in an image provided by an embodiment of the present invention in an actual scenario; Figure 4 It is a schematic structural diagram of a terminal for analyzing color relationships in an image provided by an embodiment of the present invention; Label Description: 1. A terminal for analyzing color relationships in an image; 2. A processor; 3. A memory. Detailed Embodiments

[0008] To describe the technical content, achieved objectives, and effects of the present invention in detail, the following is described in conjunction with the embodiments and with reference to the drawings.

[0009] Please refer to Figure 1 , a method for analyzing color relationships in an image, the method comprising: Receiving an image to be measured, obtaining at least two main colors in the image to be measured and pixel points corresponding to each of the main colors; Performing harmony analysis and contrast analysis on the image to be measured according to the main colors and the pixel points corresponding to the main colors to obtain a first analysis result; Receiving a color replacement request, the color replacement request including a target main color and a conversion color; Replacing the target pixel points corresponding to the target main color with the conversion color to obtain a changed image; Performing harmony analysis and contrast analysis on the changed image according to the non-converted main colors, the pixel points corresponding to the non-converted main colors, the conversion color, and the pixel points corresponding to the conversion color to obtain a second analysis result; Displaying the first analysis result and the second analysis result.

[0010] As can be seen from the above description, the beneficial effects of the present invention are as follows: for the received image to be measured, the main colors therein and the pixel points corresponding to the main colors are obtained, and harmony analysis and contrast analysis are performed on the main colors and their corresponding pixel points to obtain a first analysis result, which can intuitively present the application mode of colors in the image to be measured; at the same time, it is allowed to receive a color replacement request, and after replacing the main color with the conversion color according to the color replacement request, a changed image is obtained, and the harmony and contrast of the changed image are re-analyzed. On the basis of real-time display and analysis of the color usage of the image to be measured itself, it is also possible to replace the main color in the image to be measured in real time, experience the changes in the replaced image, and perform harmony and contrast analysis after replacement, so as to be able to experience the changes brought by different colors to the picture in real time and realize real-time analysis and display of image colors.

[0011] Further, the receiving the image to be measured and obtaining at least two main colors in the image to be measured includes: Receiving an image to be measured, and grouping all pixel points in the image to be measured by a clustering algorithm to obtain at least two color clusters; Obtaining the clustering center of each color cluster, and marking the clustering center as the main color.

[0012] As described above, by using a clustering algorithm to group the colors of all pixel points in the image to be tested, at least two color clusters are obtained, and the clustering centers of the color clusters are marked as the main colors. While retaining the representative color features of the image to be tested, it avoids the problem that excessive colors make the subsequent analysis of the image to be tested time-consuming, can meet the need for real-time analysis of the image to be tested, and can ignore the colors that have little impact on the composition of the picture, helping to capture the key color information.

[0013] Further, the obtaining the first analysis result by performing a harmony analysis and a contrast analysis on the image to be tested according to the main color and the pixel points corresponding to the main color includes: Obtaining the proportion of the main color in the image to be tested according to the main color and the number of pixel points corresponding to the main color; Calculating the angular difference according to the positions of every two main colors on the color wheel; Obtaining the harmony analysis result between two main colors according to the angular difference and the proportion.

[0014] As described above, for the obtained main color, obtaining the proportion in all pixel points of the image to be tested according to the number of corresponding pixel points can directly obtain the usage situation of the main color in the image to be tested; at the same time, for any two main colors, comprehensively analyzing the harmony according to their positions on the color wheel and their proportions can judge whether the use of any two main colors in the picture is harmonious through the characteristics of the main colors, quantifying and summarizing the use of colors in the image to be tested, which is convenient for learning and imitation.

[0015] Further, the obtaining the harmony analysis result between two main colors according to the angular difference and the proportion includes: Judging whether the angular difference between two main colors is less than a first threshold and the difference in proportions is less than a second threshold. If both are yes, output that the color matching of the two main colors is harmonious; Otherwise, judge whether the angular difference between two main colors is 180 degrees and the difference in proportions is less than the second threshold. If both are yes, output that the color matching of the two main colors is harmonious; if not satisfied, output that the color matching of the two main colors is not harmonious.

[0016] As can be seen from the above description, colors that are complementary or similar to each other are more harmonious in the visual representation, and the main colors with a relatively close color proportion, that is, the difference in proportion is less than the second threshold, will also be more harmonious in the visual representation. Therefore, whether colors are similar is represented by the relative positions of the main colors on the color wheel. If the angular difference is less than the first threshold, it indicates that the colors are similar; if the angular difference is 180 degrees, it indicates that they are complementary colors. Thus, whether colors are similar is quantitatively represented by their positions on the color wheel, thereby realizing a quantitative evaluation of color harmony, being able to automatically obtain the analysis result of the harmony degree of the image to be measured and being applicable to most images.

[0017] Further, the obtaining of the first analysis result by performing harmony degree analysis and contrast analysis on the image to be measured according to the main color and the pixel points corresponding to the main color includes: Obtain the brightness difference and saturation difference between every two of the main colors; Perform weighted scoring on the brightness difference and saturation difference to obtain the contrast score between the two main colors.

[0018] As can be seen from the above description, by obtaining the contrast between two main colors through the method of weighting the brightness difference and saturation difference, it is possible to adjust the weights according to whether more emphasis is placed on brightness or saturation to obtain the corresponding contrast value, thereby comprehensively reflecting the contrast situation between the main colors in the image to be measured.

[0019] Further, before obtaining the first analysis result by performing harmony degree analysis and contrast analysis on the image to be measured according to the main color and the pixel points corresponding to the main color, after receiving the image to be measured, it further includes: Convert the image format of the image to be measured into an image format including the representation of light and dark levels.

[0020] As can be seen from the above description, representing the image to be measured by an image format that can represent the change in light and dark levels can better reflect the details in the image and facilitate the harmony degree analysis and contrast analysis.

[0021] Further, the conversion of the image format of the image to be measured into an image format including the representation of brightness includes: Convert the image format of the image to be measured into the HSV or LAB format.

[0022] As can be seen from the above description, the HSV format includes the value V representing lightness, and the LAB format includes the lightness L, both of which can reflect the light and dark levels of colors, thereby facilitating the subsequent harmony degree and contrast analysis.

[0023] Further, it further includes: Preset color categories and match the main color with the color categories; Associate the matched color category with the main color, and jointly generate a color configuration file corresponding to the image to be tested with the proportion of the main color in the image to be tested, and save the color configuration file.

[0024] As can be seen from the above description, after obtaining the main color, match the main color according to the preset color category, and save the main color, the proportion of the main color in the image to be tested, and the corresponding color category to generate a color configuration file. Then, if subsequent color analysis of the same image to be tested is required, only the stored color configuration file needs to be directly called, without repeating the extraction and classification operations of the main color of the same image to be tested, realizing the reuse of the extracted main color; and classifying the main color according to the preset color category can match the actual color application in the image to be tested with the corresponding color theory, helping to further understand the color usage method in the image to be tested.

[0025] Further, for the preset color category, matching the main color with the color category includes: Obtain the first feature vectors of all the color categories; Obtain the second feature vector of the main color; Obtain the target first feature vector closest to the target second feature vector, and match the target main color corresponding to the target second feature vector with the color category corresponding to the target first feature vector.

[0026] As can be seen from the above description, both the color category and the main color are represented by feature vectors, so it is possible to determine whether the color category and the color main body are similar by calculating the distance, realizing the matching of the main color to the preset color category, and realizing the judgment of whether the colors are similar through quantified vectors, so that automatic calculation can be performed and the errors caused by display settings and different people's feelings during manual classification can be avoided.

[0027] Please refer to Figure 4 , a terminal for analyzing color relationships in an image, including a memory, a processor, and a computer program stored on the memory and running on the processor. When the processor executes the computer program, each step in the above method for analyzing color relationships in an image is implemented.

[0028] The above method and terminal for analyzing color relationships in an image according to the present invention can be applied to scenarios where color analysis of an image is required, especially in scenarios where colors in a painting are analyzed in an art teaching scenario, which will be described below through specific embodiments.

[0029] Please refer to Figure 1 , Embodiment 1 of the present invention is: A method for analyzing color relationships in an image, comprising the steps of: S1. Receive the image to be measured, and obtain at least two main colors in the image to be measured and the pixel points corresponding to each main color.

[0030] In an optional implementation manner, the receiving the image to be measured and obtaining at least two main colors in the image to be measured in S1 includes S11 - S12.

[0031] S11. Receive the image to be measured, and group all the pixel points in the image to be measured through a clustering algorithm to obtain at least two color clusters. Among them, the clustering algorithm can be the K - means algorithm, and the K value (the number of final color clusters) can be determined by methods such as the empirical method, the elbow method, and the silhouette score.

[0032] In an optional implementation manner, the K value can also be directly determined according to different analysis accuracy requirements.

[0033] S12. Obtain the clustering center of each color cluster, and mark the clustering center as the main color. For example, if the received image to be measured by the user is a landscape painting, then after the K - means algorithm, the main colors obtained are blue (sky), green (grassland, leaves), and brown (tree trunks, mountain rocks).

[0034] In an optional implementation manner, between S1 and S2, it further includes: converting the image format of the image to be measured into an image format including light and shade representation. For example, it can be converted into the HSV or LAB image format. Usually, painting works are saved in the RGB format. The image format including sensitivity identification is more suitable for color perception and processing, can better separate color attributes, and the conversion between various color formats is also relatively mature in the prior art, and the implementation process is convenient. There are already relatively mature color space conversion algorithms for the conversion method here in the prior art, and details will not be elaborated here.

[0035] S2. Perform harmony analysis and contrast analysis on the image to be measured according to the main color and the pixel points corresponding to the main color to obtain a first analysis result.

[0036] In an optional implementation manner, S2 includes a harmony analysis process, and the harmony analysis process includes the following S21 - S23.

[0037] S21. Obtain the proportion of the main color in the image to be measured based on the main color and the number of pixel points corresponding to the main color. For example, if the main colors include red, blue, and green, and the numbers of their corresponding pixel points are 500, 300, and 200 respectively, then the proportion of red is 50%, the proportion of blue is 30%, and the proportion of green is 20%.

[0038] S22. Calculate the angular difference based on the positions of every two main colors on the color wheel. According to the positions of colors on the color wheel, calculating the angular difference between different colors can be used as a measure of the distance between colors, and the distance between colors is a quantitative representation of the similarity of colors. For example, the angular difference between red and green on the color wheel is 120 degrees, indicating a large difference between them and producing a strong contrast effect; the angular difference between adjacent colors such as yellow-orange and orange is very small, producing a soft effect.

[0039] S23. Obtain the harmony analysis result between two main colors based on the angular difference and the proportion.

[0040] In an optional implementation manner, S23 includes S231 - S232.

[0041] S231. Determine whether the angular difference between two main colors is less than the first threshold. If so, output that the color combination of the two main colors is harmonious; otherwise, execute S232. The range of the first threshold can be set to 0 degrees to 30 degrees. For example, 0 degrees, 15 degrees, or 30 degrees can be taken. In order to further refine the evaluation of harmony and improve the accuracy of the harmony evaluation, a third threshold can also be set. In S231, determine whether the angular difference between two main colors is less than the first threshold and whether the difference in proportion is less than the third threshold. If both are true, it is considered that the color combination of the two main colors is harmonious; otherwise, execute S232. In this way, not only is it confirmed that the colors of the main colors are similar, but it is also further specified that the proportions of the two should be similar to consider the color combination harmonious. Then, by combining the settings of the first threshold and the third threshold, a smaller third threshold can be set when the first threshold is larger, and a larger third threshold can be set when the first threshold is smaller. That is, when the colors are relatively similar, the requirement for the closeness of the proportions can be reduced, making the obtained harmony judgment result closer to people's intuitive feelings.

[0042] S232. Determine whether the angular difference between the colors of the two subjects is greater than a second threshold and the difference in proportion is less than a third threshold. If both conditions are met, output that the color matching of the two subjects is harmonious; if not, output that the color matching of the two subjects is inharmonious. Among them, the range of the second threshold can be set to 120 degrees to 180 degrees, for example, 120 degrees, 150 degrees, or 180 degrees can be taken; the range of the third threshold is 0% to 5%, for example, 0%, 2.5%, or 5% can be taken. Similarly, here, a smaller third threshold can be set when the second threshold is smaller, and a larger third threshold can be set when the second threshold is larger, that is, for colors with strong contrast, the requirement for the similarity of proportions can be reduced. The effects can be verified manually and the thresholds can be adjusted twice to output different first thresholds, second thresholds, and third thresholds for different types of images to be tested. For example, the thresholds for the degree of harmony corresponding to oil paintings and ink paintings may be different.

[0043] In an alternative embodiment, after S232, it further includes: determining whether the sum of the proportions of the colors of the subjects with harmonious color matching exceeds a preset proportion. If so, it is determined that the color of the image to be tested is harmonious. Among them, the preset proportion can be a value greater than 80%, such as 80%, 85%, 90%, 98%, etc. In this way, it is not necessary for all colors to be color-matched harmoniously in pairs to consider the color matching of the entire image to be harmonious. As long as the sum of the proportions of the colors determined to be color-matched harmoniously exceeds the preset proportion, it is considered that the color matching of the entire image is harmonious, making the final judgment result closer to people's feelings and realizing the quantification of people's feelings.

[0044] In S231 and S232, the range of the angle is 0 to 180 degrees. Since the colors on both sides of the target color on the color wheel can be considered as colors similar to the target color, the angle range is limited to 0 to 180 degrees here, which can more accurately reflect the degree of closeness between colors reflected by the angular difference between colors on the color wheel.

[0045] In this way, by comprehensively considering the proportion of the main colors and the similarity of the main colors, it is determined whether the color combination in the picture is harmonious. As long as the main colors are similar, it is considered that their color matching is harmonious. If the contrast between the main colors is relatively strong, it is considered that their similar proportions are a more harmonious situation. In this way, the color theory is experienced and analyzed in a quantified form, and a more objective and accurate judgment result of the degree of harmony can be obtained.

[0046] In an alternative embodiment, S2 further includes a contrast analysis process, and the contrast analysis process includes the following S24 - S25. The harmony analysis process and the contrast analysis process in this embodiment can be carried out successively or simultaneously. The step numbers here are only for convenience of description and are not used to limit the sequence of the harmony analysis process and the contrast analysis process.

[0047] S24. Obtain the brightness difference and saturation difference between every two of the subject colors.

[0048] In this embodiment, by obtaining the brightness value and saturation value of each subject color, the brightness difference and saturation difference between two subject colors can be calculated. If the image format has been converted to LAB, the L channel therein represents brightness, the A channel represents the change degree from green to red, and the B channel represents the change degree from blue to yellow. Then, by obtaining the value of the L channel of each subject color, the brightness value of the color can be determined, and the saturation can be calculated through the A channel and the B channel. Similarly, if the image format has been converted to HSV, the H channel represents hue, the S channel represents saturation, and the V channel represents value. Then, the brightness of the color can be determined according to the value of the V channel, and the saturation of the color can be obtained according to the S channel, so that the brightness difference and saturation difference between two subject colors can be calculated.

[0049] S25. Perform weighted scoring on the brightness difference and saturation difference to obtain the contrast score between the two subject colors. According to the color principle, a high brightness difference means a stronger contrast, and a high saturation difference will also increase the visual contrast. Therefore, the data of both the brightness and saturation dimensions are comprehensively used for contrast scoring here, and the overall contrast score is obtained by the method of weighted average. The weight can be adjusted according to the type of the image to be measured. For example, if more importance is attached to brightness contrast, a higher weight can be set for the brightness difference; if more importance is attached to saturation contrast, a higher weight can be set for the saturation difference. Here, the weight for harmony contrast can also be adjusted according to manual selection to make the result automatically judged by the machine closer to the real experience of people.

[0050] In an alternative embodiment, the calculation method and weight setting of the contrast score include: 1. Calculate the contrast score by comprehensively considering the brightness difference and saturation difference. According to the color principle, both a high brightness difference and a high saturation difference will increase the visual contrast. Therefore, the contrast score can be calculated by the method of weighted average. The specific steps are as follows: (1) Calculate the brightness difference (ΔL) and saturation difference (ΔS), that is, the difference between the brightness values and the difference between the saturation values of the two colors.

[0051] (2)Set the brightness weight (W_L) and saturation weight (W_S), which can be adjusted according to the image type. For example, sketches are usually presented by light and dark contrast, so the saturation weight can be reduced and the brightness weight can be increased; oil paintings usually pay more attention to the vividness of colors and light and dark contrast, so the brightness weight can be increased; watercolor paintings pay more attention to the transparency and saturation of colors, so the saturation weight can be increased. The following is an illustration with specific values. For sketches, the brightness weight (W_L) is 0.8 and the saturation weight (W_S) is 0.2; for oil paintings, the brightness weight (W_L) is 0.6 and the saturation weight (W_S) is 0.4; for watercolors, the brightness weight (W_L) is 0.4 and the saturation weight (W_S) is 0.6. The weights can be adjusted according to specific requirements. For example, if you want to emphasize the vividness of colors more, you can appropriately increase the saturation weight; if you want to emphasize light and dark contrast more, you can increase the brightness weight.

[0052] (3)Calculate the contrast score = WL × ΔL + WS × ΔS.

[0053] 2. Obtain the contrast evaluation result based on the contrast score. According to the color principle, when the brightness difference (ΔL) > 50, it usually indicates that the contrast is very strong; when 30 < ΔL ≤ 50, it usually indicates that the contrast is strong; when 10 < ΔL ≤ 30, it usually indicates that the contrast is moderate; when ΔL ≤ 10, it usually indicates that the contrast is weak. When the saturation difference (ΔS) > 50, it usually indicates that the contrast is very strong; when 30 < ΔS ≤ 50, it usually indicates that the contrast is strong; when 10 < ΔS ≤ 30, it usually indicates that the contrast is moderate; when ΔS ≤ 10, it usually indicates that the contrast is weak.

[0054] Thus, the evaluation ranges of the brightness difference and saturation difference can be directly used for the final contrast score. That is, when the contrast score > 50, it indicates that the contrast is very strong, and so on.

[0055] Through the above method for calculating the contrast score and setting the weights, the contrast score between two colors can be calculated more scientifically, and the weights can be adjusted according to different types of artistic creations, making the results automatically judged by the machine closer to the real experience of humans.

[0056] S3. Receive a color replacement request, where the color replacement request includes the target subject color and the conversion color. In an optional implementation manner, a color selector is provided for the user to select the conversion color. For example, a color selector is constructed through color models such as RGB or HSB, and the user can directly select a color in the color selector as the conversion color or input a value to match the conversion color.

[0057] S4. Replace the target pixel points corresponding to the target subject color with the conversion color to obtain a changed image. S5. Analyze the harmony and contrast of the changed image based on the untransformed main color, the pixel points corresponding to the untransformed main color, the transformed color, and the pixel points corresponding to the transformed color to obtain a second analysis result.

[0058] The processes of harmony analysis and contrast analysis in step S5 are the same as those in step S2 above and will not be elaborated here.

[0059] S6. Display the first analysis result and the second analysis result.

[0060] In an optional implementation, after S1, S01 - S02 are further included.

[0061] S01. Preset color categories and match the main color with the color categories, including S011 - S013.

[0062] Among them, common color categories can be preset according to art theory and color science principles, so as to be able to more quickly correspond to the color matching style of the image to be measured after obtaining the main color. For example, warm colors, cool colors, natural colors, etc. can be set; corresponding color category combinations can also be set for specific art styles. After obtaining the color classification corresponding to the main color, the art style of the image to be measured can be initially judged according to the color classification combination of the image to be measured. And the main color obtained by the clustering method is usually represented by numerical values, such as numerical values in the LAB or HSV format. Therefore, by matching the main color with the color categories, the common color names corresponding to the colors expressed in digital format can be obtained. For example, if the LAB format of the main color is (51, -41, 10), the corresponding color classification is the green color system.

[0063] S011. Obtain the first feature vectors of all the color categories. If there are multiple common colors in a color category, the average feature vector of all the colors in the color category can be used as the first feature vector. For example, if there are multiple greens in the green color system, the average feature vector of all the greens in the green color system can be calculated as the first feature vector.

[0064] S012. Obtain the second feature vector of the main color. The main color is the clustering center of the color cluster and can reflect the color concentration in the color cluster. Obtaining the second feature vector of the main color can represent the concentrated color representation in the color cluster.

[0065] S013. Obtain the target first feature vector that is closest to the target second feature vector, and match the target body color corresponding to the target second feature vector with the color category corresponding to the target first feature vector. For example, the HSV format of a body color is (200, 70, 50), and its corresponding color classification is the blue color system; the HSV format of the body color is (30, 60, 80), and its corresponding color classification is the yellow color system.

[0066] S02. Associate the matched color category with the body color, and jointly generate a color configuration file corresponding to the test image with the proportion of the body color in the test image, and save the color configuration file. Among them, the color configuration file can be saved in the form of CSV or JSON, which can be recognized and read by most software, facilitating the direct import of the color configuration file into other software for further analysis or editing. For example, it can be imported into a drawing software to generate a color palette for drawing use.

[0067] In an alternative embodiment, create a digital color library, which includes the identifier of the identified test image, the body color corresponding to the test image (represented in image formats such as RGB, LAB, HSV, etc.), the color category of the body color, and the proportion of each body color in the test image, etc. Further, it may also include the coordinates of the corresponding pixel points, the judgment results of harmony and contrast, etc. The representation of the test image can be obtained by calculating the hash value corresponding to the test image. After receiving the input test image, the corresponding hash value can be calculated first and retrieved in the color library. If there is the same hash value, the saved color analysis data can be directly used without extracting it again.

[0068] It can also accept a retrieval request, and the retrieval request includes a color classification. According to the color classification, the color configuration file corresponding to the corresponding test image can be output, which can help users understand the use of the same or similar colors in different test images and realize image retrieval by color.

[0069] In an alternative embodiment, after S1, S03 is further included.

[0070] S03. Generate a color histogram corresponding to the test image, display the frequency distribution of different colors, and the color histogram can intuitively reflect the use and distribution characteristics of colors in the test image.

[0071] Please refer to Figures 2-3 , Embodiment 2 of the present invention is: Apply the above method for analyzing the color relationship in an image to an actual scenario.

[0072] During the art teaching process, teachers can use a large-screen interactive color teaching platform to display a painting (the image to be tested) and guide students to analyze its color application.

[0073] First, the teacher selects different colors through the interactive color selector and applies them to the painting in real time to show the impact of color changes on the overall work. Students can clearly see the color changes and effects on the large screen, thus intuitively understanding color selection and matching.

[0074] Next, the teacher uses the color visualization tool to show the proportion and changes of colors in the painting. Students can see the distribution and proportion of different colors in the painting and understand the role of colors in the painting. At the same time, the color analysis tool will analyze the color selection and matching in the painting and provide indicators such as color harmony and contrast to help students understand the principles and effects of color matching.

[0075] In addition, the color extraction and management module extracts the main colors from the painting, classifies and manages them. Students can view and manage the extracted colors and understand the roles and effects of different colors in the painting. Finally, the color histogram tool generates a color histogram of the painting to show the frequency distribution of different colors. Through the color histogram, students can intuitively understand the color usage and distribution characteristics in the painting.

[0076] Through the above functions, the automatic extraction, classification, and storage of colors in the input painting are realized, and the main colors affecting the painting are determined by clustering. Harmony analysis and contrast analysis are performed based on the main colors to achieve the quantification of color application. Students can not only intuitively understand the effects of color application through interactive operations but also deeply understand the principles of color selection and matching through analysis tools, thereby improving their understanding and application abilities of color expression. The high resolution and large size of the large screen enable every detail to be clearly displayed, enhancing the teaching effect and students' learning experience.

[0077] Please refer to Figure 4 , Embodiment 3 of the present invention is as follows: A terminal 1 for analyzing color relationships in an image includes a memory 3, a processor 2, and a computer program stored on the memory 3 and running on the processor 2. When the processor 2 executes the computer program, it implements each step in a method for analyzing color relationships in an image in Embodiment 1.

[0078] In summary, a method and a terminal for analyzing color relationships in an image provided by the present invention automatically extract the main color therein after inputting the image to be measured, and perform harmony analysis and contrast analysis based on the main color and the pixel points corresponding to the main color to obtain the analysis result of color usage. And it allows the user to modify the colors on the image to be measured, and intuitively experience the influence of color changes on the overall expression effect of the image to be measured. At the same time, harmony analysis and contrast analysis are performed again on the changed image after the color is modified. While the user experiences the color change, an objective analysis is performed on the changes in harmony and contrast of the changed image compared with the image to be measured brought about by the color change, and the values of harmony and contrast corresponding to the changed image are obtained, which can quantify the influence of color changes on the picture and intuitively display the images before and after the color change, helping the user feel the influence of color changes on the picture expression.

[0079] The above are only embodiments of the present invention, and do not limit the patent scope of the present invention accordingly. Any equivalent transformation made by using the content of the specification and drawings of the present invention, or directly or indirectly applied in the relevant technical field, shall be equally included in the patent protection scope of the present invention.

Claims

1. A method for analyzing color relationships in an image, characterized in that: Includes steps: Receive an image to be tested, and obtain at least two main colors of the image to be tested and the pixel points corresponding to each main color; Performing harmony analysis and contrast analysis on the image to be tested according to the main color and the pixel points corresponding to the main color to obtain a first analysis result; receiving a color replacement request, wherein the color replacement request includes a target main body color and a conversion color; Replacing the target pixel corresponding to the target main body color with the conversion color to obtain a changed image; Performing harmony analysis and contrast analysis on the changed image according to the unconverted main color, the pixel points corresponding to the unconverted main color, the converted color, and the pixel points corresponding to the converted color to obtain a second analysis result; The first analysis result and the second analysis result are displayed.

2. A method for analyzing color relationships in an image according to claim 1, characterized in that: The receiving the image to be tested and obtaining at least two main colors of the image to be tested comprises: Receiving an image to be tested, and grouping all pixels in the image to be tested by a clustering algorithm to obtain at least two color clusters; The cluster center of each color cluster is obtained, and the cluster center is marked as the main color.

3. A method for analyzing color relationships in an image according to claim 1, characterized in that: The performing harmony analysis and contrast analysis on the image to be tested according to the main body color and the pixel points corresponding to the main body color to obtain a first analysis result comprises: Obtaining a proportion of the main color in the image to be tested according to the main color and the number of pixels corresponding to the main color; Calculating the angle difference according to the positions of each two main colors on the color wheel; A harmony analysis result between the two main colors is obtained according to the angle difference and the proportion.

4. A method for analyzing color relationships in an image according to claim 3, characterized in that: The harmony analysis result between the two main colors obtained according to the angle difference and the proportion includes: Determine whether the angle difference between the two main colors is less than a first threshold and the difference in proportion is less than a second threshold, and if both are true, output that the two main colors are harmoniously matched; Otherwise, determine whether the angle difference between the two main colors is 180 degrees and the difference in proportion is less than the second threshold. If both are true, output that the two main colors are harmonious; if not, output that the two main colors are not harmonious.

5. The method for analyzing color relationships in an image according to claim 1, characterized in that: The performing harmony analysis and contrast analysis on the image to be tested according to the main body color and the pixel points corresponding to the main body color to obtain a first analysis result comprises: Obtaining the brightness difference and saturation difference between every two of the subject colors; The brightness difference and the saturation difference are weighted and scored to obtain a contrast score between the two subject colors.

6. The method for analyzing color relationships in an image according to claim 1, characterized in that: Before performing harmony analysis and contrast analysis on the image to be tested according to the main body color and the pixel points corresponding to the main body color to obtain a first analysis result, after receiving the image to be tested, the method further includes: The image format of the image to be measured is converted into an image format including brightness and darkness representation.

7. A method for analyzing color relationships in an image according to claim 6, characterized in that: The step of converting the image format of the image to be measured into an image format including brightness representation comprises: The image format of the image to be tested is converted into HSV or LAB format.

8. The method for analyzing color relationships in an image according to claim 3, characterized in that: Also includes: Preset a color category and match the subject color with the color category; The matched color category is associated with the main color, and a color profile corresponding to the image to be tested is generated together with the proportion of the main color in the image to be tested, and the color profile is saved.

9. A method for analyzing color relationships in an image according to claim 8, characterized in that: The preset color category, matching the main body color with the color category comprises: Obtaining the first eigenvectors of all the color categories; Obtaining a second eigenvector of the subject color; A target first feature vector that is closest to a target second feature vector is obtained, and a target main body color corresponding to the target second feature vector is matched with a color category corresponding to the target first feature vector.

10. A terminal for analyzing color relationships in an image, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that: When the processor executes the computer program, each step of the above-mentioned method for analyzing color relationships in an image is implemented.