A local contrast enhancement method
By performing YUV conversion, differential image optimization and Gaussian filtering on the image, the problems of edge overshoot and detail loss in local permeability enhancement are solved, and better visual effects are achieved.
Patent Information
- Application Number
- CN202411422234.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-12
- Publication Date
- 2025-05-27
- Estimated Expiration
- 2044-10-12
AI Technical Summary
Existing local permeability enhancement technologies can easily lead to edge overshoot, black and white edge phenomena, and overexposure or too darkness may lead to loss of details.
By converting the original RGB image into YUV data, extracting the brightness channel as a grayscale image for preprocessing, obtaining differential images and optimizing, combining Gaussian filtering and guide filtering, overexposure and overdarkness are suppressed, and details are avoided.
While improving image transparency, it avoids black and white edge phenomena and detail loss, significantly improving the visual quality of the image.
Smart Images

Figure CN119379573B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular to a local contrast enhancement method. Background Art
[0002] Local permeability enhancement (also known as local contrast enhancement or brightness / contrast adjustment) is an important technology in image processing. It aims to improve the visual quality of images, especially in situations where there is insufficient light, low contrast, or image details are difficult to identify. This technology adjusts the brightness and contrast of different regions in the image, making the details in the image more prominent, thereby improving the permeability and visual perception of the image. Common techniques include histogram processing, AI enhancement, tone mapping and other solutions.
[0003] USM (Unsharp Mask) local permeability enhancement is an image processing technology. By simulating the characteristics of human eye observation, that is, the human eye will see the so-called "Mach band" effect at the edge of a sharp brightness transition, it enhances the edge contrast of the image, mainly used to improve the permeability and visual perception of the image, especially by enhancing the local contrast of the image. The USM local permeability enhancement technology can effectively improve the permeability and clarity of the image, making the edges and details in the image more prominent. The USM technology can not only be used for post-processing of images, but also be embedded in the image processing system of digital cameras to improve the permeability and clarity of the captured images in real time, with high efficiency.
[0004] However, excessive sharpening may lead to edge overshoot (Halo phenomenon), which may to some extent manifest as unnatural brightness changes near the edge, including the effect that may look like black and white edges, and may cause overexposure or underexposure, resulting in the problem of detail loss. Summary of the Invention
[0005] The purpose of this part is to outline some aspects of the embodiments of the present invention and briefly introduce some preferred embodiments. Some simplifications or omissions may be made in this part, as well as in the abstract and title of the specification of this application, to avoid obscuring the purpose of this part, the abstract, and the title. However, such simplifications or omissions shall not be used to limit the scope of the present invention.
[0006] In view of the problems existing in the local permeability enhancement technology in the above-mentioned prior art, the present invention is proposed.
[0007] To solve the above technical problems, the present invention provides the following technical solution: A local contrast enhancement method, which includes the following steps:
[0008] Input the original RGB three-channel image S;
[0009] Convert the original RGB three-channel image S into YUV data, and extract the luminance channel Y as the grayscale image I;
[0010] Preprocess the grayscale image I to obtain the difference image Δ;
[0011] Optimize the difference image Δ to obtain the optimized difference image Δ_2;
[0012] Add the grayscale image I and the optimized difference image Δ_2 to obtain the grayscale image I_e with enhanced local contrast;
[0013] Replace the Y channel in the YUV space with I_e, and convert YUV to RGB to obtain the color image with enhanced local contrast.
[0014] As a preferred embodiment of the local contrast enhancement method of the present invention, wherein: the specific steps of the preprocessing are as follows,
[0015] Perform Gaussian filtering on the grayscale image I to obtain the Gaussian filtered image I_GS, and the Gaussian filtering radius is r;
[0016] Use the grayscale image I as the guidance map, and perform guided filtering on the Gaussian filtered image I_GS to obtain the guided filtered image I_GD, and the guided filtering radius is r;
[0017] Calculate the difference image Δ, Δ = I - I_GD;
[0018] Wherein, r > 1% of the minimum value of the length and width of the image.
[0019] As a preferred embodiment of the local contrast enhancement method of the present invention, wherein: the specific steps of optimizing the difference image Δ are as follows,
[0020] Change the pixel values in the difference image Δ whose absolute values are not greater than the threshold t to 0 to obtain the difference image Δ_0;
[0021] Enhance the difference image Δ_0, and the enhanced difference image is Δ_1, Δ_1 = Δ * λ;
[0022] Extract the part of the difference image Δ_1 with values < 0 as the darkening image Δ_neg, and extract the part of the difference image Δ_1 with values > 0 as the brightening image Δ_pos;
[0023] Optimize the darkening image Δ_neg based on the darkening coefficient λ_1 and the grayscale image I, and the optimized darkening image is Δ_neg1;
[0024] Optimize the brightening image Δ_pos based on the brightening coefficient λ_2 and the grayscale image I, and the optimized brightening image is Δ_pos1;
[0025] Merge the updated Δ_neg and Δ_pos to obtain the optimized difference image Δ_2;
[0026] Where λ is the enhancement intensity.
[0027] As a preferred solution of the local contrast enhancement method of the present invention, among them: the steps of optimizing the darkened image Δ_neg are,
[0028] Calculate the image darkening threshold t_neg_1 = I * λ_1, 0 < λ_1 < 1;
[0029] Calculate the dark area suppression coefficient λ_neg, λ_neg = y (i,j) 2 / (255 + y (i,j) 2 ), where y (i,j) is the gray value corresponding to the position of the i-th row and j-th column of the image;
[0030] Calculate the darkening threshold t_neg_2 = -1 * t_neg_1 * λ_neg;
[0031] Δ_neg1 = max(Δ_neg, t_neg_2).
[0032] As a preferred solution of the local contrast enhancement method of the present invention, among them: the specific steps of optimizing the brightened image Δ_pos are,
[0033] Calculate the image brightening threshold t_pos_1 = (255 - I) * λ_2, 0 < λ_2 < 1;
[0034] Calculate the bright area suppression coefficient λ_pos, λ_neg = (255 - y (i,j) ) 2 / (255 + (255 - y (i,j) ) 2 );
[0035] Calculate the brightening threshold t_pos_2 = t_pos_1 * λ_pos;
[0036] Δ_pos1 = max(Δ_pos, t_pos_2).
[0037] Advantages of the present invention: On the premise of improving permeability, the present invention solves two technical problems in the prior art, namely, easy generation of black and white edges and detail loss caused by overexposure and overdarkening. Brief Description of the Drawings
[0038] To more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings. Among them:
[0039] Figure 1 It is a flowchart of the present invention.
[0040] Figure 2 It is a curve graph of the dark area suppression coefficient and the gray value in the present invention.
[0041] Figure 3 It is a curve graph of the bright area suppression coefficient and the gray value in the present invention.
[0042] Figure 4 It is a grayscale image I of an example.
[0043] Figure 5 It is an image I_e with black and white edges existing after enhancing an example by the ordinary USM method.
[0044] Figure 6 It is an image I_e without black and white edges after enhancing by the present invention.
[0045] Figure 7 It is a grayscale image I of another example.
[0046] Figure 8 It is an image I_e with detail loss after enhancing another example by the ordinary USM method.
[0047] Figure 9 It is an image I_e without detail loss after enhancing another example by the present invention. Detailed implementation manners
[0048] To make the above objects, features, and advantages of the present invention more obvious and understandable, the following will make a detailed description of the specific implementation manners of the present invention in conjunction with the drawings of the specification. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0049] Many specific details are set forth in the following description in order to fully understand the present invention. However, the present invention can also be implemented in other ways different from those described herein. Those skilled in the art can make similar extensions without departing from the connotation of the present invention. Therefore, the present invention is not limited by the specific embodiments disclosed below.
[0050] Second, the "one embodiment" or "embodiment" referred to herein means a specific feature, structure, or characteristic that may be included in at least one implementation manner of the present invention. The appearances of "in one embodiment" in different places in this specification do not all refer to the same embodiment, nor are they separate or alternative embodiments that exclude each other with other embodiments.
[0051] The present invention will be described in detail in conjunction with schematic diagrams. When detailing the embodiments of the present invention, for the convenience of description, the cross-sectional views showing the device structure will be enlarged locally in a non-general proportion, and the schematic diagrams are only examples and should not limit the scope of protection of the present invention here. In addition, in actual production, three-dimensional spatial dimensions including length, width, and depth should be included.
[0052] Meanwhile, in the description of the present invention, it should be noted that the orientation or positional relationship indicated by terms such as "upper, lower, inner, and outer" is based on the orientation or positional relationship shown in the drawings. It is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be construed as a limitation to the present invention. In addition, the terms "first, second, or third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0053] Unless otherwise clearly defined and limited in the present invention, the terms "installed, connected, and coupled" should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral connection; it can also be a mechanical connection, an electrical connection, or a direct connection, or can be indirectly connected through an intermediate medium, or can be the communication inside two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific situations.
[0054] Embodiment 1
[0055] Refer to Figure 1 , which is the first embodiment of the present invention. This embodiment provides a local contrast enhancement method. Using this method to synthesize panoramic roaming videos, there is no need to be associated with an IP address, and it can be directly downloaded and shared in video format, saving time and effort.
[0056] A local contrast enhancement method includes the following steps.
[0057] S1: Input the original RGB three-channel image S.
[0058] S2: Convert the original RGB three-channel image S into YUV data, and extract the luminance channel Y channel as the grayscale image I.
[0059] S3: Preprocess the grayscale image I to obtain the difference image Δ.
[0060] The specific steps are as follows.
[0061] S301 performs Gaussian filtering on the grayscale image I to obtain the Gaussian filtered image I_GS. The Gaussian filtering radius is r, and the specific expression of the Gaussian kernel function GS is as follows:
[0062]
[0063] I_GS = I * GS;
[0064] where is the Gaussian kernel variance, and p and q are the relative coordinates within the Gaussian filtering radius r;
[0065] S302 uses the grayscale image I as the guidance image and performs guided filtering on the Gaussian filtered image I_GS to obtain the guided filtered image I_GD. The guided filtering radius is r, and the specific expression of the guided filtering function is as follows:
[0066]
[0067] where ω xy is the pixel block window with the center at the coordinate (x, y) and a radius of r, ω ij is the pixel block window with the center at the coordinate (i, j) and a radius of r, |ω xy | is the number of pixels in the pixel block window, a xy and b xy are the window coefficients in the pixel block ω xy I (i,j) is the pixel corresponding to the position of the i-th row and j-th column in the grayscale image, I (p,q) is the pixel corresponding to the position of the p-th row and q-th column in the pixel block window of the grayscale image, I_GS (p,q) is the pixel corresponding to the position of the p-th row and q-th column in the pixel block window of the Gaussian filtered image, μ is the mean value of the guidance image in the pixel block ω xy and is the variance of the guidance image in the pixel block ω xy ε is the linear regression coefficient, is the mean value of the image to be smoothed and filtered in the pixel block ω xy p and q are the relative coordinates within the pixel block ω xy i and j are the image coordinates;
[0068] S303 calculates the difference image Δ, Δ = I - I_GD;
[0069] where r > 1% of the minimum value of the length and width of the image;
[0070] S4: Optimize the difference image Δ to obtain the optimized difference image Δ_2. The specific steps are as follows
[0071] S401. Change the pixel values in the difference image Δ whose absolute values are not greater than the threshold t to 0 to obtain the difference image Δ_0;
[0072] S402. Enhance the difference image Δ_0. The enhanced difference image is Δ_1, and Δ_1 = Δ * λ, where λ is the enhancement intensity;
[0073] S403. Extract the part of the difference image Δ_1 with values < 0 as the darkening image Δ_neg, and extract the part of the difference image Δ_1 with values > 0 as the brightening image Δ_pos;
[0074] S404. Optimize the darkening image Δ_neg based on the darkening coefficient λ_1 and the grayscale image I. The optimized darkening image is Δ_neg1. The specific optimization steps are as follows:
[0075] S404a. Calculate the image darkening threshold t_neg_1 = I * λ_1, where 0 < λ_1 < 1;
[0076] S404b. Calculate the dark area suppression coefficient λ_neg, λ_neg = y (i,j) 2 / (255 + y (i,j) 2 ), where y (i,j) is the grayscale value corresponding to the position of the i-th row and j-th column of the image;
[0077] S404c. Calculate the darkening threshold t_neg_2 = -1 * t_neg_1 * λ_neg;
[0078] S404d. Δ_neg1 = max(Δ_neg, t_neg_2);
[0079] S405. Optimize the brightening image Δ_pos based on the brightening coefficient λ_2 and the grayscale image I. The optimized brightening image is Δ_pos1. The optimization steps are as follows:
[0080] S405a. Calculate the image brightening threshold t_pos_1 = (255 - I) * λ_2, where 0 < λ_2 < 1;
[0081] S405b. Calculate the bright area suppression coefficient λ_pos, λ_neg = (255 - y (i,j) ) 2 / (255 + (255 - y (i,j) ) 2 ); S405c. Calculate the brightening threshold t_pos_2 = t_pos_1 * λ_pos;
[0082] S405d. Δ_pos1 = max(Δ_pos, t_pos_2);
[0083] S406. Combine the updated Δ_neg1 and Δ_pos1 to obtain the optimized difference image Δ_2, i.e., Δ_2 = Δ_neg1 + Δ_pos1;
[0084] S5: Add the grayscale image I to the optimized difference image Δ_2 to obtain the grayscale image I_e with enhanced local contrast;
[0085] S6: Replace the Y channel in the YUV space with I_e, and convert YUV to RGB to obtain the color image with enhanced local contrast.
[0086] Where max(Δ_neg, t_neg_2) is the maximum value between Δ_neg and t_neg_2, and max(Δ_pos, t_pos_2) is the maximum value between Δ_pos and t_pos_2.
[0087] When using the present invention to process an image, on the premise of improving permeability, two technical problems in the prior art, namely, the easy generation of black and white edges and the loss of details caused by overexposure and underexposure, are solved.
[0088] Embodiment 2
[0089] This embodiment provides a method for enhancing local contrast. The difference from Embodiment 1 is that in this embodiment, the experimental results are compared by means of scientific demonstration to verify the actual effects of this method.
[0090] A method for enhancing local contrast includes the following steps:
[0091] S1: Input the original RGB three-channel image S;
[0092] S2: Convert the original RGB three-channel image S into YUV data, and extract the luminance channel Y channel as the grayscale image I;
[0093] S3: Preprocess the grayscale image I to obtain the difference image Δ;
[0094] The specific steps are as follows:
[0095] S301. Perform Gaussian filtering on the grayscale image I to obtain the Gaussian filtered image I_GS, and the Gaussian filtering radius is r;
[0096] S302. Use the grayscale image I as the guidance map to perform guided filtering on the Gaussian filtered image I_GS to obtain the guided filtered image I_GD, and the guided filtering radius is r;
[0097] S303. Calculate the difference image Δ, Δ = I - I_GD;
[0098] Among them, r > 1% of the minimum value of the length and width of the image. For an 8000*4000 image, r takes the value of 50;
[0099] S4: Based on the image s, the image I, the enhancement intensity λ, and the threshold information, optimize the difference image Δ to solve the overexposure and underexposure problems caused by excessive enhancement, and obtain the optimized difference image Δ_2. The specific steps are as follows:
[0100] S401, change the pixel values in the difference image Δ whose absolute values are not greater than the threshold t_1 to 0 to obtain the difference image Δ_0. In this embodiment, the threshold t is 4, which can be calibrated according to the actual situation;
[0101] S402, enhance the difference image Δ_0, and the enhanced difference image is Δ_1, Δ_1 = Δ * λ, where λ is the enhancement intensity and can be calibrated according to the actual situation;
[0102] S403, extract the part of the difference image Δ_1 with values < 0 as the darkening image Δ_neg, and extract the part of the difference image Δ_1 with values > 0 as the brightening image Δ_pos;
[0103] S404, based on the darkening coefficient λ_1 and the grayscale image I, optimize the darkening image Δ_neg, and the optimized darkening image is Δ_neg1. The optimization steps are as follows:
[0104] S404a, calculate the image darkening threshold t_neg_1 = I * λ_1, 0 < λ_1 < 1. In this embodiment, λ_1 takes the value of 0.5;
[0105] S404b, calculate the dark area suppression coefficient λ_neg, λ_neg = y (i,j) 2 / (255 + y (i,j) 2 )(as Figure 2 shown), where y (i,j) is the grayscale value corresponding to the position of the i-th row and j-th column of the image;
[0106] S404c, calculate the darkening threshold t_neg_2 = -1 * t_neg_1 * λ_neg;
[0107] S404d, Δ_neg1 = max(Δ_neg, t_neg_2);
[0108] To improve the calculation efficiency, the dark area suppression coefficient λ_neg corresponding to each grayscale value can be calculated and stored as a conversion table. When optimizing the darkening image Δ_neg, directly extract the corresponding dark area suppression coefficient λ_neg from the conversion table (as shown in the following table) according to the grayscale value for use;
[0109] Gray value Dark area suppression coefficient λ_neg 0 0 1 0.00390625 2 0.01544402 ... ... 254 0.99606305 255 0.99609375
[0110] S405. Based on the brightening coefficient λ_2 and the grayscale image I, optimize the brightening image Δ_pos. The optimized brightening image is Δ_pos1. The specific optimization steps are as follows:
[0111] S405a. Calculate the image brightening threshold t_pos_1 = (255 - I) * λ_2, where 0 < λ_2 < 1. In this embodiment, λ_2 is taken as 0.5;
[0112] S405b. Calculate the bright area suppression coefficient λ_pos, λ_pos = (255 - y (i,j) ) 2 / (255 + (255 - y (i,j) ) 2 )(as shown in Figure 3 ), where y (i,j) is the grayscale value corresponding to the position of the i-th row and j-th column of the image;
[0113] S405c. Calculate the brightening threshold t_pos_2 = t_pos_1 * λ_pos;
[0114] S405d. Δ_pos1 = max(Δ_pos, t_pos_2);
[0115] To improve the calculation efficiency, the bright area suppression coefficient λ_pos corresponding to each grayscale value can be calculated and stored as a conversion table. When optimizing the brightening image Δ_pos, directly extract the corresponding bright area suppression coefficient λ_pos from the conversion table (as shown in the following table) according to the grayscale value for use;
[0116]
[0117]
[0118] S406. Combine the updated Δ_neg1 and Δ_pos1 to obtain the optimized difference image Δ_2;
[0119] S5: Add the grayscale image I to the optimized difference image Δ_2 to obtain the grayscale image I_e with enhanced local contrast;
[0120] S6: Replace the Y channel in the YUV space with I_e and convert YUV to RGB to obtain the color image with enhanced local contrast.
[0121] As Figures 4 to 6 shown, obtain an original RGB three-channel image, convert the original RGB three-channel image to the YUV format, extract the luminance channel Y channel as the grayscale image I, as Figure 4; When enhancing the grayscale image I by the ordinary USM method, there is an obvious phenomenon of black and white edges on the image, as Figure 5 ; By the technical solution of the present invention, while performing local contrast enhancement processing, the problem of black and white edges generated in the image is eliminated.
[0122] Such as Figures 7 to 9 As shown, obtain an original RGB three-channel image, convert the original three-channel image to the YUV format, and extract the luminance channel Y channel as the grayscale image I, as Figure 7 ; When enhancing the grayscale image I by the ordinary USM method, overexposure problems occur in the areas with high brightness on the image, and underexposure problems occur in the areas with low brightness, resulting in the loss of image details, as Figure 8 ; By the technical solution of the present invention, while performing local contrast enhancement processing, the generation of overexposure and underexposure problems in the image is suppressed, and the loss of details is avoided.
[0123] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to the preferred embodiments, those of ordinary skill in the art should understand that the technical solutions of the present invention can be modified or equivalently replaced without departing from the spirit and scope of the technical solutions of the present invention, and they should all be covered within the scope of the technical solutions of the present invention.
Claims
1. A local contrast enhancement method, characterized in that: The following steps are included: Input original RGB three-channel image S; Convert the original RGB three-channel image S to YUV data, and extract the brightness channel Y as the grayscale image I; Preprocess the grayscale image I to obtain a differential image Δ; The difference image Δ is optimized to obtain the optimized difference image Δ_2. The optimization steps are: Change the pixel values in the differential image Δ whose absolute values are not greater than the threshold value t to 0, and obtain the differential image Δ_0; The difference image Δ_0 is enhanced, and the enhanced difference image is Δ_1, Δ_1 = Δ_0*λ; Extract the portion of the difference image Δ_1 with a value less than 0 as the darkened image Δ_neg, and extract the portion of the enhanced difference image Δ_1 with a value greater than 0 as the brightened image Δ_pos; Based on the darkening coefficient λ_1 and the grayscale image I, the darkened image Δ_neg is optimized, and the optimized darkened image is Δ_neg1; Based on the brightening coefficient λ_2 and the grayscale image I, the brightened image Δ_pos is optimized, and the optimized brightened image is Δ_pos1, wherein the steps for optimizing the darkened image Δ_neg are: Calculate the image darkening threshold t_neg_1 = I * λ_1, 0<λ_1<1; Calculate the dark area suppression coefficient λ_neg, ,in is the gray value corresponding to the position of the i-th row and j-th column of the image; Calculate the darkening threshold t_neg_2 = -1 * t_neg_1 * λ_neg; Δ_neg1 = max(Δ_neg, t_neg_2); Merge the updated Δ_neg and Δ_pos to obtain the optimized differential image Δ_2; Among them, λ is the enhancement strength; Add the grayscale image I and the optimized difference image Δ_2 to obtain the grayscale image I_e after local contrast enhancement; Replace the Y channel in the YUV space with I_e, and convert YUV to RGB to obtain a color image with local contrast enhancement.
2. The local contrast enhancement method according to claim 1, characterized in that: The specific steps of preprocessing are: Perform Gaussian filtering on the grayscale image I to obtain a Gaussian filtered image I_GS, where the Gaussian filter radius is r; The grayscale image I is used as the guide image, and the Gaussian filter image I_GS is subjected to a guide filter process to obtain a guide filter image I_GD, and the guide filter radius is r; Calculate the difference image Δ, Δ=I-I_GD; Where r>1% of the minimum value of the image length and width.
3. The local contrast enhancement method according to claim 1 or 2, characterized in that: The specific steps for optimizing and brightening the image Δ_pos are: Calculate the image brightening threshold t_pos_1 = (255 - I) * λ_2, 0<λ_2<1; Calculate the bright area suppression coefficient λ_pos, ; Calculate the brightening threshold t_pos_2 = t_pos_1 * λ_pos; Δ_pos1 = max(Δ_pos, t_pos_2 ).
Citation Information
Patent Citations
Brightness enhancement method for an image in dark light scene
CN108830800A
Image wide dynamic range processing method
CN112200753A