Chromatic aberration calculation method and device and storage medium
By introducing brightness weights into the chromatic aberration calculation method, the problem that chromatic aberration calculation in the prior art is solved, and more accurate chromatic aberration calculation for human eyes is realized, and the user experience is optimized.
Patent Information
- Application Number
- CN202411862966.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-17
- Publication Date
- 2025-03-28
AI Technical Summary
In the prior art, the color difference formula cannot fully reflect the perceived strength of the human eye for color differences under different brightness conditions, resulting in the calculation results that are inconsistent with the actual visual effect.
By obtaining the brightness values of the text and background in the image to be identified, the brightness weight is determined, and the color difference between the text and background colors is calculated. Brightness weight is used to characterize the perception of chromatic aberration of human eyes at different brightness.
This enables the calculated color difference to accurately determine whether the colors are similar from the perspective of the human eye, quickly identify the color matching problems between text and background, and optimize the user experience.
Smart Images

Figure CN119722820A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of Internet, and in particular to a color difference calculation method, device and storage medium. Background Art
[0002] The color difference between two colors can be used to distinguish how similar the two colors are.
[0003] In the related art, a color difference formula is used to calculate the color difference. For example, when the CIE (International Commission on illumination) Lab color system is used, the color difference formula is: Among them, ΔE is the color difference; L is the brightness channel, and its value range is 0 (black) to 100 (white); a and b are color channels, the a channel represents the color change from green (negative value) to red (positive value), and the b channel represents the color change from blue (negative value) to yellow (positive value).
[0004] Although the color difference formula can accurately calculate the color difference value, the calculated color difference value cannot fully reflect the actual situation seen by the human eye. Summary of the invention
[0005] The present application provides a method, device and storage medium for calculating color difference, which can calculate color difference based on human eye perception. The technical solution is as follows:
[0006] According to one aspect of the present application, a method for calculating color difference is provided, the method comprising:
[0007] Acquire an image to be identified; the image to be identified includes text and background;
[0008] Determine a brightness weight according to the text brightness of the text and the background brightness of the background; the brightness weight is used to characterize the intensity of human visual perception of color difference under different brightness;
[0009] The color difference between the text color of the text and the background color of the background is calculated according to the brightness weight.
[0010] According to another aspect of the present application, a color difference calculation device is provided, the device comprising:
[0011] An acquisition module, used for acquiring an image to be recognized; the image to be recognized includes text and background;
[0012] A weight module, used to determine a brightness weight according to the text brightness of the text and the background brightness of the background; the brightness weight is used to characterize the intensity of human visual perception of color difference under different brightness;
[0013] A calculation module is used to calculate the color difference between the text color of the text and the background color of the background according to the brightness weight.
[0014] According to another aspect of the present application, a computer device is provided, comprising a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the color difference calculation method as described above.
[0015] According to another aspect of the present application, a computer-readable storage medium is provided, wherein at least one instruction, at least one program, a code set or an instruction set is stored in the computer-readable storage medium, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by a processor to implement the color difference calculation method as described above.
[0016] According to another aspect of the present application, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the color difference calculation method provided in various optional implementations of the above aspects.
[0017] The beneficial effects of the technical solution provided by this application include at least:
[0018] Since brightness affects the human eye's perception of color, when the brightness is low, the human eye's perception of color difference is weaker; when the brightness is high, the human eye can sensitively distinguish color differences. The method provided in this application determines the brightness weight based on the image brightness, and uses the brightness weight to characterize the degree of human eye's perception of color difference at the current brightness. The color difference is calculated based on the brightness weight, so that the calculated color difference can accurately determine whether the colors are similar from the perspective of the human eye, so as to quickly identify the color matching problems of text and background, facilitate the adjustment of the color matching of text and background in the application, and optimize the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0020] Figure 1 is a schematic diagram of the structure of a computer system provided by an exemplary embodiment of the present application;
[0021] Figure 2 is a flow chart of a method for calculating color difference provided by an exemplary embodiment of the present application;
[0022] Figure 3 is a schematic diagram of a method for calculating color difference provided by an exemplary embodiment of the present application;
[0023] Figure 4 is a flow chart of a method for calculating color difference provided by an exemplary embodiment of the present application;
[0024] Figure 5 is a flow chart of a method for calculating color difference provided by an exemplary embodiment of the present application;
[0025] Figure 6 is a schematic diagram of the structure of a color difference calculation device provided by an exemplary embodiment of the present application;
[0026] Figure 7 It is a structural diagram of a computer device provided by an exemplary embodiment of the present application.
[0027] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application. DETAILED DESCRIPTION
[0028] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0029] Figure 1 A schematic diagram of a computer system provided by an exemplary embodiment of the present application is shown, and the computer system may include a terminal 101 and a server 103 .
[0030] Exemplarily, the color difference calculation method shown in the embodiment of the present application can be applied in a terminal, and the terminal 101 runs an application 102 that supports the display of an application interface. The terminal may include a mobile phone, a tablet computer, a notebook computer, a laptop computer, a desktop computer, an all-in-one computer, an Internet of Things device, an intelligent robot workstation, a television, a set-top box, smart glasses, a smart watch, a digital camera, an MP4 player, an MP5 player, a learning machine, a point-reading machine, an electronic paper book, an electronic dictionary, a vehicle-mounted device, a virtual reality (VR) player or an augmented reality (AR) player, etc.
[0031] Exemplarily, the color difference calculation method provided in the present application can be executed by a client in the terminal. The client is a client of an application that supports application interface display. For example, the application may include at least one of the following: an audio application, an audio player, a video application, a short video application, a social application, a shopping application, a local service application, a live broadcast application, an information application, a browser, and a game application.
[0032] The terminal 101 includes a first memory and a first processor. A color difference calculation program is stored in the first memory; the color difference calculation program is called and executed by the first processor to implement the color difference calculation method provided in the present application. The first memory may include but is not limited to the following: Random Access Memory (RAM), Read Only Memory (ROM), Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (EPROM), and Electric Erasable Programmable Read-Only Memory (EEPROM).
[0033] The first processor may be composed of one or more integrated circuit chips. Optionally, the first processor may be a general-purpose processor, such as a central processing unit (CPU) or a network processor (NP). Optionally, the first processor may implement the color difference calculation method provided in the present application by running a program or code.
[0034] In an optional embodiment, the terminal 101 and the server 103 may be connected to each other via a wired or wireless network.
[0035] The server 103 is used to provide background services for the application of the terminal 101. Optionally, the server 103 undertakes the main computing work and the terminal 101 undertakes the secondary computing work; or, the server 103 undertakes the secondary computing work and the terminal 101 undertakes the main computing work; or, the server 103 and the terminal 101 adopt a distributed computing architecture to perform collaborative computing.
[0036] The server 103 may be a single server, or a server cluster consisting of multiple servers, or a cloud computing service center.
[0037] Optionally, the server 103 includes a second memory and a second processor. The second memory stores a color difference calculation program; the color difference calculation program is called by the second processor to implement the color difference calculation method provided in the present application. Optionally, the second memory may include but is not limited to the following: RAM, ROM, PROM, EPROM, EEPROM. Optionally, the second processor may be a general-purpose processor, such as a CPU or NP.
[0038] Taking the audio player running on the terminal as an example, the terminal or server can automatically obtain the various application interfaces of the audio player and capture the regional image where the text is located from the application interface. The method provided in the embodiment of the present application is used to calculate the color difference between the text and the background in the regional image. When the color difference between the text and the background is small, the color abnormality can be fed back to facilitate the developer to adjust the text or background color at that position in the application interface, so that the text displayed on the application interface can be distinguished from the background, which is convenient for users to browse the text content and optimize the user experience.
[0039] Figure 2 FIG. 1 is a flow chart of a method for calculating color difference provided by an exemplary embodiment of the present application. The method can be used for Figure 1 The terminal or server shown in the figure. The method comprises the following steps.
[0040] Step 210: Acquire an image to be recognized; the image to be recognized includes text and background.
[0041] Exemplarily, the method may be executed by a terminal or a server, and an application may be running on the terminal or the server. The application may execute the color difference calculation method provided in the embodiment of the present application to calculate the color difference between the text and the background in the image to be recognized.
[0042] Optionally, a client of an application program may be running on the terminal, and the client may execute the color difference calculation method provided in the present application to calculate the color difference between the text and the background in the image to be identified. Alternatively, a server of an application program may be running on the server, and the server may execute the color difference calculation method provided in the present application to calculate the color difference between the text and the background in the image to be identified. Alternatively, the client may request the server to calculate the color difference between the text and the background in the image to be identified, and the server may receive the image to be identified sent by the client, calculate the color difference and feed the color difference back to the client.
[0043] In one application scenario, the image to be identified may be an application interface image of an application captured by a client, or the image to be identified may be an image captured from the application interface image; this method is used to identify interfaces with similar text or background colors in the application, so that developers can adjust the text or background colors in the application interface and improve the user experience.
[0044] In another application scenario, the image to be identified may be a photo taken by the terminal, or an area where a watermark is located captured from the photo; the method is used to identify the color difference between the watermark text in the photo (for example, text of time or location) and the photo image where the watermark text is located. If the color difference is small, the color of the watermark text may be adjusted to highlight the watermark text in the photo; or, if the color difference is large, the color of the watermark text may be adjusted to hide the watermark text in the photo.
[0045] Exemplarily, the image to be recognized may include an area where the text is located and an area where the background is located, wherein the area where the background is located surrounds the area where the text is located. Exemplarily, the optical character recognition (OCR) technology may be used to recognize the area where the text is located from the image to be recognized, and the area where the background is located is obtained by removing the area where the text is located from the image to be recognized.
[0046] For example, Figure 3 (1) is an image to be recognized, which includes text 301 "Be in a good mood every day" and background 302. Figure 3 In (1), the Chinese characters 301 are displayed in black, and the background 302 is displayed in white. The color difference between the characters and the background is large, and the user can easily distinguish the text content. Figure 3 (2) in FIG. 1 is another image to be recognized, which includes text 301 “Have a good mood every day” and background 302. Figure 3 In (2), the text 301 is displayed in black, and the background 302 is displayed in dark gray. The color difference between the text and the background is small, and it is difficult for the user to distinguish the text content. Therefore, the method provided in the embodiment of the present application calculates the color difference between the text and the background based on the human eye's perception of color tone, and accurately determines whether the user can distinguish the text content from the current background, so as to adjust the color of the text or background when it is difficult to distinguish, thereby improving the user experience.
[0047] Exemplarily, the text color of the text is usually a single color, but of course the text color may also include a combination of multiple colors; similarly, the background color of the background may be a single color or a combination of multiple colors.
[0048] The method provided in the embodiment of the present application takes the color with the largest proportion in the text colors as the final text color, takes the color with the largest proportion in the background colors as the final background color, and then calculates the color difference between the text color and the background color.
[0049] Step 220: Determine a brightness weight according to the text brightness of the text and the background brightness; the brightness weight is used to characterize the degree of human visual perception of color difference under different brightness.
[0050] For example, because the human eye has different perceptions of color tones at different brightnesses, it is difficult for the human eye to distinguish color differences when the brightness is low, and the human eye is more sensitive to color differences when the brightness is high; therefore, the brightness weight can be determined based on the text brightness of the text in the image to be recognized and the background brightness of the background, and the brightness weight is used to identify the sensitivity of the human eye to color difference at the current brightness, so as to calculate the color difference based on the sensitivity of the human eye to color difference, so that the calculated color difference is more consistent with the perception of the human eye.
[0051] The brightness weight is a positive number. Optionally, the brightness weight can be a positive integer not greater than 2. When the brightness is large, the weight is less than 1, indicating that the human eye is more sensitive to color difference at the current brightness and can clearly distinguish the color difference; when the brightness is small, the weight is greater than 1, indicating that the human eye is relatively insensitive to color difference at the current brightness and cannot distinguish the color difference.
[0052] For example, the brightness weight can be determined based on the correlation between the text brightness and the background brightness. When the text brightness and the background brightness are both low, the brightness weight can take a value greater than 1; when the text brightness and the background brightness are both high, the brightness weight can take a value less than 1; when the text brightness and the background brightness are high and low, the brightness difference between the text and the background is large, and the user can normally distinguish the color difference, then the brightness weight can take 1.
[0053] Exemplarily, the embodiments of the present application may adopt the CIE Lab color system, and a pixel includes three channels: L channel, a channel, and b channel. The L channel represents the brightness (luminance) of the pixel, and the value range is from 0 (black) to 100 (white); the larger the L value, the higher the brightness of the color. The a channel represents the red-green color difference (the positive half axis of the a axis is red, and the negative half axis is green); the change in the a value reflects the transition of the color from red to green; when a>0, it indicates that the color is red, and the larger the a value, the redder the color; when a<0, it indicates that the color belongs to the green system. The b channel represents the yellow-blue color difference (the positive half axis of the b axis is yellow, and the negative half axis is blue). The change in the b value reflects the transition of the color from yellow to blue; b>0 is yellow, and b<0 is blue.
[0054] Then, the value of the L channel can be directly taken from the pixel points corresponding to the text as the text brightness; and the value of the L channel can be directly taken from the pixel points corresponding to the background as the background brightness.
[0055] Step 230: Calculate the color difference between the text color of the text and the background color of the background according to the brightness weight.
[0056] For example, the brightness difference and color difference of the text and the background can be calculated respectively, and the weighted sum of the brightness difference and the color difference can be calculated according to the brightness weight. When the brightness weight is large, the proportion of the brightness difference in the color difference is high, and the color difference has less influence on the color difference, indicating that the human eye is relatively insensitive to the color difference; when the brightness weight is small, the proportion of the brightness difference in the color difference is small, and the color difference has a greater influence on the color difference, indicating that the human eye is relatively sensitive to the color difference.
[0057] Therefore, based on the brightness weight, the color difference can be calculated from the perspective of human eye perception so that the calculated color difference is consistent with the human eye perception result, which is convenient for evaluating the text display effect from the perspective of user experience, screening areas where the text display is blurred due to the small color difference between the text and the background, and timely adjusting the text and background colors of the area to optimize the user's visual experience.
[0058] by Figure 3 For example, white is L=100, a=0, b=0; black is L=0, a=0, b=0. It can be seen that the brightness difference between white and black is large, so the brightness weight is 1. The color difference (a and b) of white and black is 0, and the brightness difference is 100, so the color difference can be 100.
[0059] by Figure 3 For example, dark gray has L=10, a=0, b=0. It can be seen that the brightness of black and dark gray is small, so the brightness weight can be 1.9. The color difference between black and dark gray is 0, and the brightness difference is 10, so the color difference can be 19.
[0060] In summary, the method provided in this embodiment, because brightness affects the human eye's perception of color, when the brightness is low, the human eye's perception of color difference is weak; when the brightness is high, the human eye can sensitively distinguish color differences. The method provided in this application determines the brightness weight based on the image brightness, and uses the brightness weight to characterize the degree of human eye's perception of color difference at the current brightness. The color difference is calculated based on the brightness weight, so that the calculated color difference can accurately determine whether the colors are similar from the perspective of the human eye, so as to quickly identify the color matching problem of text and background, facilitate the adjustment of the color matching of text and background in the application, and optimize the user experience.
[0061] Exemplarily, a method for calculating brightness weight is given.
[0062] Figure 4 FIG. 1 is a flow chart of a method for calculating color difference provided by an exemplary embodiment of the present application. The method can be used for Figure 1 The terminal or server shown. Figure 2 In the illustrated embodiment, step 230 includes steps 231 to 234 .
[0063] Step 210: Obtain the image to be recognized; the image to be recognized includes text and background.
[0064] Step 220: Determine the brightness weight according to the text brightness of the text and the background brightness of the background; the brightness weight is used to characterize the perception strength of the color difference by the human eye vision under different brightnesses.
[0065] In an optional embodiment, obtain the text brightness of the text and the background brightness of the background; when both the text brightness and the background brightness are less than the first threshold, determine the brightness weight as the first weight; when both the text brightness and the background brightness are greater than the second threshold, determine the brightness weight as the second weight; when both the text brightness and the background brightness are not less than the first threshold and not greater than the second threshold, determine the brightness weight as the third weight corresponding to the text weight and the background brightness; when the text brightness and the background brightness are not in the same threshold interval, determine the brightness weight as the fourth weight; wherein, the first threshold is less than the second threshold; the first weight is greater than the fourth weight which is greater than the second weight, and the third weight is a value within the interval from the first weight to the second weight.
[0066] That is, if the brightness value is lower than the threshold, the brightness weight is larger; if the brightness value is higher than a certain threshold, the brightness weight is smaller. For example:
[0067] When (L < T1), w L = w {L{high}} ;
[0068] When (L > T2), w L = w {L{low}} ;
[0069] When (T1 ≤ L ≤ T2), w L can be linearly interpolated based on w {L{high}} and w {L{low}} , or obtained using other smoothing functions.
[0070] Wherein, L is the brightness value; T1 is the first threshold; T2 is the second threshold; w L is the brightness weight; w {L{high}} is the high weight, i.e., the first weight; w {L{low}} is the low weight, i.e., the second weight.
[0071] The first weight can be a value greater than 1 and less than 2, and the second weight can be a value less than 1 and greater than 0.
[0072] The third weight can be the weight value corresponding to the current text brightness and background brightness after linear interpolation of the first weight and the second weight. That is, the third weight is a value not less than the first weight and not greater than the second weight. For example, the weight when the text brightness and the background brightness are both equal to the first threshold can be determined as the first weight, and the weight when the text brightness and the background brightness are both equal to the second threshold can be determined as the second weight. A weight value plane is obtained by linear interpolation, and the value of the point (text brightness, background brightness) on the weight value plane is the third weight.
[0073] Alternatively, the third weight may be a weight value corresponding to the current text brightness and background brightness after a smooth function is generated based on the first weight and the second weight. For example, the weight when both the text brightness and the background brightness are equal to the first threshold value may be determined as the first weight, and the weight when both the text brightness and the background brightness are equal to the second threshold value may be determined as the second weight, and a smooth transition function (smooth transition plane) is generated from the point of the first weight to the point of the second weight, and the value of the point (text brightness, background brightness) on the smooth transition plane is the third weight.
[0074] In the following cases, the brightness weight can take the fourth weight: the text brightness is less than the first threshold, and the background brightness is greater than the second threshold; or, the text brightness is less than the first threshold, and the background brightness is greater than the first threshold and less than the second threshold; or, the text brightness is greater than the second threshold, and the background brightness is less than the first threshold; or, the text brightness is greater than the second threshold, and the background brightness is greater than the first threshold and less than the second threshold; or, the text brightness is greater than the first threshold and less than the second threshold, and the background brightness is less than the first threshold; or, the text brightness is greater than the first threshold and less than the second threshold, and the background brightness is greater than the second threshold. The fourth weight can be the average of the first weight and the second weight.
[0075] The brightness can be obtained by: counting the brightness values of each first pixel point in the area where the text is located, and determining the brightness value with the largest number of first pixel points as the text brightness; counting the brightness values of each second pixel point in the area where the background is located, and determining the brightness value with the largest number of second pixel points as the background brightness. The first pixel point is a pixel point in the text area, and the first pixel point includes at least one pixel point; the second pixel point is a pixel point in the background area, and the second pixel point includes at least one pixel point.
[0076] For example, a histogram of the first pixel points is drawn, the horizontal axis of the histogram is the brightness value of each first pixel point, and the vertical axis of the histogram is the number of first pixel points corresponding to the brightness value. For example, if the statistical result is that there are 100 first pixel points of the first brightness value, 5 first pixel points of the second brightness value, and 2 first pixel points of the third brightness value, then the first brightness value is the brightness value with the largest number of first pixel points, and the first brightness value is determined as the text brightness.
[0077] For another example, a histogram of second pixels is drawn, the horizontal axis of the histogram is the brightness value of each second pixel, and the vertical axis of the histogram is the number of second pixels corresponding to the brightness value. For example, if the statistical result is that there are 100 second pixels with a fourth brightness value, 5 second pixels with a fifth brightness value, and 2 second pixels with a sixth brightness value, then the fourth brightness value is the brightness value with the largest number of second pixels, and the fourth brightness value is determined as the background brightness.
[0078] In another optional embodiment, a neural network model is called to output brightness weights and color weights based on the image to be recognized.
[0079] For example, a large amount of sample data is collected, and the sample data includes images of different brightness and chromaticity. The color weights and brightness weights corresponding to these sample data are manually annotated as labels for the sample data. The neural network model can use convolutional neural networks (CNN), input the images in the sample data into the neural network model, and output the brightness weights and color weights. The brightness weights and color weights of the image to be identified are predicted by the neural network model, which can improve the accuracy of identification.
[0080] Then the brightness difference between the text brightness and the background brightness can be calculated; the text brightness is the brightness value of the brightness channel of the text color, and the background brightness is the brightness value of the brightness channel of the background color; calculate the color difference between the text color of the text and the background color of the background; the text color is the color value of the color channel of the text color, and the background color is the color value of the color channel of the background color; calculate the weighted sum of the square of the brightness difference and the square of the color difference; the weight of the brightness difference is the brightness weight, and the weight of the color difference is the color weight; calculate the square root of the weighted sum to get the color difference.
[0081] In an optional embodiment, color weights may also be calculated.
[0082] The color weight is determined according to the text color of the text and the background color of the background; the color weight is used to characterize the strength of the human eye's perception of color difference under different colors.
[0083] In an alternative embodiment, obtain the text color of the text and the background color of the background; when both the text color and the background color are less than a third threshold, determine the color weight as a fifth weight; when both the text color and the background color are greater than a fourth threshold, determine the color weight as a sixth weight; when both the text color and the background color are not less than the third threshold and not greater than the fourth threshold, determine the color weight as a seventh weight corresponding to the text weight and the background color; when the text color and the background color are not in the same threshold range, determine the color weight as an eighth weight; wherein, the third threshold is less than the fourth threshold; the fifth weight is greater than the eighth weight which is greater than the sixth weight, and the seventh weight is a value within the range from the fifth weight to the sixth weight.
[0084] That is, if the color value is lower than the threshold, the color weight is larger; if the color value is higher than a certain threshold, the color weight is smaller. For example:
[0085] When (ab < T3), w ab = w {ab{high}} ;
[0086] When (ab > T4), w ab = w {ab{low}} ;
[0087] When (T3 ≤ ab ≤ T4), w ab can be obtained based on w {ab{high}} and w {ab{low}} by linear interpolation, or by using other smoothing functions.
[0088] Wherein, ab is the color value; T3 is the third threshold; T ab is the fourth threshold; w ab is the color weight; w {ab{high}} is the high weight, i.e., the fifth weight; w {ab{low}} is the low weight, i.e., the sixth weight.
[0089] The fifth weight can be a value greater than 1 and less than 2, and the sixth weight can be a value less than 1 and greater than 0.
[0090] The seventh weight can be the weight value corresponding to the current text color and background color after linearly interpolating the fifth weight and the sixth weight. That is, the seventh weight is a value not less than the fifth weight and not greater than the sixth weight. For example, the weight when both the text color and the background color are equal to the third threshold can be determined as the fifth weight, the weight when both the text color and the background color are equal to the fourth threshold can be determined as the sixth weight, and a weight value plane can be obtained by using the method of linear interpolation. The value of the point (text color, background color) on the weight value plane is the seventh weight.
[0091] Alternatively, the seventh weight may be a weight value corresponding to the current text color and background color after a smooth function is generated based on the fifth weight and the sixth weight. For example, the weight when both the text color and the background color are equal to the third threshold value may be determined as the fifth weight, and the weight when both the text color and the background color are equal to the fourth threshold value may be determined as the sixth weight, and a smooth transition function (smooth transition plane) is generated from the point of the fifth weight to the point of the sixth weight, and the value of the point (text color, background color) on the smooth transition plane is the seventh weight.
[0092] In the following cases, the color weight may take the eighth weight: the text color is less than the third threshold, and the background color is greater than the fourth threshold; or, the text color is less than the third threshold, and the background color is greater than the third threshold and less than the fourth threshold; or, the text color is greater than the fourth threshold, and the background color is less than the third threshold; or, the text color is greater than the fourth threshold, and the background color is greater than the third threshold and less than the fourth threshold; or, the text color is greater than the third threshold and less than the fourth threshold, and the background color is less than the third threshold; or, the text color is greater than the third threshold and less than the fourth threshold, and the background color is greater than the fourth threshold. The eighth weight may be the average of the fifth weight and the sixth weight.
[0093] The method of obtaining the color may be: counting the color values of each first pixel point in the area where the text is located, and determining the color value with the largest number of first pixel points as the text color; counting the color values of each second pixel point in the area where the background is located, and determining the color value with the largest number of second pixel points as the background color. The first pixel point is the pixel point of the text area, and the first pixel point includes at least one pixel point; the second pixel point is the pixel point of the background area, and the second pixel point includes at least one pixel point.
[0094] For example, a histogram of the first pixel points is drawn, the horizontal axis of the histogram is the color value of each first pixel point, and the vertical axis of the histogram is the number of first pixel points corresponding to the color value. For example, if the statistical result is that there are 100 first pixel points of the first color value, 5 first pixel points of the second color value, and 2 first pixel points of the third color value, then the first color value is the color value with the largest number of first pixel points, and the first color value is determined as the text color.
[0095] For another example, a histogram of second pixels is drawn, the horizontal axis of the histogram is the color value of each second pixel, and the vertical axis of the histogram is the number of second pixels corresponding to the color value. For example, if the statistical result is that there are 100 second pixels of the fourth color value, 5 second pixels of the fifth color value, and 2 second pixels of the sixth color value, then the fourth color value is the color value with the largest number of second pixels, and the fourth color value is determined as the background color.
[0096] Step 231: Calculate the brightness difference between the text brightness and the background brightness; the text brightness is the brightness value of the brightness channel of the text color, and the background brightness is the brightness value of the brightness channel of the background color.
[0097] Exemplarily, the brightness value of the first pixel with the highest number in the area where the text is located is determined as the text brightness, and the brightness value of the second pixel with the highest number in the area where the background is located is determined as the background brightness, and the difference between the text brightness and the background brightness is calculated.
[0098] Alternatively, the brightness values of all pixels in the image to be identified are counted, and the first brightness value with the largest number of pixels is determined as the background brightness value, and the second brightness value with the second largest number of pixels is determined as the text brightness value. Since the image to be identified usually includes only two colors, one is the text color and the other is the background color, and the number of pixels occupied by the background is usually more than that of the text, the brightness value with the largest number in the image to be identified can be approximately determined as the background brightness; and the brightness value with the second largest number can be determined as the text brightness.
[0099] Exemplarily, the brightness difference value may be the text brightness minus the background brightness, or the background brightness minus the text brightness. For example, if the text brightness is 100 and the background brightness is 0, the brightness difference value may be 100, or the brightness difference value may be -100.
[0100] Step 232: Calculate the color difference between the text color of the text and the background color of the background; the text color is the color value of the color channel of the text color, and the background color is the color value of the color channel of the background color.
[0101] Using the CIE Lab color system, the values of the a channel and the b channel are color values, that is, the color value is the coordinate point of (a, b). Calculating the difference between two colors is to calculate the distance between the two coordinate points.
[0102] Similarly, when determining the text color and background color, the color values of the first pixel points in the area where the text is located can be counted separately, and the color value with the largest number of first pixel points can be determined as the text color; the color values of the second pixel points in the area where the background is located can be counted, and the color value with the largest number of second pixel points can be determined as the background color value.
[0103] Alternatively, the color values of all pixels in the image to be identified may be counted, and the first color value with the largest number of pixels is used as the background color of the background, and the second color value with the second largest number of pixels is used as the text color of the text.
[0104] That is, the color value of each pixel in the image to be identified is counted, and the first color value and the second color value whose number of pixels is higher than the number threshold are obtained; the difference between the first color value and the second color value is calculated to obtain the color difference value. The first color value may be the color value with the highest number of pixels, and the second color value may be the color value with the second highest number of pixels.
[0105] Optionally, when the background includes multiple colors, the two colors with the most pixels obtained by statistics may both be background colors. In this case, a quantity threshold can be set to obtain all color values with pixel numbers higher than the threshold, and then calculate the color difference between them to obtain at least two color differences. The color difference is calculated based on the at least two color differences to obtain at least two color differences. When one of the at least two color differences is lower than the color difference threshold, it is determined that the text in the image to be identified is similar to the background color.
[0106] That is, there may be at least two colors whose number of pixels is higher than the number threshold: obtain at least two color values whose number of pixels is higher than the number threshold; and select any two color values from the at least two color values as the first color value and the second color value.
[0107] In an optional embodiment, since there are many color values and the number of single color values is small, the color with the highest number cannot be accurately identified. Therefore, the color values can be divided into at least two value intervals, the color values of the pixels in the image to be identified are mapped to the respective value intervals, and the color values in one value interval are mapped to the color values corresponding to the value interval.
[0108] For example, if the value range of the a channel is 0-100, 0-100 can be divided into 5 value intervals: 0-20, 21-40, 41-60, 61-80, 81-100. 0-20 corresponds to color value 1, 21-40 corresponds to color value 2, 41-60 corresponds to color value 3, 61-80 corresponds to color value 4, and 81-100 corresponds to color value 5. Similarly, if the value range of the b channel is 0-100, 0-100 can be divided into 5 value intervals: 0-20, 21-40, 41-60, 61-80, 81-100. 0-20 corresponds to color value 1, 21-40 corresponds to color value 2, 41-60 corresponds to color value 3, 61-80 corresponds to color value 4, and 81-100 corresponds to color value 5. Then a color value with a channel of 58 and b channel of 1 can be mapped to a channel of 4 and b channel of 1.
[0109] Alternatively, the a and b channels of the entire image to be identified are quantized into 32*32 regions, the color values of each channel are divided into 32 value intervals, and the color values are mapped into 32*32 value intervals. Then the color values of each pixel in the image to be identified are counted to generate a two-dimensional histogram. The two histograms with the largest number are selected as the font color and background color.
[0110] That is, the color values are divided into at least two value intervals; the color values of the image to be identified are mapped to at least two value intervals, and the number of pixels in at least two value intervals is counted; the color values corresponding to at least two value intervals in which the number of pixels is higher than a quantity threshold are determined as at least two color values.
[0111] Step 233: Calculate the weighted sum of the square of the brightness difference and the square of the color difference; the weight of the brightness difference is the brightness weight.
[0112] Step 234: Calculate the square root of the weighted sum to obtain the color difference.
[0113] That is, the color difference formula can be:
[0114] Where ΔE is the color difference; w L is the brightness weight; ΔL is the brightness difference; w ab is the color weight, the default value is 1; ΔR is the color difference.
[0115] In summary, the method provided in this embodiment can count the brightness of each pixel in the text area respectively, and determine the brightness value with the largest number of pixels as the text brightness; count the brightness of each pixel in the background area, and determine the brightness value with the largest number of pixels as the background brightness; determine the brightness weight based on the threshold conditions satisfied by the text brightness and the background brightness. When the text brightness and the background brightness are both low, the brightness weight is set to a larger value to reduce the proportion of the color difference in the color difference and increase the proportion of the brightness difference in the color difference. When the text brightness and the background brightness are both high and low, the brightness weight is set to a smaller value to increase the proportion of the color difference in the color difference and reduce the proportion of the brightness difference in the color difference. Make the color difference result consistent with the human eye's perception of color tone in a low-brightness environment. The color difference is calculated based on the brightness weight, so that the calculated color difference can accurately judge whether the color is similar from the perspective of the human eye, so as to quickly identify the color matching problem of the text and the background, facilitate the adjustment of the color matching of the text and the background in the application, and optimize the user experience.
[0116] Figure 5 FIG. 1 is a flow chart of a method for calculating color difference provided by an exemplary embodiment of the present application. The method can be used for Figure 1 The terminal or server shown. Figure 2In the illustrated embodiment, step 210 may include step 211 and step 212 , and step 230 may further include step 240 .
[0117] Step 211: Obtain an application interface image.
[0118] The application interface diagram may be a screenshot of each application interface captured from the application program, or the application interface diagram may be an interface diagram of each application interface rendered by a server.
[0119] For example, all application interface images in an application can be traversed to filter out locations where text and background colors are similar, so that developers can adjust the text color or background color at these locations, improve the clarity of the text at these locations, and optimize the user's visual experience when browsing the application.
[0120] Step 212: Call OCR to identify and capture the area where the text is located from the application interface image to obtain an image to be recognized.
[0121] For example, OCR can be called to identify the area where the text is located from the application interface image; the area where the text is located is captured to obtain the original image; the original image is processed using an edge enhancement algorithm to obtain an image to be recognized. The size of the original image is determined according to the size of the text. For example, the height of the original image can be consistent with the height of the text, and the length of the original image can be consistent with the length of the text. Alternatively, the height of the original image can be the height of the text plus the first margin, and the length of the original image can be the length of the text plus the second margin, wherein the first margin and the second margin can be preset values.
[0122] Optionally, lower the OCR recognition accuracy threshold to ensure that the text area in the application interface image is not missed. Subsequently, the original image is converted to a grayscale image to reduce the interference of the color channel on the edge enhancement algorithm. Use an edge enhancement algorithm (e.g., Sobel operator) to enhance the image edge features and remove the influence of transition colors.
[0123] Exemplarily, the edge enhancement algorithm is used to clarify the boundary line between the text area and the background area, and replace the transition color at the boundary line with the color in the text area or the background area, so as to accurately determine the text color and background color in subsequent processing.
[0124] Step 220: Determine a brightness weight according to the text brightness of the text and the background brightness; the brightness weight is used to characterize the degree of human visual perception of color difference under different brightness.
[0125] Step 230: Calculate the color difference between the text color of the text and the background color of the background according to the brightness weight.
[0126] For example, it can be used Figure 2 or Figure 4 The method provided by the illustrated embodiment determines the brightness weight and calculates the color difference.
[0127] Step 240: When the color difference is lower than the color difference threshold, abnormal information of the application interface image is fed back.
[0128] Among them, the abnormal information includes at least one of the following: the identifier of the application interface where the application interface image is located, the image to be identified, the position of the image to be identified in the application interface image, the text of the text in the image to be identified, the text color of the text, and the background color of the background.
[0129] After the color difference is calculated, if the color difference is small according to the color difference threshold, it means that the text color is similar to the background color, and the user may not be able to clearly distinguish the text content. It is necessary to feedback that the text display at that location is abnormal. For example, the terminal can feedback the abnormal information of the application interface diagram to the server, and the abnormal information can indicate at least one of the following information: the application interface diagram (representation) where the abnormality occurs, the abnormal location (the location of the image to be identified on the application interface diagram), the text content of the abnormal location, the text color and background color used at the abnormal location, etc.
[0130] Based on the exception information, developers can accurately locate the interface position where the exception is displayed, allowing developers to quickly adjust the text color or background color of the exception position to optimize the user browsing experience.
[0131] In an optional embodiment, when the color difference is lower than the color difference threshold, the text color or the background color may be automatically adjusted. For example, when the color difference is lower than the color difference threshold, the text color is adjusted to the opposite color of the background color; or the background color is adjusted to the opposite color of the text color.
[0132] The opposite color can be obtained by taking the L channel of the text color as the first value, the a channel as the second value, and the b channel as the third value as an example; the opposite color of the text color, the L channel, is 100 minus the first value, the a channel is the negative of the second value, and the b channel is the negative of the third value.
[0133] Alternatively, when the color difference is lower than the color difference threshold, the target background color is calculated based on the color difference threshold and the text color, and the background color is adjusted to the target background color, wherein the color difference between the target background color and the text color is greater than the color difference threshold.
[0134] Alternatively, when the color difference is lower than the color difference threshold, the target text color is calculated based on the color difference threshold and the background color, and the text color is adjusted to the target text color, wherein the color difference between the target text color and the background color is greater than the color difference threshold.
[0135] Among them, the target background color or target text color can be obtained by increasing the value of the L channel of the background color or text color by n times the preset value, where n is an integer; the computer device can set n equal to 1, and calculate whether the color difference when n is equal to 1 is greater than the color difference threshold. If it is greater, the current color is determined to be the target background color or target text color; if it is not greater, n is set equal to n+1 to continue calculating the color difference until the color difference is greater than the color difference threshold or the value of the L channel takes the maximum value. If the color difference obtained after the value of the L channel takes the maximum value is still less than the color difference threshold, n is set equal to -1 and the color difference is calculated. When the color difference is still less than the color difference threshold, n is set equal to n-1 again until the calculated color difference is greater than the color difference threshold.
[0136] To summarize, the method provided in this embodiment can calculate the color difference based on the human eye's perception of color difference, so that the calculated color difference can accurately reflect the human eye's perception of text and background colors. Based on the color difference, the positions where users cannot see the text clearly can be accurately filtered out from the user interface, so that developers can adjust the text color or background color of these positions, so that users can clearly see the text content, thereby optimizing the user's visual experience when browsing the application.
[0137] The method provided in this embodiment can automatically adjust the text color and background color based on the color difference threshold, so that the user can clearly read the adjusted questions, thereby optimizing the user's browsing experience.
[0138] It should be noted that before collecting relevant data of users and during the process of collecting relevant data of users, this application can display a prompt interface, pop-up window or output voice prompt information, and the prompt interface, pop-up window or voice prompt information is used to prompt the user that its relevant data is currently being collected, so that this application only starts to execute the relevant steps of obtaining relevant data of users after obtaining the confirmation operation issued by the user to the prompt interface or pop-up window, otherwise (that is, when the confirmation operation issued by the user to the prompt interface or pop-up window is not obtained), the relevant steps of obtaining relevant data of users are terminated, that is, the relevant data of users are not obtained. In other words, all user data collected by this application are collected with the consent and authorization of the user, and the collection, use and processing of relevant user data need to comply with the relevant laws, regulations and standards of relevant countries and regions.
[0139] It should be noted that the sequence of the method steps provided in the embodiments of the present application can be appropriately adjusted, and the steps can be increased or decreased accordingly according to the circumstances. Any technician familiar with the technical field can easily think of the changed methods within the technical scope disclosed in the present application, and they should be included in the protection scope of the present application, so they will not be repeated here.
[0140] Figure 6: is a schematic diagram of a color difference calculation device provided by an exemplary embodiment of the present application. The device comprises:
[0141] The acquisition module 801 is used to acquire an image to be recognized; the image to be recognized includes text and background;
[0142] A weight module 802 is used to determine a brightness weight according to the brightness of the text and the background brightness of the background; the brightness weight is used to represent the intensity of human visual perception of color difference under different brightness;
[0143] The calculation module 803 is used to calculate the color difference between the text color of the text and the background color of the background according to the brightness weight.
[0144] In an optional embodiment, the weight module 802 is used to obtain the text brightness of the text and the background brightness of the background;
[0145] The weight module 802 is used to determine the brightness weight as a first weight when both the text brightness and the background brightness are less than a first threshold;
[0146] The weight module 802 is used to determine the brightness weight as a second weight when both the text brightness and the background brightness are greater than a second threshold;
[0147] The weight module 802 is used to determine the brightness weight as a third weight corresponding to the text weight and the background brightness when both the text brightness and the background brightness are not less than the first threshold and not greater than the second threshold;
[0148] The weight module 802 is configured to determine the brightness weight as a fourth weight when the text brightness and the background brightness are not within the same threshold interval;
[0149] Among them, the first threshold is smaller than the second threshold; the first weight is larger than the fourth weight and larger than the second weight; and the third weight is a value within the range from the first weight to the second weight.
[0150] In an optional embodiment, the weight module 802 is used to count the brightness values of each first pixel point in the area where the text is located, and determine the brightness value of the first pixel point with the largest number as the text brightness;
[0151] The weight module 802 is used to count the brightness values of each second pixel point in the area where the background is located, and determine the brightness value of the second pixel point with the largest number as the background brightness.
[0152] In an optional embodiment, the acquisition module 801 is used to acquire an application interface diagram;
[0153] The acquisition module 801 is used to call optical character recognition (OCR) to identify the area where the text is located from the application interface image;
[0154] The acquisition module 801 is used to capture the area where the text is located to obtain the image to be recognized;
[0155] The size of the image to be recognized matches the size of the text.
[0156] In an optional embodiment, the acquisition module 801 is used to call OCR to identify the area where the text is located from the application interface image;
[0157] The acquisition module 801 is used to capture the area where the text is located to obtain an original image;
[0158] The acquisition module 801 is used to process the original image using an edge enhancement algorithm to obtain the image to be recognized.
[0159] In an optional embodiment, the calculation module 803 is used to calculate the brightness difference between the text brightness and the background brightness; the text brightness is the brightness value of the brightness channel of the text color, and the background brightness is the brightness value of the brightness channel of the background color;
[0160] The calculation module 803 is used to calculate the color difference between the text color of the text and the background color of the background; the text color is the color value of the color channel of the text color, and the background color is the color value of the color channel of the background color;
[0161] The calculation module 803 is used to calculate the weighted sum of the square of the brightness difference value and the square of the color difference value; the weight of the brightness difference value is the brightness weight;
[0162] The calculation module 803 is used to calculate the square root of the weighted sum to obtain the color difference.
[0163] In an optional embodiment, the calculation module 803 is used to count the color value of each pixel in the image to be identified, and obtain the first color value and the second color value of the pixel number that is higher than the number threshold;
[0164] The calculation module 803 is used to calculate the difference between the first color value and the second color value to obtain the color difference.
[0165] In an optional embodiment, the calculation module 803 is used to obtain at least two color values whose number of pixels is higher than a number threshold;
[0166] The calculation module 803 is configured to select any two color values from the at least two color values as the first color value and the second color value.
[0167] In an optional embodiment, the calculation module 803 is used to divide the color value into at least two value intervals;
[0168] The calculation module 803 is used to map the color value of the image to be identified to the at least two value intervals, and count the number of pixels in the at least two value intervals;
[0169] The calculation module 803 is used to determine the color values corresponding to at least two value intervals in which the number of pixel points is higher than the number threshold as the at least two color values.
[0170] In an optional embodiment, the image to be recognized is captured from an application interface image; the device further includes:
[0171] A feedback module 804 is used to feedback abnormal information of the application interface image when the color difference is lower than the color difference threshold;
[0172] Among them, the abnormal information includes at least one of the following: the identifier of the application interface where the application interface image is located, the image to be identified, the position of the image to be identified in the application interface image, the text of the text in the image to be identified, the text color of the text, and the background color of the background.
[0173] In an optional embodiment, the weight module 802 is used to call a neural network model to output the brightness weight and color weight based on the image to be identified.
[0174] In an optional embodiment, the calculation module 803 is used to calculate the brightness difference between the text brightness and the background brightness; the text brightness is the brightness value of the brightness channel of the text color, and the background brightness is the brightness value of the brightness channel of the background color;
[0175] The calculation module 803 is used to calculate the color difference between the text color of the text and the background color of the background; the text color is the color value of the color channel of the text color, and the background color is the color value of the color channel of the background color;
[0176] The calculation module 803 is used to calculate the weighted sum of the square of the brightness difference value and the square of the color difference value; the weight of the brightness difference value is the brightness weight, and the weight of the color difference value is the color weight;
[0177] The calculation module 803 is used to calculate the square root of the weighted sum to obtain the color difference.
[0178] It should be noted that the color difference calculation device provided in the above embodiment is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the color difference calculation device provided in the above embodiment and the color difference calculation method embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0179] The embodiment of the present application further provides a computer device, which includes: a processor and a memory, wherein at least one instruction, at least one program, code set or instruction set is stored in the memory, and the at least one instruction, at least one program, code set or instruction set is loaded and executed by the processor to implement the color difference calculation method provided by the above-mentioned method embodiments. The computer device can be implemented as a terminal.
[0180] For example, Figure 7 It is a structural diagram of a computer device provided by an exemplary embodiment of the present application.
[0181] Typically, the computer device 1700 includes a processor 1701 and a memory 1702 .
[0182] The processor 1701 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 1701 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 1701 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 1701 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 1701 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0183] The memory 1702 may include one or more computer-readable storage media, which may be non-transitory. The memory 1702 may also include a high-speed random access memory and a non-volatile memory, such as one or more disk storage devices and flash memory storage devices. In some embodiments, the non-transitory computer-readable storage medium in the memory 1702 is used to store at least one instruction, which is used to be executed by the processor 1701 to implement the color difference calculation method provided in the method embodiment of the present application.
[0184] In some embodiments, the computer device 1700 may also optionally include: a peripheral device interface 1703 and at least one peripheral device. The processor 1701, the memory 1702 and the peripheral device interface 1703 may be connected via a bus or a signal line. Each peripheral device may be connected to the peripheral device interface 1703 via a bus, a signal line or a circuit board. Specifically, the peripheral device includes: at least one of a radio frequency circuit 1704, a display screen 1705, a camera assembly 1706, an audio circuit 1707 and a power supply 1708.
[0185] The peripheral device interface 1703 may be used to connect at least one peripheral device related to I / O (Input / Output) to the processor 1701 and the memory 1702. In some embodiments, the processor 1701, the memory 1702, and the peripheral device interface 1703 are integrated on the same chip or circuit board; in some other embodiments, any one or two of the processor 1701, the memory 1702, and the peripheral device interface 1703 may be implemented on a separate chip or circuit board, which is not limited in the embodiments of the present application.
[0186] The radio frequency circuit 1704 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The radio frequency circuit 1704 communicates with the communication network and other communication devices through electromagnetic signals. The radio frequency circuit 1704 converts the electrical signal into an electromagnetic signal for transmission, or converts the received electromagnetic signal into an electrical signal. Optionally, the radio frequency circuit 1704 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, and the like. The radio frequency circuit 1704 can communicate with other computer devices through at least one wireless communication protocol. The wireless communication protocol includes, but is not limited to: the World Wide Web, a metropolitan area network, an intranet, various generations of mobile communication networks (2G, 3G, 4G and 5G), a wireless local area network and / or a WiFi (Wireless Fidelity) network. In some embodiments, the radio frequency circuit 1704 may also include circuits related to NFC (Near Field Communication), which is not limited in this application.
[0187] The display screen 1705 is used to display a UI (User Interface). The UI may include graphics, text, icons, videos, and any combination thereof. When the display screen 1705 is a touch display screen, the display screen 1705 also has the ability to collect touch signals on the surface or above the surface of the display screen 1705. The touch signal can be input to the processor 1701 as a control signal for processing. At this time, the display screen 1705 can also be used to provide virtual buttons and / or virtual keyboards, also known as soft buttons and / or soft keyboards. In some embodiments, the display screen 1705 can be one, and the front panel of the computer device 1700 is set; in other embodiments, the display screen 1705 can be at least two, which are respectively set on different surfaces of the computer device 1700 or are folded; in some other embodiments, the display screen 1705 can be a flexible display screen, which is set on the curved surface or folded surface of the computer device 1700. Even, the display screen 1705 can also be set to a non-rectangular irregular shape, that is, a special-shaped screen. The display screen 1705 can be made of materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).
[0188] The camera assembly 1706 is used to capture images or videos. Optionally, the camera assembly 1706 includes a front camera and a rear camera. Typically, the front camera is arranged on the front panel of the computer device 1700, and the rear camera is arranged on the back of the computer device. In some embodiments, there are at least two rear cameras, which are any one of a main camera, a depth of field camera, a wide-angle camera, and a telephoto camera, so as to realize the fusion of the main camera and the depth of field camera to realize the background blur function, the fusion of the main camera and the wide-angle camera to realize the panoramic shooting and VR (Virtual Reality) shooting function or other fusion shooting functions. In some embodiments, the camera assembly 1706 may also include a flash. The flash can be a monochrome temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cold light flash, which can be used for light compensation at different color temperatures.
[0189] The audio circuit 1707 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, and convert the sound waves into electrical signals and input them into the processor 1701 for processing, or input them into the radio frequency circuit 1704 to achieve voice communication. For the purpose of stereo acquisition or noise reduction, there may be multiple microphones, which are respectively arranged at different parts of the computer device 1700. The microphone may also be an array microphone or an omnidirectional acquisition microphone. The speaker is used to convert the electrical signal from the processor 1701 or the radio frequency circuit 1704 into sound waves. The speaker may be a traditional film speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can not only convert the electrical signal into sound waves audible to humans, but also convert the electrical signal into sound waves inaudible to humans for purposes such as ranging. In some embodiments, the audio circuit 1707 may also include a headphone jack.
[0190] The power supply 1708 is used to power various components in the computer device 1700. The power supply 1708 can be an alternating current, a direct current, a disposable battery, or a rechargeable battery. When the power supply 1708 includes a rechargeable battery, the rechargeable battery can be a wired rechargeable battery or a wireless rechargeable battery. A wired rechargeable battery is a battery that is charged through a wired line, and a wireless rechargeable battery is a battery that is charged through a wireless coil. The rechargeable battery can also be used to support fast charging technology.
[0191] In some embodiments, the computer device 1700 further includes one or more sensors 1709 , including but not limited to: an acceleration sensor 1710 , a gyroscope sensor 1711 , a pressure sensor 1712 , an optical sensor 1713 , and a proximity sensor 1714 .
[0192] The acceleration sensor 1710 can detect the magnitude of acceleration on the three coordinate axes of the coordinate system established by the computer device 1700. For example, the acceleration sensor 1710 can be used to detect the components of gravity acceleration on the three coordinate axes. The processor 1701 can control the touch display screen 1705 to display the user interface in a horizontal view or a vertical view according to the gravity acceleration signal collected by the acceleration sensor 1710. The acceleration sensor 1710 can also be used to collect game or user motion data.
[0193] The gyro sensor 1711 can detect the body direction and rotation angle of the computer device 1700, and the gyro sensor 1711 can cooperate with the acceleration sensor 1710 to collect the user's 3D actions on the computer device 1700. The processor 1701 can implement the following functions based on the data collected by the gyro sensor 1711: motion sensing (such as changing the UI according to the user's tilt operation), image stabilization during shooting, game control, and inertial navigation.
[0194] The pressure sensor 1712 can be set on the side frame of the computer device 1700 and / or the lower layer of the touch display screen 1705. When the pressure sensor 1712 is set on the side frame of the computer device 1700, it can detect the user's grip signal of the computer device 1700, and the processor 1701 performs left and right hand recognition or shortcut operations according to the grip signal collected by the pressure sensor 1712. When the pressure sensor 1712 is set on the lower layer of the touch display screen 1705, the processor 1701 controls the operability controls on the UI interface according to the user's pressure operation on the touch display screen 1705. The operability controls include at least one of a button control, a scroll bar control, an icon control, and a menu control.
[0195] The optical sensor 1713 is used to collect the ambient light intensity. In one embodiment, the processor 1701 can control the display brightness of the touch display screen 1705 according to the ambient light intensity collected by the optical sensor 1713. Specifically, when the ambient light intensity is high, the display brightness of the touch display screen 1705 is increased; when the ambient light intensity is low, the display brightness of the touch display screen 1705 is reduced. In another embodiment, the processor 1701 can also dynamically adjust the shooting parameters of the camera assembly 1706 according to the ambient light intensity collected by the optical sensor 1713.
[0196] The proximity sensor 1714, also called a distance sensor, is usually arranged on the front panel of the computer device 1700. The proximity sensor 1714 is used to collect the distance between the user and the front of the computer device 1700. In one embodiment, when the proximity sensor 1714 detects that the distance between the user and the front of the computer device 1700 is gradually decreasing, the processor 1701 controls the touch display screen 1705 to switch from the screen-on state to the screen-off state; when the proximity sensor 1714 detects that the distance between the user and the front of the computer device 1700 is gradually increasing, the processor 1701 controls the touch display screen 1705 to switch from the screen-off state to the screen-on state.
[0197] Those skilled in the art will understand that Figure 7 The structure shown in the figure does not constitute a limitation on the computer device 1700, and the computer device 1700 may include more or less components than shown in the figure, or combine some components, or adopt a different arrangement of components.
[0198] In an embodiment of the present application, a computer-readable storage medium is also provided, in which at least one instruction, at least one program, code set or instruction set is stored. When the at least one instruction, at least one program, code set or instruction set is loaded and executed by a processor of a computer device, the color difference calculation method provided in the above-mentioned method embodiments is implemented.
[0199] The present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the color difference calculation method provided by each of the above method embodiments.
[0200] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned readable storage medium may be a read-only memory, a disk or an optical disk, etc.
[0201] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent switching, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A method for calculating color difference, characterized in that: The method comprises: Acquire an image to be identified; the image to be identified includes text and background; Determining a brightness weight based on the brightness of the text and the background brightness of the background; the brightness weight is used to represent the intensity of human visual perception of color difference under different brightness; The color difference between the text color of the text and the background color of the background is calculated according to the brightness weight.
2. The method according to claim 1, characterized in that The determining of the brightness weight according to the brightness of the text and the background brightness of the background includes: Obtaining the brightness of the text and the background brightness of the background; When both the text brightness and the background brightness are less than a first threshold, determining the brightness weight as a first weight; When both the text brightness and the background brightness are greater than a second threshold, determining the brightness weight as a second weight; When both the text brightness and the background brightness are not less than the first threshold and not greater than the second threshold, determining the brightness weight as a third weight corresponding to the text weight and the background brightness; When the text brightness and the background brightness are not within the same threshold range, determining the brightness weight as a fourth weight; Among them, the first threshold is smaller than the second threshold; the first weight is larger than the fourth weight and larger than the second weight; the third weight is a value within the range from the first weight to the second weight.
3. The method according to claim 2, characterized in that The obtaining of the brightness of the text and the background brightness of the background includes: Counting the brightness values of the first pixels in the area where the text is located, and determining the brightness value of the first pixel with the largest number as the brightness of the text; The brightness values of the second pixels in the area where the background is located are counted, and the brightness value of the second pixel with the largest number is determined as the background brightness.
4. The method according to any one of claims 1 to 3, characterized in that: The step of obtaining an image to be identified includes: Get the application interface image; Invoke optical character recognition (OCR) to identify the area where the text is located from the application interface image; intercepting the area where the text is located to obtain the image to be recognized; The size of the image to be recognized matches the size of the text.
5. The method according to claim 4, characterized in that The step of intercepting the area where the text is located to obtain the image to be recognized includes: Cutting out the area where the text is located to obtain the original image; The original image is processed using an edge enhancement algorithm to obtain the image to be recognized.
6. The method according to any one of claims 1 to 3, characterized in that: Calculating the color difference between the text color and the background color of the background according to the brightness weight includes: Calculating the brightness difference between the text brightness and the background brightness; the text brightness is the brightness value of the brightness channel of the text color, and the background brightness is the brightness value of the brightness channel of the background color; Calculating a color difference between the text color of the text and the background color of the background; the text color is the color value of the color channel of the text color, and the background color is the color value of the color channel of the background color; Calculating a weighted sum of the square of the brightness difference and the square of the color difference; the weight of the brightness difference is the brightness weight; The square root of the weighted sum is calculated to obtain the color difference.
7. The method according to claim 6, characterized in that The calculating the color difference between the text color of the text and the background color of the background includes: Counting the color value of each pixel in the image to be identified, and obtaining a first color value and a second color value in which the number of pixels exceeds a threshold; The color difference value is obtained by calculating the difference between the first color value and the second color value.
8. The method according to claim 7, characterized in that The step of obtaining the first color value and the second color value in which the number of pixels is greater than a number threshold comprises: Obtain at least two color values whose number of pixels is greater than a number threshold; Select any two color values from the at least two color values as the first color value and the second color value.
9. The method according to claim 8, characterized in that The acquiring of at least two color values whose number of pixel points is greater than a number threshold comprises: Dividing the color value into at least two value intervals; Mapping the color value of the image to be identified to the at least two value intervals, and counting the number of pixels in the at least two value intervals; The color values corresponding to at least two value intervals in which the number of pixel points is higher than the number threshold are determined as the at least two color values.
10. The method according to any one of claims 1 to 3, characterized in that: The image to be identified is captured from an application interface image; the method further includes: When the color difference is lower than the color difference threshold, feeding back abnormal information of the application interface image; Among them, the abnormal information includes at least one of the following: the identifier of the application interface where the application interface image is located, the image to be identified, the position of the image to be identified in the application interface image, the text of the text in the image to be identified, the text color of the text, and the background color of the background.
11. The method according to any one of claims 1 to 10, characterized in that: The determining of the brightness weight according to the brightness of the text and the background brightness of the background includes: The neural network model is called to output the brightness weight and color weight based on the image to be identified; the color weight is used to characterize the human eye's visual perception of color difference under different colors.
12. The method according to claim 11, characterized in that Calculating the color difference between the text color and the background color of the background according to the brightness weight includes: Calculating the brightness difference between the text brightness and the background brightness; the text brightness is the brightness value of the brightness channel of the text color, and the background brightness is the brightness value of the brightness channel of the background color; Calculating a color difference between the text color of the text and the background color of the background; the text color is the color value of the color channel of the text color, and the background color is the color value of the color channel of the background color; Calculating a weighted sum of the square of the brightness difference and the square of the color difference; the weight of the brightness difference is the brightness weight, and the weight of the color difference is the color weight; The square root of the weighted sum is calculated to obtain the color difference.
13. A computer device, characterized in that: The computer device includes a processor and a memory, wherein the memory stores at least one program, and the at least one program is loaded and executed by the processor to implement the color difference calculation method according to any one of claims 1 to 12.
14. A computer-readable storage medium, characterized in that The readable storage medium stores at least one program, and the at least one program is loaded and executed by a processor to implement the color difference calculation method according to any one of claims 1 to 12.
15. A computer program product, characterized in that The computer program product includes computer instructions, which are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the color difference calculation method according to any one of claims 1 to 12.
Citation Information
Cited By
Printing image-text defect detection method based on machine vision
CN120765662A