Image brightness adjustment method, image brightness adjustment device, and electronic equipment
By automatically detecting the grayscale value of the highlight area and adjusting the overall brightness of the image, it solves the shadow and overexposure problems when taking pictures in dark environments, and achieves automatic and uniform adjustment of image quality and a user-friendly solution.
Patent Information
- Application Number
- CN202180075199.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-20
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2041-02-20
AI Technical Summary
When taking photos in dark environments, shadow areas and overexposure problems often appear in the photos. The exposure or brightening processing of existing technologies can easily lead to overexposure of areas other than the shadow areas, and manual adjustment provides a poor user experience, and local exposure may cause artifacts.
By automatically detecting the grayscale value of the target pixel in the highlight area of the image, the preset threshold and mapping relationship are used to adjust the overall brightness of the image to avoid overexposure or overdarkness in the highlight area, and the image quality is improved through automatic adjustment.
It achieves automatic and uniform adjustment of image brightness, avoids overexposure and artifact problems, improves user experience and enhances image quality.
Smart Images

Figure CN116438594B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image brightness adjustment method, an image brightness adjustment device, and an electronic device. Background Art
[0002] like Figure 1 As shown, when taking photos in a dark environment, the photos taken often include shadow areas, which affects the shooting effect.
[0003] The existing technology uses exposure or brightening to process photos containing shadow areas. However, Figure 2 As shown, with simple exposure or brightening processing, areas other than shadow areas in the photo may be overexposed, especially when the photo contains multiple shadow areas, which makes it more difficult to handle. Summary of the Invention
[0004] The embodiments of the present application provide an image brightness adjustment method, an image brightness adjustment device, and an electronic device, which can improve the problem of shadow areas or image overexposure in the image through automatic adjustment, and can also avoid the problem of image artifacts.
[0005] In a first aspect, a method for adjusting image brightness is provided, comprising: obtaining an image to be processed; obtaining a target grayscale value of a target pixel among multiple pixels located in a highlight area of the image to be processed; and adjusting the brightness of the image to be processed through a preset mapping relationship and the target grayscale value based on a comparison result between the target grayscale value and a preset threshold.
[0006] In a second aspect, an image brightness adjustment device is provided. The image brightness adjustment device includes an acquisition module and a processing module. The acquisition module is configured to acquire an image to be processed and to obtain a target grayscale value of a target pixel among a plurality of pixels located in a highlight region of the image to be processed. The processing module is configured to adjust the brightness of the image to be processed using a preset mapping relationship and the target grayscale value based on a comparison result of the target grayscale value with a preset threshold.
[0007] In a third aspect, an electronic device is provided, comprising: one or more processors; a memory; and one or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more applications are used to execute the method described in the first aspect.
[0008] In a fourth aspect, a computer-readable storage medium is provided, in which a program code is stored. The program code can be called by a processor to execute the method described in the first aspect.
[0009] In the image brightness adjustment method, image brightness adjustment device, and electronic device provided in the embodiments of the present application, a target pixel and a target grayscale value of the target pixel among multiple pixels in the highlight area can be first determined. Based on the comparison result of the target grayscale value with a preset threshold, the brightness of the entire image to be processed can be adjusted using a preset mapping relationship and the target grayscale value. When the target grayscale value is greater than the preset threshold, the brightness of the entire image to be processed can be reduced to avoid the brightness of the highlight area being too bright and the problem of overexposure. When the target grayscale value is less than the preset threshold, the brightness of the entire image to be processed can be increased to prevent the brightness of the highlight area from being too low or to prevent the presence of very dark shadow areas in the highlight area. On this basis, on the one hand, the present application can automatically adjust the brightness of the image to be processed without the need for manual adjustment by the user. On the other hand, the present application achieves higher detection accuracy by detecting the target grayscale value of the target pixel rather than the skin area. On this basis, the present application adjusts the brightness of the entire image to be processed based on the comparison result of the target grayscale value with the preset threshold, rather than adjusting the brightness of only the skin area, so that the brightness of the entire image to be processed changes evenly without artifacts. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without creative work.
[0011] Figure 1 Schematic diagram of an unexposed image provided for prior art;
[0012] Figure 2 A schematic diagram of an image after exposure provided by the prior art;
[0013] Figure 3 A diagram of the process of exposing an image provided for related technology;
[0014] Figure 4 Schematic diagram after exposure image provided for related technology;
[0015] Figure 5 A flowchart of an image brightness adjustment method provided in an embodiment of the present application;
[0016] Figure 6 A schematic diagram of an exposed portrait image and its highlight area provided in an embodiment of the present application;
[0017] Figure 7 A flowchart of an image brightness adjustment method provided in an embodiment of the present application;
[0018] Figure 8 A histogram of grayscale and pixel count provided in an embodiment of the present application;
[0019] Figure 9 A line chart for determining brightness adjustment parameters provided in an embodiment of the present application;
[0020] Figure 10 A block diagram of an image brightness adjustment device provided in an embodiment of the present application;
[0021] Figure 11 A block diagram showing the relationship between various modules in the electronic device provided in an embodiment of the present application;
[0022] Figure 12 A block diagram of the relationship between the computer-readable storage medium and the application provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. It should be noted that the features in the embodiments of the present application can be combined with each other in the absence of conflict.
[0024] For the technical problems raised by the background technology, the related technology proposes two solutions:
[0025] 1. As Figure 3 As shown, when taking a photo, the user manually adjusts the exposure to brighten the preview image as a whole, and then takes the photo after confirming that the preview image is at the optimal exposure. However, this method requires the user to manually adjust the exposure and repeatedly try to determine the optimal exposure, which is not conducive to user experience.
[0026] Second, taking the photograph of a face as an example, only the pixels corresponding to the exposed skin area in the photo are partially exposed to brighten the skin area. However, there may be a problem that some skin is not detected, resulting in not all exposed skin being brightened, causing artifacts in the photo ( Figure 4 ).
[0027] In response to the problems raised in the background technology and related technologies, the inventors have proposed an image brightness adjustment method, an image brightness adjustment device, an electronic device, and a computer-readable storage medium after research. These methods can improve the shadow areas or overexposure problems in images through automatic adjustment, while also avoiding the problem of image artifacts.
[0028] like Figure 5 As shown, an embodiment of the present application provides an image brightness adjustment method, which can be applied to an electronic device. The method includes:
[0029] S110: Acquire an image to be processed.
[0030] An image that has been captured may be obtained as the image to be processed, or a newly captured image may be obtained as the image to be processed.
[0031] In some embodiments, the image to be processed is an image with content, and this application does not limit the content of the image to be processed. For example, the image to be processed can be a portrait, a landscape, etc.
[0032] In some embodiments, the image to be processed in the present application may be an original image that has not been exposed; or, the image to be processed may be an original image that has been exposed and has no artifacts. Furthermore, the image to be processed may be an exposed portrait image.
[0033] S120 , obtaining a target grayscale value of a target pixel among a plurality of pixels located in a highlight area of the image to be processed.
[0034] A target pixel among a plurality of pixels located in a highlight area of the image to be processed may be determined first, and then a target grayscale value of the target pixel may be obtained.
[0035] In some embodiments, the present application may pre-acquire the grayscale value of each pixel in the entire image to be processed, and after determining the target pixel, extract the target grayscale value of the target pixel from the grayscale values of each pixel in the entire image to be processed.
[0036] Alternatively, the grayscale values of multiple pixels located in the highlight area of the image to be processed may be obtained in advance, and after the target pixel is determined, the target grayscale value of the target pixel is extracted from the grayscale values of the multiple pixels located in the highlight area.
[0037] Alternatively, after determining the target pixel, the target grayscale value of the target pixel may be obtained.
[0038] In some embodiments, target pixels refer to some pixels in a plurality of pixels located in a highlight area of an image to be processed. The number of target pixels is related to a method of determining the target pixels, and the number of target pixels may be one or more pixels.
[0039] In some embodiments, the highlight area of the image to be processed, as the name implies, refers to an area in the image to be processed where the overall brightness is higher than the brightness of pixels in other areas of the image to be processed.
[0040] The brightness of multiple pixels in the highlight area can all be higher than the brightness of pixels in other areas; or, among the multiple pixels in the highlight area, the brightness of most pixels is higher than the brightness of pixels in other areas, and the brightness of the remaining pixels is lower than or equal to the brightness of pixels in other areas.
[0041] In some embodiments, as Figure 6 As shown, in the case where the image to be processed is an exposed portrait image, the highlight area may be, for example, a face area of the exposed portrait image.
[0042] S130 , adjusting the brightness of the image to be processed by using a preset mapping relationship and the target grayscale value according to a comparison result between the target grayscale value and the preset threshold value.
[0043] A preset threshold and a preset mapping relationship can be set in advance, the target grayscale value is compared with the preset threshold, and according to the comparison result, the brightness of the image to be processed is adjusted through the preset mapping relationship and the target grayscale value.
[0044] In some embodiments, the present application does not limit the specific preset threshold value and the preset mapping relationship. The preset threshold value can be a numerical value or a numerical range.
[0045] It is understood that when the target grayscale value is greater than the preset threshold, the grayscale of the highlight area is too large, that is, the brightness of the highlight area is too bright. Based on the preset mapping relationship and the target grayscale value, the brightness of the entire image to be processed can be reduced to reduce the brightness of the highlight area. In this case, although the brightness of other areas is further dimmed, considering that other areas are already dark compared to the highlight area, overexposure of the highlight area can be prevented without affecting the display quality of other areas of the image to be processed.
[0046] When the target grayscale value is less than the preset threshold, the grayscale of the highlight area is too small, that is, the brightness of the highlight area is too dark. Based on the preset mapping relationship and the target grayscale value, the brightness of the entire image to be processed can be increased to improve the brightness of the highlight area. In this case, if the highlight area contains a shadow area, the brightness of the shadow area can be increased by increasing the overall brightness of the image to be processed.
[0047] In some embodiments, when the image to be processed is an exposed portrait image and the highlighted area is the face area of the exposed portrait image, the target grayscale value of the face area can be compared with the preset threshold value. Based on the comparison result between the two, the brightness of the image to be processed can be adjusted through the preset mapping relationship and the target grayscale value.
[0048] Optionally, when the image to be processed is an exposed portrait image and the highlighted area is the face area of the exposed portrait image, considering that the exposed portrait image has been exposed, the brightness of the portrait image is high enough, there may be an overexposure problem due to excessive brightness, and there may not be a problem of excessively low brightness. Therefore, the brightness of the image to be processed can be reduced by using a preset mapping relationship and the target grayscale value based on the comparison result between the target grayscale value and the preset threshold.
[0049] The present invention provides an image brightness adjustment method that first determines a target pixel and a target grayscale value of the target pixel among multiple pixels in a highlight area. Based on the comparison result of the target grayscale value with a preset threshold, the brightness of the entire image to be processed is adjusted using a preset mapping relationship and the target grayscale value. When the target grayscale value is greater than the preset threshold, the overall brightness of the image to be processed can be reduced to avoid excessive brightness in the highlight area, which may cause overexposure. When the target grayscale value is less than the preset threshold, the overall brightness of the image to be processed can be increased to prevent excessive brightness in the highlight area or the presence of very dark shadow areas in the highlight area. Based on this, on the one hand, the present invention can automatically adjust the brightness of the image to be processed, eliminating the need for manual adjustment by the user. On the other hand, the present invention achieves higher detection accuracy by detecting the target grayscale value of the target pixel rather than the skin area. Based on this, the present invention adjusts the brightness of the entire image to be processed based on the comparison result of the target grayscale value with the preset threshold, rather than just the skin area, to ensure uniform brightness changes across the entire image to be processed without artifacts.
[0050] like Figure 7 As shown, an embodiment of the present application provides an image brightness adjustment method, which can be applied to an electronic device. The method includes:
[0051] S110: Acquire an image to be processed.
[0052] The explanation of step S110 is the same as that of step S110 in the aforementioned embodiment and will not be repeated here.
[0053] S121 , obtaining grayscale values of a plurality of pixels located in a highlight area of the image to be processed.
[0054] The grayscale values of multiple pixels located in the highlight area of the image to be processed can be obtained in advance; or the grayscale values of each pixel in the entire image to be processed can be obtained in advance, and after the highlight area is determined, the grayscale values of multiple pixels in the highlight area are extracted from the grayscale values of each pixel in the entire image to be processed.
[0055] For example, pre-acquiring the grayscale values of multiple pixels in a highlight area of a to-be-processed image can first detect the brightness values of the multiple pixels in the highlight area, and then convert the brightness values of the multiple pixels into grayscale values according to a gamma curve. The gamma curve in the embodiment of the present application can be, for example, a gamma2.2 curve with a grayscale range of 0 to 255. Of course, other gamma curves can also be used, as long as the target grayscale value and brightness value correspond to the same gamma curve.
[0056] In some embodiments, when the image to be processed is an exposed portrait image and the highlighted area is the face area of the exposed portrait image, the face area can be detected first, and then the grayscale values of multiple pixels located in the face area of the image to be processed are obtained.
[0057] S122, establishing a histogram of grayscale values and pixel numbers, and selecting multiple peaks based on the histogram, wherein the peak represents the number of pixels at the grayscale value, which is greater than the number of pixels at the previous grayscale value and the number of pixels at the next grayscale value.
[0058] like Figure 8 As shown in the figure, the Hist function can be used to build a histogram of grayscale values and the number of pixels. The horizontal axis is the grayscale value from small to large, and the vertical axis is the number of pixels with a certain grayscale value. In a histogram, multiple peaks can be determined ( Figure 8 The gray level where the shaded rectangle is located).
[0059] like Figure 8 As shown, assuming that the grayscale values of the multiple pixels in the highlight area range from 245 to 255, the number of pixels with grayscale 247 is greater than the number of pixels with grayscale 246 and the number of pixels with grayscale 248. Therefore, grayscale 247 is a peak. Similarly, grayscale 250 and grayscale 252 are also peaks.
[0060] S123 , selecting a maximum grayscale value from the multiple grayscale values corresponding to the multiple peak values as the target grayscale value.
[0061] After multiple peak values are determined in step S122 , the maximum grayscale value may be selected from the multiple peak values as the target grayscale value, and the pixel in the highlight area corresponding to the target grayscale value is the target pixel.
[0062] For example, Figure 8 As shown, the three peaks are 247, 250, and 252, among which 252 is the largest. Therefore, 252 is the target grayscale value.
[0063] S131 : Obtain brightness adjustment parameters according to a preset mapping relationship and grayscale values.
[0064] Among them, the preset mapping relationship can be L represents the target brightness, a represents the brightness adjustment parameter, and Lw(x,y) represents the preset threshold, which includes the minimum brightness and the maximum brightness. Indicates the average brightness of the image to be processed.
[0065] In some embodiments, after obtaining the image to be processed, the average brightness of the image to be processed can be obtained. Obtaining the average brightness of the image to be processed can include: obtaining initial grayscale values of each pixel in the image to be processed; sequentially performing linear processing and spatial processing on the initial grayscale values to obtain initial brightness values of each pixel; and obtaining the average brightness of the image to be processed based on the initial brightness values of each pixel. The linear processing and spatial processing of the initial grayscale values, i.e., converting the RGB color space into the XYZ color space, can be performed.
[0066] In some embodiments, after obtaining the target grayscale value, the brightness value corresponding to the target grayscale value may be obtained according to a preset mapping relationship and the grayscale value, but before obtaining the brightness adjustment parameter, according to a gamma curve.
[0067] In some embodiments, the target brightness L can be a numerical value or a numerical range. When the target brightness L is a numerical range, a value in the numerical range can be selected as The value of L(x,y) in the equation is set so that the brightness adjustment parameter a on the right side of the equation takes a unique value.
[0068] In some embodiments, as Figure 9 As shown, when the average brightness and the target brightness are constant, the brightness value corresponding to the target grayscale value is compared with the maximum brightness n; when the brightness value is greater than or equal to the maximum brightness n, the brightness adjustment parameter is the first adjustment parameter k1.
[0069] like Figure 9 As shown, when the average brightness and target brightness are constant, the brightness value corresponding to the target grayscale value is compared with the minimum brightness m; when the brightness value is less than or equal to the minimum brightness m, the brightness adjustment parameter is the second adjustment parameter kh, and the second adjustment parameter kh is greater than the first adjustment parameter kl.
[0070] like Figure 9 As shown, when the average brightness and the target brightness are constant, the brightness value corresponding to the target grayscale value is compared with the minimum brightness m and the maximum brightness n; when the brightness value is greater than the maximum brightness m and less than the minimum brightness n, as the brightness value increases, the brightness adjustment parameter decreases linearly between the second adjustment parameter and the first adjustment parameter.
[0071] In some embodiments, when the image to be processed is an exposed portrait image and the highlighted area is the face area of the exposed portrait image, considering that the exposed portrait image has been exposed, the brightness of the portrait image is high enough, there may be an overexposure problem due to excessive brightness, and there may not be a problem of excessively low brightness. Therefore, the brightness of the image to be processed can be reduced by using a preset mapping relationship and a target grayscale value based on the comparison result between the target grayscale value and the preset threshold.
[0072] In this way, there is no need to compare the brightness value corresponding to the target grayscale value with the minimum brightness m to further brighten the exposed portrait image.
[0073] S132: Adjust the brightness of the image to be processed according to the brightness adjustment parameter.
[0074] After the brightness adjustment parameter is determined in step S131 , the brightness of the entire image to be processed can be adjusted according to the brightness adjustment parameter.
[0075] If the target grayscale value of the image to be processed changes after adjustment in step S132, if the target grayscale value meets the target brightness, steps S140 and S150 are not performed. If the target grayscale value still does not meet the target brightness, steps S140 and S150 are performed in sequence.
[0076] The target brightness may be, for example, a brightness range, and the target grayscale value meeting the target brightness means that the brightness corresponding to the target grayscale value is within the target brightness range.
[0077] S140 , sequentially performing linearization processing and curve processing on the adjusted image to be processed.
[0078] After obtaining the image to be processed in steps S131 and S132, the initial grayscale values of the image to be processed are first linearly processed and spatialized to obtain the average brightness in the preset mapping relationship in step S131. This average brightness is the XYZ spatialized parameter. After step S132, before executing step S121 again (S150), the XYZ spatialized brightness parameters are sequentially linearized and then curved to convert them into RGB spatialized brightness parameters. The RGB space is then converted into YUV space, and the brightness information Y is extracted. Subsequently, the grayscale value of each pixel corresponding to the brightness information Y is obtained according to the gamma curve.
[0079] S150, repeatedly obtaining the target grayscale value of the target pixel among the multiple pixels located in the highlight area of the image to be processed, and adjusting the brightness of the image to be processed through the preset mapping relationship and the target grayscale value according to the comparison result between the target grayscale value and the preset threshold value, until the target grayscale value meets the target brightness.
[0080] Steps S121 , S122 , S123 , S131 , and S132 are repeated until the target grayscale value meets the target brightness.
[0081] The present invention provides an image brightness adjustment method that first determines a target pixel and a target grayscale value of the target pixel among multiple pixels in a highlight area. Based on the comparison result of the target grayscale value with a preset threshold, the brightness of the entire image to be processed is adjusted using a preset mapping relationship and the target grayscale value. When the target grayscale value is greater than the preset threshold, the overall brightness of the image to be processed can be reduced to avoid excessive brightness in the highlight area, which may cause overexposure. When the target grayscale value is less than the preset threshold, the overall brightness of the image to be processed can be increased to prevent excessive brightness in the highlight area or the presence of very dark shadow areas in the highlight area. Based on this, on the one hand, the present invention can automatically adjust the brightness of the image to be processed, eliminating the need for manual adjustment by the user. On the other hand, the present invention achieves higher detection accuracy by detecting the target grayscale value of the target pixel rather than the skin area. Based on this, the present invention adjusts the brightness of the entire image to be processed based on the comparison result of the target grayscale value with the preset threshold, rather than just the skin area, to ensure uniform brightness changes across the entire image to be processed without artifacts.
[0082] like Figure 10 As shown, this embodiment provides an image brightness adjustment device 100 , which includes an acquisition module 101 and a processing module 102 .
[0083] The acquisition module 101 is used to acquire an image to be processed.
[0084] The acquisition module 101 is further configured to acquire a target grayscale value of a target pixel among a plurality of pixels located in a highlight area of the image to be processed.
[0085] The processing module 102 is configured to adjust the brightness of the image to be processed according to a comparison result between the target grayscale value and a preset threshold value, using a preset mapping relationship and the target grayscale value.
[0086] On this basis, the acquisition module 101 is also used to obtain the grayscale values of multiple pixels located in the highlight area of the image to be processed; it is also used to establish a histogram of grayscale values and pixel numbers, and select multiple peaks based on the histogram, the peak value representing the number of pixels at the grayscale value, which is greater than the number of pixels at the previous grayscale value and the number of pixels at the next grayscale value; it is also used to select the maximum grayscale value from the multiple grayscale values corresponding to the multiple peaks as the target grayscale value.
[0087] The acquisition module 101 is further configured to acquire the grayscale value of each pixel in the image to be processed, and extract the grayscale values of a plurality of pixels located in the highlight area from the grayscale values of each pixel.
[0088] The processing module 102 is further configured to obtain a brightness adjustment parameter according to a preset mapping relationship and a grayscale value; and is further configured to adjust the brightness of the image to be processed according to the brightness adjustment parameter.
[0089] The processing module 102 is further configured to obtain a brightness value corresponding to the target grayscale value according to a gamma curve.
[0090] The acquisition module 101 is further configured to acquire the average brightness of the image to be processed.
[0091] The processing module 102 is further configured to compare the brightness value corresponding to the target grayscale value with the maximum brightness when the average brightness and the target brightness are constant; and to adjust the brightness to the first adjustment parameter when the brightness value is greater than or equal to the maximum brightness.
[0092] The processing module 102 is also used to compare the brightness value corresponding to the target grayscale value with the minimum brightness when the average brightness and the target brightness are constant; and is also used to adjust the brightness parameter to the second adjustment parameter when the brightness value is less than or equal to the minimum brightness, and the second adjustment parameter is greater than the first adjustment parameter.
[0093] The processing module 102 is also used to compare the brightness value corresponding to the target grayscale value with the minimum brightness and the maximum brightness when the average brightness and the target brightness are constant; and is also used to linearly reduce the brightness adjustment parameter between the second adjustment parameter and the first adjustment parameter as the brightness value increases when the brightness value is greater than the maximum brightness and less than the minimum brightness.
[0094] The acquisition module 101 is also used to obtain the initial grayscale value of each pixel in the image to be processed; it is also used to perform linear processing and spatial processing on the initial grayscale value in sequence to obtain the initial brightness value of each pixel; it is also used to obtain the average brightness of the image to be processed based on the initial brightness value of each pixel.
[0095] The processing module 102 is further configured to sequentially perform linearization processing and curve processing on the adjusted image to be processed.
[0096] The processing module 102 is also used to repeatedly obtain the target grayscale value of the target pixel among the multiple pixels located in the highlight area of the image to be processed, and adjust the brightness of the image to be processed through the preset mapping relationship and the target grayscale value according to the comparison result between the target grayscale value and the preset threshold value until the target grayscale value meets the target brightness.
[0097] When the image to be processed is an exposed portrait image, the acquisition module 101 is configured to obtain a target grayscale value of a target pixel from a plurality of pixels located in a face region of the image to be processed; detect the face region; obtain the grayscale values of a plurality of pixels located in the face region of the image to be processed; establish a histogram of grayscale values and pixel counts, and select a plurality of peaks based on the histogram, wherein the peak represents the number of pixels at that grayscale value, which is greater than the number of pixels at the previous grayscale value and the number of pixels at the next grayscale value; select the maximum grayscale value from the plurality of grayscale values corresponding to the plurality of peaks as the target grayscale value; obtain the grayscale value of each pixel in the image to be processed; and extract the grayscale values of the plurality of pixels located in the face region from the grayscale values of each pixel. The processing module 102 is further configured to reduce the brightness of the image to be processed by using a preset mapping relationship and the target grayscale value based on a comparison result of the target grayscale value with a preset threshold.
[0098] The embodiment of the present application provides an image brightness adjustment device 100 , the explanation and beneficial effects of which are the same as the explanation and beneficial effects of the aforementioned image brightness adjustment method, and are not repeated here.
[0099] like Figure 11 As shown, another embodiment of the present application provides an electronic device 200. The electronic device 200 of the present application may include: one or more processors 201, a memory 202, and one or more applications 203. The one or more applications 203 are stored in the memory 202 and configured to be executed by the one or more processors 201, and the one or more applications 203 are used to execute the method described in any of the above embodiments.
[0100] The processor 201 may include one or more processing cores. The processor 201 utilizes various interfaces and circuits to connect various components within the electronic device 200. It executes instructions, programs, code sets, or instruction sets stored in the memory 202, and accesses data stored in the memory 202 to perform various functions and process data within the electronic device 200. Optionally, the processor 201 may be implemented using at least one of the following hardware forms: a digital signal processing (DSP), a field-programmable gate array (FPGA), or a programmable logic array (PLA). The processor 201 may integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. The CPU primarily processes the operating system, user interface, and application programs; the GPU is responsible for rendering and drawing display content; and the modem handles wireless communications. It is understood that the modem may not be integrated into the processor 201 and may be implemented separately via a communication chip.
[0101] The memory 202 may include a random access memory (RAM) or a read-only memory (ROM). The memory 202 may be used to store instructions, programs, codes, code sets, or instruction sets. The memory 202 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the following various method embodiments, etc. The data storage area may also store data (such as a phone book, audio and video data, chat history data), etc., created by the electronic device 200 during use.
[0102] An embodiment of the present application provides an electronic device 200 . The explanation and beneficial effects of the electronic device 200 are the same as those of the aforementioned embodiment and are not repeated here.
[0103] like Figure 12 , which shows a structural block diagram of a computer-readable storage medium 300 provided in another embodiment of the present application. The computer-readable storage medium 300 stores program code, which can be called by a processor to execute the method described in the above method embodiment.
[0104] The computer-readable storage medium 300 may be an electronic memory such as a flash memory, an EEPROM (Electrically Erasable Programmable Read-Only Memory), an EPROM, a hard disk, or a ROM. Alternatively, the computer-readable storage medium 300 includes a non-transitory computer-readable storage medium.
[0105] The computer-readable storage medium 300 has storage space for application programs 203 for executing any of the method steps described above. These application programs 203 can be read from or written to one or more computer program products. The application programs 203 can be compressed in a suitable form, for example.
[0106] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for adjusting image brightness, characterized in that: include: Get the image to be processed; Obtaining a target grayscale value of a target pixel among a plurality of pixels located in a highlight area of the image to be processed, wherein the brightness of the plurality of pixels in the highlight area is all higher than the brightness of pixels in other areas of the image to be processed; Obtaining a brightness adjustment parameter according to a preset mapping relationship and the target grayscale value; The brightness of the image to be processed is adjusted according to the brightness adjustment parameter, wherein when the target grayscale value is greater than the preset threshold value, it indicates that the brightness of the highlight area is too bright, and the brightness of the entire image to be processed is reduced according to the preset mapping relationship and the target grayscale value to reduce the brightness of the highlight area; when the target grayscale value is less than the preset threshold value, it indicates that the brightness of the highlight area is too dark, and the brightness of the entire image to be processed is increased according to the preset mapping relationship and the target grayscale value to increase the brightness of the highlight area. The preset mapping relationship is , L represents the target brightness, a represents the brightness adjustment parameter, Lw (x, y) represents the preset threshold, and the preset threshold includes the minimum brightness and the maximum brightness, Represents the average brightness of the image to be processed.
2. The method according to claim 1, characterized in that The step of obtaining a target grayscale value of a target pixel among a plurality of pixels located in a highlight area of the image to be processed includes: Obtaining grayscale values of a plurality of pixels located in the highlight area in the image to be processed; Establishing a histogram of grayscale values and pixel counts, and selecting a plurality of peaks based on the histogram, wherein the peaks represent the number of pixels at the grayscale value being greater than the number of pixels at the previous grayscale value and the number of pixels at the next grayscale value; A maximum grayscale value is selected from the plurality of grayscale values corresponding to the plurality of peak values as the target grayscale value.
3. The method according to claim 2, characterized in that The obtaining of grayscale values of a plurality of pixels located in the highlight area in the image to be processed includes: Obtaining the grayscale value of each pixel in the image to be processed; Grayscale values of a plurality of pixels located in the highlight area are extracted from the grayscale values of the respective pixels.
4. The method according to claim 1, wherein Before obtaining the brightness adjustment parameter according to the preset mapping relationship and the target grayscale value, the method further includes: obtaining a brightness value corresponding to the target grayscale value according to a gamma curve.
5. The method according to claim 4, characterized in that After obtaining the image to be processed, the method further includes: Obtain the average brightness of the image to be processed.
6. The method according to claim 4, characterized in that Obtaining a brightness adjustment parameter according to the preset mapping relationship and the grayscale value includes: When the average brightness and the target brightness are constant, comparing the brightness value corresponding to the target grayscale value with the maximum brightness; When the brightness value is greater than or equal to the maximum brightness, the brightness adjustment parameter is a first adjustment parameter.
7. The method according to claim 6, characterized in that Obtaining a brightness adjustment parameter according to the preset mapping relationship and the grayscale value includes: When the average brightness and the target brightness are constant, comparing the brightness value corresponding to the target grayscale value with the minimum brightness; When the brightness value is less than or equal to the minimum brightness, the brightness adjustment parameter is a second adjustment parameter, and the second adjustment parameter is greater than the first adjustment parameter.
8. The method according to claim 7, characterized in that Obtaining a brightness adjustment parameter according to the preset mapping relationship and the grayscale value includes: When the average brightness and the target brightness are constant, comparing the brightness value corresponding to the target grayscale value with the minimum brightness and the maximum brightness; When the brightness value is greater than the maximum brightness and less than the minimum brightness, as the brightness value increases, the brightness adjustment parameter decreases linearly between the second adjustment parameter and the first adjustment parameter.
9. The method according to any one of claims 5 to 8, characterized in that The obtaining the average brightness of the image to be processed includes: Obtaining an initial grayscale value of each pixel in the image to be processed; Performing linear processing and spatial processing on the initial grayscale value in sequence to obtain an initial brightness value of each pixel; The average brightness of the image to be processed is obtained according to the initial brightness values of the pixels.
10. The method according to claim 9, characterized in that After adjusting the brightness of the image to be processed according to the brightness adjustment parameter, the method further includes: The adjusted image to be processed is sequentially subjected to linearization processing and curve processing.
11. The method according to claim 10, characterized in that After sequentially performing linearization processing and curve processing on the adjusted image to be processed, the method further includes: Repeatedly acquiring a target grayscale value of a target pixel among a plurality of pixels located in a highlight area of the image to be processed, and obtaining a brightness adjustment parameter according to a preset mapping relationship and the target grayscale value; The step of adjusting the brightness of the image to be processed according to the brightness adjustment parameter until the target grayscale value meets the target brightness.
12. The method according to claim 1, characterized in that The image to be processed is an exposed portrait image.
13. The method according to claim 12, characterized in that The step of obtaining a target grayscale value of a target pixel among a plurality of pixels located in a highlight area of the image to be processed includes: Obtain a target grayscale value of a target pixel among multiple pixels located in a face area of an image to be processed.
14. The method according to claim 13, characterized in that The step of obtaining a target grayscale value of a target pixel among a plurality of pixels located in a face area of the image to be processed includes: detecting the face area; Obtaining grayscale values of a plurality of pixels located in the face area in the image to be processed; Establishing a histogram of grayscale values and pixel counts, and selecting a plurality of peaks based on the histogram, wherein the peaks represent the number of pixels at the grayscale value being greater than the number of pixels at the previous grayscale value and the number of pixels at the next grayscale value; A maximum grayscale value is selected from the plurality of grayscale values corresponding to the plurality of peak values as the target grayscale value.
15. The method according to claim 14, characterized in that The obtaining of grayscale values of a plurality of pixels located in the face area of the image to be processed includes: Obtaining the grayscale value of each pixel in the image to be processed; Grayscale values of a plurality of pixels located in the face area are extracted from the grayscale values of the respective pixels.
16. The method according to any one of claims 14-15, characterized in that The adjusting the brightness of the image to be processed according to the brightness adjustment parameter includes: The brightness of the image to be processed is reduced according to the brightness adjustment parameter.
17. An image brightness adjustment device, characterized in that: include: An acquisition module, used for acquiring an image to be processed; The acquisition module is further used to obtain a target grayscale value of a target pixel among a plurality of pixels located in a highlight area of the image to be processed, wherein the brightness of the plurality of pixels in the highlight area is all higher than the brightness of pixels in other areas of the image to be processed; A processing module, configured to obtain a brightness adjustment parameter according to a preset mapping relationship and the target grayscale value; The brightness of the image to be processed is adjusted according to the brightness adjustment parameter, wherein when the target grayscale value is greater than the preset threshold value, it indicates that the brightness of the highlight area is too bright, and the brightness of the entire image to be processed is reduced according to the preset mapping relationship and the target grayscale value to reduce the brightness of the highlight area; when the target grayscale value is less than the preset threshold value, it indicates that the brightness of the highlight area is too dark, and the brightness of the entire image to be processed is increased according to the preset mapping relationship and the target grayscale value to increase the brightness of the highlight area. The preset mapping relationship is , L represents the target brightness, a represents the brightness adjustment parameter, Lw (x, y) represents the preset threshold, and the preset threshold includes the minimum brightness and the maximum brightness, Represents the average brightness of the image to be processed.
18. An electronic device, characterized in that: include: one or more processors; Memory; as well as, One or more applications, wherein the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more applications are used to execute the method according to any one of claims 1 to 16.
19. A computer-readable storage medium, characterized in that The computer-readable storage medium stores program code, which can be called by a processor to execute the method according to any one of claims 1 to 16.