Histogram equalization method based on gray scale redistribution
By adopting grayscale redistribution technology in the histogram equalization method, using preset thresholds and weights to redistribute image grayscale levels, the problem of over-enhanced images in traditional methods is solved, and reasonable control and detail retention of contrast enhancement is achieved.
Patent Information
- Application Number
- CN202311445188.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-02
- Publication Date
- 2025-05-06
AI Technical Summary
Traditional histogram equalization algorithms can easily lead to excessive enhancement of images during contrast enhancement, affecting visual effects.
The histogram equalization method based on grayscale redistribution is adopted to re-divider the grayscale distribution of the image through the preset dark area/bright area threshold and the allocation weight to avoid the generation of advantageous grayscale, thereby controlling the contrast enhancement.
Effectively avoid the problem of over-enhanced images, ensuring that low-contrast images have appropriate contrast after enhancement, and retaining more dark/bright area details.
Smart Images

Figure CN119941522A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of image processing, and in particular relates to a histogram equalization method based on grayscale redistribution. Background Art
[0002] In the prior art, image contrast enhancement is of great significance for improving the visual perception of digital images. An image with appropriate contrast not only has better visual effects, but also can retain more image information. In the ISP imaging process, the raw data input by the sensor undergoes a series of processing such as denoising, gamma, and color space conversion, resulting in a low contrast output image. Therefore, a contrast enhancement algorithm is needed to achieve the goal of enhancing low-contrast images to images with higher contrast. The traditional histogram equalization (HE) algorithm is the most widely used contrast enhancement algorithm, which calculates the cumulative distribution function (CDF), also called the mapping function, based on the probability density function (PDF) of the image. According to the mapping function, a narrow grayscale range is mapped to a wider grayscale range to achieve image contrast enhancement.
[0003] Histogram equalization is a common method that can effectively improve the contrast of an image. It uses the grayscale distribution of the current image to calculate a mapping function, so that the low-contrast image has a more uniform histogram distribution after enhancement. However, the histogram equalization algorithm only considers the histogram of the current image when calculating the mapping function. Due to the presence of dominant grayscale in the histogram, the processed image is over-enhanced; that is, a major problem with HE is that it causes over-enhancement of the image, that is, the contrast of the enhanced image is too high due to histogram equalization, affecting the visual effect of the image.
[0004] In addition, common terminology explanations in the prior art include:
[0005] ISP: Image signal processor, a module that performs algorithm processing on the raw data input by the sensor;
[0006] HE: histogram equalization, a method for modifying image contrast; PDF: Probability Density Function, probability density function;
[0007] CDF: Cumulative Distribution Function, cumulative distribution function;
[0008] Dominant grayscale: The grayscale with a large number of pixels in the image will affect the calculation of CDF in histogram equalization;
[0009] Over-enhancement: Excessive enhancement of image contrast. Summary of the invention
[0010] In order to solve the above problems, the purpose of this application is to:
[0011] 1. Design a histogram equalization method based on grayscale redistribution, which solves the over-enhancement problem of the traditional histogram equalization algorithm;
[0012] 2. The preset dark area / bright area threshold and dark area / bright area allocation weight realize the redivision of the total number of pixels of the cropped part into respective regions of interest, avoiding the generation of dominant grayscale during the allocation process, thereby solving the over-enhancement problem of traditional histogram equalization;
[0013] 3. The allocation method used in calculating the allocation number of each region of interest not only avoids the problem of over-enhancement, but also retains more dark / bright area details.
[0014] Specifically, the present invention proposes a histogram equalization method based on grayscale redistribution, the method comprising:
[0015] S1, statistical image histogram information, including:
[0016] S1.1, input brightness image y;
[0017] S1.2, count the histogram information of y, hist, a total of numBins gray levels;
[0018] S2, perform Gaussian smoothing filtering on the histogram information to obtain y_hist. The formula of the filter kernel is:
[0019]
[0020] Where x represents the distance from the center position, and δ represents the smoothness of the curve;
[0021] S3, histogram clipping, uses the preset parameter clipRatio to clip the filtered histogram to obtain the clipped histogram clippedHist, and counts the clipped part count, including:
[0022] S3.1, according to the width and height of the brightness image, calculate the average number of pixels at each gray level, the formula is:
[0023] meanNum=(height×width) / numBins;
[0024] S3.2, according to the preset clipping ratio clipRatio, calculate the clipping threshold clipThre, the formula is:
[0025] clipThre=meanNum×clipRatio;
[0026] Here, clipRatio can be set by yourself;
[0027] S3.3, for each gray level of the filtered histogram y_hist, clip it according to the following formula:
[0028]
[0029] Where i represents the i-th gray level of the histogram;
[0030] S3.4, counting the number of pixels cut out at each gray level, and summing them up to obtain the total number of pixels cut out, count;
[0031]
[0032]
[0033] S4, according to the preset parameters, the cropped parameters are divided into dark area, bright area and normal area respectively, and the histogram reHist after allocation is obtained, including:
[0034] S4.1, preset dark area threshold darkMark, bright area threshold brightMark, take darkMark = 63, brightMark = 192 respectively; dark area allocation weight darkWgt, bright area allocation weight brightWgt, take darkWgt = 0.2, brightWgt = 0.2 respectively;
[0035] S4.2, calculate the dark area allocation number darkNum, the bright area allocation number brightNum, and the normal area allocation number normalNum, the formula is as follows:
[0036]
[0037]
[0038] normalNum=count-darkNum-brightNum;
[0039] in Indicates rounding down;
[0040] S4.3, reallocate the dark area allocation number darkNum and the bright area allocation number brightNum to obtain reHist, and the rules are as follows:
[0041] For the dark area, darkSum is used to represent the sum of the gray levels of the dark area:
[0042]
[0043] For bright areas, brightSum is used to represent the sum of the gray levels in the bright areas:
[0044]
[0045] For the i-th gray level in numBins, if i belongs to the dark area,
[0046]
[0047] Here, if i belongs to the bright area,
[0048]
[0049] in Indicates rounding down;
[0050] S4.4, in the normal grayscale area, the allocation number normalNum is evenly distributed according to the following rules:
[0051] First, calculate the number of gray levels in the normal area:
[0052] normalGray=brightMark-darkMark;
[0053] Next, calculate the number of gray levels that should be allocated and the remainder:
[0054] normalInt=normalNum / normalGray,
[0055] normalRem=normalNum-normalInt×normalGray,
[0056] For each gray level assigned to the normal area, normalInt is assigned to the low gray level of the area;
[0057] For the i-th gray level in numBins, where i belongs to the normal gray area, we have:
[0058]
[0059] S5, calculating the cumulative distribution function cdf according to the obtained histogram reHist, and mapping the input brightness image y.
[0060] In the step S1.2, numBins=256.
[0061] In step S2, δ=3, and the filter radius x is 4.
[0062] In the step S3.2, clipRatio=2 is taken here.
[0063] The step S5 further comprises:
[0064] S5.1, calculate the probability density function pdf of all gray levels, the formula is as follows:
[0065] pdf=reHist / (height×width);
[0066] S5.2, calculate the mapping function, accumulate the probability density function, obtain the cumulative distribution function cdf, and normalize it to
[0255] , the formula is as follows:
[0067]
[0068] S5.3, enhancing the input image, using the calculated cumulative distribution function cdf to enhance the input brightness image y to obtain an enhanced image y'.
[0069] Therefore, the advantages of the present application are: by grayscale redistribution, the generation of dominant grayscale is avoided, the over-enhancement problem of the histogram equalization method is solved, and it is ensured that the low-contrast image has a suitable contrast after enhancement. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] The drawings described herein are used to provide a further understanding of the present invention, constitute a part of this application, and do not constitute a limitation of the present invention.
[0071] Figure 1 It is a flow chart of the present application method. DETAILED DESCRIPTION
[0072] In order to more clearly understand the technical content and advantages of the present invention, the present invention is now further described in detail in conjunction with the accompanying drawings.
[0073] The present application provides a histogram equalization method based on grayscale redistribution, which is used to solve the over-enhancement problem existing in the traditional histogram equalization algorithm. The method mainly includes: counting the image histogram, smoothing and filtering the histogram, calculating the clipping threshold, and clipping the histogram, calculating the number of pixels to be allocated to each area according to the preset allocation weight and the threshold of the bright and dark areas, and redistributing the number of pixels to be allocated to the dark area, the bright area and the normal grayscale area according to different allocation methods, and using the histogram obtained by the redistribution to calculate the mapping function, enhancing the input image, and obtaining an enhanced image.
[0074] The following will be combined Figure 1 The present invention is described in more detail as shown:
[0075] S1, statistical image histogram information, mainly including:
[0076] S1.1, input brightness image y;
[0077] S1.2, count the histogram information of y, hist, a total of numBins gray levels, where numBins = 256;
[0078] S2, perform Gaussian smoothing filtering on the histogram information to obtain y_hist. The formula of the filter kernel is:
[0079]
[0080] Where x represents the distance from the center position, δ represents the smoothness of the curve, here δ = 3, and the filter radius is 4;
[0081] S3, clips the filtered histogram using the preset parameter clipRatio to obtain the clipped histogram clippedHist, and counts the clipped part count, mainly including:
[0082] S3.1, according to the width and height of the brightness image, calculate the average number of pixels at each gray level, the formula is:
[0083] meanNum=(height×width) / numBins
[0084] S3.2, according to the preset clipping ratio clipRatio, calculate the clipping threshold clipThre, the formula is:
[0085] clipThre=meanNum×clipRatio
[0086] Here clipRatio can be set by yourself, here take clipRatio = 2;
[0087] S3.3, for each gray level of the filtered histogram y_hist, clip it according to the following formula:
[0088]
[0089] Where i represents the i-th gray level of the histogram;
[0090] S3.4, counting the number of pixels cut out at each gray level, and summing them up to obtain the total number of pixels cut out, count;
[0091]
[0092]
[0093] S4, according to the preset parameters, the cropped parameters are divided into dark area, bright area and normal area respectively, and the histogram reHist after allocation is obtained, which mainly includes:
[0094] S4.1, preset dark area threshold darkMark, bright area threshold brightMark, take darkMark = 63, brightMark = 192 respectively; dark area allocation weight darkWgt, bright area allocation weight brightWgt, take darkWgt = 0.2, brightWgt = 0.2 respectively;
[0095] S4.2, calculate the dark area allocation number darkNum, the bright area allocation number brightNum, and the normal area allocation number normalNum, the formula is as follows:
[0096]
[0097]
[0098] normalNum=count-darkNum-brightNum
[0099] in Indicates rounding down.
[0100] S4.3, reallocate the dark area allocation number darkNum and the bright area allocation number brightNum to obtain reHist, and the rules are as follows:
[0101] For the dark area, darkSum is used to represent the sum of the gray levels of the dark area:
[0102]
[0103] For bright areas, brightSum is used to represent the sum of the gray levels in the bright areas:
[0104]
[0105] For the i-th gray level in numBins, if i belongs to the dark area,
[0106]
[0107] If i belongs to the bright area,
[0108]
[0109] in Indicates rounding down;
[0110] S4.4, in the normal grayscale area, the allocation number normalNum is evenly distributed according to the following rules:
[0111] First, calculate the number of gray levels in the normal area:
[0112] normalGray=brightMark-darkMark
[0113] Next, calculate the number of gray levels that should be allocated and the remainder:
[0114] normalInt=normalNum / normalGray
[0115] normalRem=normalNum-normalInt×normalGray
[0116] For each gray level of the normal area, normalInt is assigned, and normalRem is assigned to the low gray levels of the area.
[0117] For the i-th gray level in numBins (where i belongs to the normal gray area), we have:
[0118]
[0119] S5, according to the obtained histogram reHist, calculates the mapping function cdf and maps the input brightness image y, mainly including:
[0120] S5.1, calculate the probability density function pdf of all gray levels, the formula is as follows:
[0121] pdf = reHist / (height × width)
[0122] S5.2, accumulate the probability density functions to obtain the cumulative distribution function cdf, and normalize it to
[0255] , the formula is as follows:
[0123]
[0124] Where numBins = 256;
[0125] S5.3, using the calculated cumulative distribution function cdf to enhance the input brightness image y, to obtain an enhanced image y'.
[0126] In summary, the grayscale redistribution method proposed in this method avoids the generation of dominant grayscale in the histogram and solves the over-enhancement problem caused by traditional histogram equalization. The focus is on the implementation process of brightness image histogram equalization. By cropping and redistributing the statistical brightness image histogram to different regions of interest, the influence of the dominant grayscale on the mapping function in the traditional histogram equalization method is avoided, thereby solving the brightness over-enhancement problem of the traditional histogram equalization algorithm. The allocation weights and allocation methods of different regions of interest retain more dark / bright details for the image after the histogram equalization process.
[0127] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the embodiments of the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A histogram equalization method based on grayscale redistribution, characterized in that: The method comprises: S1, statistical image histogram information, including: S1.1, input brightness image y; S1.2, count the histogram information of y, hist, a total of numBins gray levels; S2, perform Gaussian smoothing filtering on the histogram information to obtain y_hist. The formula of the filter kernel is: Where x represents the distance from the center position, and δ represents the smoothness of the curve; S3, histogram clipping, uses the preset parameter clipRatio to clip the filtered histogram to obtain the clipped histogram clippedHist, and counts the clipped part count, including: S3.1, according to the width and height of the brightness image, calculate the average number of pixels at each gray level, the formula is: meanNum=(height×width) / numBins; S3.2, according to the preset clipping ratio clipRatio, calculate the clipping threshold clipThre, the formula is: clipThre=meanNum×clipRatio; Here, clipRatio can be set by yourself; S3.3, for each gray level of the filtered histogram y_hist, clipping is performed according to the following formula: Where i represents the i-th gray level of the histogram; S3.4, counting the number of pixels cut out at each gray level, and summing them up to obtain the total number of pixels cut out, count; S4, according to the preset parameters, the cropped parameters are divided into dark area, bright area and normal area respectively, and the histogram reHist after allocation is obtained, including: S4.1, preset dark area threshold darkMark, bright area threshold brightMark, take darkMark = 63, brightMark = 192 respectively; dark area allocation weight darkWgt, bright area allocation weight brightWgt, take darkWgt = 0.2, brightWgt = 0.2 respectively; S4.2, calculate the dark area allocation number darkNum, the bright area allocation number brightNum, and the normal area allocation number normalNum, the formula is as follows: normalNum=count-darkNum-brightNum; in Indicates rounding down; S4.3, reallocate the dark area allocation number darkNum and the bright area allocation number brightNum to obtain reHist, and the rules are as follows: For the dark area, darkSum is used to represent the sum of the gray levels of the dark area: For bright areas, brightSum is used to represent the sum of the gray levels in the bright areas: For the i-th gray level in numBins, if i belongs to the dark area, If i belongs to the bright area, in Indicates rounding down; S4.4, in the normal grayscale area, the allocation number normalNum is evenly distributed according to the following rules: First, calculate the number of gray levels in the normal area: normalGray=brightMark-darkMark; Next, calculate the number of gray levels that should be allocated and the remainder: normalInt=normalNum / normalGray, normalRem=normalNum-normalInt×normalGray, For each gray level assigned to the normal area, normalInt is assigned to the low gray level of the area; For the i-th gray level in numBins, where i belongs to the normal gray area, we have: S5, calculating the cumulative distribution function cdf according to the obtained histogram reHist, and mapping the input brightness image y.
2. The histogram equalization method based on grayscale redistribution according to claim 1, characterized in that: In the step S1.2, numBins=256.
3. The histogram equalization method based on grayscale redistribution according to claim 1, characterized in that: In step S2, δ=3, and the filter radius x is 4.
4. The histogram equalization method based on grayscale redistribution according to claim 1, characterized in that: In the step S3.2, clipRatio=2 is taken here.
5. The histogram equalization method based on grayscale redistribution according to claim 1, characterized in that: The step S5 further comprises: S5.1, calculate the probability density function pdf of all gray levels, the formula is as follows: pdf=reHist / (height×width); S5.2, calculate the mapping function, accumulate the probability density function, obtain the mapping function cdf, and normalize it to [0255], the formula is as follows: S5.3, enhancing the input image, using the calculated mapping function cdf to enhance the input brightness image y to obtain an enhanced image y'.
Citation Information
Cited By
Aircraft engine endoscope detection image optimization method and system, medium and product
CN122066619A