Image processing method, device and storage medium
By analyzing and comparing the average brightness of the highlighted portion and the entire image in the night scene image, and setting appropriate brightness adjustment parameters, the problem of overexposure of the highlight area and overdarkness of the dark area in the night scene image is solved, and the image quality is improved.
Patent Information
- Application Number
- CN202311698871.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-12
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2043-12-12
AI Technical Summary
In night scene shooting scenarios, it is difficult for users to set appropriate shooting parameters, resulting in poor quality of captured images, especially overexposed highlight areas and too dark dark areas that cannot be displayed clearly.
By analyzing and comparing the average brightness of the highlight part and the whole image in the night scene image, different brightness adjustment parameters are set for the pixel units in different brightness intervals, and brightness adjustment and contrast correction are performed to avoid overexposure of the highlight part and overexposure of the dark part. Bright.
It achieves reasonable correction of the brightness of night scene images, improves image quality, avoids the problems of overexposure of highlight parts and overdarkness of dark parts, and significantly improves the overall effect of the image.
Smart Images

Figure CN117408927B
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal technology, and in particular to image processing methods, devices and storage media. Background Art
[0002] With the popularization of smart terminal devices, it has become a normal practice for users to use electronic devices such as mobile phones and tablets to take pictures, and users have higher and higher requirements for the quality of the pictures taken.
[0003] Limited by their professional level, most users do not know how to set appropriate shooting parameters according to the shooting scene, so it is difficult to capture high-quality images. Especially in special scenes such as night scenes, the image quality is poor. For example, the highlight areas in the night scene images are overexposed and cannot be displayed clearly, and the dark areas are too dark. Summary of the invention
[0004] The embodiments of the present application provide an image processing method, device and storage medium to avoid image overexposure and improve image quality.
[0005] In a first aspect, an embodiment of the present application proposes an image processing method that can be applied to an electronic device with shooting and image processing functions, or an image processing device, the method comprising: in a night scene shooting mode, obtaining a first image captured by a camera, the brightness value of a first pixel unit in the first image being greater than the first brightness value; displaying a second image, the brightness value of the first pixel unit in the second image being less than the brightness value of the first pixel unit in the first image.
[0006] The first image is an original image captured by the camera. The first pixel unit in the first image refers to the pixel unit of the highlighted part in the first image. The brightness value of the pixel unit of the highlighted part is greater than the first brightness value. Figure 3 , the pixel units of the highlighted part may correspond to the pixel units whose brightness values fall within the fourth brightness interval, wherein the first brightness value may correspond to Figure 3 The setting of thr3 is not limited in this embodiment.
[0007] The second image is an image processed by the first image, and the image processing includes brightness adjustment, contrast correction, etc. The brightness value of the first pixel unit in the second image is lower than the brightness value of the first pixel unit in the first image.
[0008] The above scheme realizes the correction of the brightness of the first image by darkening the brightness of the pixel units of the highlighted part in the first image, so that the brightness of the first image is more reasonable, avoiding overexposure of the highlighted part, and improving the image quality.
[0009] In an optional embodiment of the first aspect, the image processing method further includes: obtaining brightness information of the first image; determining a first parameter by comparing the brightness information with a preset threshold; and adjusting the brightness value of the first pixel unit based on the first parameter to obtain a second image. The first parameter is used to indicate the degree of brightness adjustment of the first pixel unit in the first image.
[0010] The brightness information of the first image includes the brightness mean of the first image, such as the brightness mean of the highlight portion of the first image and the brightness mean of the entire first image. The first parameter can be determined by comparing the brightness mean of the first image with a preset threshold. The first parameter is not a brightness adjustment parameter, but can be regarded as an intermediate parameter, which can be used to determine the brightness adjustment parameter for the highlight portion of the first image. The first parameter can correspond to a judge.
[0011] The above solution shows that an intermediate parameter of brightness adjustment is determined according to the brightness information of the first image, which provides data support for the subsequent determination of the brightness adjustment parameter.
[0012] In an optional embodiment of the first aspect, the brightness information of the first image includes at least one of a first brightness mean and a second brightness mean of the first image. The first brightness mean is the brightness mean of all pixel units in a preset brightness range in the first image, and the second brightness mean is the brightness mean of all pixel units in the first image. The first parameter is determined by comparing the magnitude relationship between the brightness information and a preset threshold, including: determining the first parameter by comparing the magnitude relationship between the first brightness mean and the first threshold, and the magnitude relationship between the second parameter and the second threshold; the second parameter is used to indicate the proportional coefficient between the first brightness mean and the second brightness mean.
[0013] The first brightness mean is the brightness mean of the highlight part in the first image, which can correspond to mean_highlight. The second brightness mean is the brightness mean of the entire image in the first image, which can correspond to judge_light.
[0014] The preset brightness interval may be a fourth brightness interval (thr3, 255], where thr3 may be the brightness value of the last pixel unit in the first n% after the brightness of the pixel units in the entire image are sorted, for example, n is 2.
[0015] The preset threshold includes a first threshold and a second threshold. The first threshold is used for comparison with the first brightness mean, for example, the first threshold is 200, and the second threshold is used for comparison with the second brightness mean, for example, the second threshold is 2.
[0016] In an optional embodiment of the first aspect, determining the first parameter by comparing the magnitude relationship between the first brightness mean value and the first threshold value, and the magnitude relationship between the second parameter and the second threshold value, includes:
[0017] If the first brightness mean is less than the first threshold and the second parameter is less than the second threshold, the first parameter is 1; or, if the first brightness mean is less than the first threshold, or the second parameter is less than the second threshold, the first parameter is the first value, and the first value is a positive number less than 1; or, if the first brightness value is greater than or equal to the first threshold and the second parameter is greater than or equal to the second threshold, the first parameter is the second value, and the second value is a positive number less than the first value.
[0018] Exemplarily, the first value may be 0.9, and the second value may be a value less than 0.9.
[0019] The relationship between the first parameter and the first brightness mean, the first threshold, the second brightness mean, and the second threshold can be referred to Formula 7. The parameter value of Formula 7 can be configured according to actual conditions, and this embodiment of the present application is not limited to this.
[0020] In an optional embodiment of the first aspect, the second value is determined according to the first brightness average value and the second brightness average value.
[0021] In an optional embodiment of the first aspect, if the first parameter is the second value, the image processing method further includes: determining the second parameter based on the first brightness mean and the second brightness mean, the second parameter being used to indicate a proportional coefficient between the first brightness mean and the second brightness mean; determining a third parameter based on the first brightness mean, the third parameter being used to indicate a proportional coefficient between the first brightness mean and the highest brightness value; and obtaining the second value by performing a weighted summation of the second parameter and the third parameter.
[0022] The second parameter can correspond to judge1 in formula 5, and the third parameter can correspond to judge2 in formula 6. The highest brightness value is recorded as 255. The second value can be obtained by weighted summing the second parameter and the third parameter. Referring to the third line in formula 7, the second value can be .
[0023] In an optional embodiment of the first aspect, adjusting the brightness value of the first pixel unit based on the first parameter includes: traversing each pixel unit in the first pixel unit, and determining the brightness adjustment parameter of each pixel unit in the first pixel unit based on the first parameter, the first brightness value and the brightness value of each pixel unit in the first pixel unit; adjusting the brightness value of each pixel unit in the first pixel unit based on the brightness adjustment parameter of each pixel unit in the first pixel unit.
[0024] The first pixel unit is a pixel unit of a highlighted part in the first image. The brightness adjustment parameter of each pixel unit in the highlighted part may be determined by referring to Formula 4. Formula 4 is only used as an example and is not limited to this embodiment of the present application.
[0025] In one example, the brightness value of each pixel unit in the first pixel unit can be adjusted based on the brightness adjustment parameter of each pixel unit by changing gamma, which can be referred to in Formula 8.
[0026] The above scheme traverses each pixel unit of the highlight part in the first image to determine the brightness adjustment parameter of each pixel unit of the highlight part, so as to adjust the brightness of each pixel unit of the highlight part in the first image to avoid overexposure of the highlight part of the image.
[0027] In an optional embodiment of the first aspect, the image processing method further includes: the second pixel unit is any pixel unit among the first pixel units, and based on the two-dimensional Gaussian kernel and the brightness adjustment parameters of the second pixel unit, the brightness values of multiple third pixel units are adjusted; the multiple third pixel units are pixel units within a preset area centered on the second pixel unit.
[0028] The second pixel unit is any pixel unit of the pixel unit in the highlighted part of the first image. Specifically, after determining the brightness adjustment parameter of the second pixel unit, based on the two-dimensional Gaussian kernel function and the brightness adjustment parameter of the second pixel unit, determine the brightness adjustment parameters of multiple third pixel units in a preset area centered on the second pixel unit; while adjusting the brightness value of the second pixel unit, adjust the brightness values of multiple third pixel units. The third pixel unit is a pixel unit in the adjacent area of the second pixel unit. The above processing can refer to Figure 5 .
[0029] In the above scheme, when the brightness of each pixel unit in the highlight part of the first image is adjusted (ratio is less than 1), the brightness of the pixel units in the adjacent area of each pixel unit in the highlight part can also be adjusted to avoid discontinuous brightness adjustment and improve the image brightness adjustment effect.
[0030] In an optional embodiment of the first aspect, when brightness adjustment is performed on pixel units in dark parts (darker parts and brighter parts) of the first image (ratio is greater than 1), brightness adjustment may also be performed on pixel units in adjacent areas to avoid discontinuous brightness adjustment.
[0031] In an optional embodiment of the first aspect, the image processing method further includes: traversing each pixel unit in the fourth pixel unit, the fourth pixel unit including multiple pixel units whose brightness values in the first image are greater than the second brightness value and less than the first brightness value; adjusting the brightness value of each pixel unit in the fourth pixel unit based on the second brightness value, the first brightness value and the brightness value of each pixel unit in the fourth pixel unit.
[0032] Based on the second brightness value, the first brightness value and the brightness value of each pixel unit in the fourth pixel unit, a brightness adjustment parameter of each pixel unit in the fourth pixel unit is determined to adjust the brightness value of each pixel unit in the fourth pixel unit.
[0033] In one example, the fourth pixel unit may be a pixel unit in a darker part of the first image, the second brightness value may be thr1, the first brightness value may be thr2, and the brightness adjustment parameters of each pixel unit in the fourth pixel unit may be determined referring to Formula 2.
[0034] In one example, the fourth pixel unit may be a pixel unit of a brighter part of the first image, the second brightness value may be thr2, the first brightness value may be thr3, and the brightness adjustment parameters of each pixel unit in the fourth pixel unit may be determined referring to Formula 3.
[0035] In one example, the fourth pixel unit may be a pixel unit other than an extremely dark part and a highlight part in the first image, the second brightness value may be thr1, the first brightness value may be thr3, and the brightness adjustment parameter of each pixel unit in the fourth pixel unit may be determined based on the following formula: .
[0036] The above scheme shows how to determine the brightness adjustment parameters of the dark pixel units in the first image to brighten the brightness value of the dark portion, avoid the dark portion being too dark, and improve the image brightness effect.
[0037] In an optional embodiment of the first aspect, the image processing method further includes: obtaining an average value of all brightness adjustment parameters whose brightness adjustment parameters are less than 1; if the average value of all brightness adjustment parameters whose brightness adjustment parameters are less than 1 is less than a third threshold, traversing each pixel unit in the second image; and adjusting the brightness value of each pixel unit in the second image based on the first brightness mean and the brightness value of each pixel unit in the second image.
[0038] The third threshold may be (1-x / 2), for example, x is 0.4. The first brightness mean value is the brightness mean value of the highlight portion in the first image.
[0039] In some embodiments, based on the first brightness mean and the brightness value of each pixel unit in the second image, the brightness value of each pixel unit in the second image is adjusted, and reference may be made to Formula 9. In some embodiments, other contrast correction methods may be used to adjust the brightness value of each pixel unit in the second image.
[0040] The above scheme determines whether contrast correction is required for the second image by comparing the average value of the brightness adjustment parameter with the third threshold value, thereby avoiding the phenomenon that brightness adjustment may cause blurring of the image and improving the overall effect of the image.
[0041] In a second aspect, an embodiment of the present application provides an electronic device, the electronic device comprising: a memory and a processor, the processor being configured to call a computer program in the memory to execute a method as described in any one of the first aspects.
[0042] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program runs on an electronic device, the electronic device executes the method described in any one of the first aspects.
[0043] In a fourth aspect, an embodiment of the present application provides a chip, the chip including a processor, the processor being used to call a computer program in a memory so that the chip executes any method described in the first aspect.
[0044] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed, enables a computer to execute a method as described in any one of the first aspects.
[0045] It should be understood that the second to fifth aspects of the present application correspond to the technical solutions of the first aspect of the present application, and the beneficial effects achieved by each aspect and the corresponding feasible implementation methods are similar and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 A schematic diagram of the interface operation of mobile phone photography provided in an embodiment of the present application;
[0047] Figure 2 Schematic diagram of the image processing method provided in the embodiment of the present application Figure 1 ;
[0048] Figure 3 A schematic diagram of dividing brightness intervals provided in an embodiment of the present application;
[0049] Figure 4 Schematic diagram of the image processing method provided in the embodiment of the present application Figure 2 ;
[0050] Figure 5 A schematic diagram of adjusting a current pixel unit and its adjacent areas provided in an embodiment of the present application;
[0051] Figure 6 Schematic diagram of the image processing method provided in the embodiment of the present application Figure 3 ;
[0052] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application;
[0053] Figure 8 A software architecture and interaction diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0054] In order to clearly describe the technical solutions of the embodiments of the present application, in the embodiments of the present application, words such as "first" and "second" are used to distinguish the same or similar items with substantially the same functions and effects. Those skilled in the art can understand that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit the difference.
[0055] It should be noted that 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 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.
[0056] In the embodiments of the present application, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following (kind / piece)" or similar expressions refers to any combination of these items, including any combination of single items (kind / piece) or plural items (kind / piece). For example, at least one of a, b or c (kind / piece) can represent: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or multiple.
[0057] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc., data including images or videos, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0058] The following first explains the professional terms involved in the embodiments of the present application.
[0059] First, a pixel is a basic unit constituting a digital image. A pixel is also called a pixel point or a pixel unit. A pixel unit may include one pixel point or multiple pixel points.
[0060] Second, the brightness value refers to how bright the image is.
[0061] Third, the grayscale value refers to the brightness value of a pixel. In a digital image, each pixel has a corresponding grayscale value, which is used to describe the brightness value of the pixel. The grayscale value is usually represented by an integer from 0 to 255, where 0 represents black and 255 represents white.
[0062] Fourth, ISO is a measure of the image sensor's sensitivity to light. Night scene shooting mode usually increases ISO to increase the image sensor's sensitivity to light, thereby increasing the brightness of the image.
[0063] Fifth, image blurring usually refers to insufficient image clarity and contrast, causing the image to appear blurry. This may be caused by a variety of reasons, such as improper shooting position, insufficient exposure time, too high ISO setting, improper image processing, etc.
[0064] Sixth, the normal shooting mode is the default shooting mode of the camera application. In this mode, the camera will automatically adjust parameters such as exposure, white balance and focus according to the ambient light to facilitate users to shoot quickly.
[0065] Seventh, night scene shooting mode is a shooting mode used by the camera in low-light environments. In this mode, a longer exposure time is usually used to capture more light, and the flash may be enabled for shooting.
[0066] In the night scene shooting scenario, when users use electronic devices such as mobile phones and tablets to shoot, they can manually adjust the shooting parameters in the camera application of the electronic device, such as adjusting the camera's exposure time, ISO parameters, etc. However, most users do not know how to set appropriate shooting parameters, and the quality of the night scene images they take is poor and cannot meet user expectations.
[0067] In some embodiments, the camera application of the electronic device supports a night scene shooting mode, and the user can manually switch to the night scene shooting mode to shoot, or the electronic device automatically switches to the night scene shooting mode when it detects that the current shooting scene is a night scene shooting scene.
[0068] For example, Figure 1 This is a schematic diagram of the interface operation of mobile phone shooting provided in the embodiment of the present application. Figure 1 As shown in a, in response to the user clicking the camera application 102 on the main interface 101, the mobile phone displays the shooting interface 103, such as Figure 1 As shown in b, the mobile phone camera is in the normal shooting mode, and the preview area 105 of the shooting interface 103 displays the night scene image captured by the camera, and the traffic lights in the night scene image are overexposed.
[0069] In response to a user sliding operation in the shooting mode selection area 104 of the shooting interface 103, such as sliding rightward to the night scene shooting mode, the mobile phone camera switches to the night scene shooting mode, such as Figure 1 As shown in c, the preview area 105 of the shooting interface 103 displays the night scene image after image processing in this mode, and the brightness of the traffic lights in the image is moderate.
[0070] In response to the user clicking the shooting control 106 , the image-processed night scene image is stored in the mobile phone album, and the user can click the control 107 to view the image-processed night scene image.
[0071] In night scene shooting mode, you can increase the exposure time to capture more details and light and improve the overall brightness of the image. However, the increase in the overall brightness of the image may lead to overexposure of highlights and excessive brightening of dark areas.
[0072] In this regard, an embodiment of the present application provides an image processing method. For night scene images with the above-mentioned brightness problems, by analyzing and comparing the average brightness of the highlighted parts in the night scene images and the average brightness of the entire image, different brightness adjustment parameters are set for pixel units in different brightness ranges in the night scene images. The parameter can be recorded as ratio, so as to correct the brightness of the night scene images, make the brightness of each part of the night scene images more reasonable, and avoid overexposure of the highlighted parts and over-brightening of the dark parts.
[0073] In the embodiment of the present application, a pixel unit may also be described as a pixel block or an image block, and a pixel unit includes one or more pixel points. A camera includes a camera, an image sensor, etc., adjusting camera parameters may also be described as adjusting camera parameters, and switching the camera shooting mode may also be described as switching the camera shooting mode.
[0074] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0075] Figure 2 Schematic diagram of the image processing method provided in the embodiment of the present application Figure 1 The method can be applied to electronic devices with shooting and image processing functions. For ease of understanding, the following embodiments take a mobile phone as an example to illustrate the scheme. Figure 2 As shown, the image processing method of this embodiment includes:
[0076] S201. Acquire a first image captured by a camera.
[0077] After the mobile phone camera switches to the night scene shooting mode, the camera collects the first image. The first image is an original image collected by the camera based on the current shooting parameters without image processing, and the first image may have problems such as too low brightness or overexposure.
[0078] S202. Obtain brightness information of the first image. The brightness information of the first image includes the average brightness of the highlight portion of the first image and the average brightness of the entire image of the first image.
[0079] In one example, refer to Figure 3 , the average brightness of the highlighted part in the first image may be the average brightness of all pixel units in the first image whose brightness values are greater than thr3. For example, thr3 may be determined according to the brightness ranking of all pixel units in the first image, for example, after all pixel units in the first image are ranked from high to low according to the brightness value, the brightness value of the pixel unit ranked at 85% is set to thr3. For another example, thr3 is a brightness value set according to an empirical value, such as taking 210 as thr3 in the range of 0 to 255.
[0080] In another example, the average brightness of the highlighted portion in the first image may be the average brightness of all pixel units in a preset brightness range in the first image. The preset brightness range may be determined by sorting the brightness values of all pixel units in the first image, sorting all pixel units in the first image from high to low according to the brightness value, determining the top n% of pixel units, for example, n is 2, and the brightness value of the last pixel unit in the top n% is used as the brightness value of the right endpoint of the preset brightness range, and obtaining the brightness values of all pixel units greater than or equal to the brightness value of the right endpoint to determine the average brightness of all pixel units in the preset brightness range in the first image.
[0081] The average brightness value of the entire image in the first image refers to the average brightness value of all pixel units in the first image.
[0082] The average brightness of the highlight portion of the first image and the average brightness of the entire first image can be determined by any of the following methods to determine the average brightness of the corresponding plurality of pixel units:
[0083] Method 1: Determine the average brightness value of the plurality of pixel units by extracting the Y components of the plurality of pixel units in the first image.
[0084] Method 2: After obtaining the average brightness of multiple pixel units in the first image under the red, green and blue (RGB) three channels, perform weighted summation and root mean square processing on the average brightness of the multiple pixel units under the three channels to obtain the average brightness of the multiple pixel units. For details, refer to the following formula 1:
[0085] Formula 1
[0086] In the formula, represents the average brightness of multiple pixel units in the first image, represents the average brightness of multiple pixel units in the first image under the red (red, R for short), represents the average brightness of multiple pixel units in the first image under the green (green, G for short), Indicates the average brightness of multiple pixel units in the first image under the B channel.
[0087] In some embodiments, after obtaining the brightness value of each pixel unit of the highlighted part in the first image, the brightness average light1 of the highlighted part in the first image can be determined by method 1, and light1 is used as the brightness average judge_light of the highlighted part in the first image, that is, judge_light=light1.
[0088] In some embodiments, after obtaining the brightness value of each pixel unit of the highlighted part in the first image, the brightness average light2 of the highlighted part in the first image can be determined by method 2, and light2 is used as the brightness average judge_light of the highlighted part in the first image, that is, judge_light=light2.
[0089] In some embodiments, after obtaining the brightness value of each pixel unit of the highlighted part in the first image, the brightness average value light1 of the highlighted part in the first image can be determined by method 1, and the brightness average value light2 of the highlighted part in the first image can be determined by method 2, and the average value of light1 and light2 is used as the brightness average value judge_light of the highlighted part in the first image, that is, judge_light=(light1+light2) / 2.
[0090] In some embodiments, after obtaining the brightness value of each pixel unit in the first image, the average brightness value mean_light1 of the entire image in the first image can be determined by method 1, and mean_light1 is used as the average brightness value mean_light of the entire image in the first image, that is, mean_light=mean_light1.
[0091] In some embodiments, after obtaining the brightness value of each pixel unit in the first image, the average brightness value mean_light2 of the entire image in the first image can be determined by method 2, and mean_light2 is used as the average brightness value mean_light of the entire image in the first image, that is, mean_light=mean_light2.
[0092] In some embodiments, after obtaining the brightness value of each pixel unit in the first image, the average brightness value mean_light1 of the entire image in the first image can be determined by method 1, and the average brightness value mean_light2 of the entire image in the first image can be determined by method 2, and the average of mean_light1 and mean_light2 is used as the average brightness value mean_light of the entire image in the first image, that is, mean_light=(mean_light1+mean_light2) / 2.
[0093] Obtain the brightness information of the first image, so as to subsequently determine the brightness adjustment parameters of the pixel units of the highlighted part in the first image based on the brightness information. For details, please refer to the following S204d section Figure 4 The embodiment shown.
[0094] S203. Traverse each pixel unit in the first image to obtain a brightness value of a certain pixel unit.
[0095] It should be understood that each pixel unit in the first image contains a complete set of Y, U, and V components, where Y represents luminance (luma), that is, grayscale value, and U and V represent chrominance (chroma), that is, hue and saturation. In the embodiment of the present application, the Y component of each pixel unit in the first image is extracted.
[0096] According to the brightness value of the current pixel unit, S204 may be executed, such as Figure 2 As shown, S204 includes any of the following:
[0097] S204a. If the brightness value of the pixel unit is less than thr1, the brightness value of the pixel unit remains unchanged. Or
[0098] S204b. If the brightness value of the pixel unit is between thr1 and thr2, determine the brightness adjustment parameter of the pixel unit based on the first brightness adjustment formula to adjust the brightness value of the pixel unit. Or
[0099] S204c. If the brightness value of the pixel unit is between thr2 and thr3, determine the brightness adjustment parameter of the pixel unit based on the second brightness adjustment formula to adjust the brightness value of the pixel unit. Or
[0100] S204d. If the brightness value of the current pixel unit is greater than thr3, adjust and determine the brightness adjustment parameter of the pixel unit based on the third brightness adjustment formula to adjust the brightness value of the pixel unit.
[0101] The above thr1, thr2, thr3 are all brightness values. Figure 3A schematic diagram of dividing brightness intervals is shown, such as Figure 3 As shown, the magnitude relationship of the above brightness values is: thr1<thr2<thr3, where thr1 is a positive integer greater than 0, and thr3 is a positive integer less than 255. [0, thr1] is recorded as the first brightness interval, (thr1, thr2] is recorded as the second brightness interval, (thr2, thr3] is recorded as the third brightness interval, and (thr3, 255] is the fourth brightness interval.
[0102] based on Figure 3 As shown in the brightness division, the first brightness interval can also be described as an extremely dark brightness interval, the second brightness interval is a darker brightness interval, the third brightness interval is a brighter interval, and the fourth brightness interval is a high brightness interval.
[0103] Figure 3 As an example, in some embodiments, fewer or more brightness intervals may be divided, for example, there is a transition interval between the extremely dark brightness interval and the high brightness interval, and the transition interval includes the second brightness interval and the third brightness interval mentioned above.
[0104] S204a, S204b, S204c and S204d are described in detail below.
[0105] (1) For S204a, if the brightness value of the pixel unit is less than thr1, that is, the brightness value of the pixel unit falls within the first brightness interval, it indicates that the pixel unit is a pixel unit in the extremely dark part of the first image. Usually, the brightness adjustment parameter of the pixel unit is set to ratio=1, that is, the brightness value of the pixel unit remains unchanged. The reason for this setting is that in a night scene shooting scene, brightening the extremely dark part may cause the overall picture to be inconsistent with the facts. For example, when shooting the night sky, if the night sky part in the picture is brightened, the sky part may be too bright, which is inconsistent with the actual shooting scene.
[0106] (2) For S204b, if the brightness value of the pixel unit is between thr1 and thr2, that is, the brightness value of the pixel unit falls within the second brightness interval, it indicates that the pixel unit is a pixel unit in the darker part of the first image. The brightness adjustment parameter of the pixel unit can be determined by the first brightness adjustment formula, that is, the following formula 2.
[0107] Formula 2
[0108] Where ratio is the brightness adjustment parameter of the current pixel unit, x is a positive number, for example, x is 0.35, Y[i, j] represents the brightness value of the current pixel unit, (i, j) is the coordinate position of the current pixel unit in the first image, that is, the pixel unit in the i-th row and j-th column of the first image.
[0109] (3) For S204c, if the brightness value of the pixel unit is between thr2 and thr3, that is, the brightness value of the pixel unit falls within the third brightness interval, it indicates that the pixel unit is a pixel unit in the brighter part of the first image. The brightness adjustment parameter of the pixel unit can be determined by the second brightness adjustment formula, that is, the following formula 3.
[0110] Formula 3
[0111] For explanation of the parameters in the formula, see above.
[0112] The above formula 2 and formula 3 are both linear change formulas, so that the brightness change of the pixel unit is continuous, which can avoid excessive difference in brightness adjustment between adjacent pixel units of the image, that is, the brightness adjustment parameters of adjacent pixel units are continuous.
[0113] Normally, the brightness adjustment parameter of the pixel unit falling in the second brightness range is greater than the brightness adjustment parameter of the pixel unit falling in the third brightness range, so that the brightness value of the pixel unit falling in the second brightness range is brightened by the larger brightness adjustment parameter, and the brightness value of the pixel unit falling in the third brightness range is brightened by the smaller brightness adjustment parameter. The brightening of the pixel unit falling in the third brightness range mainly serves the purpose of smooth transition.
[0114] In summary, S204b and S204c are to improve the brightness of pixel units except for the extremely dark part and the highlighted part in the first image. The brightness adjustment parameters determined by S204b and S204c are both positive numbers less than 1 to improve the brightness value of the pixel unit. The degree of brightness improvement of the pixel unit by S204b is greater than the degree of brightness improvement of the pixel unit by S204c. In some embodiments, the darker part and the brighter part in the first image are referred to as the dark part in the first image. The degree of brightening the dark part in the first image should not be too large, otherwise the image will be blurred. For details, please refer to the embodiments below.
[0115] (4) For S204d, if the brightness value of the pixel unit is greater than thr3, that is, the brightness value of the pixel unit falls within the fourth brightness interval, it indicates that the pixel unit is a pixel unit of the highlighted part in the first image. The brightness adjustment parameter of the pixel unit can be determined by the third brightness adjustment formula, that is, the following formula 4.
[0116] Formula 4
[0117] In the formula, is a positive number, usually set to 2, so that when the brightness value Y[i,j] of the pixel unit is at the critical value of thr3, the ratio is 1, so that the brightness adjustment parameter is continuous at the critical point of the brightness range.
[0118] In the formula, judge is an intermediate parameter for determining the brightness adjustment parameter, which is used to indicate the brightness adjustment degree of the pixel units falling in the fourth brightness interval, that is, judge is used to indicate the brightness adjustment degree of the pixel units in the highlighted part of the first image. The specific value of the brightness adjustment parameter can be determined based on judge.
[0119] In formula 4, when judge is 1, ratio is 1, which means that the highlight part in the first image does not need to be darkened. , indicating that the highlight part in the first image needs to be darkened. In this case, ratio is a positive number greater than 1, for example, ratio = 1.2. It should be understood that the smaller the judge value, the fewer highlights in the first image, and the smaller the ratio value, the smaller the brightness adjustment degree (i.e., the darkening degree) of the highlight part in the first image.
[0120] The judge may be determined based on the brightness information of the first image in S202. After the judge is determined, the brightness adjustment parameter of the pixel unit in the highlight part of the first image may be determined based on the above formula 4.
[0121] The following is an exemplary description of how to determine the judge.
[0122] In S202 , the brightness information of the first image includes a brightness mean value mean_highlight (which may be referred to as a highlight mean value) of a highlight portion in the first image, and a brightness mean value judge_light of the entire first image.
[0123] First, the ratio of the highlight mean to the overall image brightness mean, judge1, can be determined by the following formula 5, and the threshold judge2 of the highlight mean in the brightness range (ie, 200 to 255) can be determined by the following formula 6. Judge1 and judge2 can be used to determine judge.
[0124] judge1=clip(mean_highlight / judge_light,1,4) Formula 5
[0125] Wherein, clip is the clipping function, if mean_highlight / judge_light is less than 1, then judge1=1, if mean_highlight / judge_light is in the interval [1,4], then judge1=mean_highlight / judge_light, if mean_highlight / judge_light is greater than 4, then judge1=4.
[0126] judge2=(mean_highlight-200) / (255-200)+1 Formula 6
[0127] Secondly, by comparing the magnitude relationship between the highlight mean value in the first image and the first threshold value 200, and the magnitude relationship between the ratio of the highlight mean value to the brightness mean value of the entire image and the second threshold value 2, the judge is determined, as shown in Formula 7.
[0128] Formula 7
[0129] In the formula, and All of them have values in the interval [0,1] and can be continuously corrected through image testing, for example =5 / 16, =1 / 8.
[0130] Based on Formula 7, if , judge is set to 1, and combined with formula 4, ratio is 1, that is, the highlight part in the first image is not darkened, and the brightness value of the pixel unit in the highlight part of the first image remains unchanged. , judge is set to 0.9, and combined with formula 4, the highlight part in the first image is slightly darkened. If mean_highlight ≥ 200, and judge1 ≥ 2, the judge can be determined based on judge1 and judge2, and combined with formula 4, the highlight part in the first image is darkened.
[0131] In some embodiments, after determining the brightness adjustment parameter of the current pixel unit, the brightness value of the current pixel unit can be adjusted by using a gamma change method based on the brightness adjustment parameter of the current pixel unit, as shown in Formula 8.
[0132] Formula 8
[0133] Wherein, y1 is the brightness value of the current pixel unit, ratio is the brightness adjustment parameter of the current pixel unit, and y2 is the brightness value of the current pixel unit after processing.
[0134] Based on Formula 8, if the ratio value is less than 1, the brightness of the current pixel unit is brightened; if the ratio is greater than 1, the brightness of the current pixel unit is dimmed; if the ratio is equal to 1, the brightness of the current pixel unit remains unchanged.
[0135] After S204, it also includes:
[0136] S205. Determine whether all pixel units in the first image have been traversed. If not, jump back to S203. If all pixel units in the first image have been traversed, execute S206.
[0137] S206. Output a second image.
[0138] The second image is an image after the above image processing is performed on the first image, and the electronic device can present the second image in the preview area of the camera application. In some embodiments, when the second image is displayed in the preview area of the camera application, the user triggers shooting, and the second image can be stored in the electronic device album, and the image in the album is the image after the above image processing.
[0139] The image processing method shown in this embodiment, after obtaining the first image captured by the camera in the night scene shooting mode, analyzes and compares the brightness average of the highlighted part of the first image and the brightness average of the whole image, and adjusts the brightness of the pixel units in different brightness ranges in the first image to different degrees, thereby correcting the brightness of the first image, making the brightness of each part of the first image more reasonable, and avoiding overexposure of the highlighted part of the image and over-brightening of the dark part.
[0140] exist Figure 2 Based on the embodiment shown, in some embodiments, when traversing each pixel unit, a Gaussian kernel function can be used to adjust the brightness of the current pixel unit and its neighboring pixel units at a certain ratio to achieve the continuity of brightness adjustment and further improve the image brightness effect. Figure 4 The image processing method is described.
[0141] Figure 4 Schematic diagram of the image processing method provided in the embodiment of the present application Figure 2 .and Figure 2 The difference from the illustrated embodiment is that, after traversing a certain pixel unit in the first image and determining the brightness adjustment parameter of the current pixel unit based on S204, the image processing method of this embodiment further includes:
[0142] S401. Determine whether the brightness adjustment parameter of the current pixel unit is 1.
[0143] If it is determined that the brightness adjustment parameter of the current pixel unit is not 1, execute S402; or
[0144] If it is determined that the brightness adjustment parameter of the current pixel unit is 1, execute S205.
[0145] S402. Based on the two-dimensional Gaussian kernel and the brightness adjustment parameter of the current pixel unit, multiple pixel units in the neighboring area of the current pixel unit are adjusted.
[0146] Based on the two-dimensional Gaussian kernel and the brightness adjustment parameters of the current pixel unit, the brightness adjustment parameters of multiple pixel units in the neighboring area of the current pixel unit are determined. While adjusting the brightness value of the current pixel unit based on the brightness adjustment parameters of the current pixel unit, the multiple pixel units in the neighboring area of the current pixel unit are adjusted based on the brightness adjustment parameters of the multiple pixel units in the neighboring area of the current pixel unit.
[0147] The neighboring area of the current pixel unit refers to a preset area centered on the current pixel unit, for example, the neighboring area is 3×3 or 5×5.
[0148] For example, Figure 5 A schematic diagram of adjusting the current pixel unit and its adjacent area provided in an embodiment of the present application, Figure 5 For example, the neighboring area of the current pixel unit is 3×3. Figure 5 The 0.7 shown in is the brightness adjustment parameter of the current pixel unit. Matrix 1 may correspond to a two-dimensional Gaussian kernel. The z value of the center point of the two-dimensional Gaussian kernel is 1. The center point corresponds to the current pixel unit. The z value around the center point is multiplied by the brightness adjustment parameter 0.7 of the current pixel unit to obtain the brightness adjustment parameters of each pixel unit in the neighboring area of the current pixel unit. Matrix 2 shows the brightness adjustment parameters of the current pixel unit and the pixel units in its neighboring area.
[0149] It should be noted that the above example performs darkening processing (ratio is less than 1) on the pixel units in the highlighted part of the image, and at the same time performs corresponding brightness adjustment on the pixel units in the adjacent area of the pixel units in the highlighted part to avoid discontinuous brightness adjustment.
[0150] It should also be noted that, in other examples, when the brightness adjustment parameter of the current pixel unit is a positive number greater than 1, the same Figure 5 Similar processing logic is used to adjust the brightness adjustment parameters of the pixel units in the neighboring area of the current pixel unit, so as to brighten the pixel units in the dark part (darker part and brighter part) of the image while performing corresponding brightness adjustment on the pixel units in the neighboring area.
[0151] After S402, S205 is executed.
[0152] Figure 4 S201 to S206 in Figure 2 Embodiment, this embodiment is not described in detail.
[0153] This embodiment shows that while traversing each pixel unit in the first image and adjusting the brightness value of the pixel unit based on the brightness adjustment parameter of the pixel unit, corresponding brightness adjustments can also be made to the pixel units around the pixel unit to avoid discontinuous brightness adjustment and improve the image brightness adjustment effect.
[0154] exist Figure 2 or Figure 4 Based on the embodiment shown, in some embodiments, after adjusting the brightness of the pixel units in each part of the first image, the contrast of the entire image can also be corrected to make the image brightness effect more reasonable and avoid blurring or lack of clarity of the entire image. Figure 6 The image processing method is described.
[0155] Figure 6 Schematic diagram of the image processing method provided in the embodiment of the present application Figure 3 .and Figure 2 or Figure 4 The difference between the illustrated embodiment and the method for image processing of the embodiment is that after traversing all pixel units in the first image, or after completing brightness adjustment of each part of pixel units in the first image, the method further includes:
[0156] S601. Obtain an average value of all brightness adjustment parameters whose brightness adjustment parameters are less than 1.
[0157] S602. Determine whether the average value of all brightness adjustment parameters whose brightness adjustment parameters are less than 1 is less than (1-x / 2), where x is a positive number, that is, x in the above formula 2 or formula 3, for example, x is 0.35.
[0158] If the average value of all brightness adjustment parameters less than 1 is less than or equal to (1-x / 2), execute S603; or if the average value of all brightness adjustment parameters less than 1 is greater than (1-x / 2), execute S206.
[0159] For example, taking x as 0.4, 1-x / 2 is 0.8. If the average value of all brightness adjustment parameters whose brightness adjustment parameters are less than 1 is less than or equal to 0.8, it indicates that the degree of brightening of the dark part (darker part and brighter part) in the first image is large, and the image after brightness adjustment may be blurred, and the image contrast needs to be further adjusted to improve the image clarity. If the average value of all brightness adjustment parameters whose brightness adjustment parameters are less than 1 is greater than 0.8, it indicates that the degree of brightening of the dark part in the first image is small, the image effect is reasonable, and the image after brightness adjustment can be directly output.
[0160] S603. Correct image contrast.
[0161] In some embodiments, the image contrast is corrected by convertScaleAbs, and for each pixel unit in the image, the brightness value of the pixel unit can be corrected based on Formula 9 and Formula 10.
[0162] Formula 9
[0163] In the formula, Represents the brightness value of the current pixel unit, beta is usually set to 20, abs is the absolute value function, and dst represents the corrected brightness value of the current pixel unit.
[0164] alpha=float(20 / mean_highlight)+1 Formula 10
[0165] In the formula, alpha is the parameter to be corrected, mean_highlight is the mean brightness of the highlight part of the first image, and the float function is a commonly used data type conversion function, which is used to convert other data types into floating-point types.
[0166] In some embodiments, other contrast correction methods, such as histogram equalization, may also be used to correct the image contrast.
[0167] After S603, S206 is executed.
[0168] This embodiment shows that after adjusting the brightness of the pixel units in each part of the first image, whether image contrast correction is needed is determined by statistically analyzing the mean value of the brightness adjustment parameter, thereby avoiding the phenomenon that the brightness adjustment may cause the image to become blurry, and improving the overall effect of the image.
[0169] The image processing methods shown in the above embodiments can be applied to any electronic device with shooting and image processing functions. Electronic devices can also be called terminals, user equipment (UE), mobile stations (MS), mobile terminals (MT), etc. Electronic devices can be mobile phones with shooting and display functions, smart TVs, wearable devices, tablet computers (Pad), computers with wireless transceiver functions, virtual reality (VR) electronic devices, augmented reality (AR) electronic devices, wireless terminals in industrial control, wireless terminals in self-driving, wireless terminals in remote medical surgery, wireless terminals in smart grids, wireless terminals in transportation safety, wireless terminals in smart cities, wireless terminals in smart homes, etc. The embodiments of this application do not limit the specific technology and specific device form used by the electronic device.
[0170] For example, Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 7 As shown, the electronic device 100 includes: 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, a sensor 180, a button 190, a camera 193, and a display screen 194.
[0171] It is understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device 100. In some embodiments, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or separate 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.
[0172] It is understood that the interface connection relationship between the modules shown in the embodiment is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In some embodiments, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0173] The processor 110 may include one or more processing units. Different processing units may be independent devices or integrated into one or more processors. The processor 110 may also be provided with a memory for storing instructions and data.
[0174] In the embodiment of the present application, the processor 110 may be used to call a computer program in the memory to execute the steps of the above method embodiment to adjust the brightness of the night scene image.
[0175] The USB interface 130 is an interface that complies with USB standard specifications, and specifically may be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 may be used to connect a charger to charge the terminal device, may be used to transmit data between the terminal device and peripheral devices, or may be used to connect headphones to play audio through the headphones.
[0176] The charging management module 140 is used to receive charging input from a charger. The power management module 141 is used to connect the battery 142 , the charging management module 140 and the processor 110 .
[0177] 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 modulation and demodulation processor and the baseband processor. The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G applied to the electronic device 100. The wireless communication module 160 can provide solutions for wireless communications including wireless local area networks (WLAN), Bluetooth, global navigation satellite system (GNSS), frequency modulation (FM), NFC, infrared technology (IR), etc. applied to the electronic device 100.
[0178] The electronic device 100 can realize the display function through the GPU, the display screen 194, and the 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, which execute instructions to generate or change display information.
[0179] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0180] The electronic device 100 can realize the shooting function through an image signal processing (ISP) module, one or more cameras 193, a video codec, a GPU, one or more display screens 194 and an application processor.
[0181] The camera 193 is used to capture still images or videos. In some embodiments, the electronic device 100 may include one or N cameras 193, where N is a positive integer greater than 1. The camera 193 includes a lens, an image sensor (such as a complementary metal oxide semiconductor image sensor (CIS)), a motor, and the like.
[0182] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, data files such as music, photos, and videos are stored in the external memory card.
[0183] The internal memory 121 may be used to store one or more computer programs, which include instructions. The processor 110 may execute the instructions stored in the internal memory 121, thereby enabling the electronic device 100 to perform various functional applications and data processing.
[0184] The sensor 180 may include a pressure sensor, a gyro sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor 180K, an ambient light sensor, a bone conduction sensor, and the like.
[0185] The touch sensor 180K may also be called a touch panel. The touch sensor 180K may be disposed on the display screen 194. The touch sensor 180K and the display screen 194 form a touch screen, also called a touch screen. The touch sensor 180K is used to detect a touch operation on or near the touch sensor 180K, and transmit the detected touch operation to the application processor to determine the type of the touch event.
[0186] The buttons 190 include a power button, a volume button, etc. The buttons 190 may be mechanical buttons or touch buttons. The electronic device 100 may receive key inputs and generate key signal inputs related to user settings and function control of the electronic device 100. For example, when the camera application is turned on, the user may trigger the camera to take photos or record videos by pressing the power button.
[0187] 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 application takes the Android system as an example to illustrate the software structure of the electronic device.
[0188] Figure 8 The software architecture and interaction diagram of an electronic device provided in the embodiment of the present application. The layered architecture divides the software system of the electronic device into several layers, each with a clear role and division of labor. The layers communicate with each other through software interfaces. Figure 8 As shown, the electronic device includes an application layer, an application framework layer, a hardware abstraction layer and a driver layer.
[0189] The application layer includes a camera application, and the user can use the camera application to take images or videos. In some embodiments, the application package may also include applications such as gallery, calendar, call, map, navigation, Bluetooth, music, video, etc.
[0190] The application framework layer can provide an application programming interface (API) and a programming framework for the application programs of the application layer. In the embodiment of the present application, the application framework layer includes a camera management module and a window management module.
[0191] The camera management module is responsible for managing the camera device information, and the camera application can obtain the camera characteristics through the camera management module, such as the number of cameras, shooting capabilities and other parameters. In some embodiments, the camera management module can also be used to transmit data between the camera application and the camera hardware abstraction layer. For example, the camera application transmits a notification message to turn on the night scene shooting mode to the camera hardware abstraction layer through the camera management module, so that after receiving the night scene image taken by the camera, the camera hardware abstraction layer calls the camera algorithm module to perform image processing on the night scene image to correct the image brightness, contrast, etc. of the night scene image.
[0192] The window management module is responsible for managing the windows in the application and the interaction with the user interface. For example, it is responsible for managing the camera application window and sending the window content, including the night scene images taken by the camera or the night scene images with brightness adjustment, to the display driver for display.
[0193] The hardware abstraction layer is an interface layer between the kernel layer and the hardware circuit. In the embodiment of the present application, the hardware abstraction layer includes a camera hardware abstraction layer and a camera algorithm module. The camera hardware abstraction layer can call the camera algorithm module to optimize the image or video captured by the camera. In some embodiments, the camera algorithm module includes an image processing module, which is used to adjust the brightness and contrast of the image collected in the night scene shooting mode to obtain a high-quality night scene image.
[0194] It should be noted that the image processing module is not limited to the hardware abstraction layer, and in some embodiments, the image processing module may also be located in the application layer. For example, the image processing module may be integrated into the camera application, or the camera application may adjust the brightness and contrast of the night scene image by calling the image processing module in the application layer.
[0195] The driver layer provides drivers for different hardware devices. In the embodiment of the present application, the driver layer may include a camera driver and a display driver. The camera driver may be used to drive the camera of the electronic device to collect raw images. The display driver is used to drive the display screen of the electronic device to display the raw image collected by the camera or the image after brightness and contrast adjustment.
[0196] Based on the above-mentioned electronic equipment hardware and software architecture, Figure 8 The internal execution process of the device of the image processing method provided in the embodiment of the present application is described.
[0197] like Figure 8 As shown, the image processing method of this embodiment includes:
[0198] S801. In response to the operation of starting the night scene shooting mode, the camera application sends a notification of starting the night scene shooting mode to the camera management module.
[0199] For example, Figure 1 As shown in b, the operation of turning on the night scene shooting mode can be an operation in which the user slides right to the night scene shooting mode in the shooting mode selection area 104 of the shooting interface 103. In response to this operation, the camera application sends a notification to the camera management module to turn on the night scene shooting mode.
[0200] In some embodiments, when it is detected that the current shooting scene is a night scene shooting scene, the camera application sends a notification to the camera management module to turn on the night scene shooting mode. In this embodiment, the electronic device can automatically switch to the night scene shooting mode.
[0201] S802. The camera management module sends a notification to the camera hardware abstraction layer to enable the night scene shooting mode.
[0202] S803. The camera driver sends the first image captured by the camera to the camera hardware abstraction layer.
[0203] The first image is an original image that has not been post-processed.
[0204] S804. The camera hardware abstraction layer sends an image processing request to the image processing module, where the image processing request includes the first image.
[0205] The image processing request is used to trigger the image processing module to adjust the brightness and contrast of the first image to obtain a high-quality second image. The image processing module can perform the steps of the aforementioned method embodiment to adjust the brightness and contrast of the first image. For details, please refer to the above text and will not be repeated here.
[0206] S805. The image processing module sends an image processing response to the camera hardware abstraction layer, where the image processing response includes the second image.
[0207] S806. The camera hardware abstraction layer sends the second image to the camera management module.
[0208] S807. The camera management module sends the second image to the camera application.
[0209] S808. The camera application sends the second image to the window management module.
[0210] S809. The window management module sends the second image to the display driver.
[0211] For example, Figure 1 As shown in c in FIG. 1 , the second image is displayed in the preview area 105 of the shooting interface 103 .
[0212] It should be noted that the above device internal execution process is only an example and does not constitute a limitation on the image processing internal execution process provided by this application. In some embodiments, the image processing module is located at the application layer, and the camera application calls the image processing module to obtain the second image, and the corresponding internal execution process is different.
[0213] Based on the foregoing embodiments, the embodiments of the present application provide an image processing method, which can be applied to an electronic device with shooting and image processing functions, or an image processing device, and the method includes:
[0214] Step 1. In a night scene shooting mode, a first image captured by a camera is obtained, wherein a brightness value of a first pixel unit in the first image is greater than a first brightness value.
[0215] Step 2: Display the second image, wherein the brightness value of the first pixel unit in the second image is smaller than the brightness value of the first pixel unit in the first image.
[0216] The first image is an original image captured by the camera. The first pixel unit in the first image refers to the pixel unit of the highlighted part in the first image. The brightness value of the pixel unit of the highlighted part is greater than the first brightness value. Figure 3 , the pixel units of the highlighted part may correspond to the pixel units whose brightness values fall within the fourth brightness interval, wherein the first brightness value may correspond to Figure 3The present embodiment does not limit the setting of thr3, and the details may refer to the above-mentioned embodiment.
[0217] The second image is an image processed by the first image, and the image processing includes brightness adjustment, contrast correction, etc. The brightness value of the first pixel unit in the second image is lower than the brightness value of the first pixel unit in the first image.
[0218] In the above embodiment, the brightness of the pixel units in the highlighted part of the first image is dimmed to correct the brightness of the first image, so that the brightness of the first image is more reasonable, overexposure of the highlighted part is avoided, and the image quality is improved.
[0219] In an optional embodiment, the image processing method further includes: obtaining brightness information of the first image; determining a first parameter by comparing the brightness information with a preset threshold; and adjusting the brightness value of the first pixel unit based on the first parameter to obtain a second image. The first parameter is used to indicate the degree of brightness adjustment of the first pixel unit in the first image.
[0220] The brightness information of the first image includes the brightness mean of the first image, such as the brightness mean of the highlight portion of the first image and the brightness mean of the entire first image. The first parameter can be determined by comparing the brightness mean of the first image with a preset threshold. The first parameter is not a brightness adjustment parameter, but can be regarded as an intermediate parameter, which can be used to determine the brightness adjustment parameter for the highlight portion of the first image. The first parameter may correspond to the judge of the aforementioned embodiment.
[0221] The above embodiment shows that an intermediate parameter of brightness adjustment is determined according to the brightness information of the first image, which provides data support for the subsequent determination of the brightness adjustment parameter.
[0222] In an optional embodiment, the brightness information of the first image includes at least one of a first brightness mean and a second brightness mean of the first image. The first brightness mean is the brightness mean of all pixel units in a preset brightness range in the first image, and the second brightness mean is the brightness mean of all pixel units in the first image. The first parameter is determined by comparing the size relationship between the brightness information and a preset threshold, including: determining the first parameter by comparing the size relationship between the first brightness mean and the first threshold, and the size relationship between the second parameter and the second threshold, and the second parameter is used to indicate the proportional coefficient between the first brightness mean and the second brightness mean.
[0223] The first brightness mean is the brightness mean of the highlight part in the first image, which may correspond to mean_highlight in the aforementioned embodiment. The second brightness mean is the brightness mean of the entire image in the first image, which may correspond to judge_light in the aforementioned embodiment. The determination method of mean_highlight and judge_light may refer to the aforementioned embodiment, and this embodiment does not limit the determination method of mean_highlight and judge_light.
[0224] The preset brightness interval may be a fourth brightness interval (thr3, 255], where thr3 may be the brightness value of the last pixel unit in the first n% after the brightness of the pixel units in the entire image are sorted, for example, n is 2.
[0225] The preset threshold includes a first threshold and a second threshold. The first threshold is used for comparison with the first brightness mean value, for example, the first threshold is 200, and the second threshold is used for comparison with the second parameter, for example, the second threshold is 2.
[0226] In an optional embodiment, determining the first parameter by comparing the magnitude relationship between the first brightness mean value and the first threshold value, and the magnitude relationship between the second parameter and the second threshold value, includes:
[0227] If the first brightness mean is less than the first threshold and the second parameter is less than the second threshold, the first parameter is 1; or, if the first brightness mean is less than the first threshold, or the second parameter is less than the second threshold, the first parameter is the first value, and the first value is a positive number less than 1; or, if the first brightness value is greater than or equal to the first threshold and the second parameter is greater than or equal to the second threshold, the first parameter is the second value, and the second value is a positive number less than the first value.
[0228] Exemplarily, the first value may be 0.9, and the second value may be a value less than 0.9.
[0229] The relationship between the first parameter and the first brightness mean, the first threshold, the second brightness mean, and the second threshold can refer to Formula 7 in the aforementioned embodiment. The parameter value of Formula 7 can be configured according to actual conditions, and this embodiment of the present application is not limited to this.
[0230] In an optional embodiment, the second value is determined according to the first brightness average value and the second brightness average value.
[0231] In an optional embodiment, if the first parameter is the second value, the image processing method further includes: determining the second parameter based on the first brightness mean and the second brightness mean, the second parameter being used to indicate the proportional coefficient between the first brightness mean and the second brightness mean; determining the third parameter based on the first brightness mean, the third parameter being used to indicate the proportional coefficient between the first brightness mean and the highest brightness value; and obtaining the second value by performing weighted summation of the second parameter and the third parameter.
[0232] The second parameter may correspond to judge1 in formula 5 of the above embodiment, and the third parameter may correspond to judge2 in formula 6 of the above embodiment. The maximum brightness value is recorded as 255. The second value is obtained by weighted summing the second parameter and the third parameter. Referring to the third line in formula 7 of the above embodiment, the second value may be .
[0233] In an optional embodiment, adjusting the brightness value of the first pixel unit based on the first parameter includes: traversing each pixel unit in the first pixel unit, and determining the brightness adjustment parameter of each pixel unit in the first pixel unit based on the first parameter, the first brightness value and the brightness value of each pixel unit in the first pixel unit; adjusting the brightness value of each pixel unit in the first pixel unit based on the brightness adjustment parameter of each pixel unit in the first pixel unit.
[0234] The first pixel unit is a pixel unit of a highlighted part in the first image. The brightness adjustment parameter of each pixel unit in the highlighted part may be determined by referring to Formula 4 in the aforementioned embodiment. Formula 4 is only used as an example and is not limited to this embodiment of the present application.
[0235] In one example, the brightness value of each pixel unit in the first pixel unit can be adjusted based on the brightness adjustment parameter of each pixel unit by changing gamma, and reference can be made to Formula 8 of the aforementioned embodiment.
[0236] In the above embodiment, by traversing each pixel unit in the highlight part of the first image, the brightness adjustment parameter of each pixel unit in the highlight part is determined to adjust the brightness of each pixel unit in the highlight part of the first image to avoid overexposure of the highlight part of the image.
[0237] In an optional embodiment, the image processing method also includes: the second pixel unit is any pixel unit in the first pixel unit, and the brightness values of multiple third pixel units are adjusted based on the two-dimensional Gaussian kernel and the brightness adjustment parameters of the second pixel unit; the multiple third pixel units are pixel units within a preset area centered on the second pixel unit.
[0238] The second pixel unit is any pixel unit of the pixel unit in the highlighted part of the first image. Specifically, after determining the brightness adjustment parameter of the second pixel unit, based on the two-dimensional Gaussian kernel function and the brightness adjustment parameter of the second pixel unit, determine the brightness adjustment parameters of multiple third pixel units in a preset area centered on the second pixel unit; while adjusting the brightness value of the second pixel unit, adjust the brightness values of multiple third pixel units. The third pixel unit is a pixel unit in the adjacent area of the second pixel unit. The above processing can refer to Figure 5 .
[0239] In the above embodiment, when the brightness of each pixel unit in the highlight part of the first image is adjusted (ratio is less than 1), the brightness of the pixel units in the neighboring area of each pixel unit in the highlight part can also be adjusted to avoid discontinuous brightness adjustment and improve the image brightness adjustment effect.
[0240] In an optional embodiment, when brightness adjustment is performed on pixel units in dark areas (darker parts and brighter parts) of the first image (ratio is greater than 1), brightness adjustment may also be performed on pixel units in adjacent areas to avoid discontinuous brightness adjustment.
[0241] In an optional embodiment, the image processing method also includes: traversing each pixel unit in the fourth pixel unit, the fourth pixel unit including multiple pixel units whose brightness values in the first image are greater than the second brightness value and less than the first brightness value; adjusting the brightness value of each pixel unit in the fourth pixel unit based on the second brightness value, the first brightness value and the brightness value of each pixel unit in the fourth pixel unit.
[0242] Based on the second brightness value, the first brightness value and the brightness value of each pixel unit in the fourth pixel unit, a brightness adjustment parameter of each pixel unit in the fourth pixel unit is determined to adjust the brightness value of each pixel unit in the fourth pixel unit.
[0243] In one example, the fourth pixel unit may be a pixel unit in a darker part of the first image, the second brightness value may be thr1 in the aforementioned embodiment, the first brightness value may be thr2, and the brightness adjustment parameters of each pixel unit in the fourth pixel unit may be determined by referring to Formula 2 in the aforementioned embodiment.
[0244] In one example, the fourth pixel unit may be a pixel unit in a brighter part of the first image, the second brightness value may be thr2 in the aforementioned embodiment, the first brightness value may be thr3, and the brightness adjustment parameters of each pixel unit in the fourth pixel unit may be determined by referring to formula three in the aforementioned embodiment.
[0245] In one example, the fourth pixel unit may be a pixel unit other than an extremely dark part and a highlight part in the first image, the second brightness value may be thr1 in the aforementioned embodiment, the first brightness value may be thr3, and the brightness adjustment parameter of each pixel unit in the fourth pixel unit may be determined based on the following formula: .
[0246] The above embodiment shows how to determine the brightness adjustment parameters of the dark pixel units in the first image to brighten the brightness value of the dark portion, avoid the dark portion being too dark, and improve the image brightness effect.
[0247] In an optional embodiment, the image processing method also includes: obtaining an average value of all brightness adjustment parameters whose brightness adjustment parameters are less than 1; if the average value of all brightness adjustment parameters whose brightness adjustment parameters are less than 1 is less than a third threshold, traversing each pixel unit in the second image; and adjusting the brightness value of each pixel unit in the second image based on the first brightness mean and the brightness value of each pixel unit in the second image.
[0248] The third threshold may be (1-x / 2) in the aforementioned embodiment, for example, x is 0.4. The first brightness mean value is the brightness mean value of the highlight portion in the first image.
[0249] In some embodiments, based on the first brightness mean and the brightness value of each pixel unit in the second image, the brightness value of each pixel unit in the second image is adjusted, and reference can be made to Formula 9 of the aforementioned embodiment. In some embodiments, other contrast correction methods can also be used to adjust the brightness value of each pixel unit in the second image.
[0250] In the above embodiment, by comparing the average value of the brightness adjustment parameter with the third threshold value, it is determined whether the contrast correction of the second image needs to be performed, thereby avoiding the phenomenon that the brightness adjustment may cause the image to be blurred, and improving the overall effect of the image.
[0251] It should be noted that in the above embodiments, a "module" may be a software program, a hardware circuit, or a combination of the two to implement the above functions. The hardware circuit may include an application specific integrated circuit (ASIC), an electronic circuit, a processor (such as a shared processor, a dedicated processor, or a group processor, etc.) and a memory for executing one or more software or firmware programs, a combined logic circuit, and / or other suitable components that support the described functions.
[0252] Therefore, the modules of each example described in the embodiments of the present application can be implemented with electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in the form of hardware or software 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 be beyond the scope of this application.
[0253] An embodiment of the present application provides an electronic device, including: a memory and a processor, wherein the processor is used to call a computer program in the memory to execute a technical solution as in any of the aforementioned method embodiments, and its implementation principle and technical effect are similar to those of any of the aforementioned embodiments, which will not be repeated here.
[0254] The memory may be a read-only memory (ROM) or other type of static storage device that can store static information and instructions, a random access memory (RAM) or other type of dynamic storage device that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to these.
[0255] The memory can be independent and connected to the processor through a communication line, or it can be integrated with the processor.
[0256] The processor may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present application.
[0257] An embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program runs on an electronic device, the electronic device executes the technical solution of any of the aforementioned embodiments. The implementation principle and technical effect are similar to those of any of the aforementioned embodiments and are not repeated here.
[0258] An embodiment of the present application provides a chip, which includes a processor. The processor is used to call a computer program in a memory to execute the technical solution in any of the aforementioned embodiments. Its implementation principle and technical effect are similar to those in any of the aforementioned embodiments and will not be repeated here.
[0259] An embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes the technical solution in any of the aforementioned embodiments. The implementation principle and technical effect are similar to those in any of the aforementioned embodiments and are not described in detail here.
[0260] The above specific implementation methods further illustrate the purpose, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above are only specific implementation methods of the present invention and are not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solutions of the present invention should be included in the scope of protection of the present invention.
Claims
1. An image processing method, characterized in that: include: In a night scene shooting mode, obtaining a first image captured by a camera, wherein a brightness value of a first pixel unit in the first image is greater than a first brightness value; displaying a second image, wherein the brightness value of the first pixel unit in the second image is smaller than the brightness value of the first pixel unit in the first image; The method further comprises: Acquire brightness information of the first image; the brightness information of the first image includes at least one of a first brightness mean value and a second brightness mean value of the first image; the first brightness mean value is a brightness mean value of all pixel units in the first image whose brightness values are greater than the first brightness value, and the second brightness mean value is a brightness mean value of all pixel units in the first image; Determine the first parameter by comparing the magnitude relationship between the first brightness mean and the first threshold, and the magnitude relationship between the second parameter and the second threshold; the first parameter is used to indicate the brightness adjustment degree of the first pixel unit in the first image; the second parameter is used to indicate the proportionality coefficient between the first brightness mean and the second brightness mean; Traversing each pixel unit in the first pixel units, and determining a brightness adjustment parameter of each pixel unit in the first pixel units based on the first parameter, the first brightness value, and the brightness value of each pixel unit in the first pixel units; Based on the brightness adjustment parameter of each pixel unit in the first pixel units, the brightness value of each pixel unit in the first pixel units is adjusted.
2. The method according to claim 1, characterized in that Determining the first parameter by comparing the magnitude relationship between the first brightness mean value and the first threshold value, and the magnitude relationship between the second parameter and the second threshold value, includes: If the first brightness mean value is less than the first threshold value, and the second parameter is less than the second threshold value, the first parameter is 1; or If the first brightness mean value is less than the first threshold value, or the second parameter is less than the second threshold value, the first parameter is a first value, and the first value is a positive number less than 1; or If the first brightness mean is greater than or equal to the first threshold, and the second parameter is greater than or equal to the second threshold, the first parameter is a second value, and the second value is a positive number less than the first value.
3. The method according to claim 2, characterized in that The second value is determined according to the first average brightness value and the second average brightness value.
4. The method according to claim 2, characterized in that: If the first parameter is the second value, the method further includes: Determine a second parameter based on the first brightness mean value and the second brightness mean value, where the second parameter is used to indicate a proportional coefficient between the first brightness mean value and the second brightness mean value; Determine a third parameter based on the first brightness average value, where the third parameter is used to indicate a proportionality coefficient between the first brightness average value and the highest brightness value; The second value is obtained by performing weighted summation on the second parameter and the third parameter.
5. The method according to claim 1, characterized in that The method further comprises: Adjusting brightness values of a plurality of third pixel units based on the two-dimensional Gaussian kernel and the brightness adjustment parameter of the second pixel unit; The second pixel unit is any pixel unit among the first pixel units, and the plurality of third pixel units are pixel units within a preset area centered on the second pixel unit.
6. The method according to claim 1, characterized in that The method further comprises: Traversing each pixel unit in the fourth pixel unit, the fourth pixel unit includes a plurality of pixel units whose brightness values in the first image are greater than the second brightness value and less than the first brightness value; Based on the second brightness value, the first brightness value, and the brightness value of each pixel unit in the fourth pixel unit, the brightness value of each pixel unit in the fourth pixel unit is adjusted.
7. The method according to any one of claims 2 to 6, characterized in that: The method further comprises: Get the average value of all brightness adjustment parameters whose brightness adjustment parameters are less than 1; If the average value of all brightness adjustment parameters whose brightness adjustment parameters are less than 1 is less than a third threshold, traverse each pixel unit in the second image; Based on the first brightness mean value and the brightness value of each pixel unit in the second image, the brightness value of each pixel unit in the second image is adjusted.
8. An electronic device, characterized in that: The electronic device comprises: a memory and a processor, wherein the processor is used to call a computer program in the memory to execute the method according to any one of claims 1 to 7.
9. A chip, characterized in that: The chip comprises a processor, and the processor is used to call a computer program in a memory so that the chip executes the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed on an electronic device, the electronic device executes the method according to any one of claims 1 to 7.
