Detailed Description
The technical solution 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 is to be understood that the described embodiments are merely exemplary of the invention, and not restrictive of the full scope of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
As shown in fig. 1, an embodiment of the present invention provides an image processing method applied to an electronic device, where the method includes steps S11 to S15.
In step S11, an RGB image is acquired.
Step S12, converting the RGB image into a YUV image.
In the embodiment of the present 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 may refer to the prior art.
Step S13, raising the Y channel of the YUV image from the first luminance component to the second luminance component.
Step S14, calculating a change 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 present invention, optionally, the calculation formula of the change ratio is:
wherein Ratio is a variation Ratio, Y
outIs the second luminance component, Y
inδ is a predetermined extremum that is not zero for the first luminance component. Where δ is a minimum value used to prevent the denominator from being zero.
And step S15, compensating the saturation components of the U channel and the V channel of the YUV image according to the change proportion.
In this embodiment of the present invention, optionally, the calculation formula of the saturation component is: u shapeout=Ratio*Uin;Vout=Ratio*Vin(ii) a Wherein, UinIs the original saturation component of the U channel, UoutFor the saturation component, V, compensated for the U channelinIs the original saturation component of the V channel, VoutThe saturation component compensated for the V channel.
And correspondingly adjusting the saturation component according to the change proportion of the brightness data, so that the color of the image after color compensation is maintained, and the image quality is improved.
Referring to fig. 2, step S15 may further include steps S21 through S24.
Step S21, determining whether the variation ratio is smaller than a predetermined value.
In the embodiment of the present invention, the preset value is preferably 1.0, but is not limited thereto. By comparing the change ratio with 1.0, the fact that the Y channel of the YUV image is darkened or brightened can be known.
And step S22, when the change proportion is judged to be smaller than the preset value, adjusting the change proportion to be a first proportion.
In the embodiment of the present invention, when it is determined that the change ratio is smaller than the preset value (i.e. 1.0), it indicates that the image is darkened, and in order to prevent the image color from being darkened, the change ratio needs to be adjusted to the first ratio, and the saturation component is adjusted by the first ratio.
Referring to fig. 3, step S22 includes steps S31 through S32.
Step S31, luminance data of the YUV image is acquired.
In the embodiment of the present invention, the luminance data may be calculated in any color space. Specifically, for example, in 709 color gamut of YUV color space, the luminance data is calculated in the following manner:
Y=0.213*Rin+0.715*Gin+0.072*Bin。
step S32, a first gain coefficient corresponding to the luminance data is obtained.
A brightness lookup table (LUT) is preset in the electronic device, and a certain number of discrete coordinate points are stored in the LUT and are sampling points on the brightness mapping curve. The abscissa of the coordinate point is luminance data, i.e., the input of the luminance mapping curve, and the ordinate of the coordinate point is the first gain coefficient, i.e., the output of the luminance mapping curve. It should be understood that, since the mapping relationship in the luminance lookup table is a set of discrete points, if the input luminance data is not in the discrete points, the input luminance data may be interpolated based on the known luminance data, so as to obtain the first gain coefficient corresponding to the luminance data.
In the embodiment of the present invention, the luminance lookup table represents a simplest luminance mapping curve as shown in fig. 5.
Step S33, adjusting the change ratio to a first ratio according to the first gain factor.
In the embodiment of the present invention, the calculation formula of the first ratio is: ratio (R)L=Ratio*LUTy(ii) a Wherein RatioLIn a first ratio, LUTyIs the first gain factor.
When the change proportion is smaller than the preset value, the change proportion is adjusted to be the first gain coefficient, and when the Y channel is darkened, the image color is prevented from being darkened.
With continued reference to fig. 2.
In step S23, when it is determined that the change ratio is greater than or equal to the predetermined value, the change ratio is adjusted to a second ratio.
In the embodiment of the invention, when the change ratio is judged to be greater than or equal to the preset value (namely 1.0), the image is highlighted, in order to prevent the image from being oversaturated, the change ratio needs to be adjusted to be a second ratio, and the saturation component is adjusted through the second ratio.
Referring to fig. 4, step S23 includes steps S41 through S43.
Step S41, saturation data of the YUV image is acquired.
In the embodiment of the present invention, the saturation data may be a calculation method of any color space. Specifically, 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 in the following way
When MAX (R)
in,G
in,B
in)-MIN(R
in,G
in,B
in) When the saturation data is 0, sat is 0, where MAX represents the maximum value of the three numbers and MIN represents the minimum value of the three numbers.
And step S42, acquiring a second gain coefficient corresponding to the saturation data.
The electronic device is preset with a saturation lookup table (LUT), 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, i.e., the input of the saturation mapping curve, and the ordinate of the coordinate point is the second gain coefficient, i.e., the output of the saturation mapping curve. It should be understood that, since the mapping relationship in the saturation lookup table is a set of discrete points, if the input saturation data is not in the discrete points, the input saturation data can be interpolated based on the known saturation data, so as to obtain the second gain coefficient corresponding to the saturation data.
In the 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 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 (R)H=Ratio*LUTsat(ii) a Wherein RatioHIn a second ratio, LUTsatIs the second gain factor.
When the change proportion is larger than the preset value, the change proportion is adjusted to be the second gain coefficient, and therefore when the Y channel is lightened, the oversaturation of the image color is prevented.
As shown in fig. 7, the embodiment of the present invention provides an image processing apparatus, which includes an obtaining module 71, a converting module 72, a pull-up module 73, a calculating module 74, and a compensating 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 present 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 may refer to 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 change 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 present invention, the calculation formula of the change ratio is:
wherein Ratio is a variation Ratio, Y
outIs the second luminance component, Y
inδ is a predetermined extremum that is not zero for the first luminance component. Where δ is a minimum value used to prevent the denominator from being zero.
The compensation module 75 compensates the saturation components of the U channel and the V channel of the YUV image according to the change ratio.
In the embodiment of the present invention, the calculation formula of the saturation component is: u shapeout=Ratio*Uin;Vout×Ratio*Vin(ii) a Wherein, UinIs the original saturation component of the U channel, UoutFor the saturation component, V, compensated for the U channelinIs the original saturation component of the V channel, VoutThe saturation component compensated for the V channel.
In some embodiments of the present invention, optionally, 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 comparing the change ratio with 1.0, the fact that the Y channel of the YUV image is darkened or brightened can be known.
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 it is determined that the change ratio is smaller than the preset value (i.e. 1.0), it indicates that the image is darkened, and in order to prevent the image color from being darkened, the change ratio needs to be adjusted to the first ratio, and the saturation component is adjusted by the first ratio.
The first adjusting unit comprises a first acquiring subunit, a second acquiring subunit and a first adjusting subunit.
The acquiring subunit is used for acquiring brightness data of the YUV image.
In the embodiment of the present invention, the luminance data may be calculated in any color space. Specifically, for example, in 709 color gamut of YUV color space, the luminance data is calculated in the following manner:
Y=0.213*Rin+0.715*Gin+0.072*Bin。
the second obtaining subunit is configured to obtain a first gain coefficient corresponding to the luminance data.
A brightness lookup table (LUT) is preset in the electronic device, and a certain number of discrete coordinate points are stored in the LUT and are sampling points on the brightness mapping curve. The abscissa of the coordinate point is luminance data, i.e., the input of the luminance mapping curve, and the ordinate of the coordinate point is the first gain coefficient, i.e., the output of the luminance mapping curve. It should be understood that, since the mapping relationship in the luminance lookup table is a set of discrete points, if the input luminance data is not in the discrete points, the input luminance data may be interpolated based on the known luminance data, so as to obtain the first gain coefficient corresponding to the luminance data.
In the embodiment of the present invention, the luminance lookup table represents a simplest luminance mapping curve as shown in fig. 5.
The first adjusting subunit is configured to adjust the change proportion to 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 (R)L=Ratio*LUTy(ii) a Wherein RatioLIn a first ratio, LUTyIs the first gain factor.
The second adjusting unit is used for adjusting the change proportion to be a second proportion when the change proportion is judged to be larger than or equal to the preset value.
In the embodiment of the invention, when the change ratio is judged to be greater than or equal to the preset value (namely 1.0), the image is highlighted, in order to prevent the image from being oversaturated, the change ratio needs to be adjusted to be a second ratio, and the saturation component is adjusted through the second ratio.
The second adjusting unit comprises a third acquiring subunit, a fourth acquiring subunit and a second adjusting subunit.
And the third acquisition subunit is used for acquiring the saturation data of the YUV image.
In the embodiment of the present invention, the saturation data may be a calculation method of any color space. Specifically, 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 in the following way
When MAX (R)
in,G
in,B
in)-MIN(R
in,G
in,B
in) When the saturation data is 0, sat is 0, where MAX represents the maximum value of the three numbers, and MIN represents the maximum value of the three numbersA minimum value.
The fourth obtaining subunit is configured to obtain a second gain coefficient corresponding to the saturation data.
The electronic device is preset with a saturation lookup table (LUT), 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, i.e., the input of the saturation mapping curve, and the ordinate of the coordinate point is the second gain coefficient, i.e., the output of the saturation mapping curve. It should be understood that, since the mapping relationship in the saturation lookup table is a set of discrete points, if the input saturation data is not in the discrete points, the input saturation data can be interpolated based on the known saturation data, so as to obtain the second gain coefficient corresponding to the saturation data.
In the 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 change 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 (R)H=Ratio*LUTsat(ii) a Wherein RatioHIn a second ratio, LUTsatIs 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 an application program 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 memory partitions, where the plurality of memory partitions includes a system partition and a target partition, and the processor 801 in the electronic device 800 loads instructions corresponding to processes of one or more application programs into the memory 802 according to the following steps, and the processor 801 runs the application programs stored in the memory 802, so as to implement various functions:
acquiring an RGB image;
converting the RGB image into a YUV image;
raising a Y-channel of the YUV image from a first luma component to a second luma 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 the saturation components of the U channel and the V channel of the YUV image according to the change proportion.
Referring to fig. 9, fig. 9 is a block diagram illustrating a specific structure 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 foregoing embodiment. The electronic device 900 may be a mobile phone or a tablet. The electronic device 900 also includes the following components.
The RF circuit 910 is used for receiving and transmitting electromagnetic waves, and interconverting the electromagnetic waves and electrical signals, so as to communicate with a communication network or other devices. RF circuit 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 so forth. The RF circuit 910 may communicate with various networks such as the internet, an intranet, a wireless network, or with other devices over a wireless network. The wireless network may comprise 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 Communication (GSM), Enhanced Data GSM Environment (EDGE), Wideband Code Division Multiple Access (WCDMA), Code Division Multiple Access (CDMA), Time Division Multiple Access (TDMA), Wireless Fidelity (Wi-Fi) (e.g., IEEE802.11a, IEEE802.11 b, IEEE 802.2.access, and/or IEEE802.11 n), Voice over Internet Protocol (VoIP), world wide Internet Microwave Access (Microwave for Wireless Communication), other suitable protocols for short message service (Max), and any other suitable protocols, and may even include those protocols that have not yet been developed.
The memory 920 may be used to store software programs and modules, such as program instructions/modules corresponding to the image processing method in the above-described embodiments, and the processor 980 may execute various functional applications and data processing, i.e., implement the functions of the image processing method, by running the software programs and modules stored in the memory 920. The memory 920 may include high-speed random access memory, and 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, the memory 920 may further include memory located remotely from the processor 980, which may be connected to the electronic device 900 over 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 generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control. In particular, the input unit 930 may include a touch-sensitive surface 931 as well as other input devices 932. The touch-sensitive surface 931, also referred to as a touch screen or a touch pad, may collect touch operations by a user on or near the touch-sensitive surface 931 (e.g., operations by a user on or near the touch-sensitive surface 931 using a finger, a stylus, or any other suitable object or attachment) and drive the corresponding connecting device according to a predetermined program. Alternatively, the touch sensitive surface 931 may include both a touch detection device and a touch controller. The touch detection device detects the touch direction 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 sensing device, converts the touch information into touch point coordinates, sends the touch point coordinates to the processor 980, and can receive and execute commands sent by the processor 980. In addition, the touch sensitive surface 931 may be implemented in various types, such as resistive, capacitive, infrared, and surface acoustic wave. The input unit 930 may also include other input devices 932 in addition to the touch-sensitive surface 931. 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, a mouse, a joystick, and the like.
The display unit 940 may be used to display information input by or provided to the user and various graphical user interfaces of the electronic device 900, which may be made up of graphics, text, icons, video, and any combination thereof. The Display unit 940 may include a Display panel 941, and optionally, 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 when a touch operation is detected on or near the touch-sensitive surface 931, the touch operation is transmitted 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 according to 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 and the display panel 941 may be integrated to implement input and output functions.
The electronic device 900 may also include at least one sensor 950, such as a light sensor, 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 a backlight when the electronic device 900 is moved to the ear. As one of the motion sensors, the gravity acceleration sensor can detect the magnitude of acceleration in each direction (generally, three axes), can detect the magnitude and direction of gravity when the mobile phone is stationary, and can be used for applications of recognizing the posture of the mobile phone (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer and tapping), and the like; as for other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, and an infrared sensor, which may be further configured to the electronic device 900, detailed descriptions thereof are omitted.
The audio circuitry 960, speaker 961, microphone 962 may provide an audio interface between a user and the electronic device 900. The audio circuit 960 may transmit the electrical signal converted from the received audio data to the speaker 961, and convert the electrical signal into a sound signal for output by the speaker 961; on the other hand, the microphone 962 converts the collected sound signal into an electric signal, converts the electric signal into audio data after being received by the audio circuit 960, and outputs the audio data to the processor 980 for processing, and then transmits the audio data to another terminal via the RF circuit 910, or outputs the audio data to the memory 920 for further processing. The audio circuit 960 may also include an earbud jack to provide communication of a peripheral headset with the electronic device 900.
The electronic device 900, via the transport module 970 (e.g., Wi-Fi module), may assist the user in sending and receiving e-mail, browsing web pages, accessing streaming media, etc., 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 may be omitted entirely within the scope not changing the essence of the invention as needed.
The processor 980 is a control center of the electronic device 900, connects various parts of the entire cellular phone using various interfaces and lines, and performs various functions of the electronic device 900 and processes data by operating or executing software programs and/or modules stored in the memory 920 and calling data stored in the memory 920, thereby integrally monitoring the cellular phone. Optionally, processor 980 may include one or more processing cores; in some embodiments, the processor 980 may integrate an application processor, which primarily handles operating systems, user interfaces, applications, etc., and a modem processor, which 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 via a power management system that provides management of charging, discharging, and power consumption. Power supply 990 may also include any component of one or more dc or ac power sources, recharging systems, power failure detection circuits, power converters or inverters, power status indicators, and the like.
Although not shown, the electronic device 900 may further include a camera (e.g., a front camera, a rear camera), a bluetooth module, etc., which are not described in detail herein. Specifically, 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, where the one or more programs are stored in the memory and configured to be executed by the one or more processors, and the one or more programs include instructions for:
acquiring an RGB image;
converting the RGB image into a YUV image;
raising a Y-channel of the YUV image from a first luma component to a second luma 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 the saturation components of the U channel and the V channel of the YUV image according to the change proportion.
In specific implementation, the above modules may be implemented as independent entities, or may be combined arbitrarily to be implemented as the same or several entities, and specific implementation of the above modules may refer to the foregoing method embodiments, which are not described herein again.
It will be understood by those skilled in the art that all or part of the steps of the methods of the above embodiments may be performed by instructions or by instructions controlling associated hardware, and the instructions may be stored in a computer readable storage medium and loaded and executed by a processor. To this end, the present invention provides a readable storage medium, in which a plurality of instructions are stored, where the instructions can be loaded by a processor to execute the steps in any one of the image processing methods provided by the embodiments of the present invention.
Wherein the readable storage medium may include: read Only Memory (ROM), Random Access Memory (RAM), magnetic or optical disks, and the like.
Since the instructions stored in the readable storage medium can execute the steps in any image processing method provided in the embodiment of the present invention, the beneficial effects that can be achieved by any image processing method provided in the embodiment of the present invention can be achieved, which are detailed in the foregoing embodiments and will not be described herein again. The above operations can be implemented in the foregoing embodiments, and are not described in detail herein.
The invention has the beneficial effects that: by acquiring the change proportion of the brightness component of the Y channel, comparing the change proportion with a preset value and correspondingly compensating the saturation component according to the comparison result, the phenomenon of color shearing caused when the saturation of the image is compensated after the brightness of the image is processed is avoided, the details of the image are protected, and the image display with higher quality is realized.
In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
The image processing method, the image processing system, the readable storage medium and the electronic device provided by the embodiments of the present invention are described in detail above, and a specific example is applied in the present disclosure to explain the principle and the implementation of the present invention, and the description of the above embodiments is only used to help understanding the technical solution and the core idea of the present invention; those of ordinary skill in the art will understand that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.