Image processing method, electronic device, storage medium and program product
By dividing the image into blocks and determining the gain value, the white balance processing of the image in the mixed light source scene is realized, the color deviation problem is solved, and the authenticity and quality of the image are improved.
Patent Information
- Application Number
- CN202410581928.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-11
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2044-05-11
AI Technical Summary
Existing white balance processing methods cannot effectively solve the problem of color deviation in images taken under mixed light source scenarios.
By dividing the original image into two blocks, the gain value of each pixel is determined, and white balance processing is performed based on these gain values to ensure that the image presents a uniform color under different light sources.
The white balance adjustment effect is improved, the color deviation of the image in mixed light source scenes is reduced, and the authenticity of the image is significantly improved.
Smart Images

Figure CN118200748B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of image processing technology, and in particular to an image processing method, electronic device, storage medium, and program product. Background Art
[0002] With the development of electronic devices, more and more electronic devices have shooting functions, allowing users to shoot anytime and anywhere. Images shot in mixed light source scenes may have a certain degree of deviation between the captured image color and the real color. In order to improve the quality of images shot in mixed light source scenes, the captured images can be processed by an image white balance algorithm. However, the existing white balance processing method cannot solve the problem of color deviation in images shot in mixed light source scenes. Summary of the invention
[0003] The embodiments of the present application provide an image processing method, an electronic device, a storage medium, and a program product. After determining the gain value corresponding to each pixel in the original image, the original image is color corrected based on the gain value of each pixel, so that the processed target image presents a uniform color under different light sources, thereby improving the white balance adjustment effect.
[0004] To achieve the above objectives, the embodiments of the present application adopt the following technical solutions:
[0005] In a first aspect, an image processing method is provided, which is applied to an electronic device having a camera, and the method comprises:
[0006] In response to a preset operation, a shooting preview interface is displayed, the shooting preview interface includes an original image captured by a camera under a variety of light source scenes; in response to the shooting operation, the original image is subjected to a first block processing to obtain a plurality of first image blocks, and the original image is subjected to a second block processing to obtain a plurality of second image blocks; the gain value of each of the plurality of first image blocks is determined respectively to obtain a plurality of first gain values; and the gain value of each of the plurality of second image blocks is determined respectively to obtain a plurality of second gain values; according to the plurality of first gain values, a plurality of gain weight values corresponding to each pixel point in the original image are determined, the gain weight value being used to characterize the contribution ratio of each light source to the gain value of the pixel point; according to the plurality of second gain values, the gain value corresponding to the second image block where the regions respectively irradiated by the plurality of light sources are located is determined; according to the plurality of gain weight values of each pixel point and the gain value corresponding to the second image block where the regions respectively irradiated by the plurality of light sources are located, a target gain value corresponding to each pixel point is determined; according to the target gain value corresponding to each pixel point, white balance processing is performed on the original image to obtain a target image.
[0007] The size of the second image block is greater than that of the first image block. The gain value is used to adjust the white balance of the image block, and one first image block corresponds to one first gain value, and one second image block corresponds to one second gain value.
[0008] The preset operation here may be an operation for starting a shooting application. For example, the preset operation may be a voice operation, an operation of double-clicking or clicking an icon of a shooting application, an operation of touching an icon of a shooting application, and the like.
[0009] In an embodiment of the present application, the electronic device performs two block processing of different sizes on the original image to obtain multiple first image blocks and multiple second image blocks, and then determines multiple gain weight values of each pixel in the original image based on the multiple first image blocks, and determines the gain values corresponding to the second image blocks where the areas illuminated by multiple light sources are located based on the multiple second image blocks. After determining the target gain value of each pixel, the original image is white balanced according to the gain value of each pixel, so that the processed target image presents a uniform color under different light sources, thereby improving the white balance adjustment effect.
[0010] In some embodiments, determining a plurality of gain weight values corresponding to each pixel point in the original image according to the plurality of first gain values includes:
[0011] Density estimation is performed on multiple first gain values corresponding to multiple first image blocks to obtain first density estimation results; multiple first maximum points are determined based on the first density estimation results, and multiple gain weight values corresponding to each pixel point in the original image are determined based on the multiple first gain values and the multiple first maximum points. The multiple first maximum points are gain values corresponding to the first image blocks where the regions illuminated by the multiple light sources are located.
[0012] The number of gain weight values corresponding to each pixel point is the same as the number of first maximum points. For example, if there are two first maximum points, the number of gain weight values corresponding to each pixel point is also two.
[0013] It can be understood that in a scene with multiple light sources in the shooting scene, the contribution ratio of each light source to the gain value of each pixel in the original image is different. Therefore, after determining the gain value corresponding to the first image block where the areas illuminated by multiple light sources are located, multiple gain weight values corresponding to each pixel can be determined based on multiple first gain values and multiple first maximum points.
[0014] In some embodiments, determining a plurality of gain weight values corresponding to each pixel point in the original image according to the plurality of first gain values and the plurality of first maximum points includes:
[0015] Determine a plurality of distance values between each of a plurality of first gain values corresponding to a plurality of first image blocks and a plurality of first maximum points; determine a plurality of weight values corresponding to each first gain value according to the plurality of distance values between each first gain value and the plurality of first maximum points; perform upsampling processing on a plurality of weight values corresponding to each of a plurality of first gain values corresponding to a plurality of first image blocks, to obtain a plurality of gain weight values corresponding to each pixel point in the original image.
[0016] Exemplarily, the electronic device may determine the Euclidean distance between each gain value and a plurality of first maximum points, as a plurality of distance values.
[0017] It can be understood that each first image block corresponds to a first gain value that corresponds to multiple weight values. By upsampling the multiple weight values corresponding to the multiple first gain values, the gain weight value corresponding to each pixel in the original image can be obtained.
[0018] In some embodiments, determining multiple weight values corresponding to each first gain value according to multiple distance values between each first gain value and multiple first maximum value points includes:
[0019] Determine the sum of the first gain value and multiple distance values between the multiple first maximum points to obtain a distance sum; and determine the ratios of the multiple distance values to the distance sum as multiple weight values corresponding to the first gain value.
[0020] In some embodiments, after determining a plurality of weight values corresponding to each first gain value according to a plurality of distance values between each first gain value and a plurality of maximum value points, the method further comprises:
[0021] For each first gain value, multiple weight values corresponding to the first gain value are added and normalized to obtain multiple normalized weight values corresponding to the first gain value;
[0022] Upsampling a plurality of weight values corresponding to each of the plurality of first gain values to obtain a plurality of gain weight values corresponding to each pixel in the original image includes:
[0023] Up-sampling is performed on the normalized multiple weight values corresponding to the multiple first gain values to obtain multiple gain weight values corresponding to each pixel in the original image.
[0024] It can be understood that the electronic device normalizes the weight value so that the normalized weight value is scaled to a specific range, which is helpful for comparing data of different magnitudes or performing operations between different data.
[0025] In some embodiments, upsampling a plurality of weight values corresponding to each of the plurality of first gain values corresponding to the plurality of first image blocks includes:
[0026] A bilateral filtering up-sampling algorithm is adopted to perform up-sampling processing on a plurality of weight values corresponding to each of a plurality of first gain values corresponding to a plurality of first image blocks.
[0027] It can be understood that the bilateral filtering upsampling algorithm combines the operations of bilateral filtering and upsampling, which can effectively maintain the original image edges and details, while reducing the noise and jagged effects that may be generated during the upsampling process, and avoiding the uneven weight values obtained after the upsampling process.
[0028] In some embodiments, performing density estimation on a plurality of first gain values corresponding to a plurality of first image blocks includes:
[0029] A kernel density estimation method is used to perform density estimation on the multiple first gain values.
[0030] It can be understood that the result of performing density estimation on multiple first gain values using the kernel density estimation method is a continuous density curve, which can provide a smoother and more accurate probability density estimation.
[0031] In some embodiments, determining, according to the plurality of second gain values, gain values corresponding to the second image blocks where the regions illuminated by the plurality of light sources are located includes:
[0032] Density estimation is performed on the multiple second gain values to obtain a second density estimation result; based on the second density estimation result, a plurality of second maximum points are determined, where the plurality of second maximum points are gain values corresponding to the plurality of second image blocks where the regions illuminated by the plurality of light sources are located.
[0033] In some embodiments, according to multiple gain weight values of each pixel point and gain values corresponding to the second image blocks where the regions illuminated by multiple light sources are located, determining the target gain value corresponding to each pixel point includes:
[0034] For each pixel point, determine the multiple gain weight values corresponding to the pixel point and the multiple product values of the corresponding second maximum point. The larger the gain weight value, the larger the value of the corresponding second maximum point; determine the sum of the multiple product values as the target gain value corresponding to the pixel point.
[0035] In some embodiments, according to the target gain value corresponding to each pixel point, white balance processing is performed on the original image to obtain the target image, including:
[0036] Obtain the pixel value of each pixel in the original image; divide the pixel value of each pixel by the target gain value corresponding to the pixel to obtain the target image.
[0037] It can be understood that the electronic device assigns different gain values to each pixel in the original image, and uses the target gain value corresponding to each pixel to perform white balance processing on the pixel, which is conducive to improving the white balance adjustment effect.
[0038] In some embodiments, determining the gain value of each of the plurality of first image blocks respectively to obtain the plurality of first gain values includes:
[0039] For each first image block, determine the average value of the red channel, the average value of the green channel, and the average value of the blue channel of the pixels in the first image block; determine a first ratio of the average value of the red channel to the average value of the green channel, and a second ratio of the average value of the blue channel to the average value of the green channel; and determine the first ratio and the second ratio as a first gain value corresponding to the first image block.
[0040] In some embodiments, determining the gain value of each of the plurality of first image blocks respectively to obtain the plurality of first gain values includes:
[0041] For each first image block, determining a target pixel point having the maximum pixel value in each color channel of the first image block;
[0042] Calculate a third ratio of the pixel value of the red channel to the pixel value of the green channel, and a fourth ratio of the pixel value of the blue channel to the pixel value of the green channel of the target pixel point; determine the third ratio and the fourth ratio as the first gain value.
[0043] In some embodiments, in a photo-taking scenario, the target image is an image obtained by performing white balance processing on the original image obtained by shooting;
[0044] In a video recording scenario, the target image is an image frame obtained by performing white balance processing on the original image in the captured video.
[0045] In a second aspect, the present application provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program so that the electronic device performs the image processing method as described in any one of the above-mentioned first aspects.
[0046] In a third aspect, the present application provides a computer-readable storage medium having a computer program / instruction stored thereon. When the computer program / instruction is executed by a processor, the electronic device executes the image processing method as described in any one of the first aspects.
[0047] In a fourth aspect, the present application provides a computer program product, comprising a computer program / instruction, which, when executed by a processor, enables an electronic device to perform an image processing method as described in any one of the first aspects.
[0048] It can be understood that the electronic device described in the second aspect, the computer-readable storage medium described in the third aspect, and the computer program product described in the fourth aspect are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;
[0050] Figure 2 A software structure diagram of an electronic device provided in an embodiment of the present application;
[0051] Figure 3 An example diagram of image processing provided in an embodiment of the present application;
[0052] Figure 4 A flowchart of an image processing method provided in an embodiment of the present application;
[0053] Figure 5 An example diagram of image block processing provided in an embodiment of the present application;
[0054] Figure 6 An example diagram of a density function provided in an embodiment of the present application;
[0055] Figure 7 An example diagram of an image processing method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0056] The technical solution in the embodiment of the present application will be described below in conjunction with the drawings in the embodiment of the present application. In the description of the embodiment of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0057] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of the present application, unless otherwise specified, "plurality" means two or more.
[0058] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0059] In order to facilitate the understanding of the present application, some professional terms involved in the embodiments of the present application are first introduced below.
[0060] Color temperature refers to the temperature at which a black body is heated to a temperature, and the color of the light it emits is the same as the color of the light emitted by a certain light source. The temperature at which the black body is heated is called the color temperature of the light source, or simply color temperature. The bluer the light color of the black body is, the higher the color temperature of the light source; the redder it is, the lower the color temperature of the light source. The color temperature of a light source is measured in Kelvin (K), which is a measure of the color quality of the light source. Light sources with low color temperature (such as tungsten filament lamps) emit light that is yellowish and has a low color temperature (about 3200K); light sources with high color temperature (such as sunlight in a clear sky) emit light that is bluish and has a high color temperature (about 5600K).
[0061] The characteristic of a low color temperature light source is that in the energy distribution, red radiation is relatively more, which is usually called "warm light"; when the color temperature increases, the proportion of blue radiation in the energy distribution increases, which is usually called "cold light".
[0062] Color correction refers to increasing or decreasing the amount of red, green, and blue channels to offset the color cast caused by the light source. For example, if an electronic device is shot under a tungsten light source, the amount of the blue channel can be increased to neutralize the yellow, making the white in the captured image look more natural.
[0063] White point refers to the color value of the area in an image that should appear white when an electronic device performs color correction on the image.
[0064] When shooting in a mixed light source scene, such as when there is warm light indoors and cold light outdoors, the user controls the electronic device to shoot an outdoor scene from indoors; or in a night scene environment, high and low color temperature light sources appear in the same scene; or when shooting scenes such as high color temperature displays in a warm light environment, the electronic device can perform white balance processing on the captured image through the auto white balance (AWB) algorithm. Among them, the automatic white balance is to compensate the original image captured by a camera such as a complementary metal oxide semiconductor (CMOS) through white balance gain so that the color of the image is restored to the true color seen by the human eye. White balance processing is actually the electronic device determining the color temperature of the current shooting environment in order to perform corresponding color correction. However, in a mixed light source scene, after the electronic device uses a global white balance algorithm to perform white balance processing on the image using a unified white balance coefficient, color deviation will appear in certain areas of the image after white balance processing.
[0065] Among them, mixed light source refers to the simultaneous presence of multiple different types of lighting sources in the shooting scene, and these light sources may have different color temperatures, brightness, directions and colors.
[0066] To this end, the present application provides an image processing method, which is applied to an electronic device with a camera. After the camera of the electronic device acquires the original image under multiple light source scenes, the electronic device determines the target gain value of each pixel in the original image, and then performs white balance processing on each pixel based on the target gain value of each pixel, thereby effectively solving the white balance problem under mixed light sources and improving the white balance adjustment effect. Exemplarily, the image processing method provided in the embodiment of the present application can be applied to mobile phones, tablet computers, personal computers (personal computers, PCs), personal digital assistants (personal digital assistants, PDAs), smart watches, netbooks, wearable electronic devices, augmented reality technology (augmented reality, AR) devices, virtual reality (virtual reality, VR) devices, vehicle-mounted devices, smart cars and other electronic devices with shooting functions, and the embodiment of the present application does not impose any restrictions on this.
[0067] like Figure 1 As shown, Figure 1 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0068] The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0069] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0070] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0071] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0072] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0073] The charging management module 140 is used to receive charging input from a charger, where the charger can be a wireless charger or a wired charger.
[0074] The power management module 141 is used to connect the battery 142 , the charging management module 140 and the processor 110 .
[0075] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.
[0076] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0077] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0078] The electronic device 100 can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.
[0079] ISP is used to process the data fed back by camera 193. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to ISP for processing and converts it into an image visible to the naked eye. ISP can also perform algorithm optimization on the noise, brightness, and skin color of the image. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, ISP can be set in camera 193.
[0080] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.
[0081] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0082] Video codecs are used to compress or decompress digital videos. The electronic device 100 may support one or more video codecs. Thus, the electronic device 100 may play or record videos in a variety of coding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
[0083] The electronic device 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.
[0084] The software system of the electronic device may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present invention takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device.
[0085] Figure 2A software structure diagram of an electronic device provided in an embodiment of the present application.
[0086] It is understandable that the layered architecture divides the software into several layers, each with a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system may include an application layer (abbreviated as application layer), an application framework layer (abbreviated as framework layer), a hardware abstraction layer, and a kernel layer.
[0087] The electronic device also includes a hardware layer, which includes a camera sensor.
[0088] like Figure 2 As shown, the application layer includes the camera application, of course, it can also include Figure 2 Applications not shown in the figure, such as gallery, calendar, music, short message, memo and weather programs.
[0089] The application framework layer includes the camera service, which is used to read various information from the camera application.
[0090] The hardware abstraction layer is a layer of encapsulation for the underlying hardware driver, providing a general interface for calling the driver to the application framework layer. In the embodiment of the present application, the hardware abstraction layer may include a camera hardware abstraction module and an image processing module.
[0091] The camera hardware abstraction module is used to control the target camera to perform camera initialization operations. For example, the camera hardware abstraction module can perform initialization operations such as powering on and parameter configuration on the target camera. The target camera is a camera used to capture images. The target camera can be a front camera or a rear camera, which is not limited here.
[0092] The image processing module is used to process the image captured by the target camera. For example, the image processing module can adjust the size of the preview image, and can also perform beauty processing, night scene processing, and denoising processing on the photographed image.
[0093] In the embodiment of the present application, the image processing module is also used to perform white balance processing on the image captured by the target camera. The specific implementation process is shown in the subsequent embodiments and is not described in detail here.
[0094] The kernel layer is the layer between hardware and software. The kernel layer contains at least sensor driver, camera driver and display driver.
[0095] In some embodiments, the sensor driver may be used to obtain information collected by at least one sensor in real time or periodically, and report the information collected by the sensor.
[0096] The camera driver can be used to trigger the target camera that has completed the initialization operation to send and display images.
[0097] The camera driver may include a front camera driver and a rear camera driver, wherein the front camera driver may be used to drive the front camera, and the rear camera driver may be used to drive the rear camera.
[0098] like Figure 2 As shown, after the camera application is started, the camera application detects the shooting operation triggered by the user, and in response to the user's triggering operation, the camera application sends a shooting request to the camera service. After receiving the shooting request, the camera service sends the shooting request to the hardware abstraction layer.
[0099] In some embodiments, after receiving the shooting request, the camera hardware abstraction module of the hardware abstraction layer initializes the camera and triggers the camera sensor to capture an image. After the camera sensor captures the image data 1, the camera sensor sends the image data 1 to the camera driver. After receiving the image data 1, the camera driver sends the image data 1 to the image processing module. After receiving the image data 1, the image processing module performs white balance processing on the image data 1 to obtain the image data 2 after the white balance processing. The image processing module sends the processed image data 2 to the camera application for display.
[0100] For ease of understanding, the following examples of this application will be Figure 1 and Figure 2 The electronic device shown is a mobile phone as an example, and the image processing method provided in the embodiment of the present application is specifically described in conjunction with the accompanying drawings.
[0101] Figure 3 (a) in FIG. 1 shows a graphical user interface (GUI) of a mobile phone, and the GUI is a desktop 310 of the mobile phone. When the mobile phone detects that a user clicks an icon 320 of a camera application (APP) on the desktop 310, the camera application can be started and a display such as Figure 3 Another GUI shown in (b) of FIG. 3 may be referred to as a photographing interface 330 . In the preview state, the photographing interface 330 may display a preview image in real time.
[0102] For example, see Figure 3In (b), after the mobile phone starts the camera, the shooting interface 330 can display the image captured and sent by the camera. In the shooting mode, when the mobile phone detects that the user clicks the shooting control 340, the mobile phone performs the shooting operation, and the target image captured by the mobile phone can be an image obtained by white balancing the original image captured; in the video recording mode, when the mobile phone detects that the user clicks the shooting control 340, the mobile phone performs the video shooting operation, and each frame of the video captured is an image frame obtained by white balancing the original image. For example, the image displayed in the above shooting interface 330 is an image after white balancing.
[0103] Assumptions Figure 3 The mobile phone is in a variety of light source scenes. In order to make the images captured by the mobile phone more realistically restore the image colors, after the mobile phone obtains the original images captured by the camera in various light source scenes, the target gain value of each pixel in the original image can be determined, and the original image can be white balanced based on the white balance gain value of each pixel to obtain the target image.
[0104] In some embodiments, the mobile phone may perform a first block processing on the original image to obtain a plurality of first image blocks. Then, the mobile phone determines the gain value of each first image block in the plurality of first image blocks respectively to obtain a plurality of first gain values. Further, the mobile phone determines a plurality of gain weight values corresponding to each pixel in the original image according to the plurality of first gain values, wherein the gain weight value is used to characterize the contribution ratio of each light source to the gain value of the pixel. The mobile phone may also perform a second block processing on the original image to obtain a plurality of second image blocks, and the mobile phone determines the gain value of each second image block in the plurality of first image blocks respectively. After obtaining the plurality of second gain values, the mobile phone determines the gain value corresponding to the second image block where the plurality of light sources are respectively irradiated according to the plurality of second gain values. After the mobile phone determines the target gain value corresponding to each pixel according to the plurality of gain weight values of each pixel and the gain value corresponding to the second image block where the plurality of light sources are located, the mobile phone performs white balance processing on the original image according to the target gain value corresponding to each pixel to obtain the target image.
[0105] In some embodiments, when the mobile phone determines the multiple gain weight values corresponding to each pixel in the original image, the mobile phone can first determine the multiple distance values between each first gain value in the multiple first gain values corresponding to the multiple first image blocks and the multiple first maximum points. Then, according to the multiple distance values between each first gain value and the multiple first maximum points, determine the multiple weight values corresponding to each first gain value. Thereafter, up-sample the multiple weight values corresponding to each first gain value in the multiple first gain values corresponding to the multiple first image blocks to obtain the multiple gain weight values corresponding to each pixel in the original image. Among them, the multiple first maximum points are the gain values corresponding to the first image blocks where the areas illuminated by the multiple light sources are located.
[0106] In some embodiments, the mobile phone determines the first gain value and the sum of multiple distance values between multiple first maximum points. After obtaining the distance sum, the ratios of the multiple distance values to the distance sum can be determined as multiple weight values corresponding to the first gain value.
[0107] It should be explained that since the color content of different image blocks may be different, the gain values corresponding to different image blocks may be different. Therefore, after the mobile phone determines the target gain value of each pixel in the original image, it uses the target gain value corresponding to different pixel points to perform white balance processing on the corresponding pixel points, so that the image color of the processed image is more realistic.
[0108] Combine the following Figure 4 Taking the original image captured under two types of light sources as an example (for example, light generated by lamps and the display screen of electronic devices), the process of white balancing the captured original image is described in detail. Figure 4 As shown, the method may include steps 401 to 412.
[0109] Step 401, obtaining the original image captured by the camera.
[0110] Among them, the original image is the image to be processed. In the present application, the original image is the image that has not been white balanced. The original image can be a RAW image, that is, the original image is an image captured by the camera sensor without any image processing. The original image can be an image obtained by the camera shooting the object to be photographed in a mixed light source scene (that is, multiple types of light sources), or it can be each frame of the video recorded by the camera, which is not limited here. For example, there are low color temperature light sources (such as tungsten filament lamps with a color temperature of approximately 3200K) and high color temperature light sources (such as the color temperature of a computer screen display is approximately 7000K) in the scene to be shot, and the original image captured by the camera includes two light sources.
[0111] In an embodiment of the present application, the original image may be a preview image captured by the camera under various light source scenarios when the shooting application of the mobile phone is displayed in the preview interface. The original image may also be an image captured by the shooting application in response to the user's shooting operation. The original image may also be an image pre-stored in the mobile phone, and so on. The source of the original image is not limited in this application.
[0112] The above-mentioned original image can be a RAW three-channel image, which refers to the information of the three color channels of red, green and blue contained in the RAW format image data. It can be understood that in a mobile phone, each pixel on the image sensor usually contains one or more photodiodes, which are sensitive to light of different colors. Most cameras use a Bayer filter to separate light into three basic colors of red, green and blue, and then each pixel only records the information of one color channel. Therefore, the data in the RAW image is composed of the data of these three color channels, which need to be processed to form a complete color image.
[0113] In the embodiment of the present application, the camera used to shoot the object may be one or more cameras. For example, the camera may include any one or a combination of a main camera, a telephoto camera, a wide-angle camera, and a macro camera.
[0114] Step 402: Perform a first block processing on the original image to obtain a plurality of first image blocks.
[0115] When a mobile phone camera captures a frame of original image or captures a frame of original image when shooting a video, the mobile phone can divide the frame of original image into multiple first image blocks according to a preset division rule. For example, the mobile phone divides the original image into M*N first image blocks, where M and N are both positive integers greater than 1.
[0116] In the embodiment of the present application, the mobile phone can pre-set the size of the first image block (patch) and the step length (step) between each first image block. Then, the mobile phone divides the original image into blocks according to the pre-set image block size and step length to obtain multiple first image blocks.
[0117] The size of a patch refers to a rectangular area in an image, usually used for local processing or feature extraction. The size of a patch is usually a two-dimensional dimension, such as 32x32 pixels, 64x64 pixels, etc. The size of the patch depends on the specific task being processed and the level of detail in the image. Smaller patches are suitable for analyzing fine structures in an image, while larger patches are better for capturing global features of an image.
[0118] Step refers to the number of pixels moved each time when moving the patch in the image to segment the image. The choice of step size affects the efficiency and results of the processing. Smaller step sizes lead to more overlap and more detailed analysis, but also increase the amount of calculation. Larger step sizes reduce the amount of calculation, but may miss details in the image or cause discontinuities in the processing results.
[0119] For example, Figure 5 As shown, the original image to be processed is Figure 5 As shown in (a), Figure 5 As shown in (b), assume that the mobile phone divides the original image into blocks with a patch size of 64 pixels and a step size of 32 pixels. Then, the mobile phone starts from the upper left corner (0, 0) of the original image, and extracts the image blocks in the original image one by one with a patch size of 64 pixels and a step size of 32 pixels. After each extraction, the image block is moved according to the step size until the entire original image is covered, and multiple image blocks are obtained. For example, A1A2A3A4 constitutes image block 1, B1B2B3B4 constitutes image block 2, and image block 1 and image block 2 have overlapping areas.
[0120] For example, Figure 5 As shown in (c), assume that the mobile phone determines to divide the original image into blocks with a patch size of 128 pixels and a step size of 32 pixels. Then, starting from the upper left corner of the original image, the mobile phone extracts the image blocks in the original image one by one with a patch size of 128 pixels and a step size of 32 pixels. After each extraction, the image block is moved according to the step size until the entire original image is covered, and multiple image blocks are obtained. For example, C1C2C3C4 constitutes image block 3, D1D2D3D4 constitutes image block 4, and image blocks 3 and 4 have overlapping areas.
[0121] For example, Figure 5 As shown in (d), assume that the mobile phone determines to divide the original image into blocks with a patch size of 64 pixels and a step size of 64 pixels. Then, starting from the upper left corner of the original image, the mobile phone extracts the image blocks in the original image one by one with a patch size of 64 pixels and a step size of 64 pixels. After each extraction, the image block is moved according to the step size until the entire original image is covered, and multiple image blocks are obtained. For example, E1E2E3E4 constitutes image block 5, and F1F2F3F4 constitutes image block 6, and there is no overlapping area between image block 5 and image block 6.
[0122] It needs to be explained that the above Figure 5 The method of dividing the original image into blocks is only used as an example. Figure 5The patch size and stride are only used as examples. For example, the patch size can also be 32 pixels, the stride size can be 16 pixels, etc. The stride can be equal to the width or height of the patch, or a part of the width or height of the patch, or even smaller than the patch.
[0123] In other embodiments, the mobile phone may divide the original image into a plurality of first image blocks of equal size. The size of the first image block may be set arbitrarily, for example, the mobile phone may divide the original image into 8*8, 16*16, etc. The mobile phone may divide the original image into blocks, which may be uniformly divided into the original image, or adaptively divided into the image according to the content of each area in the original image, which is not limited here.
[0124] It should be noted that the sizes of multiple first image blocks may be the same or different, there may be some overlapping areas between the multiple first image blocks, or there may be no overlapping areas between the multiple first image blocks, which is not limited in the embodiments of the present application.
[0125] Step 403: determine the gain value of each of the plurality of first image blocks respectively to obtain a plurality of first gain values. One first image block corresponds to one first gain value.
[0126] Among them, the gain value is used to adjust the white balance of the image block. The gain value here is a set of numerical values used to adjust the white balance of the image block to ensure that the white or gray area in the image block appears neutral under all lighting conditions. The gain value usually includes the gain or attenuation of the red, green, and blue channels, and these coefficients are used to multiply each pixel value in the image to correct the color cast. The purpose of white balancing the image is to compensate for the impact of the color temperature of different types of light sources on the color of the image. For example, when shooting under tungsten light, the image may be yellowish, so the value of the blue channel needs to be increased to neutralize this yellow. Conversely, on a cloudy day or under fluorescent light, the image may be bluish, and the values of the red and green channels need to be increased.
[0127] The gain value can be color temperature, hue, or gain factor. For example, a mobile phone can adjust the white balance by adjusting the color temperature of an image. Hue adjustment is a complement to color temperature adjustment and is used to fine-tune the balance of green and magenta in an image. In some cases, adjusting color temperature alone may not be enough to completely correct color cast. In this case, hue adjustment is performed on the image after color temperature adjustment to solve the white balance problem.
[0128] Here, the gain value may be the ratio of the mean of R and B to the mean of G of all gray points in the image to be processed, that is, R mean / G mean and B mean / G mean. Here, the first gain value of the first image block may be the ratio of the mean of R and B to the mean of G of all gray points in each image block, that is, R / G value and B / G value.
[0129] It should be noted that the mobile phone may calculate the first gain values of multiple first image blocks simultaneously, or may calculate the first gain value of each first image block in sequence, which is not specifically limited here.
[0130] In some embodiments, for each first image block, the mobile phone can determine the average value of the red channel, the average value of the green channel, and the average value of the blue channel of the pixels in the first image block; after determining a first ratio of the average value of the red channel to the average value of the green channel, and a second ratio of the average value of the blue channel to the average value of the green channel, the first ratio and the second ratio are determined as the first gain value corresponding to the first image block.
[0131] In other embodiments, for each first image block, after the mobile phone determines the target pixel point with the largest pixel value in each color channel in the first image block, it calculates a third ratio of the pixel value of the red channel to the pixel value of the green channel of the target pixel point, and a fourth ratio of the pixel value of the blue channel to the pixel value of the green channel; the third ratio and the fourth ratio are determined as the first gain value.
[0132] In the embodiment of the present application, the algorithm used by the mobile phone to determine the gain value of each first image block includes but is not limited to: a gray world method, a total reflection method (white block method) and a white point-color temperature calibration method.
[0133] In some embodiments, the process of the mobile phone using the gray world method to determine the first gain value of the first image block is as follows: first, the average values of each color channel in the first image block are calculated, which are Rmean, Gmean and Bmean respectively; a reference value K is determined, for example, Gmean can be determined as the reference value K; then, Rgain = Rmean / Gmean, Bgain = Bmean / Gmean are calculated. The first gain value corresponding to the first image block is determined to be (Rgain, Bgain).
[0134] In other embodiments, the mobile phone may use the total reflection method to determine the first gain value of the first image block in the following process: first, the mobile phone searches for the brightest point with the largest RGB value in the first image block as the target point; then, Rgain=R / G, Bgain=B / G are used to calculate the Rgain and Bgain of the target point; and the Rgain and Bgain of the target point are determined as the first gain value of the first image block.
[0135] In other embodiments, the mobile phone may also use a white point-color temperature calibration method to determine the first gain value of the first image block. The purpose of the white point-color temperature calibration method is to find a neutral white area (i.e., a white point) in the first image block, and adjust the color temperature of the neutral white area accordingly, so that the neutral white area in the first image block is displayed as a neutral white without color cast.
[0136] The process of the mobile phone using the white point-color temperature calibration method to determine the first gain value of the first image block is as follows: first, the R / G and B / G values of white imaging of different sensors under different color temperature light sources measured in a laboratory environment are obtained; then, the mobile phone obtains the R / G and B / G values of the entire first image block to determine the current color temperature; and the corresponding Rgain and Bgain are determined according to the current color temperature.
[0137] It should be explained that the method for determining the first gain value of the first image block introduced above is only an example and is not specifically limited in this application. Other methods for determining the gain value of an image may also be applicable to this application.
[0138] In addition, the mobile phone can start multiple threads to simultaneously determine the gain value of each of the multiple first image blocks to obtain multiple first gain values, so as to improve the image processing efficiency.
[0139] Step 404: perform density estimation on a plurality of first gain values corresponding to a plurality of first image blocks to obtain a first density estimation result.
[0140] In the embodiment of the present application, the mobile phone can use a kernel density estimation algorithm (kernel density estimation, KDE) to perform density estimation on multiple first gain values corresponding to multiple first image blocks to obtain a kernel density estimation result, wherein the kernel density estimation result is a probability density function estimation of the sample.
[0141] Typically, KDE is viewed as a continuous version of a histogram. A histogram is a discretization method for visualizing data distribution that divides the data range into a series of bins (intervals) and counts the number of data in each interval. However, one limitation of the histogram is that it relies on the choice of intervals, and different interval divisions may result in different distribution shapes. Kernel density estimation provides a smoother way to estimate the probability density function of the data by applying a kernel function (usually a symmetric function centered on the data point, such as a Gaussian kernel) to each data point and summing the results of all kernel functions to estimate the probability density. The result of kernel density estimation is a continuous density curve, which can provide a smoother and more accurate probability density estimate.
[0142] In some embodiments, the process of using KDE by the mobile phone to perform density estimation on multiple first gain values corresponding to multiple first image blocks is as follows: First, select a suitable kernel function, such as Gaussian kernel, uniform kernel, Epanechnikov kernel, triangular kernel, quartic kernel, etc. The choice of kernel function here has a certain influence on the final density estimation result, but the density estimation results given by different kernel functions are not much different. Secondly, the mobile phone pre-sets the bandwidth. Finally, the density estimate is calculated. For each first gain value, use the kernel function to calculate its probability density contribution at each position, and then sum the contributions of all points to obtain the density estimate of the position.
[0143] It should be explained that bandwidth is a key parameter in kernel density estimation, which determines the width of the kernel function. A smaller bandwidth will cause the estimated density function to fluctuate greatly, while a larger bandwidth will make the density estimate too smooth. Common bandwidth selection methods include empirical rules, cross-validation, etc.
[0144] For example, the kernel density estimation algorithm can be expressed as follows: Formula (1).
[0145] Where f(x) is the density estimate at position x; n is the number of data points; K() is the kernel function; are data points; h is the bandwidth.
[0146] In the embodiment of the present application, the mobile phone performs kernel density estimation on the multiple first gain values corresponding to the multiple first image blocks, and after obtaining the kernel density estimation result, a kernel density function graph can be drawn according to the kernel density result. Figure 6 This is an example diagram of the kernel density function diagram provided in the embodiment of the present application. Figure 6 The horizontal axis represents the gain value of the red channel (Rgain), the vertical axis represents the gain value of the green channel (Bgain), and the color depth of different areas represents different densities.
[0147] It should be noted that the above-mentioned use of the kernel density estimation algorithm to perform density estimation on the multiple first gain values corresponding to the multiple first image blocks is only an example, and other density estimation algorithms may also be used for estimation, which is not limited here.
[0148] Step 405: determine two first maximum points according to the density estimation result.
[0149] Here, the two first maximum value points may be a first extreme value point and a second extreme value point.
[0150] In the embodiment of the present application, the two maximum points determined by the mobile phone correspond to the gain values of the first image block where the areas illuminated by the two light sources in the original image are located. Here, the purpose of the mobile phone determining the first extreme point and the second extreme point is to find the gain value corresponding to the area illuminated by the two light sources in the original image, and to more accurately adjust the color of the image taken under the mixed light source by correcting the color of the image block corresponding to the extreme point.
[0151] Among them, extreme value points usually refer to the points in the function graph where the function reaches the maximum or minimum value. Extreme value points refer to the points in a certain interval where the function value of a continuous function cannot be exceeded by the function values of other interval points. Specifically, they can be divided into local extreme value points and global extreme value points. Among them, local extreme value points refer to the point where the value of the function at a certain point is the maximum or minimum value of the surrounding points. This point is the local maximum point or the local minimum point. Local extreme value points can be found by taking derivatives. The derivative of the function at the local maximum point is 0 or does not exist, and the same is true for the local minimum point. A global extreme value point means that within the function domain, if there is a point whose function value is the largest or smallest among all points, then this point is the global maximum point or the global minimum point.
[0152] For example, the mobile phone can Figure 7 The kernel density function graph in is subjected to a maximum suppression operation to retain local extreme values. Then, the mobile phone determines two maximum points from the local extreme values. Here, the two extreme points are referred to as the first extreme point and the second extreme point.
[0153] Among them, the local extreme value refers to the maximum or minimum point in a local area of the function. For a continuous function f(x), if in the neighborhood of a certain point x0, for all x values, f(x) ≤ f(x0) (i.e., local maximum value) or f(x) ≥ f(x0) (i.e., local minimum value), then point x0 is the local extreme point of the function.
[0154] Step 406: Determine the gain weight value of each pixel in the original image according to the multiple first gain values and the two first maximum points.
[0155] The gain weight value is used to characterize the contribution ratio of each light source to the gain value of the pixel point, that is, the gain weight value is the weight value corresponding to the gain value of each pixel point.
[0156] In an embodiment of the present application, the mobile phone can determine the two weight values corresponding to each first gain value based on the first gain value, the first extreme point and the second extreme point corresponding to each first image block in the multiple image blocks. Then, the mobile phone upsamples the two weight values corresponding to each first gain value among the multiple first gain values corresponding to the multiple first image blocks to obtain the two gain weight values corresponding to each pixel in the original image.
[0157] For each first gain value, the distances between the first gain value and the first extreme point and the second extreme point are calculated to obtain the first distance and the second distance. Then, the mobile phone determines the first weight value and the second weight value of the first gain value according to the first distance and the second distance.
[0158] In some embodiments, the mobile phone may calculate the Euclidean distances between the first gain value and the first extreme point and the second extreme point, respectively, to obtain the first distance and the second distance.
[0159] For example, assume that the mobile phone determines that the first gain value awb of the first image block 1 is (Rg, Bg), the first extreme point ill1 is (Rg1, Bg1), and the second extreme point ill2 is (Rg2, Bg2). And the first extreme point is greater than the second extreme point. For example, the following formula (2) is used to calculate the Euclidean distance d1 between the first gain value and the first extreme point.
[0160] Formula (2).
[0161] Similarly, the mobile phone can use the above formula (2) to calculate the Euclidean distance d2 between the first gain value and the second extreme point.
[0162] Furthermore, the mobile phone may determine the first weight value and the second weight value of the first gain value according to the Euclidean distances d1 and d2. For example, the first weight value w1=d1 / (d1+d2), and the second weight value w2=1-w1.
[0163] It should be noted that the mobile phone can use the above method to calculate the weight value of the first gain value of the first image block 1 to calculate the weight value corresponding to each first gain value. The specific calculation process will not be repeated here.
[0164] In the embodiment of the present application, after the mobile phone calculates and obtains two weight values corresponding to each of the multiple first gain values corresponding to the multiple image blocks, the mobile phone can perform upsampling processing on the two weight values corresponding to the multiple first gain values to obtain the gain weight value corresponding to each pixel in the original image. The gain weight value corresponding to each pixel includes the first gain weight value and the second gain weight value.
[0165] That is to say, when the shooting scene is a scene containing two types of light sources, the gain weight value corresponding to each pixel point is two. Similarly, assuming that the shooting scene is a scene with three or more types of light sources, the gain weight value corresponding to each pixel point can be three or more. The specific determination process can refer to the determination process in the above two light source scenes, which will not be repeated here.
[0166] In some embodiments, after the mobile phone determines the weight values corresponding to the plurality of first gain values, respectively, it can draw a weight graph according to the weight values corresponding to the first gain values.
[0167] It should be explained that the step size of the first block processing of the original image by the mobile phone is smaller than the size of the image block. After the white balance estimation is performed on different first image blocks and different first gain values are obtained, the weight map obtained by drawing according to the weight values corresponding to the multiple first gain values is inconsistent with the size of the original image. In this case, the mobile phone can upsample the weight map to obtain the upsampled weight map. Among them, the weight values in the upsampled weight map include the gain weight values corresponding to each pixel in the original image.
[0168] Exemplarily, the mobile phone may use a bilateral filtering upsampling algorithm to upsample the weight map, so that the upsampled weight map is smoother and includes a gain weight value corresponding to each pixel in the original image.
[0169] Among them, the bilateral filtering upsampling algorithm combines bilateral filtering and upsampling operations and is often used for image enlargement or super-resolution reconstruction. This algorithm can effectively maintain image edges and details while reducing the noise and jagged effects that may be generated during the upsampling process, thus avoiding the uneven weight values obtained after the upsampling process.
[0170] Optionally, the mobile phone may first preprocess the weight map to obtain a preprocessed weight map. For example, the weight map is subjected to denoising, edge enhancement and other operations. Then, the mobile phone performs upsampling on the preprocessed weight map. For example, an interpolation algorithm (such as nearest neighbor interpolation, bilinear interpolation, bicubic interpolation, etc.) is used to enlarge the preprocessed weight map to the size corresponding to the original image. Furthermore, the mobile phone performs bilateral filtering on the upsampled image to reduce defects that may be introduced by upsampling and maintain smooth transitions and edges of the image. In order to further improve the image quality, the weight map may be subjected to multiple iterations of bilateral filtering upsampling.
[0171] It should be explained that the method of using the bilateral filtering upsampling algorithm to upsample the weight value in the above mobile phone is only an example, and other upsampling methods can also be used in the embodiments of the present application, and the upsampling method is not limited here. For example, the mobile phone can also use the nearest neighbor interpolation, bilinear interpolation and other methods to upsample the weight value.
[0172] In some embodiments, after the mobile phone determines the first weight value and the second weight value corresponding to each first gain value, it can perform a normalization operation on the first weight value and the second weight value, so that the normalized first weight value and the normalized second weight value are scaled to a specific range (usually between 0 and 1), which is helpful for comparing data of different magnitudes or performing operations between different data.
[0173] Exemplarily, the normalized first weight value w1′=w1 / (w1+w2), and the normalized second weight value w2′=w2 / (w1+w2).
[0174] Furthermore, the mobile phone upsamples the multiple first gain values corresponding to the multiple first image blocks, the corresponding normalized first weight values and the normalized second weight values to obtain the normalized gain weight value corresponding to each pixel in the original image.
[0175] Step 407: perform a second block processing on the original image to obtain a plurality of second image blocks.
[0176] Among them, the size of the second image block is larger than the size of the first image block. That is, the size of the patch used by the mobile phone to perform block processing on the original image this time is larger than the size of the patch used in the first block processing in step 402, and the step size is also larger than the step size used in the first block processing. For example, the mobile phone uses a patch size of 64 pixels and a step of 32 pixels to perform the first block processing on the original image. The mobile phone uses a patch size of 256 pixels and a step of 64 pixels to perform the second block processing on the original image.
[0177] The process of dividing the original image into blocks by the mobile phone can refer to the implementation process of the above step 402, which will not be repeated here.
[0178] It should be explained that since smaller image blocks are suitable for analyzing the fine structure of an image, and larger image blocks can more accurately capture the global features of an image, the use of a smaller first image block in the present application can more accurately determine the gain weight value of each pixel.
[0179] Here, the mobile phone can perform the first block processing and the second block processing on the original image at the same time, or can first perform the first block processing on the original image and then perform the second block processing on the original image. Of course, it can also first perform the second block processing on the original image and then perform the first block processing on the original image. In other words, the process of the two block processing performed by the mobile phone on the original image in the embodiment of the present application is not limited.
[0180] Step 408: Determine the gain value of each second image block in the plurality of second image blocks respectively to obtain a plurality of second gain values. One second image block is applied to one second gain value.
[0181] Step 409: perform density estimation on the multiple second gain values to obtain a second density estimation result.
[0182] Step 410: Determine two second maximum points according to the second density estimation result, namely the third maximum point and the fourth maximum point.
[0183] The two second maximum points are gain values corresponding to the second image blocks where the regions illuminated by the two light sources are located.
[0184] Since larger patches are more suitable for capturing the global features of an image, in order to more accurately find the light source in the original image, the mobile phone can process the original image in blocks to obtain multiple second image blocks larger than the first image block. Then, the mobile phone obtains multiple second gain values based on the gain values of the multiple second image blocks. Furthermore, the mobile phone performs density estimation on the multiple second gain values, and determines the third extreme point and the fourth extreme point (that is, the gain value corresponding to the second image block where the area illuminated by the two light sources is located) based on the density estimation result. Therefore, compared with the first extreme point and the second extreme point obtained by processing the multiple first image blocks in the above process, the third extreme point and the fourth extreme point determined here can more accurately determine the gain value corresponding to the image block where the mixed light source illumination area is located.
[0185] The implementation process of step 408 to step 410 here can refer to the implementation process of step 403 to step 405 above, and will not be repeated here.
[0186] It should be explained that the mobile phone can execute the above-mentioned process from step 402 to step 410 sequentially, or can execute the implementation process from step 402 to step 406 and step 407 to step 410 simultaneously to improve the image processing efficiency.
[0187] Step 411, determining the target gain value corresponding to each pixel point in the original image according to the gain weight value corresponding to each pixel point and the two second maximum points.
[0188] In some embodiments, for each pixel point, two product values of two gain weight values corresponding to the pixel point and the corresponding second maximum point are determined. The sum of multiple product values is determined as the target gain value corresponding to the pixel point. The larger the gain weight value, the larger the value of the corresponding second maximum point.
[0189] Exemplarily, for each pixel point, the mobile phone first calculates the first product value of the first gain weight value and the third extreme point, and the second product value of the second gain weight value and the fourth extreme point, and then determines the sum of the first product value and the second product value as the target gain value of the pixel point.
[0190] For example, the mobile phone may use the following formula (3) to determine the target gain value corresponding to each pixel point.
[0191] Formula (3).
[0192] Among them, Tg is the target gain value corresponding to the pixel point, w1 is the first gain weight value corresponding to the pixel point, w2 is the second gain weight value corresponding to the pixel point, L1 is the third extreme value point, L2 is the fourth extreme value point, and the third extreme value point is greater than the fourth extreme value point.
[0193] It should be explained that the mobile phone can determine the target gain value corresponding to each pixel in the original image according to the above method, which will not be described in detail here.
[0194] Step 412: perform white balance processing on the original image using the target gain value corresponding to each pixel in the original image to obtain a target image.
[0195] In the photo scene, the target image is the image obtained by white balancing the original image. In the video scene, the target image is the image frame in the video obtained by white balancing the original image.
[0196] In an embodiment of the present application, the mobile phone can perform white balance processing on each pixel in the original image according to the target gain value corresponding to each pixel in the original image to obtain a target image.
[0197] In some embodiments, the mobile phone may divide the pixel value corresponding to each pixel in the original image by the target gain value of the corresponding pixel to perform white balance processing on each pixel to obtain a target image.
[0198] For example, assuming that the target gain value corresponding to a certain pixel point is (Rg', Bg'), the mobile phone can convert the target gain value corresponding to the pixel point into a three-channel gain value, namely (Rg', 1, Bg'), the pixel value corresponding to the pixel point is (R, G, B), and the pixel value after white balance processing of the pixel point is (R / Rg', G, B / Bg').
[0199] In the embodiment of the present application, the mobile phone determines the target gain value corresponding to each pixel in the original image, and uses the target gain value corresponding to each pixel to perform white balance processing on each pixel. It can be seen that by assigning different gain values to each pixel, it is beneficial to improve the white balance adjustment effect.
[0200] In one scenario, Figure 7 As shown in , it is assumed that the mobile phone takes the original image under two light sources, such as Figure 7 The original image shown includes areas illuminated by two light sources, namely, the light source displayed by the bright computer screen and the light source illuminated by the tungsten filament lamp. The mobile phone performs a first block processing on the original image to obtain multiple first image blocks. For example, the mobile phone performs block processing on the original image with a patch size of 64 pixels and a step size of 32 pixels. Then, the mobile phone determines the gain value of each first image block to obtain multiple first gain values. The mobile phone performs density estimation on the multiple first gain values corresponding to the multiple first image blocks to obtain a first density estimation result, and draws a density function graph, such as Figure 7 Further, the mobile phone performs a maximum value suppression operation on the density function graph and determines two maximum value points, such as Figure 7 The first and second extreme points in .
[0201] For each first image block, the mobile phone determines the distances between the first gain value of the first image block and the first extreme point and the second extreme point, respectively, to obtain the first distance d1 and the second distance d2. Then, the mobile phone determines the first weight value and the second weight value of the first image block according to the first distance and the second distance. Based on this, the mobile phone can determine the first weight value and the second weight value of all first image blocks, and then perform upsampling processing on the weight values corresponding to all first image blocks to determine the gain weight value of each pixel in the original image.
[0202] The mobile phone divides the original image into blocks again, obtains multiple second image blocks larger than the first image block, and repeats the above process of determining the maximum point to determine the third extreme point and the fourth extreme point. The mobile phone determines the target gain value corresponding to each pixel in the original image based on the gain weight value, the third extreme point and the fourth extreme point corresponding to each pixel in the original image, and then uses the target gain value corresponding to each pixel in the original image to perform white balance processing on the original image to obtain the target image.
[0203] It needs to be explained that the above Figure 4 and Figure 7 This article takes the shooting scene with two types of light sources as an example to introduce the process of white balance processing of the original image. Figure 7From the white balance processing process, it can be seen that the mobile phone determines two maximum points to determine the image blocks where the areas illuminated by the two light sources are located. Assuming that the shooting scene includes three or more types of light sources, the mobile phone can determine three or more maximum points to more accurately perform white balance processing on the original image. The process of performing white balance processing on the original image collected when the shooting scene includes three or more types of light sources is not described here, and you can refer to the process of the above shooting scene including two light sources.
[0204] The process of performing white balance processing on the original image by the mobile phone may be executed by an image processing module in the mobile phone, which will not be described in detail here.
[0205] It is understandable that, in order to realize the above functions, the above-mentioned electronic devices, etc. include hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily realize that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the embodiments of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the embodiments of the present invention.
[0206] The embodiment of the present application can divide the functional modules of the above-mentioned electronic device etc. according to the above-mentioned method example. For example, each functional module can be divided corresponding to each function, or two or more functions can be integrated into one processing module. The above-mentioned integrated module can be implemented in the form of hardware or in the form of software functional modules. It should be noted that the division of modules in the embodiment of the present invention is schematic and is only a logical function division. There may be other division methods in actual implementation.
[0207] In the case of dividing each functional module according to each function, a possible composition diagram of the electronic device involved in the above embodiment, the electronic device may include: a display unit, a transmission unit and a processing unit, etc. It should be noted that all relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module, and will not be repeated here.
[0208] The embodiment of the present application also provides an electronic device, including one or more processors and one or more memories. The one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer program codes, and the computer program codes include computer instructions. When the one or more processors execute the computer instructions, the electronic device executes the above-mentioned related method steps to implement the image processing method in the above-mentioned embodiment.
[0209] An embodiment of the present application further provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on an electronic device, the electronic device executes the above-mentioned related method steps to implement the image processing method in the above-mentioned embodiment.
[0210] An embodiment of the present application further provides a computer program product, which includes computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the above-mentioned related method steps to implement the image processing method in the above-mentioned embodiment.
[0211] In addition, an embodiment of the present application also provides a device, which may specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor may execute the computer-executable instructions stored in the memory so that the device executes the image processing method performed by the electronic device in the above-mentioned method embodiments.
[0212] Among them, the electronic device, computer-readable storage medium, computer program product or device provided in this embodiment is used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be repeated here.
[0213] Through the description of the above implementation methods, technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above functional modules is used as an example. 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. The specific working process of the system, device and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0214] Each functional unit in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of software functional units.
[0215] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as flash memory, mobile hard disk, read-only memory, random access memory, disk or optical disk.
[0216] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. An image processing method, characterized in that: Applied to an electronic device having a camera, the method comprises: In response to a preset operation, displaying a shooting preview interface, the shooting preview interface including original images captured by the camera under various light source scenes; In response to the shooting operation, the original image is subjected to a first block processing to obtain a plurality of first image blocks, and the original image is subjected to a second block processing to obtain a plurality of second image blocks, wherein the size of the second image blocks is larger than the size of the first image blocks; Determine the gain value of each of the plurality of first image blocks respectively to obtain a plurality of first gain values; and determine the gain value of each of the plurality of second image blocks respectively to obtain a plurality of second gain values; the gain values are used to adjust the white balance of the image blocks, one of the first image blocks corresponds to one of the first gain values, and one of the second image blocks corresponds to one of the second gain values; Determine, according to the multiple first gain values, multiple gain weight values corresponding to each pixel in the original image, the gain weight values being used to characterize the contribution ratio of each light source to the gain value of the pixel; Determine, according to the plurality of second gain values, gain values corresponding to the second image blocks where the regions illuminated by the plurality of light sources are located; Determine a target gain value corresponding to each pixel point according to a plurality of gain weight values of each pixel point and a gain value corresponding to a second image block where regions illuminated by a plurality of light sources are located; According to the target gain value corresponding to each pixel point, white balance processing is performed on the original image to obtain a target image.
2. The method according to claim 1, characterized in that The step of determining, according to the plurality of first gain values, a plurality of gain weight values corresponding to each pixel point in the original image comprises: Performing density estimation on the multiple first gain values corresponding to the multiple first image blocks to obtain a first density estimation result; Determine a plurality of first maximum value points according to the first density estimation result, where the plurality of first maximum value points are gain values corresponding to a first image block where regions illuminated by the plurality of light sources are located; According to the multiple first gain values and the multiple first maximum points, multiple gain weight values corresponding to each pixel point in the original image are determined.
3. The method according to claim 2, characterized in that The step of determining a plurality of gain weight values corresponding to each pixel point in the original image according to the plurality of first gain values and the plurality of first maximum points comprises: Determine a plurality of distance values between each of the plurality of first gain values corresponding to the plurality of first image blocks and the plurality of first maximum points; Determining a plurality of weight values corresponding to each first gain value according to a plurality of distance values between each first gain value and the plurality of first maximum value points; Among the multiple first gain values corresponding to the multiple first image blocks, multiple weight values corresponding to each first gain value are up-sampled to obtain multiple gain weight values corresponding to each pixel in the original image.
4. The method according to claim 3, characterized in that The determining, according to the multiple distance values between each first gain value and the multiple first maximum value points, multiple weight values corresponding to each first gain value comprises: Determine the sum of multiple distance values between the first gain value and the multiple first maximum value points, and obtain a distance sum; The ratios of the multiple distance values to the sum of the distances are determined as multiple weight values corresponding to the first gain value.
5. The method according to claim 3 or 4, characterized in that: After determining the multiple weight values corresponding to each first gain value according to the multiple distance values between each first gain value and the multiple first maximum points, the method further includes: For each of the first gain values, multiple weight values corresponding to the first gain value are added, and normalized to obtain multiple normalized weight values corresponding to the first gain value; The up-sampling of the multiple weight values corresponding to each first gain value among the multiple first gain values corresponding to the multiple first image blocks to obtain multiple gain weight values corresponding to each pixel in the original image includes: Upsampling is performed on the normalized multiple weight values respectively corresponding to the multiple first gain values to obtain multiple gain weight values corresponding to each pixel point in the original image.
6. The method according to claim 3 or 4, characterized in that: The up-sampling of the plurality of weight values corresponding to each of the plurality of first gain values corresponding to the plurality of first image blocks comprises: A bilateral filtering up-sampling algorithm is adopted to perform up-sampling processing on a plurality of weight values corresponding to each of the plurality of first gain values corresponding to the plurality of first image blocks.
7. The method according to any one of claims 2 to 4, characterized in that: The performing density estimation on the multiple first gain values corresponding to the multiple first image blocks comprises: A kernel density estimation method is used to perform density estimation on the multiple first gain values.
8. The method according to any one of claims 1 to 4, characterized in that: The step of determining, according to the plurality of second gain values, gain values corresponding to the second image blocks where the regions illuminated by the plurality of light sources are located comprises: Performing density estimation on the multiple second gain values to obtain a second density estimation result; According to the second density estimation result, a plurality of second maximum points are determined, where the plurality of second maximum points are gain values corresponding to a plurality of second image blocks where the regions respectively illuminated by the plurality of light sources are located.
9. The method according to claim 8, characterized in that The determining, according to the multiple gain weight values of the pixels and the gain values corresponding to the second image blocks where the regions illuminated by the multiple light sources are located, the target gain values corresponding to the pixels comprises: For each pixel point, determine a plurality of product values of the gain weight values corresponding to the pixel point and the corresponding second maximum value points, wherein the larger the gain weight value is, the larger the value of the corresponding second maximum value point is; The sum of the multiple product values is determined as the target gain value corresponding to the pixel point.
10. The method according to any one of claims 1 to 4, characterized in that: The step of performing white balance processing on the original image according to the target gain value corresponding to each pixel point to obtain a target image includes: Obtaining the pixel value of each pixel in the original image; The target image is obtained by dividing the pixel value of each pixel by the target gain value corresponding to the pixel.
11. The method according to any one of claims 1 to 4, characterized in that: The step of respectively determining the gain value of each of the plurality of first image blocks to obtain a plurality of first gain values comprises: For each first image block, determine an average value of a red channel, an average value of a green channel, and an average value of a blue channel of pixels in the first image block; Determining a first ratio of the average value of the red channel to the average value of the green channel, and a second ratio of the average value of the blue channel to the average value of the green channel; The first ratio and the second ratio are determined as the first gain value corresponding to the first image block.
12. The method according to any one of claims 1 to 4, characterized in that: The step of respectively determining the gain value of each of the plurality of first image blocks to obtain a plurality of first gain values comprises: For each first image block, determining a target pixel point having the maximum pixel value in each color channel of the first image block; Calculating a third ratio of a pixel value of a red channel to a pixel value of a green channel of the target pixel point, and a fourth ratio of a pixel value of a blue channel to a pixel value of the green channel; The third ratio and the fourth ratio are determined as the first gain value.
13. The method according to any one of claims 1 to 4, characterized in that: In a photo-taking scenario, the target image is an image obtained by performing white balance processing on the original image; In a video recording scenario, the target image is an image frame obtained by performing white balance processing on the original image in the captured video.
14. An electronic device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 13.
15. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 13 are implemented.
16. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 13 are implemented.
Citation Information
Patent Citations
White balance calibration method and electronic equipment
CN107483908A
White balance adjustment method and device, terminal and storage medium
CN113497927A
Mixed color temperature scene white balance processing method and device, storage medium and terminal
CN114745532A
Image white balance correction method and device for multiple light sources, equipment and storage medium
CN115988335A
KR20210069597A
