Image enhancement method and image-based automobile headlamp angle adjustment method
By using improved CLAHE and YOLOv5 algorithms, the cropping threshold for nighttime waterlogged images is dynamically adjusted, solving the problem of unstable image enhancement effects for nighttime waterlogged roads. This enables accurate identification of waterlogged locations and precise adjustment of headlight angles, ensuring safe driving in rainy nighttime conditions.
Patent Information
- Application Number
- CN202310555282.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-15
- Publication Date
- 2026-02-24
- Estimated Expiration
- 2043-05-15
AI Technical Summary
Existing image enhancement methods cannot adapt to complex road environments such as flooded roads at night, resulting in unstable image enhancement effects, affecting the accurate identification of flood locations, and thus failing to meet the safety requirements for driving in rainy nights.
An improved CLAHE algorithm is adopted, which dynamically adjusts the cropping threshold based on the central and target sub-blocks of the nighttime water accumulation image, performs contrast-limited adaptive histogram equalization on the image, and combines the YOLOv5 algorithm model to identify the water accumulation location and adjust the headlight angle.
It achieves stable enhancement effects under changing nighttime water accumulation images, ensuring accurate identification of water accumulation locations and precise adjustment of vehicle headlight angles, thus improving safety when driving at night in rainy weather.
Smart Images

Figure CN116843882B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of machine vision and image processing technology, specifically to an image enhancement method and a method for adjusting the angle of car headlights based on nighttime water accumulation images. Background Technology
[0002] As we all know, when driving at night, the bright headlights can easily dazzle drivers when passing other vehicles. Worse still, road conditions are much more complex at night than on sunny days. Water accumulation in front of vehicles creates "mirror-like" surfaces, acting as light reflectors and causing glare, which can also dazzle drivers. This glare poses a serious safety hazard to traffic safety.
[0003] Currently, in practical applications, when roads are flooded at night, simply making random, manual adjustments to the headlight angle is insufficient to handle complex flooded road conditions and fails to meet the safety requirements for nighttime driving in rainy weather. Theoretically, for flooded roads at night, image enhancement methods can be used to help identify the location of the floodwater, and then the headlight angle can be adjusted based on the identified location.
[0004] However, most existing image enhancement methods use traditional histogram equalization enhancement algorithms, but these methods do not redistribute the number of pixels at each gray level in nighttime flooded images. Since the cumulative probability of any gray level in the gray-level histogram of the equalized image is the sum of the probabilities of the corresponding gray levels in the original image, if the probability of a certain gray level in the original image is too high, the difference between the cumulative probability of that normalized gray level and the cumulative probability of the previous normalized gray level will be too large. Therefore, directly performing histogram equalization enhancement on the gray-level histogram of the original image will result in over-enhancement of the equalized image. This will cause the equalized image to lose detail information, making the contrast between the flooded area and the road surface less obvious, resulting in poor enhancement. Therefore, the quality of the equalized image obtained by traditional methods is poor, affecting the accurate identification of the flooded area.
[0005] Researchers also explored using the CLAHE algorithm to perform contrast-limited adaptive histogram equalization enhancement on images, resulting in a new histogram equalized image. In this process, the number of pixels for all gray levels in the gray-level histogram was redistributed. For some gray levels with a number of pixels exceeding the cropping threshold, their pixel count was redistributed to limit them to a fixed range. This prevents over-enhancement caused by some gray levels having too many pixels and thus too high a probability during subsequent equalization enhancement, resulting in a new image of better quality.
[0006] However, the cropping threshold in the CLAHE algorithm is a fixed value determined manually. In the field of nighttime driving in rainy weather, the size of the water in different nighttime water accumulation images varies, resulting in different numbers of pixels at the gray level of the water accumulation. Furthermore, the nighttime water accumulation image is constantly changing during vehicle movement, while the cropping threshold remains unchanged. This makes it unreasonable to allocate the number of pixels based on the distribution of the original number of pixels at the gray level relative to the same fixed cropping threshold for different nighttime water accumulation images. Consequently, the CLAHE algorithm cannot adapt to the constantly changing situation of nighttime water accumulation images during vehicle movement, resulting in unstable enhancement effects. Therefore, existing image enhancement methods based on the CLAHE algorithm cannot solve the problem of road image recognition in rainy nighttime conditions. Summary of the Invention
[0007] The purpose of this invention is to provide an image enhancement method and a method for adjusting the angle of car headlights based on nighttime water accumulation images. This image enhancement method can adapt to the constantly changing nighttime water accumulation images during car driving, and can obtain images with stable enhancement effects, thereby helping to accurately identify the location of water accumulation, and thus achieving accurate adjustment of the car headlight angle, so that the car can avoid water accumulation areas and ensure the safety of driving at night in rainy weather.
[0008] To achieve the above objectives, embodiments of this disclosure provide an image enhancement method, including:
[0009] S110, determine the target sub-block cropping threshold in the CLAHE algorithm based on the central sub-block image of the central region of the nighttime water accumulation image and the target sub-block image of the nighttime water accumulation image. The target sub-block image is obtained by dividing the nighttime water accumulation image according to a predetermined division rule. The predetermined division rule is: based on the overall layout of the nighttime water accumulation image, the nighttime water accumulation image is divided evenly. The number of target sub-block images obtained after even division satisfies that it is divisible by both the number of rows and the number of columns. The number of rows is the total number of pixel rows in the nighttime water accumulation image, and the number of columns is the total number of pixel columns in the nighttime water accumulation image.
[0010] S120, according to the CLAHE algorithm, perform contrast-limited adaptive histogram equalization processing on each target sub-block image to obtain the enhanced sub-image;
[0011] S130, based on a predetermined partitioning rule, the enhanced sub-images of all target sub-block images are stitched together to obtain an enhanced image.
[0012] Preferably, step S110 specifically includes:
[0013] S111, Determine the reference threshold for the number of clipping elements based on the central sub-block image P. Specifically, this means: setting the number of cuts as a reference threshold. Set as the quotient of the first value and the second value, where the first value is all values in set X that are not less than... The smallest element in set X, and the second value is the index of the element in set X corresponding to the first value. ,in It is the first in set X An element with index n, and equal to the element with index n from the first index to the nth index n in set M. The sum of the elements corresponding to each index, set M = ,in This indicates that after all normalized gray levels in the central sub-block image are sorted in descending order of their respective pixel counts, the i-th... The number of pixels at each normalized gray level, 1 ≤ ≤ , The number of normalized gray levels in the central sub-block image. This represents the total number of pixels in the central sub-block image.
[0014] S112, determine the target sub-block pruning threshold according to the following formula:
[0015]
[0016] in, The threshold for the number of target sub-blocks to be pruned. This serves as a reference threshold for the number of cuts. The total number of pixels in the central sub-block image. This represents the total number of pixels in the target sub-block image.
[0017] Preferably, in step S110, the number of target sub-block images further satisfies the condition that it is divisible by 640.
[0018] Preferably, step S120 includes:
[0019] S121, based on the CLAHE algorithm, determines the number of pixels that should be allocated to each normalized gray level in the gray-level histogram of each target sub-block image according to the target sub-block cropping number threshold, thus obtaining a new gray-level histogram for each target sub-block image. The allocation formula for the number of pixels at each normalized gray level is as follows:
[0020]
[0021] Where i is the sequence number of the target sub-block image in the nighttime water accumulation image, and all normalized gray levels in each target sub-block image are sorted in ascending order according to their corresponding gray value range, and the sorting sequence number starts from 0; For the i-th target sub-block image, the th The original number of pixels for each normalized gray level; For the i-th target sub-block image, the th The number of pixels allocated to the normalized gray level of each index, 0≤ ≤ , The number of normalized gray levels in the i-th target sub-block image; The threshold for the number of target sub-blocks to be pruned; Let be the number of pixels that are averaged across all normalized gray levels in the i-th target sub-block image. The calculation formula is as follows:
[0022]
[0023] in, For the i-th target sub-block image, the number of target sub-blocks exceeding the target sub-block cropping threshold is... The number of pixels is calculated using the following formula:
[0024]
[0025] in, This represents the total number of pixels in the target sub-block image.
[0026] Preferably, step S120 further includes:
[0027] S122, based on the CLAHE algorithm, performs histogram equalization on the new gray-level histogram of each target sub-block image to obtain the cumulative probability distribution function of each normalized gray level. The formula for calculating the cumulative probability of each normalized gray level is as follows:
[0028]
[0029] In the formula: For the i-th target sub-block image, the th The cumulative probability of the normalized gray level of each index, 0 ≤ ≤ ; The number of normalized gray levels in the i-th target sub-block image; This represents the normalized gray level of the j-th index in the image of the i-th target sub-block, 0 ≤ ≤ ; For the i-th target sub-block image, the th The probability of a normalized gray level with a given index appearing after allocating a certain number of pixels. The calculation formula is:
[0030]
[0031] in, For the i-th target sub-block image, the th The number of pixels assigned to each sequence number's normalized gray level. For the i-th target sub-block image, the th The number of pixels assigned to each normalized gray level of a sequence number, 0 ≤ ≤ ; The number of normalized gray levels in the i-th target sub-block image;
[0032] S123, for each target sub-block image, update the gray value of the corresponding pixel using the cumulative probability distribution function of the normalized gray level of each pixel to obtain the enhanced sub-image.
[0033] Preferably, step S123 specifically includes:
[0034] (1) For each pixel in each target sub-block image, update the gray value of the pixel according to the cumulative probability of the normalized gray level corresponding to the gray value of the pixel. The gray value update formula is:
[0035]
[0036] in, Let be the index of the normalized gray level corresponding to the original gray value of the current pixel in the i-th target sub-block image, 0 ≤ 0. ≤ , The number of normalized gray levels in the i-th target sub-block image; The original gray value of the current pixel in the i-th target sub-block image corresponds to the first... The cumulative probability of the normalized gray level of each index; c is the preset value of the number of bits of gray value of the enhanced sub-image; Let be the updated grayscale value of the current pixel in the i-th target sub-block image;
[0037] (2) For each target sub-block image, replace the original gray value with the updated gray value of each pixel to obtain the enhanced sub-image.
[0038] This invention also provides a method for adjusting the angle of automotive headlights based on nighttime water accumulation images, comprising the following steps:
[0039] S210, Obtain an image training set, and use the above image enhancement method to enhance each image in the image training set to obtain an enhanced image training set, wherein the image training set includes images of water accumulation at night.
[0040] S220: Use the enhanced image training set and manually labeled water accumulation location information to train the YOLOv5 algorithm model and obtain the trained YOLOv5 algorithm model.
[0041] S230, upon receiving a request to adjust the angle of the car headlights, the location of the nighttime water accumulation is determined based on the nighttime water accumulation image corresponding to the request and the trained YOLOv5 algorithm model.
[0042] S240 adjusts the headlight angle based on the nighttime water accumulation location output by the trained YOLOv5 algorithm model, thereby preventing the car from illuminating the water accumulation location.
[0043] Preferably, the image training set also includes pothole images taken during the day and / or at dusk, including images of dry pothole areas and images of waterlogged pothole areas.
[0044] Step S220 specifically includes:
[0045] S221: Train the YOLOv5 algorithm model using the enhanced image training set corresponding to the pothole images during the day and / or evening and the manually labeled pothole location information to obtain the preliminarily trained YOLOv5 algorithm model.
[0046] S223, using the enhanced image training set corresponding to the nighttime water accumulation image and the manually labeled water accumulation location information, train the initially trained YOLOv5 algorithm model to obtain the trained YOLOv5 algorithm model.
[0047] Preferably, step S240 specifically includes:
[0048] S241, The PC terminal determines the headlight angle adjustment strategy based on the location of water accumulation at night;
[0049] S242, the PC sends the headlight angle adjustment command to the Freescale control module. The headlight angle adjustment command contains data about the headlight angle adjustment strategy.
[0050] S243, the Freescale control module converts the headlight angle adjustment strategy data contained in the headlight angle adjustment command into headlight angle control signal data, and transmits the headlight angle control signal data to the LED driver module.
[0051] S244, the LED driver module adjusts the illumination angle of the car headlights according to the headlight angle control signal data, thereby avoiding illuminating the water accumulation area.
[0052] Preferably, step S241 specifically includes:
[0053] S241a, the PC terminal determines whether the difference d between the vertical distance of the center coordinates of the nighttime water accumulation area included in the nighttime water accumulation location and the center point coordinates of the nighttime water accumulation image meets a predetermined condition, wherein the predetermined condition is: the difference d is within... Within the range, The total number of pixel rows in the nighttime water accumulation image corresponding to the vehicle headlight angle adjustment request;
[0054] S241b, if the value d satisfies a predetermined condition, then when the difference d is in When within the range, adjust the vertical illumination angle of both the left and right headlights to 2°; when the difference d is within... Within the range, adjust the vertical illumination angle of both the left and right headlights to -2°;
[0055] S241c, if the value d does not meet the predetermined conditions, then it is not necessary to adjust the vertical illumination angle of the left and right headlights of the car.
[0056] The beneficial effects of the technical solutions provided in this disclosure are:
[0057] First, the image enhancement method of the improved CLAHE algorithm in this embodiment of the invention is as follows: Since the target sub-block cropping threshold in the CLAHE algorithm is determined based on the center sub-block image and the target sub-block image of different nighttime flood images, different nighttime flood images correspond to different target sub-block cropping thresholds. The target sub-block cropping threshold can be dynamically adjusted according to the changes of each nighttime flood image. In this way, for different nighttime flood images, the number of pixels is allocated by using the distribution of the original number of pixels at all normalized gray levels relative to their respective independent target sub-block cropping thresholds. The allocation strategy is more reasonable, enabling the improved CLAHE algorithm to adapt to the constantly changing situation of nighttime flood images during vehicle movement, and the enhancement effect of the resulting histogram equalized new image is relatively stable.
[0058] Furthermore, the headlight angle adjustment method for vehicles based on nighttime water accumulation images in this embodiment of the invention utilizes the enhanced image training set of nighttime water accumulation images processed by the improved CLAHE algorithm and manually labeled water accumulation location information to train the YOLOv5 algorithm model, thereby determining the location of nighttime water accumulation. This method can adjust the illumination angle of the vehicle's headlights according to the location of nighttime water accumulation, so that the vehicle avoids illuminating the water accumulation location, preventing glare and ensuring driving safety in rainy nighttime conditions.
[0059] Finally, the training of the YOLOv5 algorithm model of this invention is first performed using datasets of water accumulation and potholes during the day and evening, which optimizes the YOLOv5 algorithm network model's ability to identify water accumulation locations. Then, the YOLOv5 algorithm network model trained in the first training is trained again using nighttime data, which further enhances the YOLOv5 algorithm's ability to identify water accumulation locations in front of vehicles at night. Attached Figure Description
[0060] To more clearly illustrate the technical solutions in the embodiments of this disclosure, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0061] Figure 1 This is a flowchart of an image enhancement method according to an embodiment of the present invention;
[0062] Figure 2 for Figure 1 The flowchart shown is a method for determining the cropping quantity threshold in the image enhancement method.
[0063] Figure 3 This is a flowchart of a method for adjusting the angle of car headlights based on nighttime water accumulation images, according to an embodiment of the present invention.
[0064] Figure 4 This is a flowchart illustrating another embodiment of the present invention of a method for adjusting the angle of automotive headlights based on nighttime water accumulation images. Detailed Implementation
[0065] To make the objectives, technical solutions, and advantages of this disclosure clearer, the embodiments of this disclosure will be described in further detail below with reference to the accompanying drawings.
[0066] First, some nouns or terms that appear in the description of the embodiments of this application shall be interpreted as follows:
[0067] Gray value: Represents the brightness of a single pixel in an image. The higher the gray value, the brighter it is. In this embodiment, an 8-bit gray histogram is used, with gray values ranging from 0 to 255. The gray value of white is 255, and the gray value of black is 0.
[0068] Gray level: Represents the brightness level corresponding to the gray value of different pixels in an image. Different gray levels in an image are divided into their own corresponding gray value ranges. The larger the gray level, the wider the brightness range of the image. In this embodiment, an 8-bit gray-level histogram is used, that is, divided into 256 gray levels.
[0069] Normalized gray level: refers to the normalized gray level obtained by dividing the above gray levels by 255, which facilitates subsequent probability calculations and the calculation of gray values for new images.
[0070] Gray-level histogram: A gray-level histogram is a function of the gray-level distribution, and it is a statistical representation of the gray-level distribution in an image. The gray-level histogram calculates the frequency of occurrence of all pixels in an image according to their gray-level values.
[0071] Histogram equalization enhancement processing: The gray levels with a large number of pixels in the image (i.e., the gray levels that play a major role in the image) are widened, while the gray levels with a small number of pixels (i.e., the gray levels that do not play a major role in the image) are merged, thereby increasing the contrast and making the image clearer, thus achieving the purpose of enhancement. The process of histogram equalization enhancement processing is as follows: (1) Histogram equalization processing is performed on the gray histogram of the image to obtain the cumulative probability distribution function of each normalized gray level; (2) The gray values of the image are updated according to the cumulative probability distribution function of each normalized gray level, and the enhanced image is obtained after the gray values are updated.
[0072] CLAHE (Contrast Limited Adaptive Histogram Equalization) is an algorithm used to enhance image contrast. It is an adaptive histogram equalization technique used to enhance the local contrast of an image. The algorithm includes: (1) allocating pixels to the grayscale histogram of the original image according to a cropping threshold to avoid over-enhancement; and (2) performing histogram equalization enhancement processing on the grayscale histogram of the allocated image to obtain an image with increased contrast. CLAHE is generally used for image enhancement in fields such as dehazing and medical imaging.
[0073] YOLOv5 is an end-to-end deep learning model that can directly detect and locate objects from raw images. It uses a convolutional neural network (CNN) to learn the features of objects in an image and employs multi-scale prediction and grid segmentation to detect and locate objects. YOLOv5's advantages include its high speed and excellent performance across various image resolutions.
[0074] First, it should be noted that during the development of this solution, the inventors discovered that when the road surface water is concentrated in the central area of a nighttime water accumulation image, the water accumulation area corresponding to the central area is easily illuminated and reflected by car headlights, causing glare to oncoming drivers. Conversely, water accumulation areas not in the central area are less likely to be illuminated and reflected by car headlights, thus reducing the likelihood of glare. Furthermore, when the road surface water is not concentrated in the central area, it is also less likely to be illuminated and reflected by car headlights, again reducing the likelihood of glare. Simultaneously, the grayscale histogram of the central area of the nighttime water accumulation image still exhibits the characteristic that gray levels with more pixels represent the main road or water accumulation area, while gray levels with fewer pixels represent less important areas. Based on this characteristic, the inventors determined the target sub-block clipping threshold in the CLAHE algorithm by using the gray levels with more pixels in the grayscale histogram of the central area of the nighttime water accumulation image. This can be used in subsequent algorithms to improve the contrast between the water accumulation and the road surface in the central area of the nighttime water accumulation image, facilitating the subsequent YOLOv5 algorithm's determination of the water accumulation location based on the enhanced nighttime water accumulation image.
[0075] The improved image enhancement method of this embodiment will be described in detail below. It should be noted that this scheme is applicable to image enhancement processing in all complex situations, such as pothole images during the day and / or at dusk. Pothole images include dry pothole areas and waterlogged pothole areas. It can achieve the effect of identifying potholes and detecting their location information. Of course, this method is also applicable to the enhancement processing of ordinary images. It can avoid the over-enhancement phenomenon of traditional histogram equalization enhancement processing algorithms while improving the contrast effect of ordinary images.
[0076] The following uses a nighttime flooded image as an example to illustrate the image enhancement method of this embodiment. The enhancement process for other complex or ordinary images is similar to that for nighttime flooded images.
[0077] refer to Figure 1 The image enhancement processing method in this embodiment includes:
[0078] S110, determine the target sub-block cropping threshold in the CLAHE algorithm based on the central sub-block image of the central region of the nighttime water accumulation image and the target sub-block image of the nighttime water accumulation image. The target sub-block image is obtained by dividing the nighttime water accumulation image according to a predetermined division rule. The predetermined division rule is: based on the overall layout of the nighttime water accumulation image, the nighttime water accumulation image is divided evenly. The number of target sub-block images obtained after even division satisfies that it is divisible by both the number of rows and the number of columns. The number of rows is the total number of pixel rows in the nighttime water accumulation image, and the number of columns is the total number of pixel columns in the nighttime water accumulation image.
[0079] It should be noted that this embodiment can use a common vehicle-mounted camera to capture images of the road surface directly in front of the vehicle at a suitable angle to obtain images of the waterlogged area at night. The vehicle-mounted camera captures 30 frames per second. The PC then converts the captured images into grayscale images, which is the nighttime waterlogged image obtained in this embodiment. The nighttime waterlogged image is the image obtained after converting the captured image into a grayscale image. This method of converting the original color image into a grayscale image reduces the amount of data by three times, which can speed up the subsequent algorithm's processing speed.
[0080] S120, according to the CLAHE algorithm, perform contrast-limited adaptive histogram equalization processing on each target sub-block image to obtain the enhanced sub-image;
[0081] S130, based on a predetermined partitioning rule, the enhanced sub-images of all target sub-block images are stitched together to obtain an enhanced image.
[0082] To more effectively enhance nighttime flooded areas in nighttime flooded images, this embodiment improves the CLAHE algorithm. It addresses the issue of manually determining a fixed cropping threshold in the traditional CLAHE algorithm. Specifically, the target sub-block cropping threshold in the CLAHE algorithm is determined based on the central and target sub-block images of different nighttime flooded images. Different nighttime flooded images correspond to different target sub-block cropping thresholds, thus enabling dynamic adjustment of the target sub-block cropping threshold as each nighttime flooded image changes. Therefore, for different nighttime flooded images, the pixel allocation strategy is more reasonable, utilizing the distribution of the original pixel count at all normalized gray levels relative to their respective independent target sub-block cropping thresholds. This results in a more stable enhancement effect in the final enhanced sub-image after applying contrast-limited adaptive histogram equalization to the target sub-block image with the improved CLAHE algorithm after reallocating the pixel count at all normalized gray levels. In the field of nighttime rainy driving, this solution addresses the challenges of constantly changing nighttime water accumulation images and varying water sizes across different nighttime water accumulation images, resulting in different numbers of pixels at different gray levels for the water accumulation. It achieves stable image enhancement based on independent target sub-block cropping thresholds determined for each independent nighttime water accumulation image, which further facilitates accurate identification of water accumulation locations based on the enhanced images.
[0083] refer to Figure 2 In this embodiment, the method for determining the clipping threshold in the CLAHE algorithm can be as follows:
[0084] S111, Obtain the central sub-block image P based on the central region of the nighttime water accumulation image.
[0085] Specifically, the line intervals are cropped from the central region of the nighttime flood image. The column interval is The image is taken as the central sub-block image P, where This represents the total number of pixel rows in the nighttime flood image. This represents the total number of pixel columns in the nighttime flood image. At this time, the total number of pixels in the central sub-block image P is... .
[0086] S112, Determine the reference threshold for the number of clipping operations in the CLAHE algorithm based on the central sub-block image P. .
[0087] Specifically, in this embodiment, the number of cuts is referenced to a threshold. Set as the quotient of the first value and the second value, where the first value is all values in set X that are not less than... The smallest element in set X, and the second value is the index of the element in set X corresponding to the first value. ,in It is the first in set X An element with index n, and equal to the element with index n from the first index to the nth index n in set M. The sum of the elements corresponding to each index, set M = ,in This indicates that all normalized gray levels of the central sub-block image P are sorted in descending order according to the number of pixels they correspond to in the central sub-block image P, and the gray level located at the [number]th [position]. The number of pixels corresponding to the normalized gray level of each index in the central sub-block image P, 1 ≤ ≤ , The number of normalized gray levels in the central sub-block image P. Let P be the total number of pixels in the central sub-block image P.
[0088] Specifically, after sorting all normalized gray levels of the central sub-block image P in descending order of their corresponding pixel count, the following steps are performed: ,in This indicates that all normalized gray levels of the central sub-block image P are sorted in descending order of their corresponding pixel counts and are located at the [number]th [position]. The normalized gray levels of each index, 1≤ ≤ , Let P be the number of normalized gray levels in the central sub-block image; the number of pixels corresponding to each normalized gray level after sorting is... ,in Indicates the first The number of pixels in the central sub-block image P with each indexed normalized gray level, 1 ≤ ≤ Sum the number of pixels corresponding to the normalized gray levels from largest to smallest. When the sum is first greater than or equal to... When, determine that the first time is greater than The summation value is the first The summation of the corresponding pixel counts, i.e.
[0089] (1)
[0090] Then the number of cuts reference thresholds The calculation formula is as follows:
[0091] (2)
[0092] S113, the nighttime water accumulation image is divided according to a predetermined division rule to obtain multiple target sub-block images, wherein the predetermined division rule is: based on the overall layout of the nighttime water accumulation image, the nighttime water accumulation image is divided into... Images of target sub-blocks of equal size that do not overlap In order to be able to be simultaneously and Divisible integers, where This represents the total number of pixel rows in the nighttime flood image. This represents the total number of pixel columns in the nighttime flooded image.
[0093] Understandably, the total number of pixels in each target sub-block image All target sub-block images constitute set B, and set B = ,in Let represent the target sub-block image with the i-th index, where 1 ≤ i ≤ t.
[0094] In this embodiment, to ensure that the target sub-block images do not overlap and are more suitable for subsequent YOLOv5 algorithm model training and recognition, Ideally, the integer should be divisible by Rows, Cols, and 640, so that the YOLOv5 algorithm model performs better when trained and recognized using image units of size 640×640.
[0095] S114, determine the target sub-block cropping threshold based on the cropping number reference threshold, the total number of pixels in each central sub-block image, and the total number of pixels in the target sub-block image. The formula is as follows:
[0096] (3)
[0097] in, The threshold for the number of target sub-blocks to be pruned. This serves as a reference threshold for the number of cuts. The total number of pixels in the central sub-block image. The total number of pixels in each target sub-block image.
[0098] As can be seen from the above scheme, the target sub-block pruning threshold in the improved CLAHE algorithm of this embodiment... The target sub-block cropping threshold is determined based on the central sub-block image and the target sub-block image of different nighttime water accumulation images. The threshold is dynamically adjusted based on the pixel count distribution of the normalized grayscale levels in the central sub-block image of different nighttime water accumulation images. Using a dynamically changing target sub-block pruning threshold The CLAHE algorithm, after performing contrast-limited adaptive histogram equalization on nighttime flooded images, can ensure a relatively stable enhancement effect for different nighttime flooded images.
[0099] In a preferred embodiment, step S120 involves performing contrast-limited adaptive histogram equalization on each target sub-block image to obtain an enhanced sub-image, specifically including:
[0100] S121, based on the CLAHE algorithm, determines the number of pixels that should be allocated to each normalized gray level in the gray-level histogram of each target sub-block image according to the target sub-block cropping number threshold, thus obtaining a new gray-level histogram for each target sub-block image. The allocation formula for the number of pixels at each normalized gray level is as follows:
[0101] (4)
[0102] Where i is the index of the target sub-block image in the nighttime water accumulation image, 1≤i≤t; The number of normalized gray levels in the i-th target sub-block image is given. All normalized gray levels in the i-th target sub-block image are sorted in ascending order according to their corresponding gray value ranges, and the sorting sequence number starts from 0. For the i-th target sub-block image, the th The original number of pixels for each normalized gray level. For the i-th target sub-block image, the th The number of pixels that should be allocated to the normalized gray level of each index, 0≤ ≤ ; The threshold for the number of target sub-blocks to be pruned; Let be the number of pixels in the i-th target sub-block image that are evenly distributed across all normalized gray levels. The calculation formula is as follows:
[0103] (5)
[0104] in, The number of normalized gray levels in the i-th target sub-block image; For the i-th target sub-block image, the number of target sub-blocks exceeding the target sub-block cropping threshold is... The number of pixels is calculated using the following formula:
[0105] (6)
[0106] in, Let be the total number of pixels in the i-th target sub-block image.
[0107] It should be noted that in the original grayscale histogram of the i-th target sub-block image, the horizontal axis represents the normalized grayscale level, which corresponds one-to-one with each grayscale level of the i-th target sub-block image, and the vertical axis represents the number of original pixels corresponding to the normalized grayscale level on the horizontal axis. In the new grayscale histogram of the i-th target sub-block image, the horizontal axis represents the normalized grayscale level, which is the same as in the original grayscale histogram, and the vertical axis represents the number of pixels allocated to the normalized grayscale level on the horizontal axis.
[0108] S122, based on the CLAHE algorithm, performs histogram equalization on the new gray-level histogram of each target sub-block image to obtain the cumulative probability distribution function of each normalized gray level. The formula for calculating the cumulative probability of each normalized gray level is as follows:
[0109] (7)
[0110] In the formula: For the i-th target sub-block The cumulative probability of the normalized gray level of each sequence number; The number of normalized gray levels in the i-th target sub-block image; This represents the normalized gray level of the j-th index in the image of the i-th target sub-block, 0 ≤ ≤ ; For the i-th target sub-block image, the th The probability of a normalized gray level with a given index appearing after allocating a certain number of pixels. The calculation formula is:
[0111] (8)
[0112] in, For the i-th target sub-block image, the th The number of pixels assigned to each normalized gray level of a sequence number; For the i-th target sub-block image, the th The number of pixels assigned to each normalized gray level of a sequence number, 0 ≤ ≤ ; The number of normalized gray levels in the i-th target sub-block image.
[0113] It should be noted that after the normalized gray level of the i-th target sub-block image is redistributed to a certain number of pixels, the number of pixels is... The probability of the normalized gray level of each index appearing in the image of the i-th target sub-block is changed from the original... Change to ,in , For the i-th target sub-block image, the th The original probability of the normalized gray level of each index. For the i-th target sub-block image, the th The original number of pixels for each normalized gray level. Let be the original total number of pixels in the i-th target sub-block image.
[0114] S123, for each target sub-block image, update the gray value of the corresponding pixel using the cumulative probability distribution function of the normalized gray level of each pixel to obtain the enhanced sub-image.
[0115] Specifically, step S123 includes:
[0116] (1) For each pixel in each target sub-block image, update the gray value of the pixel according to the cumulative probability of the normalized gray level corresponding to the gray value of the pixel. The gray value update formula is:
[0117] (9)
[0118] In this context, all normalized gray levels in the i-th target sub-block image are sorted in ascending order according to their corresponding gray value ranges, with the sorting sequence number starting from 0. The original grayscale value of the current pixel in the i-th target sub-block image. The corresponding normalized gray level index, 0≤ ≤ , The number of normalized gray levels in the i-th target sub-block image; The original grayscale value of the current pixel in the i-th target sub-block image. The corresponding number Normalized gray levels of each sequence number The cumulative probability; c is the preset value for the number of grayscale bits of the enhanced sub-image; Let be the updated grayscale value of the current pixel in the i-th target sub-block image.
[0119] It should be noted that the number of bits c in the grayscale value of the enhanced sub-image can be freely set. In this embodiment, the enhanced sub-image corresponding to the i-th target sub-block uses 8-bit grayscale value, in which case c equals 8; this method can also use 32-bit grayscale value, in which case c equals 32.
[0120] (2) For each target sub-block image, replace the original gray value with the updated gray value of each pixel to obtain the enhanced sub-image.
[0121] Understandably, the total number of pixels in the enhanced sub-image is the same as the total number of pixels in the target sub-image, and each pixel in the enhanced sub-image has a corresponding pixel in the target sub-image.
[0122] For pixels in the target sub-image that belong to the same normalized gray level, these pixels have the same updated gray value. Since the updated gray values of these pixels form the enhanced sub-image, the gray values of pixels in the enhanced sub-image that were updated from the same normalized gray level in the target sub-image are the same. Because the normalized gray levels in the image are divided according to the gray value range of pixels, pixels with the same gray value in the enhanced sub-image belong to the same normalized gray level. Furthermore, since all normalized gray levels in the image are sorted from smallest to largest according to the gray value in their corresponding gray value range, the gray value of a pixel at a later normalized gray level in the enhanced sub-image is greater than the gray value of a pixel at a previous normalized gray level.
[0123] Since the gray values of each pixel at the same normalized gray level in the enhanced sub-image are calculated based on the cumulative probability of the normalized gray level of the corresponding pixel in the target sub-block image, and since all pixels at the same normalized gray level in the enhanced sub-image also belong to the same normalized gray level as pixels in the target sub-block image, the index of the normalized gray level in the enhanced sub-image is the same as the index of the normalized gray level in the target sub-block image. Therefore, in formula (9)... Not only the current pixel in the i-th target sub-block image (the original grayscale value of the current pixel) The i-th target sub-block image corresponds to the i-th The updated gray value (the normalized gray level of the sequence number) is also the gray value of the corresponding pixel in the enhanced sub-image, where the gray value of the corresponding pixel corresponds to the first... The normalized gray levels of each sequence number, i.e. It is the enhanced sub-image corresponding to the i-th target sub-block image. The gray value corresponding to the normalized gray level of each sequence number.
[0124] In this embodiment, a loop traversal method can be used to update the grayscale values of all pixels in the target sub-block image. After traversing all pixels in the target sub-block image, the updated grayscale values of each pixel are used. Replace the original grayscale values in the target sub-block image. This process yields an enhanced sub-image for each target sub-block image. Subsequently, based on predetermined partitioning rules, the enhanced sub-images corresponding to all target sub-block images are stitched together to obtain the enhanced image.
[0125] It should be noted that in nighttime flooded images, the normalized gray levels with more pixels represent either the main road surface area or the main flooded area, while the normalized gray levels with fewer pixels represent less important areas, i.e., image edges or the boundaries between the road surface area and the flooded area. Because the gray values of the main road surface area and the main flooded area in the original nighttime flooded image are very close, although they differ slightly, it is impossible to distinguish between them.
[0126] In step S121 of this scheme, the normalized gray levels of each target sub-block image in the gray-level histogram of the nighttime water accumulation image are adjusted according to an adaptively varying target sub-block cropping threshold. The number of pixels is redistributed to obtain a new grayscale histogram. The maximum number of pixels with normalized gray levels in the new grayscale histogram is limited to a certain value. Within this range, the difference between the cumulative probability of the normalized gray level and the cumulative probability of the previous normalized gray level in the gray-level histogram after redistribution is limited. This not only avoids the over-enhancement phenomenon caused by directly performing traditional histogram equalization enhancement on the gray-level histogram of the original target sub-block image, but also dynamically ensures that the contrast between water accumulation and road surface in different nighttime water accumulation images generated during driving is stably improved.
[0127] Based on the pixel distribution rules of each normalized gray level in the gray-level histogram of the target sub-block image of the nighttime flooded area, and the pixel characteristics of the normalized gray levels corresponding to the main road area, the main flooded area, and the non-important areas in the nighttime flooded area image, it can be concluded that in the new gray-level histogram obtained after redistributing the pixel count from the original gray-level histogram of the target sub-block image, the normalized gray levels with a larger number of pixels still represent the main road area or the main flooded area, while the normalized gray levels with a smaller number of pixels still represent the non-important areas. According to steps S122 and S123 of this scheme, since It is the enhanced sub-image corresponding to the i-th target sub-block image. The gray values corresponding to the normalized gray levels of each index are given. Therefore, the difference between the gray values corresponding to adjacent gray levels in the gray-level histogram of the enhanced sub-image is:
[0128]
[0129] As can be seen from the above formula, in the enhanced sub-image corresponding to the i-th target sub-block image, the i-th target sub-block image... The gray value corresponding to the normalized gray level of the sequence number and the number of the sequence number. The difference corresponding to the normalized gray levels of -1 sequence number The first grayscale histogram of the i-th target sub-block image is compared with the second grayscale histogram of the i-th target sub-block image. The probability of the normalized gray level of each index Related. When the first [value] in the new grayscale histogram of the target sub-block image... Number of pixels at each normalized gray level When the value is large, it is easy to know, according to equation (8), the probability of its appearance in the i-th target sub-block image is obtained. It is also relatively large, that is, the corresponding difference. It is also relatively large. Similarly, if the first gray-level histogram of the new gray-level image of the target sub-block is larger... Number of pixels at each normalized gray level When it is small, the corresponding difference The gray values are also relatively small. Therefore, this method can broaden the gray values corresponding to the normalized gray levels with a large number of pixels in nighttime flooded images (i.e., the gray values of the water and road in the central area of the nighttime flooded image that play a major role in the image), while compressing the gray values corresponding to the normalized gray levels with a small number of pixels (i.e., the gray values of non-important areas such as edge details that do not play a major role in the image). This increases the difference between the gray values of the main road area and the main water area, enhances the contrast between the water and the road, increases the overall image contrast, and makes the image clearer. It can better distinguish which area is the water area and which area is the road area. This method is the improved CLAHE algorithm proposed in this embodiment. At this time, the nighttime flooded image has achieved adaptive dynamic range histogram equalization enhancement, which facilitates the subsequent YOLOv5 algorithm model to accurately identify the location of the water in the enhanced image.
[0130] refer to Figure 3 This embodiment provides a method for adjusting the angle of car headlights based on nighttime water accumulation images, including the following steps:
[0131] S210, Obtain an image training set, and use the aforementioned image enhancement method to enhance each image in the image training set to obtain an enhanced image training set, wherein the image training set includes images of water accumulation at night.
[0132] In this embodiment, an image acquisition device, such as a camera, is used to acquire images of waterlogged areas on the road at night, resulting in nighttime waterlogged images.
[0133] In this embodiment, the PC uses the aforementioned image enhancement method to perform contrast-limited adaptive histogram equalization (HMAE) on each target sub-block of the nighttime flooded image. HMAE involves broadening the gray values corresponding to normalized gray levels with a large number of pixels in the original nighttime flooded image, while compressing the gray values corresponding to normalized gray levels with a small number of pixels without over-enhancing. After HMAE, the enhanced image shows a greater difference in gray values between the main road area and the main flooded area, thus enhancing the overall image contrast. This results in a clear difference in contrast between the flooded area and the road, facilitating more accurate recognition of the new histogram-equalized image using the YOLOv5 algorithm.
[0134] S220: Use the enhanced image training set and manually labeled water accumulation location information to train the YOLOv5 algorithm model and obtain the trained YOLOv5 algorithm model.
[0135] S230: Upon receiving a request to adjust the angle of the car headlights, determine the location of the nighttime water accumulation based on the nighttime water accumulation image corresponding to the request and the trained YOLOv5 algorithm model.
[0136] Specifically, after receiving a request to adjust the headlight angle of a car, a nighttime water accumulation image corresponding to the request is obtained. The nighttime water accumulation image is then enhanced using the aforementioned image enhancement method. The enhanced nighttime water accumulation image is then input into the trained YOLOv5 algorithm model, at which point the location of the nighttime water accumulation is obtained. The location of the nighttime water accumulation includes the center coordinate data of the nighttime water accumulation area.
[0137] S240 adjusts the headlight angle based on the nighttime water accumulation location output by the trained YOLOv5 algorithm model, thereby preventing the car from illuminating the water accumulation location.
[0138] Specifically, step S240 includes:
[0139] S241, The PC determines the headlight angle adjustment strategy based on the nighttime water accumulation location output by the trained YOLOv5 algorithm model.
[0140] S242, the PC sends the headlight angle adjustment command to the Freescale control module. The headlight angle adjustment command contains data about the headlight angle adjustment strategy.
[0141] S243, the Freescale control module converts the headlight angle adjustment strategy data contained in the headlight angle adjustment command into 16-bit frame headlight angle control signal data, and transmits the headlight angle control signal data to the LED driver module via the SPI protocol.
[0142] S244, the LED driver module adjusts the illumination angle of the car headlights according to the headlight angle control signal data, thereby avoiding illuminating the water accumulation area.
[0143] More specifically, step S241 may include a headlight angle adjustment strategy for automobiles:
[0144] S241a, the PC terminal determines whether the vertical distance *d* between the center coordinates of the nighttime water accumulation area (as output by the YOLOv5 algorithm model) and the center point coordinates of the nighttime water accumulation image satisfies a predetermined condition. The predetermined condition is: the difference *d* is within... Within the range, The total number of pixel rows in the nighttime water accumulation image corresponding to the vehicle headlight angle adjustment request;
[0145] S241b, if the value d satisfies a predetermined condition, then when the center coordinates of the water accumulation location output by the YOLOv5 algorithm model are below the center coordinates of the nighttime water accumulation image, that is, when the difference d satisfies... The vertical illumination angles of both the left and right headlights are adjusted to 2°. When the center coordinates of the water accumulation location output by the YOLOv5 algorithm model are in the same row or above the center coordinates of the nighttime water accumulation image, i.e., the difference d satisfies... The vertical illumination angles of both the left and right headlights are adjusted to -2°. Based on the center coordinates of the water accumulation on the road surface identified by the YOLOv5 algorithm model, the angle between the headlights and the road surface is dynamically adjusted in reverse to ensure that there is at least a 2° gap between the headlights and the water accumulation on the road surface during rainy weather. This at least 2° gap allows the car to avoid the water accumulation area, thus preventing the headlights from directly illuminating the center of the water accumulation. Therefore, it will not cause glare to oncoming drivers and can ensure the safety of driving at night in rainy weather.
[0146] S241c, if the value d does not meet the predetermined conditions, then it is not necessary to adjust the vertical illumination angle of the left and right headlights of the car.
[0147] refer to Figure 4 This embodiment provides another method for adjusting the angle of car headlights based on nighttime water accumulation images, including the following steps:
[0148] S310, Obtain an image training set, and enhance each image in the image training set using the aforementioned image enhancement method to obtain an enhanced image training set. The image training set includes nighttime water accumulation images and daytime and / or evening pothole images. The pothole images include dry pothole area images and water-filled pothole area images.
[0149] S320: Use the enhanced image training set corresponding to the pothole images during the day or evening and the manually labeled pothole location information to train the YOLOv5 algorithm model and obtain the initially trained YOLOv5 algorithm model.
[0150] S330: Use the enhanced image training set corresponding to the nighttime water accumulation image and the manually labeled water accumulation location information to train the pre-trained YOLOv5 algorithm model, and obtain the trained YOLOv5 algorithm model.
[0151] S340, upon receiving a request to adjust the angle of the car headlights, determines the location of the nighttime water accumulation based on the nighttime water accumulation image corresponding to the request and the trained YOLOv5 algorithm model.
[0152] S350: Adjusts the angle of the car's headlights according to the location of water accumulation at night, so that the car avoids illuminating the water accumulation.
[0153] In the training process of both the initially trained YOLOv5 algorithm model and the final trained YOLOv5 algorithm model, image features are not trained; only the location information corresponding to the image features is trained.
[0154] In the above scheme, the YOLOv5 algorithm network model is first trained using daytime and evening datasets of water accumulation and potholes, which optimizes the model's ability to identify water accumulation locations. Then, the YOLOv5 algorithm network model is trained again using nighttime data, which further enhances the YOLOv5 algorithm's ability to identify water accumulation locations in front of vehicles at night.
[0155] The main function of this method is to accurately identify the location of water accumulation in front of the vehicle's travel area and transmit the water accumulation location information to a Freescale microcontroller to control the vehicle's headlights to achieve anti-glare. Addressing the issue of decreased accuracy in water accumulation recognition by machine vision methods under insufficient nighttime lighting, this method first employs an improved CLAHE algorithm for contrast-limited adaptive histogram equalization, increasing the contrast between water accumulation and road in nighttime water accumulation images, facilitating retraining and improvement of the YOLOv5 algorithm. Then, to ensure accurate recognition of nighttime water accumulation images after contrast-limited adaptive histogram equalization, a transfer learning method is used to retrain and improve the YOLOv5 algorithm network using a dataset of manually labeled images taken on rainy nights. During dataset creation, targets irrelevant to the road scene are excluded, while potential water accumulation targets that may appear on the road are categorized according to the present invention, such as potholes. To reduce the types of targets to be recognized and make the network more targeted at nighttime targets, transfer learning is required for the target model. Furthermore, to reduce the total training time of the YOLOv5 model and facilitate faster convergence of model parameters, this method is implemented. In the transfer learning process, the image feature extraction part of the model is frozen, and only the classification and recursive recognition of target classification and location are trained separately. In the actual program, the `requires_grad` parameter of the corresponding part of the model is set to 0, so that the gradient loss is not backpropagated during the training of this part of the model, thus saving overall training time. First, the model is trained using datasets of puddles and potholes from daytime and evening to optimize the network's ability to recognize puddles. After more than 300 rounds of training, when the loss function curve and accuracy curve tend to stabilize, training is stopped and the parameter model is saved as the initially trained YOLOv5 algorithm model.
[0156] Since the application scenario of this invention is mainly nighttime driving environments, to further enhance the YOLOv5 algorithm's ability to recognize pedestrians and vehicles ahead of vehicles at night, it is necessary to retrain the initially trained YOLOv5 algorithm model using nighttime data. The nighttime water accumulation images in this invention were mainly captured by an onboard camera during nighttime rainy driving, including a total of 7 hours and 15,000 videos and photos of various road sections such as urban roads and highways. From these, 5,000 clear and suitable photos were selected as the training set. LabelImg software was used to label the selected photos with water accumulation and potholes. Finally, 4,000 photos were selected as the training set, and 1,000 photos as the test set. The model was trained using the dataset prepared above. During training, the initial learning rate was set to 0.001, the number of iterations was 300, and the training time was approximately 26 hours. After the loss function curve and accuracy curve stabilized, training was stopped, and the parameter model was saved as the final trained YOLOv5 algorithm model.
[0157] The inventors of this method jointly deployed and experimented with the final trained YOLOv5 algorithm model and the improved CLAHE algorithm. Experimental results show that the improved CLAHE algorithm can increase the contrast between water accumulation and road surface by 40.35%, and the accuracy of the YOLOv5 object detection algorithm reaches over 80%, meeting the requirements for practical applications. Overall, it exhibits high flexibility and improves safety for driving at night in rainy weather.
[0158] The above description is merely an optional embodiment of this disclosure and is not intended to limit this disclosure. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this disclosure should be included within the protection scope of this disclosure.
Claims
1. An image enhancement method, comprising: S110, determine the target sub-block cropping threshold in the CLAHE algorithm based on the central sub-block image of the central region of the nighttime water accumulation image and the target sub-block image of the nighttime water accumulation image. The target sub-block image is obtained by dividing the nighttime water accumulation image according to a predetermined division rule. The predetermined division rule is: based on the overall layout of the nighttime water accumulation image, the nighttime water accumulation image is divided evenly. The number of target sub-block images obtained after even division satisfies that it is divisible by both the number of rows and the number of columns. The number of rows is the total number of pixel rows in the nighttime water accumulation image, and the number of columns is the total number of pixel columns in the nighttime water accumulation image. S120, according to the CLAHE algorithm, perform contrast-limited adaptive histogram equalization processing on each target sub-block image to obtain the enhanced sub-image; S130, based on a predetermined partitioning rule, the enhanced sub-images of all target sub-block images are stitched together to obtain the enhanced image. Specifically, step S110 is as follows: S111, Determine the reference threshold for the number of clipping elements based on the central sub-block image P. Specifically, this means: setting the number of cuts as a reference threshold. Set as the quotient of the first value and the second value, where the first value is all values in set X that are not less than... The smallest element in set X, and the second value is the index of the element in set X corresponding to the first value. ,in It is the first in set X An element with index n, and equal to the element with index n from the first index to the nth index n in set M. The sum of the elements corresponding to each index, set M = ,in This indicates that after all normalized gray levels in the central sub-block image are sorted in descending order of their respective pixel counts, the i-th... The number of pixels at each normalized gray level, 1 ≤ ≤ , The number of normalized gray levels in the central sub-block image; S112, determine the target sub-block pruning threshold according to the following formula: in, The threshold for the number of target sub-blocks to be pruned. This serves as a reference threshold for the number of cuts. The total number of pixels in the central sub-block image. This represents the total number of pixels in the target sub-block image.
2. The image enhancement method as described in claim 1, characterized in that, In step S110, the number of target sub-block images further satisfies the condition that it is divisible by 640.
3. The image enhancement method as described in claim 2, characterized in that, Step S120 includes: S121, based on the CLAHE algorithm, determines the number of pixels that should be allocated to each normalized gray level in the gray-level histogram of each target sub-block image according to the target sub-block cropping number threshold, thus obtaining a new gray-level histogram for each target sub-block image. The allocation formula for the number of pixels at each normalized gray level is as follows: Where i is the sequence number of the target sub-block image in the nighttime water accumulation image, and all normalized gray levels in each target sub-block image are sorted in ascending order according to their corresponding gray value range, and the sorting sequence number starts from 0; For the i-th target sub-block image, the th The original number of pixels for each normalized gray level; For the i-th target sub-block image, the th The number of pixels allocated to the normalized gray level of each index, 0≤ ≤ , The number of normalized gray levels in the i-th target sub-block image; The threshold for the number of target sub-blocks to be pruned; Let be the number of pixels that are averaged across all normalized gray levels in the i-th target sub-block image. The calculation formula is as follows: in, For the i-th target sub-block image, the number of target sub-blocks exceeding the target sub-block cropping threshold is... The number of pixels is calculated using the following formula: in, This represents the total number of pixels in the target sub-block image.
4. The image enhancement method as described in claim 3, characterized in that, Step S120 further includes: S122, based on the CLAHE algorithm, performs histogram equalization on the new gray-level histogram of each target sub-block image to obtain the cumulative probability distribution function of each normalized gray level. The formula for calculating the cumulative probability of each normalized gray level is as follows: In the formula: For the i-th target sub-block image, the th The cumulative probability of the normalized gray level of each index, 0 ≤ ≤ ; The number of normalized gray levels in the i-th target sub-block image; This represents the normalized gray level of the j-th index in the image of the i-th target sub-block, 0 ≤ ≤ ; For the i-th target sub-block image, the th The probability of a normalized gray level with a given index appearing after allocating a certain number of pixels. The calculation formula is: in, For the i-th target sub-block image, the th The number of pixels assigned to each sequence number's normalized gray level. For the i-th target sub-block image, the th The number of pixels assigned to each normalized gray level of a sequence number, 0 ≤ ≤ ; The number of normalized gray levels in the i-th target sub-block image; S123, for each target sub-block image, update the gray value of the corresponding pixel using the cumulative probability distribution function of the normalized gray level of each pixel to obtain the enhanced sub-image.
5. The image enhancement method as described in claim 4, characterized in that, Step S123 specifically includes: (1) For each pixel in each target sub-block image, update the gray value of the pixel according to the cumulative probability of the normalized gray level corresponding to the gray value of the pixel. The gray value update formula is: in, It is the index of the normalized gray level corresponding to the original gray value of the current pixel in the i-th target sub-block image; The original gray value of the current pixel in the i-th target sub-block image corresponds to the first... The cumulative probability of the normalized gray level of each index; c is the preset value of the number of bits of gray value of the enhanced sub-image; Let be the updated grayscale value of the current pixel in the i-th target sub-block image; (2) For each target sub-block image, replace the original gray value with the updated gray value of each pixel to obtain the enhanced sub-image.
6. A method for adjusting the angle of automotive headlights based on nighttime water accumulation images, comprising the following steps: S210, obtain an image training set, and use the image enhancement method according to any one of claims 1 to 5 to enhance each image in the image training set to obtain an enhanced image training set, wherein the image training set includes nighttime water accumulation images; S220: Use the enhanced image training set and manually labeled water accumulation location information to train the YOLOv5 algorithm model and obtain the trained YOLOv5 algorithm model. S230, upon receiving a request to adjust the angle of the car headlights, the location of the nighttime water accumulation is determined based on the nighttime water accumulation image corresponding to the request and the trained YOLOv5 algorithm model. S240 adjusts the headlight angle based on the nighttime water accumulation location output by the trained YOLOv5 algorithm model, thereby preventing the car from illuminating the water accumulation location.
7. The method for adjusting the angle of car headlights based on nighttime water accumulation images as described in claim 6, characterized in that, The image training set also includes daytime and / or evening images of potholes, including images of dry pothole areas and images of waterlogged pothole areas. Step S220 specifically includes: S221: Train the YOLOv5 algorithm model using the enhanced image training set corresponding to the pothole images during the day and / or evening and the manually labeled pothole location information to obtain the preliminarily trained YOLOv5 algorithm model. S223, using the enhanced image training set corresponding to the nighttime water accumulation image and the manually labeled water accumulation location information, train the initially trained YOLOv5 algorithm model to obtain the trained YOLOv5 algorithm model.
8. The method for adjusting the angle of automotive headlights based on nighttime water accumulation images as described in claim 7, characterized in that, Step S240 specifically includes: S241, The PC terminal determines the headlight angle adjustment strategy based on the location of water accumulation at night; S242, the PC sends the headlight angle adjustment command to the Freescale control module. The headlight angle adjustment command contains data about the headlight angle adjustment strategy. S243, the Freescale control module converts the headlight angle adjustment strategy data contained in the headlight angle adjustment command into headlight angle control signal data, and transmits the headlight angle control signal data to the LED driver module. S244, the LED driver module adjusts the illumination angle of the car headlights according to the headlight angle control signal data, thereby avoiding illuminating the water accumulation area.
9. The method for adjusting the angle of automotive headlights based on nighttime water accumulation images as described in claim 8, characterized in that, Step S241 specifically includes: S241a, the PC terminal determines whether the difference d between the vertical distance of the center coordinates of the nighttime water accumulation area included in the nighttime water accumulation location and the center point coordinates of the nighttime water accumulation image meets a predetermined condition, wherein the predetermined condition is: the difference d is within... Within the range, The total number of pixel rows in the nighttime water accumulation image corresponding to the vehicle headlight angle adjustment request; S241b, if the value d satisfies a predetermined condition, then when the difference d is in When within the range, adjust the vertical illumination angle of both the left and right headlights to 2°; when the difference d is within... Within the range, adjust the vertical illumination angle of both the left and right headlights to -2°; S241c, if the value d does not meet the predetermined conditions, then it is not necessary to adjust the vertical illumination angle of the left and right headlights of the car.
Citation Information
Patent Citations
Image local contrast enhancement method for optimizing CLAHE
CN114092361A
Foggy weather ship detection method based on image enhancement algorithm and improved YOLOv5
CN115457258A