Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. It will be apparent that the described embodiments are only some, but not all, embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to fall within the scope of the invention.
As shown in fig. 1, an embodiment of the present invention provides an image processing method, which is applied to an electronic device, and the method includes steps S11 to S15.
Step S11, an RGB image is acquired.
Step S12, converting the RGB image into a YUV image.
In the embodiment of the invention, in the process of converting an RGB image into a YUV image, converting RGB to obtain a luminance signal Y channel and two saturation signals U and V channels, and specifically converting RGB into YUV can be seen in the prior art.
Step S13, pulling up the Y channel of the YUV image from the first luminance component to the second luminance component.
Step S14, calculating the change proportion of the brightness component of the Y channel according to the first brightness component and the second brightness component.
In the embodiment of the present invention, optionally, the calculation formula of the variation ratio is:wherein Ratio is a change Ratio, Y out For the second luminance component, Y in For the first luminance component, δ is a preset extremum that is not zero. Where δ is a minimum value for preventing the denominator from being zero.
And S15, compensating saturation components of a U channel and a V channel of the YUV image according to the change proportion.
In the embodiment of the present invention, optionally, the calculation formula of the saturation component is: u (U) out =Ratio*U in ;V out =Ratio*V in The method comprises the steps of carrying out a first treatment on the surface of the Wherein U is in For the primary saturation component of the U channel, U out For the saturation component after the U channel compensation, V in For the primary saturation component of V channel, V out And compensating the saturation component for the V channel.
And the saturation component is correspondingly adjusted according to the change proportion of the brightness data, so that the color of the color-compensated image is kept, and the image quality is improved.
Referring to fig. 2, step S15 may further include steps S21 to S24.
Step S21, judging whether the change proportion is smaller than a preset value.
In the embodiment of the present invention, the preset value is preferably 1.0, but is not limited thereto. By judging the change proportion and comparing with 1.0, the Y channel of the YUV image can be known to be darkened or lightened.
And S22, when the change proportion is smaller than the preset value, adjusting the change proportion to be a first proportion.
In the embodiment of the present invention, when the variation ratio is determined to be smaller than the preset value (i.e., 1.0), it is indicated that the image is darkened, and in order to prevent the image color from being darkened, the variation ratio needs to be adjusted to a first ratio, and the saturation component is adjusted by the first ratio.
Referring to fig. 3, step S22 includes steps S31 to S32.
Step S31, obtaining luminance data of the YUV image.
In the embodiment of the invention, the brightness data can be calculated in any color space. Specifically, for example, 709 color gamut of YUV color space, the calculation mode of brightness data is as follows:
Y=0.213*R in +0.715*G in +0.072*B in 。
step S32, obtaining a first gain coefficient corresponding to the brightness data.
The electronic device is preset with a Look-up table (LUT) in which a number of discrete coordinate points are stored, where the coordinate points are sampling points on the luminance mapping curve. The abscissa of the coordinate point is the brightness data, namely the input of the brightness mapping curve, and the ordinate of the coordinate point is the first gain coefficient, namely the output of the brightness mapping curve. It should be appreciated that since the mapping relationship in the luminance look-up table is a set of discrete points, if the input luminance data is not among the discrete points, the input luminance data may be interpolated based on the known luminance data, thereby obtaining the first gain coefficient corresponding to the luminance data.
In an embodiment of the present invention, the luminance look-up table represents a simplest luminance mapping curve as shown in fig. 5.
And step S33, adjusting the change proportion to be a first proportion according to the first gain coefficient.
In the embodiment of the present invention, the calculation formula of the first ratio is: ratio L =Ratio*LUT y The method comprises the steps of carrying out a first treatment on the surface of the Wherein Ratio is L For a first ratio LUT y Is the first gain factor.
When the change proportion is smaller than a preset value, the change proportion is adjusted to be a first gain coefficient, and when the Y channel is darkened, the image color is prevented from darkening.
With continued reference to fig. 2.
Step S23, when the change proportion is larger than or equal to the preset value, the change proportion is adjusted to be a second proportion.
In the embodiment of the present invention, when the variation ratio is determined to be greater than or equal to the preset value (i.e., 1.0), it is indicated that the image is to be lightened, and in order to prevent oversaturation of the image color, the variation ratio needs to be adjusted to a second ratio, and the saturation component is adjusted by the second ratio.
Referring to fig. 4, step S23 includes steps S41 to S43.
Step S41, obtaining saturation data of the YUV image.
In the embodiment of the invention, the saturation data can be calculated in any color space. Specifically, as HSV color space, when MAX (R in ,G in ,B in )-MIN(R in ,G in ,B in ) When not equal to 0, the saturation data is calculated byWhen MAX (R in ,G in ,B in )-MIN(R in ,G in ,B in ) When=0, the saturation data is calculated by sat=0, wherein MAX represents threeThe maximum value of the numbers, MIN, represents the minimum value of the three numbers.
Step S42, obtaining a second gain coefficient corresponding to the saturation data.
The electronic device is preset with a Look-up table (LUT) of saturation, and a certain number of discrete coordinate points are stored in the LUT, and the coordinate points are sampling points on the saturation mapping curve. The abscissa of the coordinate point is the saturation data, namely the input of the saturation mapping curve, and the ordinate of the coordinate point is the second gain coefficient, namely the output of the saturation mapping curve. It should be appreciated that since the mapping relationship in the saturation lookup table is a set of discrete points, if the input saturation data is not among the discrete points, the input saturation data may be interpolated based on the known saturation data to obtain the second gain coefficient corresponding to the saturation data.
In an embodiment of the present invention, the saturation lookup table represents a simplest saturation mapping curve as shown in fig. 6.
And step S43, adjusting the change proportion to be a second proportion according to the second gain coefficient.
In the embodiment of the present invention, the calculation formula of the second ratio is: ratio H =Ratio*LUT sat The method comprises the steps of carrying out a first treatment on the surface of the Wherein Ratio is H For a second ratio LUT sat Is the second gain factor.
When the change proportion is larger than a preset value, the change proportion is adjusted to be a second gain coefficient, and when the Y channel is lightened, oversaturation of the image color is prevented.
As shown in fig. 7, an embodiment of the present invention provides an image processing apparatus, which includes an acquisition module 71, a conversion module 72, a pull-up module 73, a calculation module 74, and a compensation module 75.
The acquisition module 71 is used for acquiring RGB images.
The conversion module 72 is configured to convert the RGB image into a YUV image.
In the embodiment of the invention, in the process of converting an RGB image into a YUV image, converting RGB to obtain a luminance signal Y channel and two saturation signals U and V channels, and specifically converting RGB into YUV can be seen in the prior art.
The pull-up module 73 is configured to pull up the Y channel of the YUV image from the first luminance component to the second luminance component.
The calculating module 74 is configured to calculate a variation ratio of the luminance component of the Y channel according to the first luminance component and the second luminance component.
In the embodiment of the invention, the calculation formula of the change ratio is as follows:wherein Ratio is a change Ratio, Y out For the second luminance component, Y in For the first luminance component, δ is a preset extremum that is not zero. Where δ is a minimum value for preventing the denominator from being zero.
The compensation module 75 compensates the saturation components of the U-channel and V-channel of the YUV image according to the variation ratio.
In the embodiment of the invention, the calculation formula of the saturation component is as follows: u (U) out =Ratio*U in ;V out ×Ratio*V in The method comprises the steps of carrying out a first treatment on the surface of the Wherein U is in For the primary saturation component of the U channel, U out For the saturation component after the U channel compensation, V in For the primary saturation component of V channel, V out And compensating the saturation component for the V channel.
In some embodiments of the present invention, the compensation module 75 includes a determination unit, a first adjustment unit, a second adjustment unit, and a compensation unit.
The judging unit is used for judging whether the change proportion is smaller than a preset value.
In the embodiment of the present invention, the preset value is preferably 1.0, but is not limited thereto. By judging the change proportion and comparing with 1.0, the Y channel of the YUV image can be known to be darkened or lightened.
The first adjusting unit is used for adjusting the change proportion to be a first proportion when the change proportion is judged to be smaller than the preset value.
In the embodiment of the present invention, when the variation ratio is determined to be smaller than the preset value (i.e., 1.0), it is indicated that the image is darkened, and in order to prevent the image color from being darkened, the variation ratio needs to be adjusted to a first ratio, and the saturation component is adjusted by the first ratio.
The first adjusting unit comprises a first acquisition subunit, a second acquisition subunit and a first adjusting subunit.
The acquisition subunit is used for acquiring brightness data of the YUV image.
In the embodiment of the invention, the brightness data can be calculated in any color space. Specifically, for example, 709 color gamut of YUV color space, the calculation mode of brightness data is as follows:
Y=0.213*R in +0.715*G in +0.072*B in 。
the second obtaining subunit is configured to obtain a first gain coefficient corresponding to the luminance data.
The electronic device is preset with a Look-up table (LUT) in which a number of discrete coordinate points are stored, where the coordinate points are sampling points on the luminance mapping curve. The abscissa of the coordinate point is the brightness data, namely the input of the brightness mapping curve, and the ordinate of the coordinate point is the first gain coefficient, namely the output of the brightness mapping curve. It should be appreciated that since the mapping relationship in the luminance look-up table is a set of discrete points, if the input luminance data is not among the discrete points, the input luminance data may be interpolated based on the known luminance data, thereby obtaining the first gain coefficient corresponding to the luminance data.
In an embodiment of the present invention, the luminance look-up table represents a simplest luminance mapping curve as shown in fig. 5.
The first adjusting subunit is configured to adjust the variation ratio to a first ratio according to the first gain coefficient.
In the embodiment of the present invention, the calculation formula of the first ratio is: ratio L =Ratio*LUT y The method comprises the steps of carrying out a first treatment on the surface of the Wherein Ratio is L For a first ratio LUT y Is the first gain factor.
And the second adjusting unit is used for adjusting the change proportion to be a second proportion when judging that the change proportion is larger than or equal to the preset value.
In the embodiment of the present invention, when the variation ratio is determined to be greater than or equal to the preset value (i.e., 1.0), it is indicated that the image is to be lightened, and in order to prevent oversaturation of the image color, the variation ratio needs to be adjusted to a second ratio, and the saturation component is adjusted by the second ratio.
The second adjusting unit comprises a third acquiring subunit, a fourth acquiring subunit and a second adjusting subunit.
The third acquisition subunit is configured to acquire saturation data of the YUV image.
In the embodiment of the invention, the saturation data can be calculated in any color space. Specifically, as HSV color space, when MAX (R in ,G in ,B in )-MIN(R in ,G in ,B in ) When not equal to 0, the saturation data is calculated byWhen MAX (R in ,G in ,B in )-MIN(R in ,G in ,B in ) When=0, the saturation data is calculated in such a manner that sat=0, where MAX represents the maximum value of three numbers and MIN represents the minimum value of three numbers.
The fourth obtaining subunit is configured to obtain a second gain coefficient corresponding to the saturation data.
The electronic device is preset with a Look-up table (LUT) of saturation, and a certain number of discrete coordinate points are stored in the LUT, and the coordinate points are sampling points on the saturation mapping curve. The abscissa of the coordinate point is the saturation data, namely the input of the saturation mapping curve, and the ordinate of the coordinate point is the second gain coefficient, namely the output of the saturation mapping curve. It should be appreciated that since the mapping relationship in the saturation lookup table is a set of discrete points, if the input saturation data is not among the discrete points, the input saturation data may be interpolated based on the known saturation data to obtain the second gain coefficient corresponding to the saturation data.
In an embodiment of the present invention, the saturation lookup table represents a simplest saturation mapping curve as shown in fig. 6.
The second adjusting subunit is configured to adjust the variation ratio to a second ratio according to the second gain coefficient.
In the embodiment of the present invention, the calculation formula of the second ratio is: ratio H =Ratio*LUT sat The method comprises the steps of carrying out a first treatment on the surface of the Wherein Ratio is H For a second ratio LUT sat Is the second gain factor.
Referring to fig. 8, an embodiment of the present invention further provides an electronic device 800, where the electronic device 800 may be a mobile phone, a tablet, a computer, or the like. As shown in fig. 8, the electronic device 800 includes a processor 801, a memory 802. The processor 801 is electrically connected to the memory 802.
The processor 801 is a control center of the electronic device 800, connects various parts of the entire electronic device using various interfaces and lines, and performs various functions of the electronic device and processes data by running or loading application programs stored in the memory 802, and calling data stored in the memory 802, thereby performing overall monitoring of the electronic device.
In this embodiment, the electronic device 800 is provided with a plurality of storage partitions, where the plurality of storage partitions include a system partition and a target partition, and the processor 801 in the electronic device 800 loads instructions corresponding to the processes of one or more application programs into the memory 802 according to the following steps, and the processor 801 executes the application programs stored in the memory 802, so as to implement various functions:
acquiring RGB images;
converting the RGB image into a YUV image;
pulling up a Y channel of the YUV image from a first luminance component to a second luminance component;
calculating the change proportion of the brightness component of the Y channel according to the first brightness component and the second brightness component; and
and compensating saturation components of a U channel and a V channel of the YUV image according to the change proportion.
Referring to fig. 9, fig. 9 shows a specific block diagram of an electronic device 900 according to an embodiment of the present invention, where the electronic device 900 may be used to implement the image processing method provided in the above embodiment. The electronic device 900 may be a cell phone or tablet. The electronic device 900 also includes the following components.
The RF circuit 910 is configured to receive and transmit electromagnetic waves, and to perform mutual conversion between the electromagnetic waves and the electrical signals, so as to communicate with a communication network or other devices. The RF circuitry 910 may include various existing circuit elements for performing these functions, such as an antenna, a radio frequency transceiver, a digital signal processor, an encryption/decryption chip, a Subscriber Identity Module (SIM) card, memory, and the like. The RF circuitry 910 may communicate with various networks such as the internet, intranets, wireless networks, or with other devices via wireless networks. The wireless network may include a cellular telephone network, a wireless local area network, or a metropolitan area network. The wireless network may use various communication standards, protocols, and technologies including, but not limited to, global system for mobile communications (Global System for Mobile Communication, GSM), enhanced mobile communications technology (Enhanced Data GSM Environment, EDGE), wideband code division multiple access technology (Wideband Code Division Multiple Access, WCDMA), code division multiple access technology (Code Division Access, CDMA), time division multiple access technology (Time Division Multiple Access, TDMA), wireless fidelity technology (Wireless Fidelity, wi-Fi) (e.g., american society of electrical and electronic engineers standard IEEE802.11a, IEEE 802.11.11 b, IEEE802.11g, and/or IEEE802.11 n), internet telephony (Voice over Internet Protocol, voIP), worldwide interoperability for microwave access (Worldwide Interoperability for Microwave Access, wi-Max), other protocols for mail, instant messaging, and short messaging, and any other suitable communication protocols, even those not currently developed.
The memory 920 may be used to store software programs and modules, such as program instructions/modules corresponding to the image processing methods in the above embodiments, and the processor 980 executes various functional applications and data processing, i.e., functions for implementing the image processing methods, by running the software programs and modules stored in the memory 920. Memory 920 may include high-speed random access memory, but may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, memory 920 may further include memory located remotely from processor 980, which may be connected to electronic device 900 by a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input unit 930 may be used to receive input numeric or character information and to generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control. In particular, the input unit 930 may comprise a touch-sensitive surface 931 and other input devices 932. The touch-sensitive surface 931, also referred to as a touch display screen or touch pad, may collect touch operations thereon or thereabout by a user (e.g., operations of the user on or thereabout the touch-sensitive surface 931 using a finger, stylus, or any other suitable object or accessory) and actuate the corresponding connection device according to a predetermined program. Alternatively, the touch sensitive surface 931 may include two portions, a touch detection device and a touch controller. The touch detection device detects the touch azimuth of a user, detects a signal brought by touch operation and transmits the signal to the touch controller; the touch controller receives touch information from the touch detection device and converts it into touch point coordinates, which are then sent to the processor 980, and can receive commands from the processor 980 and execute them. In addition, the touch-sensitive surface 931 may be implemented in various types of resistive, capacitive, infrared, surface acoustic wave, and the like. In addition to the touch-sensitive surface 931, the input unit 930 may also include other input devices 932. In particular, other input devices 932 may include, but are not limited to, one or more of a physical keyboard, function keys (e.g., volume control keys, switch keys, etc.), a trackball, mouse, joystick, etc.
The display unit 940 may be used to display information entered by a user or provided to a user as well as various graphical user interfaces of the electronic device 900, which may be composed of graphics, text, icons, video, and any combination thereof. The display unit 940 may include a display panel 941, and alternatively, the display panel 941 may be configured in the form of an LCD (Liquid Crystal Display ), an OLED (Organic Light-Emitting Diode), or the like. Further, the touch-sensitive surface 931 may overlay the display panel 941, and upon detection of a touch operation thereon or thereabout, the touch-sensitive surface 931 is passed to the processor 980 to determine the type of touch event, and the processor 980 then provides a corresponding visual output on the display panel 941 depending on the type of touch event. Although in fig. 9 the touch-sensitive surface 931 and the display panel 941 are implemented as two separate components, in some embodiments the touch-sensitive surface 931 may be integrated with the display panel 941 to implement the input and output functions.
The electronic device 900 may also include at least one sensor 950, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor that may adjust the brightness of the display panel 941 according to the brightness of ambient light, and a proximity sensor that may turn off the display panel 941 and/or the backlight when the electronic device 900 is moved to the ear. As one of the motion sensors, the gravity acceleration sensor can detect the acceleration in all directions (generally three axes), and can detect the gravity and the direction when the mobile phone is stationary, and can be used for applications of recognizing the gesture of the mobile phone (such as horizontal and vertical screen switching, related games, magnetometer gesture calibration), vibration recognition related functions (such as pedometer and knocking), and the like; other sensors such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc. that may also be configured with the electronic device 900 are not described in detail herein.
Audio circuitry 960, speaker 961, microphone 962 may provide an audio interface between a user and electronic device 900. Audio circuit 960 may transmit the received electrical signal converted from audio data to speaker 961, where it is converted to a sound signal by speaker 961 for output; on the other hand, microphone 962 converts the collected sound signals into electrical signals, which are received by audio circuit 960 and converted into audio data, which are processed by audio data output processor 980 for transmission to, for example, another terminal via RF circuit 910 or for output to memory 920 for further processing. Audio circuitry 960 may also include an ear bud jack to provide communication of a peripheral ear bud with electronic device 900.
The electronic device 900 may facilitate user email, web browsing, streaming media access, etc. via a transmission module 970 (e.g., wi-Fi module), which provides wireless broadband internet access to the user. Although fig. 9 shows the transmission module 970, it is understood that it does not belong to the essential constitution of the electronic device 900, and can be omitted entirely as required within the scope not changing the essence of the invention.
Processor 980 is a control center for electronic device 900, and uses various interfaces and lines to connect the various parts of the overall handset, performing various functions of electronic device 900 and processing data by running or executing software programs and/or modules stored in memory 920, and invoking data stored in memory 920, thereby performing overall monitoring of the handset. Optionally, processor 980 may include one or more processing cores; in some embodiments, processor 980 may integrate an application processor with a modem processor, where the application processor primarily handles operating systems, user interfaces, applications programs, and the like, and the modem processor primarily handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 980.
The electronic device 900 also includes a power supply 990 (e.g., a battery) that provides power to the various components, and in some embodiments, may be logically coupled to the processor 980 through a power management system to perform functions such as managing charging, discharging, and power consumption by the power management system. The power source 990 may also include one or more of any components, such as a direct current or alternating current power source, a recharging system, a power failure detection circuit, a power converter or inverter, a power status indicator, and the like.
Although not shown, the electronic device 900 may further include a camera (e.g., front camera, rear camera), a bluetooth module, etc., which will not be described in detail herein. In particular, in this embodiment, the display unit of the electronic device is a touch screen display, the electronic device further includes a memory, and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including instructions for:
acquiring RGB images;
converting the RGB image into a YUV image;
pulling up a Y channel of the YUV image from a first luminance component to a second luminance component;
calculating the change proportion of the brightness component of the Y channel according to the first brightness component and the second brightness component; and
and compensating saturation components of a U channel and a V channel of the YUV image according to the change proportion.
In the implementation, each module may be implemented as an independent entity, or may be combined arbitrarily, and implemented as the same entity or several entities, and the implementation of each module may be referred to the foregoing method embodiment, which is not described herein again.
Those of ordinary skill in the art will appreciate that all or a portion of the steps of the various methods of the above embodiments may be performed by instructions or by controlling associated hardware, which may be stored in a computer-readable storage medium and loaded and executed by a processor. To this end, an embodiment of the present invention provides a readable storage medium having stored therein a plurality of instructions capable of being loaded by a processor to perform the steps of any one of the image processing methods provided by the embodiment of the present invention.
Wherein the readable storage medium may include: read Only Memory (ROM), random access Memory (RAM, random Access Memory), magnetic or optical disk, and the like.
The steps in any image processing method provided by the embodiment of the present invention can be executed due to the instructions stored in the readable storage medium, so that the beneficial effects that can be achieved by any image processing method provided by the embodiment of the present invention can be achieved, and detailed descriptions of the previous embodiments are omitted herein. The specific implementation of each operation above may be referred to the previous embodiments, and will not be described herein.
The invention has the beneficial effects that: the change proportion of the brightness component of the Y channel is obtained, the change proportion is compared with a preset value, the saturation component is correspondingly compensated according to the comparison result, the phenomenon of color shearing caused by the compensation processing of the saturation of the image after the brightness processing of the image is avoided, the details of the image are protected, and the higher-quality image display is realized.
In the foregoing embodiments, the descriptions of the embodiments are emphasized, and for parts of one embodiment that are not described in detail, reference may be made to related descriptions of other embodiments.
The image processing method, system, readable storage medium and electronic device provided by the embodiments of the present invention are described in detail, and specific examples are applied to illustrate the principles and embodiments of the present invention, and the description of the above embodiments is only used to help understand the technical solution and core idea of the present invention; those of ordinary skill in the art will appreciate that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit of the invention.