Image processing method and device, electronic device, and storage medium
By converting the image to the HSV color space, statistically analyzing the brightness and darkness distribution and histogram values of a single-channel image, and calculating the stretching ratio and maximum stretching degree, the shortcomings of existing technologies in image quality improvement are addressed, effectively enhancing contrast and saturation and improving visual effects.
Patent Information
- Application Number
- CN202211225881.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-09
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2042-10-09
AI Technical Summary
Existing image post-processing methods cannot effectively improve image quality, especially in cases of low contrast and low saturation, and require subjective adjustments based on user experience, resulting in poor performance.
The image is converted to the HSV color space. By statistically analyzing the pixel distribution, mean, and highest and lowest histogram values of the bright and dark areas of the single-channel image, the stretching ratio and maximum stretching degree are calculated, and the image is corrected to improve contrast and saturation.
It significantly improves image quality, especially in low contrast and low saturation conditions, providing a better visual experience and reducing reliance on user experience.
Smart Images

Figure CN115953526B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, in particular to an image processing method and device, electronic equipment and storage medium. BACKGROUND
[0002] The role of color enhancement is generally used to improve the quality of the image, so that the picture color is more rich and realistic, and the human visual subjective feeling is improved. Due to the diversity of device cameras, the influence of light source or environmental noise when shooting, sometimes the video shot will have problems such as insufficient saturation, gray picture, color deficiency, insufficient or excessive brightness, and overall color deviation of the picture. These situations are particularly prone to occur when shooting outdoor scenery and color-rich scenes. These situations can be improved by adjusting appropriate post-processing algorithms. For example, the post-processing adopts a color adjustment scheme, which generally has two different goals, "restoration" and "beautiful". "Restoration" means that the picture can truly present the real color of the current light scene, and the color is not deviated. "Beautiful" means that the color level of the picture is rich and natural enough to improve the comfort of human vision, so that the sky is bluer and the grass is greener, and the picture is more in line with human preferences.
[0003] However, the post-processing technology in the related art is usually one-sided to enhance the picture, such as using histogram equalization to stretch the image contrast to obtain the effect of contrast enhancement; or adjusting the saturation / natural saturation of the image according to the parameters to adjust the saturation of the picture, so the improvement effect is limited. In addition, the above scheme requires the user to provide an adjustment parameter according to experience to obtain the adjustment effect of the image, so the subjectivity is strong and cannot obtain a good satisfaction degree. SUMMARY
[0004] In view of the problems existing in the prior art, the embodiments of the present application provide an image processing method and device, electronic equipment and storage medium, which can effectively improve the image quality of the image or video, and further improve the visual effect.
[0005] In a first aspect, the embodiments of the present application provide an image processing method, comprising:
[0006] Obtaining an original image and converting the original image into an HSV color space image;
[0007] According to the pixel statistics of the single-channel image in the HSV color space image, obtaining a histogram;
[0008] Obtaining the total pixel distribution of the bright part and the total pixel distribution of the dark part of the single-channel image, the pixel mean value of the single-channel image, the highest order value and the lowest order value in the histogram;
[0009] The stretching ratio and maximum stretching degree are obtained based on the total pixel distribution of the bright and dark parts of the single-channel image, the average pixel value of the single-channel image, and the highest and lowest order values in the histogram.
[0010] Based on the stretching ratio and maximum stretching degree, the single-channel image is corrected, and the target image of the original image is obtained based on the corrected single-channel image.
[0011] In some examples, obtaining the total pixel distribution of the bright areas and the total pixel distribution of the dark areas of the single-channel image, the pixel mean of the single-channel image, and the highest and lowest order values in the histogram includes:
[0012] Based on the pixel value of each pixel in the single-channel image, the total pixel distribution of the bright part and the total pixel distribution of the dark part of the single-channel image are obtained.
[0013] The average pixel value of the single-channel image is obtained based on the number of pixels in the single-channel image and the pixel value of each pixel in the single-channel image.
[0014] Starting from the minimum and maximum order of the histogram, the search proceeds towards higher and lower order directions, respectively. When the first non-zero order value is found, it is determined as the lowest and highest order values, respectively.
[0015] In some examples, obtaining the stretching ratio and maximum stretching degree based on the total pixel distribution of the bright and dark areas of the single-channel image, the average pixel value of the single-channel image, and the highest and lowest order values in the histogram includes:
[0016] Based on the pixel mean of the single-channel image, the highest-order value and the lowest-order value in the histogram, determine the position ratio of the pixel mean in the histogram;
[0017] Based on the total pixel distribution of the bright areas and the total pixel distribution of the dark areas, determine the proportion of the largest portion of the total pixel distribution of the bright areas and the dark areas;
[0018] Based on the pixel mean of the single-channel image and the position ratio of the pixel mean in the histogram, the proportion of the pixel mean in the distance to the middle value of the order value when it is located in the bright or dark area is obtained.
[0019] Based on the highest and lowest order values, the proportion of the highest or lowest order value is obtained;
[0020] The stretching ratio and maximum stretching degree are obtained based on the proportion of the average pixel value at the distance from the median value when it is located in the bright or dark area, and the proportion of the highest or lowest value.
[0021] In some examples, obtaining the proportion of the highest-order value or the lowest-order value based on the highest-order value and the lowest-order value includes:
[0022] Obtain the lowest non-zero order distance in the histogram, corresponding to the lowest order value, and the first distance of the lowest order.
[0023] Obtain the second distance of the highest order corresponding to the highest non-zero order distance in the histogram, which is the highest order value.
[0024] Obtain the maximum distance between the first distance and the second distance;
[0025] Based on the maximum distance, the proportion of the highest or lowest order value is obtained.
[0026] In some examples, the single-channel image is an S-channel image, then:
[0027] The stretching ratio and maximum stretching degree are obtained based on the proportion of the average pixel value in the bright or dark region relative to the median value and the proportion of the highest or lowest value, using the following formula:
[0028] When totalL>totalH, ratio=abs(v1-v2)*tmp_v1; when Max>127.0, tmp_range=Max+min(Min,255.0-Max); when Max<=127.0, tmp_range=Max*(1.0+Max / 127.0).
[0029] When totalL <= totalH, if meanV < 127.0 and MaxRange < 0.6, ratio = abs(v1 - v2) * tmp_v1; when Max > 127.0, tmp_range = Max + min(Min, 255.0 - Max); when Max <= 127.0, tmp_range = Max * (1.0 + Max / 127.0); otherwise, ratio = 0.05 and tmp_range = 255.
[0030] If the single-channel image is a V-channel image, then:
[0031] The stretching ratio and maximum stretching degree are obtained based on the proportion of the average pixel value in the bright or dark region relative to the median value and the proportion of the highest or lowest value, using the following formula:
[0032] When totalL > totalH, ratio = max(v1, v2), tmp_range = 255;
[0033] When totalL <= totalH, when meanV < 127.0 && MaxRange < 0.6, ratio = max(v1,v2) and tmp_range = 255; otherwise, ratio = 0.05 and tmp_range = 255.
[0034] Wherein, totalL is the total number of pixels distributed in the dark area, totalH is the total number of pixels distributed in the bright area, ratio is the stretching ratio, v1 is the proportion of the average pixel value at the distance from the median of the order value when it is located in the bright or dark area, v2 is the proportion of the highest or lowest order value, Min is the lowest order value, Max is the highest order value, tmp_range is the maximum stretching degree, meanV is the average pixel value, and MaxRange is the proportion of the maximum portion of the total number of pixels distributed in the bright and dark areas.
[0035] In some examples, before correcting the single-channel image based on the stretching ratio and maximum stretching degree, and obtaining the target image of the original image based on the corrected single-channel image, the method further includes: imposing the following constraints on the stretching ratio and maximum stretching degree:
[0036] tmp_range=min(tmp_range, 255);
[0037] ratio=min(tmp+ratio*tmp,1.0f);
[0038] Calculate Gamma=log(ratio) / log(tmp), Gamma=max(0.8f,Gamma).
[0039] In some examples, the correction of the single-channel image based on the stretching ratio and the maximum stretching degree is obtained as follows:
[0040] s_new=pow((s_old-MinS) / (MaxS-MinS),GammaS)*tmp_rangeS;
[0041] v_new=pow((v_old-MinV) / (MaxV-MinV),GammaV)*tmp_rangeV,
[0042] Wherein, s_new is the corrected value of the S-channel image, v_new is the corrected value of the V-channel image, s_old is the original value of the S-channel image, v_old is the original value of the V-channel image, S refers to the S-channel image, and V refers to the V-channel image.
[0043] Secondly, embodiments of the present invention also provide an image processing apparatus, comprising:
[0044] The first conversion module is used to convert the original image into an HSV color space image;
[0045] The histogram generation module is used to obtain a histogram based on the pixel statistics of a single channel image in the HSV color space image;
[0046] The acquisition module is used to obtain the total pixel distribution of the bright part and the total pixel distribution of the dark part of the single-channel image, the pixel mean of the single-channel image, and the highest and lowest order values in the histogram;
[0047] The correction value determination module is used to obtain the stretching ratio and the maximum stretching degree based on the total pixel distribution of the bright part and the total pixel distribution of the dark part of the single-channel image, the pixel mean of the single-channel image, and the highest and lowest order values in the histogram.
[0048] The correction module is used to correct the single-channel image based on the stretching ratio and the maximum stretching degree, and to obtain the target image of the original image based on the corrected single-channel image.
[0049] Thirdly, embodiments of the present invention also provide an electronic device, comprising: a memory and a processor, the memory being used to store and support the processor in executing a program of any of the methods described in the first aspect, the processor being configured to execute the program stored in the memory.
[0050] Fourthly, embodiments of the present invention also provide a computer-readable storage medium having processor-executable non-volatile program code, wherein the program code causes the processor to perform any of the methods described in the first aspect.
[0051] Fifthly, embodiments of the present invention also provide a computer program product having processor-executable non-volatile program code, wherein the program code causes the processor to perform any of the methods described in the first aspect.
[0052] The embodiments of the present invention bring the following beneficial effects:
[0053] The image processing method, apparatus, electronic device, and storage medium provided in this invention convert the original image into an HSV color space image, and then enhance the saturation single-channel image and luminance single-channel image in the HSV color space image. That is, the image quality is enhanced by improving contrast and saturation. In particular, it has a better enhancement effect on low-contrast and low-saturation images obtained by shooting, significantly improving the image quality and providing a better visual experience. Attached Figure Description
[0054] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on the structures shown in these drawings without creative effort.
[0055] Figure 1 A flowchart of the image processing method provided in the embodiments of this application;
[0056] Figure 2 This is a schematic diagram of the original image;
[0057] Figure 3 for Figure 2 The image shows the result of processing the original image using the image processing method provided in this application embodiment.
[0058] Figure 4 This is a structural block diagram of the image processing apparatus provided in the embodiments of this application;
[0059] Figure 5 A schematic diagram of an electronic device provided in an embodiment of this application.
[0060] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0061] The present application will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the relevant disclosure and not intended to limit the scope of the disclosure. Furthermore, it should be noted that, for ease of description, only the parts relevant to the disclosure are shown in the accompanying drawings.
[0062] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0063] The following describes an image processing method, apparatus, electronic device, and storage medium according to embodiments of the present invention, in conjunction with the accompanying drawings.
[0064] Figure 1 This is a flowchart of an image processing method according to an embodiment of the present invention. Figure 1 As shown, the image processing method of this invention includes the following steps:
[0065] S101: Obtain the original image and convert it to an HSV color space image.
[0066] Specifically, input an original image, referred to as the original image or src, and convert the color space of the original image src, that is, convert the original image src from the BGR color space (where B represents the blue channel, G represents the green channel, and R represents the red channel) to HSV (where H represents hue, S represents saturation, and V represents brightness).
[0067] Generally, images acquired in natural environments are easily affected by natural lighting, occlusion, and shadows, making them highly sensitive to brightness. The three components of the RGB color space are all closely related to brightness; that is, any change in brightness will cause a corresponding change in all three components, without a more intuitive way of representing this. However, the human eye's sensitivity to these three color components varies. In monochrome, the human eye is least sensitive to red and most sensitive to blue, making the RGB color space a color space with poor uniformity. If color similarity is directly measured using Euclidean distance, the result will deviate significantly from human visual perception. For a given color, it is difficult to deduce precise values for the three components. Therefore, this application first converts it to an HSV color space image. Subsequent processing of the HSV color space image can effectively improve the visual effect of the image.
[0068] Specifically, when performing color space conversion, the range of each channel in BGR should first be normalized to 32-bit floating-point numbers, meaning the value of each channel should range from 0 to 1. After this, the color of each pixel in the original image's src can be converted using the following formula:
[0069] V = max(R,G,B);
[0070] When V is not equal to 0, S = (V - min(R,G,B)) / V; when V = 0, S = 0.
[0071] If V = R, H = 60*(GB) / (V-min(R,G,B));
[0072] If V = G, H = 120 + 60 * (BR) / (V - min(R, G, B));
[0073] If V = R, H = 240 + 60*(RG) / (V - min(R,G,B)).
[0074] Thus, the HSV value of each pixel in the original image's src field is obtained, where the calculated H value ranges from 0 to 360, the S value ranges from 0 to 1, and the V value ranges from 0 to 1. After the above processing, the original image is converted into an image in the HSV color space. In the example of this application, the contrast and saturation of the image are optimized and improved. Therefore, the HSV image is first decomposed into three single-channel images, and then the S (saturation) channel image and the V (luminance) channel image are processed.
[0075] In the above description, the BGR color space is based on the three primary colors: red, green, and blue. The HSV color space, on the other hand, is based on hue, saturation, and brightness. Hue (H) refers to the color of light; for example, in a rainbow, red, orange, yellow, green, cyan, blue, and violet represent different hues. In OpenCV, hue values range from [0, 180]. For example, the hue values representing red, yellow, green, and blue are 0, 30, 60, and 120, respectively. Saturation (S) represents the lightness or darkness of a color. In OpenCV, saturation values range from [0, 255]. When saturation is 0, the image becomes a grayscale image. Brightness (V) refers to the lightness or darkness of light. Similar to saturation, in OpenCV, brightness values range from [0, 255]. The higher the brightness value, the brighter the image; when the brightness value is 0, the image is pure black.
[0076] S102: Obtain the histogram based on the pixel statistics of a single channel image in the HSV color space image.
[0077] Taking an S-channel image as an example, specifically, the histogram of the S-channel image is calculated, and the number of pixels at each order in the image is counted. Since the value range of an S-channel image is 0 to 255, the order in the image is divided into 256 levels (from order 0 to order 255). That is, for each pixel in the S-channel, if its corresponding value is represented as s, the number of pixels at the s-th order is incremented by one, and finally, the statistical histogram of the image is obtained.
[0078] S103: Obtain the total pixel distribution of the bright part and the total pixel distribution of the dark part of the single-channel image, the pixel mean of the single-channel image, and the highest and lowest order values in the histogram.
[0079] In a specific example, obtaining the total pixel distribution of the bright and dark parts of the single-channel image, the average pixel value of the single-channel image, and the highest and lowest order values in the histogram includes: obtaining the total pixel distribution of the bright and dark parts of the single-channel image based on the pixel value of each pixel in the single-channel image; obtaining the average pixel value of the single-channel image based on the number of pixels in the single-channel image and the pixel value of each pixel in the single-channel image; and searching from the lowest and highest order values of the histogram towards higher and lower order values, respectively, wherein the first non-zero order value is determined as the lowest and highest order values, respectively.
[0080] Taking the S-channel image as an example again, after obtaining the histogram, it is necessary to find the highest and lowest order values with non-zero statistical counts. Starting from the 0th and 255th order of the histogram, respectively, the search is extended to higher and lower orders. When the first order value with a non-zero statistical count is found, it is recorded as Min (the first non-zero lower order value) and Max (the first non-zero higher order value), respectively.
[0081] The total pixel distribution in the bright and dark areas is calculated and denoted as totalL and totalH, respectively, with an initial value of 0. For a given pixel location in the image, if the value is below 127 (inclusive), it is considered a dark pixel, and the value of totalL is incremented by one; if the value is above 127 (inclusive), it is considered a bright pixel, and the value of totalH is incremented by one. At this point, the total non-zero pixel value of the entire image, totalHist, equals total + totalH.
[0082] Calculate the pixel mean of the current single-channel image. This involves summing the values at each pixel location, then dividing by the total number of pixels in the image, denoted as meanV.
[0083] S104: Based on the total pixel distribution of the bright and dark parts of the single-channel image, the average pixel value of the single-channel image, and the highest and lowest order values in the histogram, the stretching ratio and the maximum stretching degree are obtained.
[0084] In a specific example, the stretching ratio and maximum stretching degree are obtained based on the total pixel distribution in the bright and dark areas of the single-channel image, the pixel mean of the single-channel image, and the highest and lowest order values in the histogram. This includes: determining the position ratio of the pixel mean in the histogram based on the pixel mean of the single-channel image, the highest and lowest order values in the histogram; determining the proportion of the largest portion of the total pixel distribution in the bright and dark areas based on the total pixel distribution in the bright and dark areas; obtaining the percentage of the pixel mean when it is located in the bright or dark area from the median order value based on the pixel mean of the single-channel image and the position ratio of the pixel mean in the histogram; obtaining the percentage of the highest or lowest order value based on the highest and lowest order values; and obtaining the stretching ratio and maximum stretching degree based on the percentage of the pixel mean when it is located in the bright or dark area from the median order value and the percentage of the highest or lowest order value.
[0085] In this example, obtaining the proportion of the highest or lowest order value based on the highest and lowest order values includes: obtaining a first distance from the lowest non-zero order in the histogram to the lowest order corresponding to the lowest order value; obtaining a second distance from the highest non-zero order in the histogram to the highest order corresponding to the highest order value; obtaining the maximum distance between the first and second distances; and obtaining the proportion of the highest or lowest order value based on the maximum distance.
[0086] In the above description, a single-channel image is an S-channel image, then:
[0087] The stretching ratio and maximum stretching degree are obtained based on the proportion of the average pixel value in the bright or dark region relative to the median value and the proportion of the highest or lowest value, using the following formula:
[0088] When totalL>totalH, ratio=abs(v1-v2)*tmp_v1; when Max>127.0, tmp_range=Max+min(Min,255.0-Max); when Max<=127.0, tmp_range=Max*(1.0+Max / 127.0).
[0089] When totalL <= totalH, if meanV < 127.0 and MaxRange < 0.6, ratio = abs(v1 - v2) * tmp_v1; when Max > 127.0, tmp_range = Max + min(Min, 255.0 - Max); when Max <= 127.0, tmp_range = Max * (1.0 + Max / 127.0); otherwise, ratio = 0.05 and tmp_range = 255.
[0090] In the above description, the single-channel image is a V-channel image, then:
[0091] The stretching ratio and maximum stretching degree are obtained based on the proportion of the average pixel value in the bright or dark region relative to the median value and the proportion of the highest or lowest value, using the following formula:
[0092] When totalL > totalH, ratio = max(v1, v2), tmp_range = 255;
[0093] When totalL <= totalH, when meanV < 127.0 && MaxRange < 0.6, ratio = max(v1,v2) and tmp_range = 255; otherwise, ratio = 0.05 and tmp_range = 255.
[0094] Wherein, totalL is the total number of pixels distributed in the dark area, totalH is the total number of pixels distributed in the bright area, ratio is the stretching ratio, v1 is the proportion of the average pixel value at the distance from the median of the order value when it is located in the bright or dark area, v2 is the proportion of the highest or lowest order value, Min is the lowest order value, Max is the highest order value, tmp_range is the maximum stretching degree, meanV is the average pixel value, and MaxRange is the proportion of the maximum portion of the total number of pixels distributed in the bright and dark areas.
[0095] Specifically, taking the S-channel image as an example, the proportion of the mean value in the histogram is calculated and denoted as (meanV-Min) / (Max-Min).
[0096] Calculate the proportion of the largest portion of the total pixel distribution in the bright and dark areas, denoted as MaxRange = max(totalL, totalH) / totalHist. Use MaxRange to analyze the high and low saturation (S) distribution of the entire image.
[0097] Let v1 = abs(meanV - 127.0) / 127.0. v1 is used to record the proportion of the mean value when it is located in the bright or dark area, and the distance from the middle value of the order value.
[0098] The formula v2 = max(Min, 255.0 - Max) / 255.0 is used to analyze the proportion of the maximum value of the lowest non-zero order distance and the highest non-zero order distance in the entire order value of the image. This allows us to analyze the range within which low saturation and high saturation can be stretched (increased or decreased).
[0099] The formula tmp_v1 = MaxRange - 0.5 is used to analyze the proportion of the larger portion of the statistics in the dark and bright areas.
[0100] Let tmp_range = 255, and use this as the maximum stretching degree after stretching the saturation. The stretching ratio is denoted as ratio. Based on the above calculations, the following judgments are made to obtain ratio and tmp_range, so as to calculate a new s value to replace the current value:
[0101] Formula 1: When totalL>totalH, ratio=abs(v1-v2)*tmp_v1; when Max>127.0, tmp_range=Max+min(Min,255.0-Max); when Max<=127.0, tmp_range=Max*(1.0+Max / 127.0).
[0102] When totalL <= totalH, and meanV < 127.0 && MaxRange < 0.6, the ratio and tmp_range are calculated as shown in Formula 1. In other cases, ratio = 0.05 and tmp_range = 255.
[0103] Taking the V channel as an example, tmp_range = 255, which is used as the maximum stretching degree after brightness stretching (to enhance contrast). The stretching ratio is denoted as ratio. Based on the above calculations, the following judgment is made to obtain ratio and tmp_range, so as to calculate a new v value to replace the current value.
[0104] Formula 2: When totalL > totalH, ratio = max(v1,v2), tmp_range = 255.
[0105] When totalL <= totalH, and meanV < 127.0 && MaxRange < 0.6, the ratio and tmp_range are calculated as shown in Formula 2. In other cases, ratio = 0.05 and tmp_range = 255.
[0106] It should be noted that, to prevent excessive contrast stretching from causing color cast, the stretching ratio and maximum stretching degree can be corrected based on the stretching ratio and maximum stretching degree before obtaining the target image of the original image based on the corrected single-channel image. Specifically, after calculating the ratio and tmp_range of the S and V channels respectively, the following subsequent calculations are required:
[0107] 1) Constrain tmp_range, i.e. tmp_range = min(tmp_range, 255);
[0108] 2) Constrain the ratio, i.e., ratio = min(tmp + ratio * tmp, 1.0f);
[0109] 3) Calculate Gamma=log(ratio) / log(tmp), Gamma=max(0.8f,Gamma).
[0110] S105: Based on the stretching ratio and maximum stretching degree, the single-channel image is corrected, and the target image of the original image is obtained based on the corrected single-channel image.
[0111] That is: after the constraints are completed, calculate the new s and v values:
[0112] Among them, s_new=pow((s_old-MinS) / (MaxS-MinS),GammaS)*tmp_rangeS;
[0113] Where, v_new=pow((v_old-MinV) / (MaxV-MinV),GammaV)*tmp_rangeV.
[0114] Wherein, s_new is the corrected value of the S-channel image, v_new is the corrected value of the V-channel image, s_old is the original value of the S-channel image, v_old is the original value of the V-channel image, S refers to the S-channel image, and V refers to the V-channel image.
[0115] Finally, the newly calculated single-channel images of s and v are combined with the unmodified h channel to form a BGR channel image, thus obtaining the target image with enhanced contrast and saturation.
[0116] It should be noted that if processing video, the first frame can be processed according to steps S101 to S105 above to obtain the new parameters s and v. Then, these two parameters can be applied to each subsequent frame to obtain each frame image with enhanced contrast and saturation.
[0117] like Figure 2 The image shown is a schematic diagram of the original image. Figure 3 As shown, Figure 2 The image shown is an example of the original image enhanced in contrast and saturation using the method described in this embodiment of the invention. Figure 2 and Figure 3 By comparison, it is clear that the image quality is significantly improved and has a better visual effect after processing by the method of the present invention.
[0118] According to the image processing method of the present invention, the original image is converted into an HSV color space image, and then the saturation single-channel image and the luminance single-channel image in the HSV color space image are enhanced. That is, the image quality is enhanced by improving the contrast and saturation. In particular, it has a better enhancement effect on low-contrast and low-saturation images obtained by shooting, which significantly improves the image quality and provides a better visual experience.
[0119] Figure 4 This is a structural block diagram of an image processing apparatus according to an embodiment of the present invention. Figure 4 As shown, the image processing apparatus of this embodiment includes: a first conversion module 410, a histogram generation module 420, an acquisition module 430, a correction value determination module 440, and a correction module 450, wherein:
[0120] The first conversion module 410 is used to convert the original image into an HSV color space image;
[0121] The histogram generation module 420 is used to obtain a histogram based on the pixel statistics of a single channel image in the HSV color space image;
[0122] The acquisition module 430 is used to obtain the total pixel distribution of the bright part and the total pixel distribution of the dark part of the single-channel image, the pixel mean of the single-channel image, and the highest and lowest order values in the histogram.
[0123] The correction value determination module 440 is used to obtain the stretching ratio and the maximum stretching degree based on the total pixel distribution of the bright part and the total pixel distribution of the dark part of the single-channel image, the pixel mean of the single-channel image, and the highest and lowest order values in the histogram.
[0124] The correction module 450 is used to correct the single-channel image based on the stretching ratio and the maximum stretching degree, and to obtain the target image of the original image based on the corrected single-channel image.
[0125] According to the image processing apparatus of the present invention, the original image is converted into an HSV color space image, and then the saturation single-channel image and the luminance single-channel image in the HSV color space image are enhanced. That is, the image quality is enhanced by improving the contrast and saturation. In particular, it has a better enhancement effect on low-contrast and low-saturation images obtained by shooting, which significantly improves the image quality and provides a better visual experience.
[0126] It should be noted that the specific implementation of the image processing device in this embodiment of the invention is similar to the specific implementation of the image processing method in this embodiment of the invention. Please refer to the description in the method section for details, which will not be repeated here.
[0127] Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application.
[0128] like Figure 5 As shown, the electronic device 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from the storage section 702 into a random access memory (RAM) 703. The RAM 703 also stores various programs and data required for the operation of the electronic device 700. The CPU 701, ROM 702, and RAM 703 are interconnected via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0129] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, mouse, etc.; an output section 707 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 710 as needed so that computer programs read from it can be installed into the storage section 708 as needed.
[0130] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a machine-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 709, and / or installed from removable medium 711. When the computer program is executed by central processing unit (CPU) 701, it performs the functions defined in the electronic device of this application.
[0131] It should be noted that the computer-readable medium shown in this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electronic device, apparatus, or device that is electrical, magnetic, optical, electromagnetic, infrared, or semiconductor, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an electronic device, apparatus, or device that executes instructions. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit programs for use by or in connection with an electronic device, apparatus, or device whose instructions are executed. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0132] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of processing and receiving devices, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based electronic device that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0133] The units or modules described in the embodiments of this application can be implemented in software or hardware. The described units or modules can also be housed in a processor, which executes the program to implement the image processing method: acquiring an original image and converting it into an HSV color space image; obtaining a histogram based on pixel statistics of a single channel image in the HSV color space image; obtaining the total pixel distribution of bright and dark areas in the single channel image, the average pixel value of the single channel image, and the highest and lowest order values in the histogram; obtaining a stretching ratio and a maximum stretching degree based on the total pixel distribution of bright and dark areas in the single channel image, the average pixel value of the single channel image, and the highest and lowest order values in the histogram; correcting the single channel image based on the stretching ratio and the maximum stretching degree, and obtaining the target image of the original image based on the corrected single channel image.
[0134] In another aspect, this application also provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiments; or it may exist independently and not assembled into the electronic device. The aforementioned computer-readable storage medium stores one or more programs, which, when used by one or more processors, execute the image processing method described in this application: acquiring an original image and converting the original image into an HSV color space image; obtaining a histogram based on pixel statistics of a single-channel image in the HSV color space image; obtaining the total pixel distribution of bright and dark areas of the single-channel image, the average pixel value of the single-channel image, and the highest and lowest order values in the histogram; obtaining a stretching ratio and a maximum stretching degree based on the total pixel distribution of bright and dark areas of the single-channel image, the average pixel value of the single-channel image, and the highest and lowest order values in the histogram; correcting the single-channel image based on the stretching ratio and the maximum stretching degree, and obtaining a target image of the original image based on the corrected single-channel image.
[0135] In another aspect, this application also provides a computer program product, which may be included in the electronic device described in the above embodiments; or it may exist independently and not assembled into the electronic device. The computer program product stores one or more programs, which, when used by one or more processors, execute the image processing method described in this application: acquiring an original image and converting the original image into an HSV color space image; obtaining a histogram based on pixel statistics of a single-channel image in the HSV color space image; obtaining the total pixel distribution of bright and dark areas of the single-channel image, the average pixel value of the single-channel image, and the highest and lowest order values in the histogram; obtaining a stretching ratio and a maximum stretching degree based on the total pixel distribution of bright and dark areas of the single-channel image, the average pixel value of the single-channel image, and the highest and lowest order values in the histogram; correcting the single-channel image based on the stretching ratio and the maximum stretching degree, and obtaining a target image of the original image based on the corrected single-channel image.
[0136] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the foregoing disclosed concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this application.
Claims
1. An image processing method, characterized in that, include: Acquire the original image and convert it into an HSV color space image; A histogram is obtained based on the pixel statistics of a single channel image in the HSV color space image; Obtain the total pixel distribution of the bright part and the total pixel distribution of the dark part of the single-channel image, the pixel mean of the single-channel image, and the highest and lowest order values in the histogram; Based on the pixel mean of the single-channel image, the highest-order value and the lowest-order value in the histogram, determine the position ratio of the pixel mean in the histogram; Based on the total pixel distribution of the bright areas and the total pixel distribution of the dark areas, determine the proportion of the largest portion of the total pixel distribution of the bright areas and the dark areas; Based on the pixel mean of the single-channel image and the position ratio of the pixel mean in the histogram, the proportion of the pixel mean in the distance to the middle value of the order value when it is located in the bright or dark area is obtained. Based on the highest and lowest order values, the proportion of the highest or lowest order value is obtained; Based on the proportion of the average pixel value at the distance from the median value when it is located in the bright or dark area, and the proportion of the highest or lowest value, the stretching ratio and the maximum stretching degree are obtained. and Based on the stretching ratio and maximum stretching degree, the single-channel image is corrected, and the target image of the original image is obtained based on the corrected single-channel image.
2. The image processing method according to claim 1, characterized in that, Obtaining the total pixel distribution of the bright areas and the total pixel distribution of the dark areas of the single-channel image, the pixel mean of the single-channel image, and the highest and lowest order values in the histogram includes: Based on the pixel value of each pixel in the single-channel image, the total pixel distribution of the bright part and the total pixel distribution of the dark part of the single-channel image are obtained. The average pixel value of the single-channel image is obtained based on the number of pixels in the single-channel image and the pixel value of each pixel in the single-channel image. Starting from the minimum and maximum order of the histogram, the search proceeds towards higher and lower order directions, respectively. When the first non-zero order value is found, it is determined as the lowest and highest order values, respectively.
3. The image processing method according to claim 2, characterized in that, The step of obtaining the proportion of the highest-order value or the lowest-order value based on the highest-order value and the lowest-order value includes: Obtain the lowest non-zero order distance in the histogram, corresponding to the lowest order value, and the first distance of the lowest order. Obtain the second distance of the highest order corresponding to the highest non-zero order distance in the histogram, which is the highest order value. Obtain the maximum distance between the first distance and the second distance; Based on the maximum distance, the proportion of the highest or lowest order value is obtained.
4. The image processing method according to claim 3, characterized in that, If the single-channel image is an S-channel image, then: The stretching ratio and maximum stretching degree are obtained based on the proportion of the average pixel value in the bright or dark region relative to the median value and the proportion of the highest or lowest value, using the following formula: When totalL>totalH, ratio=abs(v1-v2)*tmp_v1; when Max>127.0, tmp_range=Max+min(Min,255.0-Max); when Max<=127.0, tmp_range=Max*(1.0+Max / 127.0). When totalL <= totalH, if meanV < 127.0 and MaxRange < 0.6, ratio = abs(v1 - v2) * tmp_v1; when Max > 127.0, tmp_range = Max + min(Min, 255.0 - Max); when Max <= 127.0, tmp_range = Max * (1.0 + Max / 127.0); otherwise, ratio = 0.05 and tmp_range = 255. If the single-channel image is a V-channel image, then: The stretching ratio and maximum stretching degree are obtained based on the proportion of the average pixel value in the bright or dark region relative to the median value and the proportion of the highest or lowest value, using the following formula: When totalL > totalH, ratio = max(v1, v2), tmp_range = 255; When totalL <= totalH, when meanV < 127.0 && MaxRange < 0.6, ratio = max(v1,v2) and tmp_range = 255; otherwise, ratio = 0.05 and tmp_range = 255. Wherein, totalL is the total number of pixels distributed in the dark area, totalH is the total number of pixels distributed in the bright area, ratio is the stretching ratio, v1 is the proportion of the average pixel value at the distance from the median of the order value when it is located in the bright or dark area, v2 is the proportion of the highest or lowest order value, Min is the lowest order value, Max is the highest order value, tmp_range is the maximum stretching degree, meanV is the average pixel value, and MaxRange is the proportion of the maximum portion of the total number of pixels distributed in the bright and dark areas.
5. The image processing method according to claim 1, characterized in that, Before correcting the single-channel image based on the stretching ratio and maximum stretching degree, and obtaining the target image of the original image based on the corrected single-channel image, the method further includes: imposing the following constraints on the stretching ratio and maximum stretching degree: tmp_range=min(tmp_range, 255); ratio=min(tmp+ratio*tmp,1.0f); Calculate Gamma=log(ratio) / log(tmp), Gamma=max(0.8f,Gamma).
6. The image processing method according to claim 5, characterized in that, The single-channel image is corrected based on the stretching ratio and the maximum stretching degree, and is obtained in the following way: s_new=pow((s_old-MinS) / (MaxS-MinS),GammaS)*tmp_rangeS; v_new=pow((v_old-MinV) / (MaxV-MinV),GammaV)*tmp_rangeV, Where s_new is the corrected value of the S-channel image, v_new is the corrected value of the V-channel image, s_old is the original value of the S-channel image, v_old is the original value of the V-channel image, S refers to the S-channel image, and V refers to the V-channel image.
7. An image processing apparatus, characterized in that, include: The first conversion module is used to acquire the original image and convert the original image into an HSV color space image; The histogram generation module is used to obtain a histogram based on the pixel statistics of a single channel image in the HSV color space image; The acquisition module is used to obtain the total pixel distribution of the bright part and the total pixel distribution of the dark part of the single-channel image, the pixel mean of the single-channel image, and the highest and lowest order values in the histogram; The correction value determination module is used to determine the position ratio of the pixel mean in the histogram based on the pixel mean of the single-channel image, the highest order value and the lowest order value in the histogram; Based on the total pixel distribution of the bright areas and the total pixel distribution of the dark areas, determine the proportion of the largest portion of the total pixel distribution of the bright areas and the dark areas; Based on the pixel mean of the single-channel image and the position ratio of the pixel mean in the histogram, the proportion of the pixel mean in the distance to the middle value of the order value when it is located in the bright or dark area is obtained. Based on the highest and lowest order values, the proportion of the highest or lowest order value is obtained; Based on the proportion of the average pixel value at the distance from the median value when it is located in the bright or dark area, and the proportion of the highest or lowest value, the stretching ratio and the maximum stretching degree are obtained. The correction module is used to correct the single-channel image based on the stretching ratio and the maximum stretching degree, and to obtain the target image of the original image based on the corrected single-channel image.
8. An electronic device, characterized in that, The device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the image processing method according to any one of claims 1-6.
9. A computer-readable storage medium having a computer program stored thereon for implementing the image processing method according to any one of claims 1-6.