A detail-preserving histogram equalization method
By using block processing and histogram redistribution, combined with a preset fusion weight curve to weight the mapping function, the problem of detail loss in bright and dark areas in traditional histogram equalization methods is solved, achieving a balance between contrast enhancement and detail preservation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HEFEI JUNZHENG TECH CO LTD
- Filing Date
- 2024-12-19
- Publication Date
- 2026-06-23
AI Technical Summary
Traditional histogram equalization methods, while enhancing image contrast, result in the loss of details in both bright and dark areas, failing to effectively protect the visual details of the image.
A histogram equalization method using block processing is adopted. By calculating the clipping threshold and redistributing the histogram, and combining it with a preset fusion weight curve, the mapping function is weighted to avoid over-enhancement of bright and dark areas.
It effectively improves image contrast while preserving details in both bright and dark areas, avoiding the loss of details that occurs in traditional methods.
Smart Images

Figure CN122265046A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of image processing technology, and specifically relates to a histogram equalization method based on preserving details. Background Technology
[0002] In existing technologies, image contrast enhancement is of great significance for improving the visual perception of digital images. An image with appropriate contrast not only has a comfortable visual effect, but also provides more information for the receiving end to use. However, in ISP imaging systems, the raw image input by the image data acquisition device, after brightness transformation, noise reduction, and color adjustment, results in an image with low contrast and varying degrees of loss of detail in both bright and dark areas.
[0003] Therefore, a method is needed to improve image contrast. This method can process a low-contrast input image into an image with a more suitable contrast. The traditional histogram equalization method is the most widely used contrast enhancement method. It can map the originally concentrated gray range to a larger gray range according to the gray distribution characteristics of the image, thereby enhancing the contrast of the input image.
[0004] While traditional histogram equalization (HE) is a commonly used method to effectively improve image contrast, it calculates the cumulative distribution function (CDF), also known as the mapping function, based on the current radian distribution of the image. This CDF is then used to map the input image, thereby enhancing contrast. However, this method calculates the mapping function based on the current grayscale distribution, leading to a loss of detail in both bright and dark areas. In other words, a major problem with HE is that bright and dark areas are over-enhanced, resulting in the loss of detail in these areas. Consequently, the receiver cannot observe the information in these bright and dark areas.
[0005] In addition, the terminology commonly used in this technology includes:
[0006] ISP: Image Signal Processor, a module that performs algorithmic processing on the raw data input from the sensor;
[0007] HE: Histogram equalization, a method to modify image contrast; PDF: Probability Density Function.
[0008] CDF: Cumulative Distribution Function;
[0009] CLAHE: Limit contrast adaptive histogram equalization. Summary of the Invention
[0010] To address the aforementioned issues, the purpose of this application is to resolve the over-enhancement problem in bright and dark areas of the histogram equalization method, ensuring that low-contrast images do not lose detail information in bright and dark areas after enhancement.
[0011] Specifically, the present invention provides a histogram equalization method that preserves details, the method comprising the following steps:
[0012] S1, divide the input brightness image into blocks;
[0013] S2, Statistical image histogram; calculates the average gray level of the current block;
[0014] S3, Histogram Redistribution, includes: calculating the clipping threshold; histogram clipping redistribution;
[0015] S3.1, Calculate the clipping threshold; Calculate the clipping threshold (clipThre) for this block according to the preset clipping ratio (clipRatio). h,w The calculation process is as follows:
[0016]
[0017] Here, clipRatio is set to 2;
[0018] S3.2, within each block, use the clipThre obtained in step S3.1. h,w For hist h,w Cutting:
[0019] The remaining part is denoted as histRem hw The cutting process is as follows:
[0020]
[0021] Count the number of pixels (num) cropped out at each gray level, and sum them up to get the total number of pixels in the cropped portion, denoted as total. hw :
[0022]
[0023]
[0024] The cutting process needs to meet the following requirements:
[0025]
[0026] S3.3, Histogram Clipping and Redistribution: Within each block, the clipped portion is redistributed according to a fixed distribution method, and the resulting histogram is denoted as alloc. h,w ;
[0027] S4, calculate the mapping function, including:
[0028] S4.1, within each block, the reallocated alloc h,w Overlay onto the remaining histRem h,w Above, obtain the new histogram. h,w ':
[0029] hist h,w '(m) = histRem h,w (m)+alloc h,w (m), 0 ≤ m < avg h,w (17)
[0030] S4.2, within each block, make the histogram histogram... h,w Perform histogram equalization within the current grayscale range to obtain the mapping function CDF. h,w ;
[0031] S5, Mapping function adjustment; within each block, the mapping function cdf is controlled according to the preset fusion weight curves wgt1 and wgt2. h,w Apply the preset mapping function CDF to both the bright and dark areas respectively. def Weighted;
[0032] S6, Enhance the input image; based on pixel location and the CDF mapping function in each block. h,w The input brightness image y is enhanced using bilinear interpolation to obtain the enhanced image y'.
[0033] Step S1 further includes:
[0034] S1.1, Input brightness image y, the width and height of the input image are imgWidth and imgHeight respectively;
[0035] S1.2, set the number of vertical blocks (bloVer) and the number of horizontal blocks (bloHor), where bloVer = 8 and bloHor = 8; during the vertical block division process, the block division method is as follows:
[0036] sideVer=((imgHeight / 2) / bloVer)×2 (1)
[0037] remVer=(imgHeight / 2)%bloVer (2)
[0038] Where sideVer represents the minimum number of pixels in the vertical block, and remVer determines whether the image pixel height is divisible by the number of vertical blocks during vertical block division; when remVer is not equal to 0, that is, when a situation of non-divisibility occurs during the block division process, the pixel height of the first remVer blocks of the vertical block will be increased by 2, as shown in the following formula (3), to ensure that the allocation method can satisfy the following formula (4); that is
[0039]
[0040] (sideVer+2)×remVer+sideVer×(bloVer-remVer)=imgHeight(4) In formula (3), bloHeight(h) represents the pixel height of the h-th block when dividing vertically, h∈[1,bloVer]; similarly, in the process of dividing horizontally:
[0041] sideHor=((imgWidth / 2) / bloHor)×2 (5)
[0042] remHor=(imgWidth / 2)%bloHor (6)
[0043]
[0044] (sideHor+2)×remHor+sideHor×(bloHor-remHor)=imgWidth (8) In formulas (5)-(7), sideHor represents the minimum number of pixels in the horizontal block, remHor determines whether the image pixel width can be divided by the number of horizontal blocks when dividing horizontally, and bloWidth(w) represents the pixel width of the w-th block when dividing horizontally, w∈[1,bloHor];
[0045] S1.3, divide the input image y into bloVer×bloHor blocks according to the calculated result.
[0046] Step S2 further includes: in each block y h,w Inside:
[0047] S2.1, Calculate the current block y h,w histogram information h,w There are a total of numBins gray levels;
[0048] S2.2, Calculate y h,w The average grayscale value (avg) is calculated using the following formula:
[0049]
[0050] in Hist means round down. h,w (m) represents y h,w The number of pixels with an inner pixel value of m, where m ∈ [0, numBins); avg will be used as the basis for histogram redistribution.
[0051] The allocation method for step S3.3 is as follows:
[0052] S3.3.1, Calculate the allocation ratio (allocRatio) for each grayscale segment:
[0053]
[0054] S3.3.2, according to the allocation ratio allocRatio, cut off the total portion. h,w The histogram obtained from the reallocation is denoted as alloc. hw :
[0055]
[0056] Step S4.2 further includes:
[0057] S4.2.1, Calculate hist h,w The probability density function of the gray level (pdf) h,w The formula is as follows:
[0058]
[0059] S4.2.2, transfer the PDF h,w The probability density functions are accumulated, and the mapping function cdf is calculated within its gray range [0 numBins-1]. h,w The formula is as follows:
[0060]
[0061] The specific operation method of step S5 includes:
[0062] S5.1 First, based on the preset parameters Amp1, Sigma1, Mean1 and Amp2, Sigma2, Mean2, calculate the preset fusion weight curves wgt1 and wgt2 respectively. The calculation method is as follows:
[0063]
[0064] Where [Amp1 Sigma1 Mean1] = [256, 255, 255], [Amp1 Sigma1 Mean1] = [256, 255, 0];
[0065] S5.2, Preset mapping function cdf def The expression is:
[0066] cdf def (m)=m,0≤m≤255 (21)
[0067] S5.3, Compare the CDF mapping function h,w and the preset mapping function CDF def If CDF h,w (m) is greater than cdf def (m), then wgt1 is used to control fusion; if cdf h,w (m) is less than cdf def If (m), then wgt2 is used to control the fusion, and finally the mapping function CDF of the current block is obtained. h,w The specific integration method is as follows:
[0068] When CDF h,w (m) is greater than cdf def When (m), this is reflected in the image as a brighter image:
[0069] CDF h,w (m)=wgt1(m)*cdf h,w (m)+(256-wgt1(m))*cdf def (m) (22)
[0070] When CDF h,w (m) is less than cdf def When (m), this is reflected in the image as a darkening of the image brightness:
[0071] CDF h,w (m)=wgt2(m)*cdf h,w (m)+(256-wgt2(m))*cdf def (m) (23)
[0072] The image in the method includes an 8-bit image, assuming numBins = 256.
[0073] Therefore, the advantage of this application is:
[0074] Traditional histogram equalization methods suffer from over-enhancement, which, while enhancing the image, results in the loss of details in the brighter and darker grayscale ranges. The weighted method of mapping curve and preset curve proposed in this invention limits the enhancement level in the brighter and darker regions of the image, avoiding the loss of image details and thus protecting image details. Attached Figure Description
[0075] The accompanying drawings, which are provided to further illustrate the invention and form part of this application, are not intended to limit the scope of the invention.
[0076] Figure 1 This is a flowchart illustrating the method described in this application. Detailed Implementation
[0077] To better understand the technical content and advantages of the present invention, the present invention will now be described in further detail with reference to the accompanying drawings.
[0078] This application proposes a detail-preserving histogram equalization method. The introduction of histogram equalization can improve the contrast of the input image while avoiding the loss of details in both dark and bright areas during the contrast enhancement process. Figure 1 As shown, the process mainly includes image segmentation; statistical histogram of segmented images; histogram cropping and redistribution; calculation of the mapping function; weighting of the mapping function; and obtaining the enhanced image.
[0079] The present invention will now be described in more detail with reference to the accompanying drawings:
[0080] S0, Input brightness image;
[0081] S1 divides the input brightness image into blocks, mainly including:
[0082] S1.1, Input brightness image y, the width and height of the input image are imgWidth and imgHeight respectively;
[0083] S1.2, set the number of vertical blocks (bloVer) and the number of horizontal blocks (bloHor), where bloVer = 8 and bloHor = 8. bloVer and bloHor can be other values. The block division method is as follows during vertical block division:
[0084] sideVer = ((imgHeight / 2) / bloVer) × twenty one)
[0085] remVer=(imgHeight / 2) % bloVer (2)
[0086] Where sideVer represents the minimum number of pixels in the vertical block, and remVer determines whether the image pixel height is divisible by the number of vertical blocks during vertical block division; when remVer is not equal to 0, that is, when a situation of non-divisibility occurs during the block division process, the pixel height of the first remVer blocks of the vertical block will be increased by 2, as shown in the following formula (3), to ensure that the allocation method can satisfy the following formula (4); that is
[0087]
[0088] (sideVer+2)×remVer+sideVer×(bloVer-remVer)=imgHeight (4) In formula (3), bloHeight(h) represents the pixel height of the h-th block when dividing vertically, h∈[1,bloVer]; similarly, in the process of dividing horizontally:
[0089] sideHor = ((imgWidth / 2) / bloHor) × 2 (5)
[0090] remHor=(imgWidth / 2) % bloHor (6)
[0091]
[0092] (sideHor+2)×remHor+sideHor×(bloHor-remHor)=imgWidth (8) In formulas (5)-(7), sideHor represents the minimum number of pixels in the horizontal block, remHor determines whether the image pixel width can be divided by the number of horizontal blocks when dividing horizontally, and bloWidth(w) represents the pixel width of the w-th block when dividing horizontally, w∈[1,bloHor];
[0093] S1.3, Divide the input image y into bloVer×bloHor blocks according to the calculated result; S2, Calculate the image histogram; Calculate the average gray level of the current block; Further includes:
[0094] In each block y h,w Inside:
[0095] S2.1, Calculate the current block y h,w histogram information h,w There are a total of numBins gray levels; the image includes, but is not limited to, 8 bits, which is related to the input bit bits of the actual image used. Here, we take an 8-bit image as an example, numBins = 256; the value of numBins changes with the current input bit bits. When the input is 8 bits: numBins = 2^8 (bit) = 256. If the bit bits change, this parameter needs to be changed accordingly.
[0096] S2.2, Calculate y h,w The average grayscale value (avg) is calculated using the following formula:
[0097]
[0098] in Hist means round down. h,w (m) represents y h,w The number of pixels with an inner pixel value of m, where m ∈ [0, numBins); avg will be used as the basis for histogram redistribution;
[0099] S3, Histogram Redistribution, includes: calculating the clipping threshold; histogram clipping redistribution;
[0100] S3.1, Calculate the clipping threshold;
[0101] Calculate the clipping threshold (clipThre) for this block based on the preset clipping ratio (clipRatio). h,w The calculation process is as follows:
[0102]
[0103] Here, clipRatio = 2, but it can also be any other value;
[0104] Within each block, the clipThre obtained in step S3 is used. h,w For hist h,w Cutting:
[0105] The remaining part is denoted as histRem hw The cutting process is as follows:
[0106]
[0107] Count the number of pixels (num) cropped out at each gray level, and sum them up to get the total number of pixels in the cropped portion, denoted as total. hw :
[0108]
[0109]
[0110] The cutting process needs to meet the following requirements:
[0111]
[0112] S3.3, Histogram clipping and redistribution; Within each block, the clipped portion is redistributed according to a fixed allocation method, as follows:
[0113] S3.3.1, Calculate the allocation ratio (allocRatio) for each grayscale segment:
[0114]
[0115] S3.3.2, according to the allocation ratio allocRatio, cut off the total portion. h,w The histogram obtained from the reallocation is denoted as alloc. h,w :
[0116]
[0117] S4, calculate the mapping function, including:
[0118] S4.1, within each block, the reallocated alloc h,w Overlay onto the remaining histRem h,w Above, obtain the new histogram. h,w ':
[0119] hist h,w '(m) = histRem h,w (m)+alloc h,w (m), 0 ≤ m < avg h,w (17)
[0120] S4.2, within each block, make the histogram histogram... h,w Performing histogram equalization within the current grayscale range mainly includes:
[0121] S4.2.1, Calculate hist h,w The probability density function of the gray level (pdf) h,w The formula is as follows:
[0122]
[0123] S4.2.2, transfer the PDF h,w The probability density functions are accumulated, and the mapping function cdf is calculated within its gray range [0 numBins-1]. hw The formula is as follows:
[0124]
[0125] S5, Mapping function adjustment; within each block, the mapping function cdf is controlled according to the preset fusion weight curves wgt1 and wgt2. h,w Apply the preset mapping function CDF to both the bright and dark areas respectively. def Weighted, the specific operation method is as follows:
[0126] S5.1 First, based on the preset parameters Amp1, Sigma1, Mean1 and Amp2, Sigma2, Mean2, calculate the preset fusion weight curves wgt1 and wgt2 respectively. The calculation method is as follows:
[0127]
[0128] Where [Amp1 Sigma1 Mean1] = [256, 255, 255], [Amp1 Sigma1 Mean1] = [256, 255, 0];
[0129] S5.2, Preset mapping function cdf def The expression is:
[0130] cdf def (m)=m,0≤m≤255 (21)
[0131] S5.3, Compare the CDF mapping function h,w and the preset mapping function CDF def If CDF h,w (m) is greater than cdf def (m), then wgt1 is used to control fusion; if cdf h,w (m) is less than cdf def If (m), then wgt2 is used to control the fusion, and finally the mapping function CDF of the current block is obtained. h,w The specific integration method is as follows:
[0132] When CDF h,w (m) is greater than cdf def When (m), this is reflected in the image as a brighter image:
[0133] CDF h,w (m)=wgt1(m)*cdf h,w (m)+(256-wgt1(m))*cdf def (m) (22)
[0134] When CDF h,w (m) is less than cdf def When (m), this is reflected in the image as a darkening of the image brightness:
[0135] CDF h,w (m)=wgt2(m)*cdf h,w (m)+(256-wgt2(m))*cdf def (m) (23)
[0136] S6, Enhance the input image; based on pixel location and the CDF mapping function in each block. h,w The input brightness image y is enhanced using bilinear interpolation to obtain the enhanced image y'.
[0137] In summary, this invention proposes a histogram equalization method that preserves details, addressing the problem of lost details in both bright and dark areas of the enhanced image caused by traditional histogram equalization methods.
[0138] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, various modifications and variations can be made to the embodiments of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A histogram equalization method that preserves details, characterized in that, The method includes the following steps: S1, divide the input brightness image into blocks; S2, Statistical image histogram; calculates the average gray level of the current block; S3, Histogram Redistribution, includes: calculating the clipping threshold; histogram clipping redistribution; S3.1, Calculate the clipping threshold; According to a preset clipping ratio clipRatio, a clipping threshold clipThre of the block is calculated h,w The calculation process is as follows: Here, clipRatio is preferably 2, that is, clipRatio = 2; Within each tile, clipThre h,w hist h,w histRem hw The clipping process is as follows: The number of pixels num clipped out at each gray level is counted, and the total number of pixels in the clipped-out portion is accumulated and recorded as total h,w : The cutting process needs to meet the following requirements: S3.3, histogram clipping redistribution; within each bin, the clipped part is redistributed according to a fixed redistribution manner, the obtained histogram is denoted as alloc h,w ; S4, calculate the mapping function, including: S4.1, within each patch, re-allocate the obtained alloc h,w to the remaining part histRem h,w above, obtain the new histogram hist h,w ' hist h,w '(m) = histRem h,w (m) + alloc h,w (m), 0 ≤ m < avg h,w (17) S4.2, within each patch, make a histogram hist h,w Do histogram equalization in the current gray range, get the mapping function cdf h,w ; S5, mapping function adjustment; in each block, according to preset fusion weight curve wgt1, wgt2, control mapping function cdf h,w respectively in the bright area and dark area and preset mapping function cdf def weighted; S6, enhancing the input image; according to the pixel position and the mapping function CDF in each block h,w The input luminance image y is enhanced in a bilinear interpolation manner to obtain the enhanced image y'.
2. The histogram equalization method for preserving details according to claim 1, characterized in that, Step S1 further includes: S1.1, Input brightness image y, the width and height of the input image are imgWidth and imgHeight respectively; S1.2, set the number of vertical blocks (bloVer) and the number of horizontal blocks (bloHor). Here, bloVer and bloHor are preferably 8. Let bloVer = 8 and bloHor = 8. During the vertical block division process, the block division method is as follows: sideVer=((imgHeight / 2) / bloVer)×2 (1) remVer=(imgHeight / 2)%bloVer (2) Where sideVer represents the minimum number of pixels in the vertical block, and remVer determines whether the image pixel height is divisible by the number of vertical blocks during vertical block division; when remVer is not equal to 0, that is, when a situation of non-divisibility occurs during the block division process, the pixel height of the first remVer blocks of the vertical block will be increased by 2, as shown in the following formula (3), to ensure that the allocation method can satisfy the following formula (4); that is (sideVer+2)×remVer+sideVer×(bloVer-remVer)=imgHeight (4) In formula (3), bloHeight(h) represents the pixel height of the h-th block during vertical segmentation, where h ∈ [1, bloVer]. Similarly, during horizontal segmentation: sideHor=((imgWidth / 2) / bloHor)×2 (5) remHor=(imgWidth / 2)%bloHor (6) (sideHor+2)×remHor+sideHor×(bloHor-remHor)=imgWidth (8) In formulas (5)-(7), sideHor represents the minimum number of pixels in the horizontal block, remHor determines whether the image pixel width can be divided by the number of horizontal blocks when the horizontal blocks are divided, and bloWidth(w) represents the pixel width of the w-th block when the horizontal blocks are divided, w∈[1,bloHor]. S1.3, divide the input image y into bloVer×bloHor blocks according to the calculated result.
3. The histogram equalization method for preserving details according to claim 2, characterized in that, The step S2 further comprises, within each sub-block y h,w : S2.1, statistics of the current block y h,w histogram information hist of y h,w numBins total number of gray levels; S2.2, calculate y h,w the average gray level avg of the pixels of the image, as follows: in Hist means round down. h,w (m) represents y h,w The number of pixels with an inner pixel value of m, where m ∈ [0, numBins); avg will be used as the basis for histogram redistribution.
4. The histogram equalization method for preserving details according to claim 3, characterized in that, The allocation method for step S3.3 is as follows: S3.3.1, Calculate the allocation ratio (allocRatio) for each grayscale segment: S3.3.2, the cropped portion total is allocated according to the allocation ratio allocRatio h,w re-allocating, the obtained histogram is denoted as alloc hw :
5. A histogram equalization method for preserving details according to claim 4, characterized in that, Step S4.2 further includes: S4.2.1, compute hist h,w the probability density function pdf of the gray levels h,w , as follows: S4.2.
2. Accumulate the probability density function pdf h,w over its gray scale range [0 numBins - 1] to compute the mapping function cdf h,w , which is given by 6. The histogram equalization method for preserving details according to claim 5, characterized in that, The specific operation method of step S5 includes: S5.1 First, based on the preset parameters Amp1, Sigma1, Mean1 and Amp2, Sigma2, Mean2, calculate the preset fusion weight curves wgt1 and wgt2 respectively. The calculation method is as follows: Where [Amp1 Sigma1 Mean1] = [256, 255, 255], [Amp1 Sigma1 Mean1] = [256, 255, 0]; S5.2, Preset mapping function cdf def The expression is: cdf def (m)=m,0≤m≤255 (21) S5.3, Compare the CDF mapping function h,w and the preset mapping function CDF def If CDF h,w (m) is greater than cdf def (m), then wgt1 is used to control fusion; if cdf h,w (m) is less than cdf def If (m), then wgt2 is used to control the fusion, and finally the mapping function CDF of the current block is obtained. h,w The specific integration method is as follows: When CDF h,w (m) is greater than cdf def When (m), this is reflected in the image as a brighter image: CDF h,w (m)=wgt1(m)*cdf h,w (m)+(256-wgt1(m))*cdf def (m) (22) When CDF h,w (m) is less than cdf def When (m), this is reflected in the image as a darkening of the image brightness: CDF h,w (m)=wgt2(m)*cdf h,w (m)+(256-wgt2(m))*cdf def (m) (23)。 7. The histogram equalization method for preserving details according to claim 1, characterized in that, The image in the method includes an 8-bit image, which is related to the input bit position of the actual image used; the value of numBins changes with the current input bit position. When the input is 8 bits: numBins = 2^8 (bit) = 256. If the bit position changes, this parameter needs to be changed accordingly.