A histogram equalization method
By analyzing the non-zero histogram type of Y component data of color images, determining the correction parameters and platform values, and performing platform histogram equalization processing, solving the problem of large color difference in color image processing, and achieving the equalization effect of detail enhancement and color difference reduction.
Patent Information
- Application Number
- CN202111545468.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-16
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2041-12-16
AI Technical Summary
In color image processing, traditional platform histogram equalization method will lead to large chromatic aberration, making it difficult to reduce chromatic aberration on the basis of enhancing image details.
By analyzing the non-zero histogram type of the Y component data of the color image, the correction parameter x is determined, and the appropriate platform value and correction histogram are calculated based on this parameter, and the platform histogram equalization is performed to reduce the color difference and enhance the contrast.
On the basis of ensuring the enhancement of color images details, it can reduce the color aberration and achieve the balance of contrast enhancement effect, avoiding the problem of excessive color aberration in traditional methods.
Smart Images

Figure CN114283098B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing, and in particular to a histogram equalization method. Background Art
[0002] Histogram equalization is used to enhance the contrast of images with a small dynamic range, thereby rebalancing the grayscale values of the image. Based on this method, some scholars proposed platform histogram equalization, which processes the grayscale of the histogram of the original image through the platform value T, that is, the grayscale that exceeds the platform value T is directly modified to the platform value T, and the grayscale that does not exceed is not processed, so that the modified histogram is equalized, thereby enhancing the detail information of the image.
[0003] At present, the selection of platform value mainly adopts the adaptive platform value selection method. This method has a good effect in grayscale image processing. It can avoid the overall brightness being too smooth while ensuring the enhancement of contrast. However, when processing color images, the three channels of the color image are subjected to platform histogram equalization processing separately, which will result in a large color cast phenomenon, that is, a large color difference.
[0004] Therefore, how to reduce chromatic aberration while enhancing color image details has become an urgent problem to be solved. Summary of the invention
[0005] The present application provides a histogram equalization method, which can reduce chromatic aberration on the basis of enhancing color image details, and achieve a balance between chromatic aberration reduction and histogram enhancement effects.
[0006] In view of the above problems, the present application provides a histogram equalization method, including:
[0007] Acquire first color image data in a YUV format, wherein the first color image data includes Y component data, U component data, and V component data;
[0008] Obtaining an original histogram according to the Y component data;
[0009] Obtaining a non-zero histogram according to the original histogram, wherein the number of occurrences of grayscale values in the non-zero histogram is not 0;
[0010] Determining whether the type of the non-zero histogram is a unimodal histogram or a multimodal histogram;
[0011] The correction parameter x is determined according to the type of the non-zero histogram. If it is a unimodal histogram, 0.6≤x<1; if it is a multimodal histogram, 0 <x<0.6;
[0012] determining a platform value according to the correction parameter and the non-zero histogram;
[0013] Determining a corrected histogram according to the correction parameter and the original histogram, wherein the number of occurrences of the same grayscale value in the corrected histogram is greater than the number of occurrences in the original histogram;
[0014] Processing the corrected histogram using the platform value to obtain a platform histogram;
[0015] The platform histogram is equalized to obtain second color image data in a YUV format, and the second color image data is converted into third color image data in an RGB format.
[0016] Optionally, determining whether the type of the non-zero histogram is a unimodal histogram or a multimodal histogram includes:
[0017] Determine the maximum value Fm of the number of occurrences of the non-zero histogram grayscale value, and the grayscale value dm corresponding to Fm;
[0018] Determine the number of points z whose grayscale value in the non-zero histogram differs from dm by more than the first threshold and whose corresponding times are greater than y times Fm, where 0 <y<1;
[0019] If z is 0, then the type of the non-zero histogram is a unimodal histogram;
[0020] If z is greater than 0, then the type of the non-zero histogram is a multimodal histogram.
[0021] Optionally, determining the platform value according to the correction parameter and the non-zero histogram includes:
[0022] Determine an extreme point of the non-zero histogram, wherein the extreme point is a point where the number of occurrences of the grayscale value is greater than that of the left adjacent value and the right adjacent value;
[0023] Sum the number of occurrences of the grayscale values corresponding to all extreme value points of the non-zero histogram and calculate the average value, which is the platform value to be corrected;
[0024] The product of the correction parameter and the platform value to be corrected is taken as the platform value.
[0025] Optionally, determining the corrected histogram according to the correction parameter and the original histogram includes:
[0026] Comparing the number of occurrences of each gray value in the original histogram with the size of the platform value to be corrected;
[0027] Calculate the difference between the number of occurrences greater than the platform value to be corrected and the platform value to be corrected, and sum up all the differences to obtain Tsum;
[0028] Modify Tsum using the modification parameter;
[0029] The number of occurrences of each gray value in the original histogram is superimposed on the corrected Tsum to obtain a corrected histogram.
[0030] Optionally, the using the correction parameter to correct Tsum includes:
[0031] Use the correction parameter to correct Tsum according to the following formula:
[0032] Tsum1=Tsum×(1-x) / 256
[0033] Among them, Tsum1 is the corrected Tsum.
[0034] Optionally, determining the correction parameter x according to the type of the non-zero histogram includes:
[0035] The non-zero histogram is a unimodal histogram, and the correction parameter x is 0.75;
[0036] The non-zero histogram is a multi-peak histogram, and the correction parameter x is 0.5.
[0037] Optionally, the first threshold is 10.
[0038] Optionally, y is 0.8.
[0039] Optionally, the acquiring a non-zero histogram according to the original histogram includes:
[0040] Acquire a non-zero histogram to be filtered according to the original histogram;
[0041] Performing median filtering on the non-zero histogram to be filtered to obtain a non-zero histogram.
[0042] Optionally, the using the platform value to process the modified histogram to obtain a platform histogram includes:
[0043] Comparing the platform value with the number of occurrences of each gray value in the corrected histogram;
[0044] If the number of occurrences of the grayscale value in the modified histogram is greater than the platform value, the number of occurrences corresponding to the grayscale value is modified to the platform value to obtain a platform histogram.
[0045] It can be seen from the above embodiments that in a histogram equalization method provided by the present application, by processing only the Y component data (i.e., brightness data) of the color image, while ensuring the originality of the color data as much as possible, the brightness details of the image are enhanced and the color difference is reduced. Specifically, by analyzing the type of the non-zero histogram of the Y component data of the color image, whether it is a unimodal histogram or a multimodal histogram, and then using the correction parameter, a suitable platform value and a corrected histogram are obtained. If it is a unimodal histogram, it is judged that the color of the current image is relatively single, and it is necessary to perform contrast enhancement while ensuring that the color difference is small enough, so as to select a larger correction parameter; if it is a multimodal histogram, it is judged that the current image is relatively complex, and the contrast enhancement effect is improved by reducing the correction parameter. Finally, a platform histogram is obtained using a suitable platform value and a corrected histogram, and the platform histogram is equalized to obtain the final color image data. After the above processing, the improved platform histogram equalization can be performed by obtaining the characteristics of the color image, and the contrast enhancement of the color image is completed while ensuring that the color difference is small enough. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the embodiments are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0047] Figure 1 is a schematic flow chart of a histogram equalization method provided according to some embodiments;
[0048] Figure 2 It is a comparison diagram of the Y domain histogram before and after processing using the method of the present application. DETAILED DESCRIPTION
[0049] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present application.
[0050] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.
[0051] Histogram equalization is a method used to enhance the contrast of images with a small dynamic range and rebalance the grayscale values of the image. It mainly changes the pixel grayscale values of the image by changing the original histogram of the image, transforming the histogram of the original image into a uniform distribution, increasing the overall dynamic range of the image, and thus enhancing the contrast of the original image.
[0052] However, traditional histogram equalization only stretches the image pixel values uniformly. After processing, the image details are not obvious and the overall brightness is too smooth. Therefore, some scholars have proposed a platform histogram equalization algorithm based on this. Platform histogram equalization mainly adds a platform value T on the basis of the original histogram equalization. After counting the histogram of the original image, the grayscale that exceeds the platform value is directly modified to the platform value, and the grayscale that does not exceed the platform value is not processed. Then the modified histogram is equalized, and finally the image is redistributed using the redistributed histogram.
[0053] The selection of a suitable platform value determines the quality of the final image processing effect. Currently, the selection of platform values is mostly based on the experience of experimenters and is relatively random. The existing method for selecting adaptive platform values is mainly for grayscale images. This method of selecting platform values has a good effect in grayscale image processing, which can ensure enhanced contrast while avoiding excessive smoothness of the overall brightness. However, when processing color images, a large color cast will occur when the three channels of the color image are subjected to platform histogram equalization processing separately. This application tests the method by processing the original color image according to the three channels separately and selecting the platform value according to the existing adaptive method. The result is that although the contrast enhancement effect is good, obvious color difference occurs.
[0054] Regarding how to reduce chromatic aberration while enhancing color image details, and achieve a balanced effect of chromatic aberration size and contrast enhancement effect, this application proposes the following solution.
[0055] Figure 1 is a schematic flow chart of a histogram equalization method provided according to some embodiments. Figure 1 The histogram equalization method of the present application is described below.
[0056] S10, acquiring first color image data in a YUV format, where the first color image data includes Y component data, U component data, and V component data.
[0057] In one example, first color image data in YUV format is obtained according to color image data in RGB format, as shown in formula (1):
[0058] Y=0.299·R+0.587·G+0.144·B
[0059] U=0.713·(RY)+128
[0060] V=0.564·(BY)+128 (1)
[0061] The image is converted from the RGB display domain to the YUV display domain and then processed to reduce the color difference.
[0062] S11, obtaining an original histogram according to the Y component data.
[0063] The Y component data is brightness data. The grayscale value of the original histogram obtained according to the Y component data is 0 to 255. Each grayscale value in the original histogram has its corresponding number of occurrences, regardless of whether the number is 0.
[0064] S12, obtaining a non-zero histogram according to the original histogram, wherein the number of occurrences of grayscale values in the non-zero histogram is not zero.
[0065] In one example, the part of the original image histogram where the number of grayscale values appears is not zero is counted, which is denoted as F. The size of each element in F is the number of times each grayscale value appears in the entire image, and F is a one-dimensional matrix. For example, F is [25, 36, 66, 77], where 25 is the number of times the grayscale value 125 appears in the image, 36 is the number of times the grayscale value 147 appears in the image, 66 is the number of times the grayscale value 160 appears in the image, 77 is the number of times the grayscale value 250 appears in the image, and the number of times the remaining grayscale values appear in the image is 0.
[0066] Optionally, F is smoothed, for example, by performing a 1×3 median filter, and the matrix after filtering is recorded as Fmed.
[0067] It should be noted that the histogram in the present application can be in the form of a bar graph with the horizontal axis being the grayscale value and the vertical axis being the number of occurrences, or it can be in the form of a one-dimensional matrix, where the elements in the matrix are the number of occurrences of the grayscale value in the image.
[0068] By adopting the above method, by obtaining a non-zero histogram, invalid points whose gray value occurrence times are 0 are eliminated, which is conducive to subsequent efficient processing of the histogram.
[0069] S13, determining whether the type of the non-zero histogram is a unimodal histogram or a multimodal histogram.
[0070] In one example, the type of the non-zero histogram is determined by performing the following processing on the non-zero histogram. Specifically, the following steps are included:
[0071] Step a, determining the maximum value Fm of the number of occurrences of the non-zero histogram grayscale value, and the grayscale value dm corresponding to Fm;
[0072] Step b, determining the number z of points in the non-zero histogram whose grayscale value and dm have a difference greater than a first threshold and whose corresponding number is greater than y times Fm, where 0 <y<1;
[0073] Step c: if z is 0, then the type of the non-zero histogram is a unimodal histogram; if z is greater than 0, then the type of the non-zero histogram is a multimodal histogram.
[0074] Optionally, the first threshold is 10.
[0075] Optionally, y is 0.8.
[0076] The following uses Fmed as an example to illustrate the above example:
[0077] Calculate the maximum value Fm1 of the number of occurrences of the gray value in Fmed, and the gray value corresponding to Fm1 is dm1;
[0078] Find the number of points in the entire histogram whose difference with dm1 is greater than 10 and whose corresponding times are greater than 0.8Fm1;
[0079] If the number of outputs is 0, it is a unimodal histogram. If the number of outputs is greater than 0, it is a multimodal histogram.
[0080] In an example, the type of the non-zero histogram can also be determined by connecting the vertices of each column in the histogram to form a curve. If the curve has one peak, it is a unimodal histogram; if the curve has multiple peaks, it is a multimodal histogram.
[0081] S14, determining a correction parameter x according to the type of the non-zero histogram, if it is a unimodal histogram, 0.6≤x<1, if it is a multimodal histogram, 0 <x<0.6。
[0082] In one example, if it is a unimodal histogram, the correction parameter x=0.75, and if it is a multimodal histogram, the correction parameter x=0.5.
[0083] In the above method, whether the type of histogram is a unimodal histogram or a multimodal histogram reflects whether the color of the original color image is relatively simple or relatively complex. Different correction parameters are selected according to the type of histogram. If the color is relatively simple, the correction parameters need to be used to enhance the contrast while ensuring that the color difference is small enough. If the color is relatively complex, the correction parameters need to be used to improve the contrast enhancement effect.
[0084] S15, determining a platform value according to the correction parameter and the non-zero histogram.
[0085] In one example, the extreme point of the non-zero histogram is determined, and the extreme point is a point where the number of occurrences of the grayscale value is greater than the left adjacent value and the right adjacent value; the number of occurrences of the grayscale values corresponding to all extreme points of the non-zero histogram are summed, and the average value is calculated, and the average value is the platform value to be corrected; the product of the correction parameter and the platform value to be corrected is used as the platform value.
[0086] Take Fmed as an example to illustrate the above example, find the extreme value in Fmed, record it as Fex, and the elements in Fex are the number of occurrences of gray values;
[0087] Then, sum up all the elements in Fex and calculate the mean value. The obtained parameter is the platform value Torigin to be corrected.
[0088] Calculate the platform value Tnew after processing using the correction parameter x, Tnew = Torigin*x.
[0089] In one example, the plateau value is the product of the correction parameter and the maximum value Fm in the non-zero histogram.
[0090] S16, determining a modified histogram according to the correction parameter and the original histogram, wherein the number of occurrences of the same gray value in the modified histogram is greater than the number of occurrences in the original histogram.
[0091] In one example, the number of occurrences of each grayscale value in the original histogram is compared with the size of the platform value to be corrected; the difference between the number of occurrences greater than the platform value to be corrected and the platform value to be corrected is calculated, and all differences are summed up to obtain Tsum; Tsum is corrected using the correction parameter; the number of occurrences of each grayscale value in the original histogram is superimposed on the corrected Tsum to obtain a corrected histogram Fnew.
[0092] Optionally, using the correction parameter to correct Tsum includes: using the correction parameter to correct Tsum according to the following formula (2):
[0093] Tsum1=Tsum×(1-x) / 256 (2)
[0094] Among them, Tsum1 is the corrected Tsum.
[0095] By adopting the above method, the area greater than the platform value is not directly discarded, but evenly added to each gray level of the original histogram. Compared with the background technology in which the gray level exceeding the platform value is directly modified to the platform value after the histogram of the original image is statistically analyzed, which causes obvious whitening of local details and large color difference, the present application can achieve a balance between the color difference size and the histogram enhancement effect.
[0096] In an example, the median Fmid of the number of occurrences of the grayscale values in the original histogram is determined, and the number of occurrences of each grayscale value in the original histogram is compared with Fmid; the difference between the number of occurrences greater than Fmid and Fmid is calculated, and all differences are summed up to obtain Tsum1; Tsum1 is corrected using the correction parameter; the number of occurrences of each grayscale value in the original histogram is superimposed on the corrected Tsum1 to obtain a corrected histogram Fnew1.
[0097] S17, using the platform value to process the corrected histogram to obtain a platform histogram.
[0098] In one example, the platform value is compared with the number of occurrences of each grayscale value in the modified histogram; if the number of occurrences of the grayscale value in the modified histogram is greater than the platform value, the number of occurrences corresponding to the grayscale value is modified to the platform value to obtain a platform histogram.
[0099] Taking Tnew and Fnew as examples, the platform histogram P is obtained according to the following formula (3): T (k):
[0100]
[0101] Among them, P(k) is the number of occurrences of gray value k in the modified histogram Tnew, and k is the gray value.
[0102] S18, performing equalization processing on the platform histogram to obtain second color image data in a YUV format, and converting the second color image data into third color image data in an RGB format.
[0103] Specifically, after the platform histogram is equalized, each gray level will be rearranged, and each gray level will correspond to a new gray level. Using this gray level mapping relationship, the gray levels of the original image are redistributed. Finally, the image is converted from the YUV domain back to the RGB domain. The conversion formula is as follows:
[0104] R=Y+1.403·(U-128)
[0105] G=Y-0.344·(U-128)-0.714·(V-128)
[0106] B=Y+1.773·(V-128) (4)
[0107] It can be seen from the above embodiments that the method proposed in the present application determines the type of color image by calculating the type of histogram, and uses correction parameters to process different parameters according to different image characteristics. If it is a unimodal histogram, it is judged that the current image color is relatively simple, and it is necessary to perform contrast enhancement while ensuring that the color difference is small enough; if it is a multi-modal histogram, it is judged that the current image is relatively complex, and the contrast enhancement effect is improved by increasing the correction parameters. After the above processing, the improved platform histogram equalization can be performed by obtaining the characteristics of the color image, and the contrast enhancement of the color image is completed while ensuring that the color difference is small enough.
[0108] Effect Description
[0109] Figure 2 This is a comparison of the Y domain histograms before and after the processing using the method of the present application. Figure 2 It can be seen that after being processed by the method of the present application, the number of occurrences of the low gray value area (gray value 100-gray value 150) is increased, and the details of the low gray value part are enhanced (that is, the dark details of the image are enhanced). At the same time, since only the Y domain brightness data is corrected and the color data is not changed, a balance is achieved between enhancing details and reducing color differences.
[0110] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0111] The above description is only a partial implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A histogram equalization method, characterized in that: include: Acquire first color image data in a YUV format, wherein the first color image data includes Y component data, U component data, and V component data; Obtaining an original histogram according to the Y component data; Obtaining a non-zero histogram according to the original histogram, wherein the number of occurrences of grayscale values in the non-zero histogram is not 0; Determining whether the type of the non-zero histogram is a unimodal histogram or a multimodal histogram; The correction parameter x is determined according to the type of the non-zero histogram. If it is a unimodal histogram, 0.6≤x<1; if it is a multimodal histogram, 0 <x<0.6; Determine an extreme point of the non-zero histogram, wherein the extreme point is a point where the number of occurrences of the grayscale value is greater than that of the left adjacent value and the right adjacent value; Sum the number of occurrences of the grayscale values corresponding to all extreme value points of the non-zero histogram and calculate the average value, which is the platform value to be corrected; Taking the product of the correction parameter and the platform value to be corrected as the platform value; Comparing the number of occurrences of each gray value in the original histogram with the size of the platform value to be corrected; Calculate the difference between the number of occurrences greater than the platform value to be corrected and the platform value to be corrected, and sum up all the differences to obtain Tsum; Modify Tsum using the modification parameter; The number of occurrences of each gray value in the original histogram is superimposed on the corrected Tsum to obtain a corrected histogram; Processing the corrected histogram using the platform value to obtain a platform histogram; The platform histogram is equalized to obtain second color image data in a YUV format, and the second color image data is converted into third color image data in an RGB format.
2. The method according to claim 1, characterized in that The determining whether the type of the non-zero histogram is a unimodal histogram or a multimodal histogram comprises: Determine the maximum value Fm of the number of occurrences of the non-zero histogram grayscale value, and the grayscale value dm corresponding to Fm; Determine the number of points z whose grayscale value in the non-zero histogram differs from dm by more than the first threshold and whose corresponding times are greater than y times Fm, where 0 <y<1; If z is 0, then the type of the non-zero histogram is a unimodal histogram; If z is greater than 0, then the type of the non-zero histogram is a multimodal histogram.
3. The method according to claim 1, characterized in that The using the correction parameter to correct Tsum includes: Use the correction parameter to correct Tsum according to the following formula: Tsum1=Tsum×(1-x) / 256 Among them, Tsum1 is the corrected Tsum.
4. The method according to claim 1, characterized in that: The determining of the correction parameter x according to the type of the non-zero histogram comprises: The non-zero histogram is a unimodal histogram, and the correction parameter x is 0.75; The non-zero histogram is a multi-peak histogram, and the correction parameter x is 0.
5.
5. The method according to claim 2, characterized in that: The first threshold is 10.
6. The method according to claim 2, characterized in that The y is 0.
8.
7. The method according to claim 1, characterized in that The step of obtaining a non-zero histogram according to the original histogram comprises: Acquire a non-zero histogram to be filtered according to the original histogram; Performing median filtering on the non-zero histogram to be filtered to obtain a non-zero histogram.
8. The method according to claim 1, characterized in that The using the platform value to process the modified histogram to obtain a platform histogram includes: Comparing the platform value with the number of occurrences of each gray value in the corrected histogram; If the number of occurrences of the grayscale value in the modified histogram is greater than the platform value, the number of occurrences corresponding to the grayscale value is modified to the platform value to obtain a platform histogram.
Citation Information
Patent Citations
Adaptive double-platform based infrared image enhancement method
CN102693531A
Gamma correction and smoothing filtering based image histogram equalization enhancing method
CN104700376A