Automatic exposure control method and related apparatus
Patent Information
- Application Number
- CN202611374093.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-04
- Publication Date
- 2026-10-30
AI Technical Summary
[0003]相关技术中,测光通常采用固定权重对像素亮度进行平均,并根据测光值与目标亮度的偏差逐次调节曝光参数,部分方案再分阶段调节光源,因此测光结果易受背景面积、局部反光及暗部区域影响,且多参数串行调整时容易产生耦合误差,进而影响曝光控制的收敛速度和稳定性
[0051]借由上述技术方案,本申请根据当前相机曝光参数和当前光源参数下采集的待测图像生成灰度直方图,并利用直方图偏度调整灰度均值和灰度中位数在亮度计算中所占的比重,以减少背景区域、局部反光区域和局部暗部区域对亮度判断结果的干扰;同时,利用过曝像素比例和欠曝像素比例对基础亮度进行修正,使得到的反馈亮度能够反映待测图像的整体亮度以及局部过曝、局部欠曝情况。在此基础上,根据反馈亮度与预设目标亮度之间的亮度误差确定曝光调整量,并调整相机曝光时间参数、相机增益参数和光源亮度参数中的至少一项,通过重新采集图像并重复调整,使待测图像逐步达到预设目标亮度所需的曝光要求,从而提高自动曝光控制的准确性和稳定性,并减少亮部或暗部图像细节丢失。
Smart Images

Figure CN123020985A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of machine vision and image processing technology, and in particular to automatic exposure control methods and related devices. Background Technology
[0002] In industrial visual inspection, in order to ensure that target features such as chip solder joints and component surface defects are clearly identifiable, it is usually necessary to adjust the camera exposure time, analog gain and external light source brightness according to the brightness of the acquired image, so as to maintain the image at an appropriate exposure level.
[0003] In related technologies, metering typically uses a fixed weight to average pixel brightness and adjusts exposure parameters sequentially based on the deviation between the metered value and the target brightness. Some schemes further adjust the light source in stages. Therefore, metering results are easily affected by background area, local reflections, and dark areas. Furthermore, when multiple parameters are adjusted serially, coupling errors are easily generated, which in turn affect the convergence speed and stability of exposure control. Summary of the Invention
[0004] In view of the above problems, this application provides an automatic exposure control method and related apparatus to reduce the influence of local reflections, dark areas and background distribution on metering results, and improve the accuracy and stability of automatic exposure control.
[0005] The first aspect of this application provides an automatic exposure control method, comprising:
[0006] Acquire the image to be tested captured by the camera under the current camera exposure parameters and current light source parameters;
[0007] The image to be tested is converted into a grayscale image, and a grayscale histogram is generated based on the number of pixels corresponding to each grayscale level in the grayscale image.
[0008] Based on the grayscale histogram, determine the histogram skewness, grayscale mean, grayscale median, overexposed pixel ratio, and underexposed pixel ratio of the image to be tested.
[0009] The fusion weights corresponding to the mean gray level and the median gray level are determined based on the histogram skewness, and the mean gray level and the median gray level are fused based on the fusion weights to obtain the base brightness.
[0010] The base brightness is corrected based on the overexposed pixel ratio and the underexposed pixel ratio to obtain the feedback brightness of the image under test;
[0011] The brightness error is determined based on the feedback brightness and the preset target brightness, and the exposure adjustment amount is determined based on the brightness error.
[0012] Based on the exposure adjustment amount, at least one of the camera exposure time parameter, camera gain parameter, and light source brightness parameter is adjusted and the test image is re-acquired until the re-acquired test image meets the preset convergence condition.
[0013] Optionally, determining the histogram skewness, gray-level mean, gray-level median, overexposed pixel ratio, and underexposed pixel ratio of the image to be tested based on the gray-level histogram includes:
[0014] Based on the pixel probability corresponding to each gray level in the gray histogram, the gray mean, gray standard deviation, and gray cumulative distribution are determined.
[0015] The histogram skewness is determined based on the mean gray level and the standard deviation of gray level, and the median gray level is determined based on the cumulative distribution of gray level.
[0016] Based on the grayscale histogram, the probability of pixels whose grayscale value is greater than or equal to a preset high grayscale threshold is accumulated to obtain the overexposed pixel ratio.
[0017] The probability of pixels with grayscale values less than or equal to a preset low grayscale threshold is accumulated to obtain the underexposed pixel ratio; wherein, the preset high grayscale threshold and the preset low grayscale threshold are determined based on at least one of the image bit depth, black level and saturation grayscale value of the image to be tested.
[0018] Optionally, determining the fusion weights corresponding to the mean and median gray levels of the image under test based on the histogram skewness includes:
[0019] The first fusion weight corresponding to the grayscale median is determined based on the ratio of the absolute value of the histogram skewness to the preset reference skewness.
[0020] The second fusion weight corresponding to the grayscale mean is determined based on the first fusion weight, wherein the sum of the first fusion weight and the second fusion weight is one, and the first fusion weight increases as the absolute value of the histogram skewness increases.
[0021] Optionally, the step of correcting the base brightness based on the overexposed pixel ratio and the underexposed pixel ratio includes:
[0022] The brightness correction coefficient is determined based on the overexposed pixel ratio, the underexposed pixel ratio, the preset overexposed sensitivity coefficient, and the preset underexposed sensitivity coefficient.
[0023] The base brightness is corrected using the brightness correction coefficient, such that when the proportion of overexposed pixels increases, the corrected brightness value increases relative to the base brightness, and when the proportion of underexposed pixels increases, the corrected brightness value decreases relative to the base brightness.
[0024] Optionally, the method further includes:
[0025] Based on the grayscale histogram of the image to be tested, determine the first grayscale quantile value corresponding to the first preset quantile ratio and the second grayscale quantile value corresponding to the second preset quantile ratio.
[0026] The grayscale distribution span of the image under test is determined based on the difference between the first grayscale quantile and the second grayscale quantile.
[0027] The photometric reliability is determined based on the grayscale distribution span, and the base brightness after brightness correction and the preset target brightness are weighted and fused based on the photometric reliability to obtain the current feedback brightness; wherein, the photometric reliability increases as the grayscale distribution span increases.
[0028] Optionally, determining the exposure adjustment amount based on the brightness error includes:
[0029] Obtain the historical exposure value and historical feedback brightness corresponding to at least two iterations;
[0030] The response gradient of brightness relative to the exposure value is determined based on the change in exposure value and the change in feedback brightness between two adjacent iterations;
[0031] Based on the brightness error and the response gradient, predict the amount of exposure adjustment required to bring the current feedback brightness to the preset target brightness.
[0032] Optionally, determining the response gradient of brightness relative to the exposure value includes:
[0033] Calculate the ratio of the change in feedback brightness to the change in exposure value between two adjacent iterations to obtain the current gradient estimate;
[0034] When the change in the exposure value is less than a preset change threshold, or when the current gradient estimate exceeds a preset gradient range, the preset default gradient is determined as the current gradient estimate.
[0035] The current gradient estimate is fused with the historical smoothed gradient using an exponential moving average method to obtain the response gradient.
[0036] Optionally, the method for determining the exposure adjustment amount based on the brightness error further includes:
[0037] The predicted brightness for the current iteration is determined based on the feedback brightness, response gradient, and exposure value change corresponding to the previous iteration.
[0038] The prediction error is determined based on the difference between the predicted brightness and the current feedback brightness, and the prediction confidence level is determined based on the prediction error.
[0039] Based on the brightness ratio between the current feedback brightness and the preset target brightness, a conservative exposure adjustment amount is determined;
[0040] Based on the prediction confidence level, the predicted exposure adjustment amount and the conservative exposure adjustment amount are weighted and fused to obtain the exposure adjustment amount; wherein, the prediction confidence level decreases as the prediction error increases.
[0041] Optionally, adjusting at least one of the camera exposure time, analog gain, and light source brightness based on the exposure adjustment amount includes:
[0042] The candidate exposure time is determined based on the exposure adjustment amount;
[0043] When the candidate exposure time is within the preset exposure time range, the exposure adjustment amount is handled by adjusting the camera exposure time.
[0044] When the candidate exposure time exceeds the preset exposure time range, the camera exposure time is adjusted to the corresponding exposure time boundary, and the light source brightness is adjusted according to the remaining adjustment amount not borne by the camera exposure time.
[0045] When both the camera exposure time and the light source brightness reach the corresponding parameter boundaries, the analog gain is adjusted based on the remaining adjustment amount not borne by the camera exposure time and the light source brightness.
[0046] Optionally, it also includes:
[0047] The current feedback brightness is modeled as a function of the camera exposure value and the light source brightness;
[0048] In the first type of iteration, the brightness of the light source is kept constant while the camera exposure value is changed, and the exposure response gradient is determined based on the feedback brightness change and the camera exposure value change.
[0049] In the second type of iteration, the camera exposure value is kept constant while the light source brightness is changed, and the light source response gradient is determined based on the feedback brightness change and the light source brightness change.
[0050] Based on the exposure response gradient, the light source response gradient, and the brightness error, the camera exposure value adjustment amount and the light source brightness adjustment amount are determined respectively.
[0051] Using the above technical solution, this application generates a grayscale histogram based on the image to be tested acquired under the current camera exposure parameters and current light source parameters. The histogram skewness is then used to adjust the proportions of the mean and median grayscale values in brightness calculation, reducing interference from background areas, localized reflective areas, and localized dark areas on the brightness judgment results. Simultaneously, the base brightness is corrected using the proportions of overexposed and underexposed pixels, ensuring that the obtained feedback brightness reflects the overall brightness of the image to be tested, as well as localized overexposure and underexposure. Based on this, the exposure adjustment amount is determined according to the brightness error between the feedback brightness and the preset target brightness. At least one of the camera exposure time parameter, camera gain parameter, and light source brightness parameter is adjusted. By re-acquiring the image and repeating the adjustment, the image to be tested gradually reaches the exposure requirements of the preset target brightness, thereby improving the accuracy and stability of automatic exposure control and reducing the loss of image details in bright or dark areas. Attached Figure Description
[0052] Figure 1 This is a schematic flowchart of an automatic exposure control method provided in an embodiment of this application;
[0053] Figure 2 A schematic flowchart illustrating a brightness measurement method based on grayscale histogram perception, provided for an embodiment of this application;
[0054] Figure 3 A flowchart illustrating an exposure parameter allocation method based on signal-to-noise ratio optimization provided in an embodiment of this application;
[0055] Figure 4 This is a schematic diagram of another automatic exposure control method provided in an embodiment of this application;
[0056] Figure 5 This is a schematic diagram of an automatic exposure control device provided in an embodiment of this application;
[0057] Figure 6 This is a schematic diagram of a computer device structure provided in an embodiment of this application. Detailed Implementation
[0058] In existing technologies, industrial vision metering typically employs methods such as average metering, center-weighted metering, spot metering, or zone metering to obtain image brightness values. These values are then compared to a preset target brightness. Based on the deviation, methods such as proportional adjustment, proportional-integral-derivative (PID) control, fixed-step iteration, or binary search are used to adjust exposure time and analog gain. Some solutions also adjust the brightness of the external light source separately before and after adjusting the camera exposure parameters, and through multiple image acquisitions and repeated corrections, the measured brightness gradually approaches the target brightness. However, in industrial scenarios, the position, area ratio, surface reflectivity, and background brightness of the target object may vary depending on the type and orientation of the workpiece. The image may also contain bright reflective areas, dark truncated areas, or bimodal distributions. In such cases, metering results obtained based on fixed spatial weights and a single average brightness value are easily affected by large-area backgrounds or local extreme gray levels. This causes the controller to repeatedly adjust the exposure time, gain, or light source brightness based on the metering results, leading to the technical problem that the exposure parameters are difficult to converge quickly and stably to match the actual exposure state of the target object.
[0059] To address the aforementioned problems, this application provides an automatic exposure control method. The automatic exposure control method of this application embodiment is described in detail below with reference to the accompanying drawings. The overall process of the automatic exposure control method provided in this application embodiment can be understood as follows: first, an image is acquired; then, brightness is analyzed; then, parameters are adjusted based on the brightness analysis results; and finally, the image is reacquired, repeating this process cyclically. This continuously corrects the camera and light source parameters based on the actual brightness state of the image, gradually bringing the image brightness to the preset brightness requirement. Here, the image to be tested refers to the image acquired by the camera under the current exposure time, current gain, and current light source brightness. The image to be tested is mainly used to determine whether the current scene is too bright or too dark, and serves as the basis for each round of parameter adjustment. Each time, based on the brightness analysis results of the image to be tested, at least one parameter among the camera exposure time, camera gain, and light source brightness is adjusted. After the adjusted parameters take effect, a new image to be tested is acquired, which is considered a completed adjustment iteration. By performing one or more adjustment iterations, the reacquired image to be tested gradually reaches the preset brightness requirement.
[0060] Reference Figure 1 , Figure 1 This is a flowchart illustrating an automatic exposure control method provided in an embodiment of this application. Figure 1 As shown in the embodiment of this application, an automatic exposure control method may include steps 110 to 170, which are described in detail below.
[0061] 110. Acquire the image to be tested captured by the camera under the current camera exposure parameters and current light source parameters.
[0062] The camera is controlled to acquire images according to the current camera exposure parameters, and an external light source is controlled to illuminate the object under test according to the current light source parameters, in order to obtain the image under test. Here, the camera exposure parameters may include camera exposure time parameters and camera gain parameters. The camera exposure time parameter is used to control the duration for which the image sensor receives light signals during a single imaging process, and the camera gain parameter is used to control the amplification of the image sensor's output signal; the current light source parameters may include current light source brightness parameters, used to control the light intensity illuminating the object under test.
[0063] 120. Convert the image to be tested into a grayscale image, and generate a grayscale histogram based on the number of pixels corresponding to each grayscale level in the grayscale image.
[0064] For a color image to be tested, the multiple color channel values of each pixel can be converted into a single grayscale value according to a preset color channel conversion relationship to obtain a grayscale image. For grayscale images directly output by the camera, the image can be directly used as a grayscale image, and the number of pixels corresponding to each grayscale level can be counted. Taking an 8-bit grayscale image as an example, the grayscale value ranges from 0 to 255, where a smaller grayscale value indicates a darker pixel, and a larger grayscale value indicates a brighter pixel. Specifically, the number of pixels with grayscale values from 0 to 255 can be counted to generate a grayscale histogram. Specifically, the number of pixels with a grayscale value of v can be set to n. v If the total number of pixels participating in the statistics is N, then the pixel ratio p corresponding to gray level v is... v It can be represented as: p v =n v / N; where v is the gray level, ranging from 0 to 255; n v v is the number of pixels with a grayscale value equal to v; N is the total number of pixels in the grayscale image. The sum of the pixel proportions corresponding to each grayscale level is 1, that is: This allows us to construct a grayscale histogram from the pixel ratios corresponding to each grayscale level, which can then be used to represent the distribution of the number of pixels of different grayscale levels in the image under test.
[0065] 130. Based on the grayscale histogram, determine the histogram skewness, grayscale mean, grayscale median, overexposed pixel ratio, and underexposed pixel ratio of the image to be tested.
[0066] In industrial vision images, the area and brightness of the background region, the area to be measured, and locally reflective areas are often different. For example, an image may contain a large area of dark background and a small area of bright solder joints, as well as a few strongly reflective pixels. If only the grayscale mean is used to determine the image brightness, a few overly bright or dark pixels may inflate or deflate the calculated result, leading to a discrepancy between the calculated brightness and the actual brightness of the area to be measured.
[0067] Therefore, in addition to determining the grayscale mean, this application also determines the grayscale median and histogram skewness. The grayscale mean represents the average brightness of the entire image under test; the grayscale median represents the brightness level of most pixels in the image. It can be understood that the grayscale median is less affected by a small number of extremely bright or extremely dark pixels; the histogram skewness is used to determine whether the grayscale distribution is significantly biased towards bright or dark areas, that is, to determine whether the grayscale mean is easily skewed by local reflective areas, dark areas, or background areas. In practical applications, the proportion of grayscale mean and grayscale median can be changed according to the histogram skewness, so that the grayscale mean is used more when the grayscale distribution is relatively uniform, and the grayscale median is referred more when the grayscale distribution is significantly skewed.
[0068] Furthermore, judging only the average brightness of an image may still miss local exposure anomalies. For example, although the overall brightness of the image may be close to the preset target brightness, some areas may be too bright and lose highlight details, or some areas may be too dark and make it impossible to see shadow features. To address this, embodiments of this application also determine the proportion of overexposed pixels and underexposed pixels to reflect the proportion of near-saturated bright pixels and near-black dark pixels in the image under test, respectively. Subsequent correction of the brightness results using the overexposed and underexposed pixel proportions avoids ignoring local overexposure or underexposure simply because the overall brightness is suitable, thus ensuring that the determined image brightness is closer to the actual exposure state of the image under test.
[0069] 140. Determine the fusion weights corresponding to the gray mean and gray median based on the histogram skewness, and fuse the gray mean and gray median based on the fusion weights to obtain the basic brightness.
[0070] In actual industrial visual images, the grayscale mean and grayscale median reflect image brightness differently. The grayscale mean includes the brightness of all pixels in the entire image, thus reflecting the overall brightness changes of the image well. However, it is easily inflated or deflated by a few highly reflective areas, shadow areas, or large background areas. The grayscale median is less affected by a few extremely bright and dark pixels, thus reflecting the brightness level of most pixels in the image more stably. However, if only the grayscale median is used, it may not fully reflect the overall brightening or darkening of the entire image.
[0071] Therefore, this application does not fixate on either the grayscale mean or the grayscale median, but rather adaptively changes their respective weights in brightness calculation based on the grayscale distribution reflected by the histogram skewness. Here, the fusion weight can be understood as the extent to which the grayscale mean and grayscale median each influence the final calculation result. When the grayscale distribution of the image under test is relatively uniform and there is no obvious bias towards bright or dark areas, the grayscale mean can usually reflect the image brightness more accurately, thus increasing the weight of the grayscale mean. When there are obvious local reflections, local shadows, or uneven distribution of bright and dark areas in the image under test, the grayscale mean is easily skewed by these areas, thus increasing the weight of the grayscale median.
[0072] The base brightness is obtained by fusing the grayscale mean and grayscale median determined in the above manner. Base brightness can be understood as the brightness value used to make a preliminary judgment on the current brightness state of the image under test. By adjusting the influence of the grayscale mean and grayscale median according to the image's own grayscale distribution, a fixed metering method can be avoided, ensuring that the obtained base brightness reflects the overall brightness changes of the image without being easily affected by excessively bright or dark areas.
[0073] 150. Based on the proportion of overexposed and underexposed pixels, perform brightness correction on the base brightness to obtain the feedback brightness of the image under test.
[0074] In this embodiment, the base brightness is mainly used to reflect the overall brightness of the image under test. However, adjusting the exposure solely based on the base brightness may not accurately detect exposure anomalies in local areas. For example, when both bright and dark areas exist in the image under test, they may cancel each other out, making the base brightness appear close to the preset target brightness. However, some bright areas in the image may actually be overexposed, or some dark areas may still be underexposed. If the exposure control is stopped directly at this point, the texture in the overexposed areas may be indistinguishable due to excessive brightness, and the details in the underexposed areas may be unrecognizable due to insufficient brightness.
[0075] Therefore, this embodiment of the application utilizes the overexposed pixel ratio and the underexposed pixel ratio to further correct the base brightness. A larger overexposed pixel ratio indicates more pixels with excessive brightness in the image under test; in this case, correcting the base brightness towards a brighter direction can appropriately reduce exposure. A larger underexposed pixel ratio indicates more pixels with excessively low brightness in the image under test; in this case, correcting the base brightness towards a darker direction can appropriately increase exposure. The brightness obtained after correction is called the feedback brightness. The feedback brightness is used to represent the actual exposure state of the image under test in this round of automatic exposure control. Thus, even if the overall brightness of the image under test appears appropriate, the brightness judgment result can be corrected based on the actual overexposed and underexposed areas in the image, thereby more accurately reflecting whether the image under test needs to be further brightened or darkened.
[0076] 160. Determine the brightness error based on the feedback brightness and the preset target brightness, and determine the exposure adjustment amount based on the brightness error.
[0077] In this embodiment, the preset target brightness represents the desired brightness level of the image to be tested. Comparing the feedback brightness with the preset target brightness determines how much the current image to be tested differs from the desired brightness. Here, the difference between the two is called the brightness error. The brightness error is used not only to determine whether the image to be tested is too bright or too dark, but also to determine the degree of brightness or darkness. When the feedback brightness is lower than the preset target brightness, it indicates that the image to be tested is too dark, and the image brightness needs to be increased in the next round of adjustment; when the feedback brightness is higher than the preset target brightness, it indicates that the image to be tested is too bright, and the image brightness needs to be decreased in the next round of adjustment; when the feedback brightness is close to the preset target brightness, it indicates that the brightness of the image to be tested is close to the desired state, and the adjustment range in the next round can be reduced, or the adjustment can be stopped.
[0078] After determining the brightness error, the exposure adjustment amount is then determined based on this error. Here, the exposure adjustment amount indicates whether the image needs to be brightened or darkened in the next round, and by how much. Generally, the greater the difference between the measured image and the preset target brightness, the larger the determined exposure adjustment amount, in order to quickly reduce the brightness difference; the smaller the difference between the measured image and the preset target brightness, the smaller the determined exposure adjustment amount, to avoid excessive adjustment that causes the image to repeatedly change between being too bright and too dark.
[0079] 170. Based on the exposure adjustment amount, adjust at least one of the camera exposure time parameter, camera gain parameter, and light source brightness parameter, and re-acquire the test image until the re-acquired test image meets the preset convergence condition.
[0080] It's understandable that the exposure adjustment amount only indicates whether the image needs to be brightened or darkened in the next round, and by how much. Therefore, it's necessary to determine a new value for at least one of the camera's exposure time parameter, camera gain parameter, and light source brightness parameter based on the exposure adjustment amount, so that the brightness of the re-acquired image changes in the expected direction.
[0081] Camera exposure time, camera gain, and light source brightness all affect the brightness of the image under test. Adjusting the camera exposure time changes the time it takes for the image sensor to receive the light signal; adjusting the camera gain changes the amplification of the acquired signal; and adjusting the light source brightness changes the intensity of light illuminating the object under test. In practice, you can adjust only one parameter, or adjust two or three parameters simultaneously, depending on the device's parameter range and current status. Parameters not adjusted in this round will retain their current values.
[0082] For example, when the image to be tested is too dark, at least one of the following can be increased: camera exposure time, camera gain, or light source brightness, to brighten the image captured in the next test. Conversely, when the image to be tested is too bright, at least one of the following can be decreased: camera exposure time, camera gain, or light source brightness, to darken the image captured in the next test. A larger exposure adjustment indicates a greater difference between the current image and the preset target brightness, allowing for a larger adjustment range for the corresponding parameters. A smaller exposure adjustment indicates that the current image is already close to the preset target brightness, allowing for a smaller adjustment range for the corresponding parameters.
[0083] After parameter adjustments are completed, it is necessary to wait for the adjusted camera and light source parameters to take effect before re-acquiring the test image and analyzing it again. For the re-acquired test image, the baseline brightness, feedback brightness, and brightness error are determined, and the next exposure adjustment amount is determined based on the new brightness error. This process of image acquisition, brightness analysis, and parameter adjustment is repeated until the re-acquired test image meets the preset convergence conditions, gradually bringing the brightness of the test image closer to the preset target brightness.
[0084] Preset convergence conditions refer to a pre-defined set of conditions used to determine whether to stop the adjustment iteration. For example, the number of adjustment iterations is denoted as iter, representing the number of parameter adjustments and re-imaging operations completed since the initial image to be tested; the preset minimum number of iterations is denoted as iter. min The preset brightness tolerance, denoted as tolerance, is used to limit the maximum allowable deviation between the feedback brightness and the preset target brightness. In one optional implementation, the preset convergence condition can be expressed as:
[0085] converged=(iter≥iter min )∧(|B c -Bt |≤tolerance);
[0086] Where `converged` represents the convergence determination result, and `∧` indicates that all determination conditions are met simultaneously. This applies when the iteration number `iter` is greater than or equal to the preset minimum iteration number `iter`. min And feedback brightness B c With preset target brightness B t If the absolute value of the difference between the two values is less than or equal to the preset brightness tolerance, the current image under test is determined to meet the preset convergence condition, and the automatic exposure adjustment is stopped. For 8-bit grayscale images, the preset minimum number of iterations is iter. min For example, it can be set to 3, and the preset brightness tolerance can be set to 5 gray levels. The specific value can be set according to the camera parameter activation delay, image noise level and the brightness stability requirements of industrial vision inspection tasks. This application embodiment does not limit it here.
[0087] In implementations that require simultaneous limitation of image brightness and shadow quality, the preset convergence condition may further include the overexposed pixel ratio R. over Less than or equal to the preset overexposure ratio threshold, and the underexposure pixel ratio R under Less than or equal to the preset underexposure ratio threshold. Let the preset overexposure ratio threshold be R. over,th The preset underexposure threshold is R. under,th In another alternative implementation, the preset convergence condition can be expressed as:
[0088] converged=(iter≥iter min )∧(|B c -B t |≤tolerance)∧(R over ≤R over,th )∧(R under ≤R under,th );
[0089] The preset overexposure ratio threshold and preset underexposure ratio threshold are used to limit the proportion of bright pixels and dark pixels allowed in the image under test, respectively. The specific values of the preset overexposure ratio threshold and preset underexposure ratio threshold can be predetermined according to the surface reflection characteristics of the object under test, the importance of the defect detection area, and the requirements of the subsequent visual detection algorithm for bright and dark information. This embodiment of the application does not impose such limitations. When all the above conditions are met simultaneously, it is determined that the re-acquired image under test meets the preset convergence condition; when any condition is not met, a new exposure adjustment amount is determined based on the current image under test, and the next adjustment iteration is executed.
[0090] Using the above technical solution, this application generates a grayscale histogram based on the image to be tested acquired under the current camera exposure parameters and current light source parameters. The histogram skewness is then used to adjust the proportions of the mean and median grayscale values in brightness calculation, reducing interference from background areas, localized reflective areas, and localized dark areas on the brightness judgment results. Simultaneously, the base brightness is corrected using the proportions of overexposed and underexposed pixels, ensuring that the obtained feedback brightness reflects the overall brightness of the image to be tested, as well as localized overexposure and underexposure. Based on this, the exposure adjustment amount is determined according to the brightness error between the feedback brightness and the preset target brightness. At least one of the camera exposure time parameter, camera gain parameter, and light source brightness parameter is adjusted. By re-acquiring the image and repeating the adjustment, the image to be tested gradually reaches the exposure requirements of the preset target brightness, thereby improving the accuracy and stability of automatic exposure control and reducing the loss of image details in bright or dark areas.
[0091] In the aforementioned automatic exposure control process, in order for the camera to accurately adjust according to the actual brightness state of the currently acquired image, a reliable brightness measurement of the image under test is first required. Because industrial vision scenarios may involve areas of high reflectivity, dark areas, and background variations on the surface of the object being measured, simply using the overall average brightness of the image as the basis for exposure adjustment can easily lead to metering results deviating from actual requirements. For example, when there are a few highly reflective areas in the image, the average brightness may be inflated by locally bright pixels; conversely, when there is a large background area in the image, the average brightness may not accurately reflect the true exposure state of the target area.
[0092] Therefore, embodiments of this application provide a brightness measurement method based on grayscale histogram perception, such as... Figure 2 As shown, this method performs grayscale statistics on the image under test to obtain histogram features that reflect the overall brightness distribution of the image. It then combines these features with information such as the mean grayscale value, median grayscale value, histogram skewness, proportion of overexposed pixels, proportion of underexposed pixels, and effective dynamic range to comprehensively determine the current image brightness. Based on these multi-dimensional image features, this embodiment of the application can obtain feedback brightness that more closely matches the actual exposure state.
[0093] Specifically, in one feasible implementation, the above steps, based on the gray-level histogram, determine the histogram skewness, gray-level mean, gray-level median, overexposed pixel ratio, and underexposed pixel ratio of the image under test. This specifically includes: determining the gray-level mean, gray-level standard deviation, and gray-level cumulative distribution based on the pixel probabilities corresponding to each gray level in the gray-level histogram; determining the histogram skewness based on the gray-level mean and standard deviation; and determining the gray-level median based on the gray-level cumulative distribution. Here, determining the gray-level median based on the gray-level cumulative distribution includes: sorting each gray level in ascending order of gray level... The pixel probabilities corresponding to each level are accumulated; the gray level corresponding to the first time the accumulated pixel probability reaches or exceeds a preset quantile ratio is determined as the gray median, where the preset quantile ratio is 50%; according to the gray histogram, the pixel probabilities of gray values greater than or equal to a preset high gray threshold are accumulated to obtain the overexposed pixel ratio; the pixel probabilities of gray values less than or equal to a preset low gray threshold are accumulated to obtain the underexposed pixel ratio; wherein, the preset high gray threshold and the preset low gray threshold are determined based on at least one of the image bit depth, black level, and saturation gray value of the image to be tested.
[0094] In one feasible implementation, the pixel probability corresponding to gray level v is denoted as p. v This represents the proportion of pixels with a gray value of v in the entire image. Based on each gray level and its pixel probability, the gray mean can be obtained. Gray standard deviation And the cumulative distribution function (CDF) CDF(v). Wherein, CDF(v) represents the proportion of pixels that have been counted when the gray value is accumulated from the lowest gray value to v.
[0095] The gray-scale median, also known as the weighted median, can be specifically represented as: ;in, Indicates the median of grayscale; Indicates candidate gray levels; for an 8-bit grayscale image, The value range is from 0 to 255; This represents the gray level index during the accumulation process of gray levels from low to high. Represents grayscale level The corresponding pixel probability, which is the grayscale value The proportion of pixels in a grayscale image to the total number of pixels in the entire image; This indicates that the grayscale level is accumulated from 0 to the grayscale level. At that time, it represents the cumulative proportion of the corresponding pixels; 0.5 indicates a preset quantile proportion of 50%. The median grayscale value is selected from all grayscale levels that have a cumulative pixel proportion greater than or equal to 50%. In other words, it accumulates pixel probabilities starting from the lowest grayscale level, and the corresponding grayscale value is used as the median when the cumulative proportion first reaches or exceeds 50%. Compared to the grayscale mean, the median grayscale value is less susceptible to being skewed by a small number of strongly reflective pixels or extremely dark pixels. For example, in a solder joint image, if only a small area is reflective and appears white, the grayscale mean may increase significantly, while the median grayscale value still reflects the actual brightness of most areas of the image.
[0096] Histogram skewness can be expressed as: ;in, Indicates the skewness of the histogram; Let be the grayscale value of the pixel in the i-th row and j-th column. This represents the total number of pixels. and These represent the row index and column index of the pixel, respectively. This represents the total number of pixels included in the statistics; This represents the mean gray level of the image under test. The gray standard deviation of the image under test is used to represent the degree of dispersion of each pixel's gray value relative to the gray mean. This indicates that the histogram is summed up for all pixels in the image being tested. S>0 indicates a right-skewed histogram, meaning there are more dark pixels in the image; S<0 indicates a left-skewed histogram, meaning there are more bright pixels. This allows direct determination of whether the grayscale mean is skewed by a large area of dark background or bright reflective areas.
[0097] Taking an 8-bit image as an example, the overexposed pixel ratio R over and underexposed pixel ratio R under They can be represented as:
[0098] ;
[0099] ;
[0100] Representing grayscale levels, for an 8-bit grayscale image, The value range is from 0 to 255; Represents grayscale level The corresponding pixel probability, i.e., grayscale value The percentage of pixels in the image is 240; 240 is the preset high grayscale threshold, and 255 is the maximum grayscale value of an 8-bit image. This indicates the proportion of pixels with grayscale values between 240 and 255 in the entire image; 15 is the preset low grayscale threshold, therefore... This indicates the proportion of pixels with grayscale values between 0 and 15 in the entire image. R over This indicates how many pixels have been brightened to near their maximum grayscale; these areas may appear washed out and lose texture. R under This indicates how many pixels have darkened to near the lowest grayscale level; these areas may be completely black, making defects invisible. 240 and 15 are the preset high grayscale threshold and preset low grayscale threshold, respectively, and can also be adjusted based on the image's bit depth, black level, and saturation grayscale value. These parameters allow you to specifically determine whether the image is generally too bright or too dark, whether there are strong reflections or large dark areas, and whether the current brightness calculation result has been skewed by abnormal areas.
[0101] In one feasible implementation, the fusion weights corresponding to the gray mean and gray median of the image under test are determined based on the histogram skewness, including: determining a first fusion weight corresponding to the gray median based on the ratio of the absolute value of the histogram skewness to a preset reference skewness; and determining a second fusion weight corresponding to the gray mean based on the first fusion weight, wherein the sum of the first fusion weight and the second fusion weight is one, and the first fusion weight increases as the absolute value of the histogram skewness increases.
[0102] Specifically, the first fusion weight corresponding to the median gray level can be denoted as w. m Let w be the second fusion weight corresponding to the grayscale mean. μ The basic brightness is denoted as B. base Then we have:
[0103] ;
[0104] B base =w μ ·μ+w m ·B wm ;
[0105] Where S is the histogram skewness, μ is the gray-level mean, and B... wm S is the weighted median. ref The preset reference skew is a pre-set positive number used to control how quickly the weight of the grayscale median increases with the skewness; for example, it can be set to 1.0. `min` is used to take the minimum value, limiting the first fusion weight to between 0 and 1.
[0106] When the absolute value of the histogram skewness is small, it indicates that the distribution of bright and dark pixels in the image is relatively uniform, and the gray-level mean is not easily skewed by local reflections or dark areas. Therefore, the gray-level mean is mainly used. When the absolute value of the skewness is large, it indicates that the image may have large areas of dark background, small areas of bright solder joints, or areas of strong reflection. In this case, the gray-level mean is easily skewed by a few abnormal areas. Therefore, the proportion of the gray-level median is increased. For example, Sref When |S| = 1.0 and |S| = 0.3, the first blending weight is 0.3 and the second blending weight is 0.7; when |S| ≥ 1.0, the first blending weight reaches 1. The resulting base brightness can reflect the overall brightness in a normal image, and is not easily skewed by local areas when the brightness and darkness distribution is uneven.
[0107] In one feasible implementation, the base brightness is corrected based on the overexposed pixel ratio and the underexposed pixel ratio, including: determining a brightness correction coefficient based on the overexposed pixel ratio, the underexposed pixel ratio, a preset overexposed sensitivity coefficient, and a preset underexposed sensitivity coefficient; and using the brightness correction coefficient to correct the base brightness so that when the overexposed pixel ratio increases, the corrected brightness value increases relative to the base brightness, and when the underexposed pixel ratio increases, the corrected brightness value decreases relative to the base brightness.
[0108] One feasible implementation is to use overexposure / underexposure penalty correction to adjust the base brightness. This penalty can be understood as actively changing the brightness value used for exposure control when there are already many overexposed or underexposed pixels in the image, avoiding stopping adjustments simply because the overall brightness looks appropriate.
[0109] Specifically, the brightness correction coefficient λ can be expressed as: The corrected brightness value can be obtained by multiplying the base brightness value by the brightness correction factor. The percentage of overexposed pixels indicates how many pixels in the image are bright enough to be close to their maximum grayscale. The percentage of underexposed pixels indicates how many pixels in the image have darkened to near the lowest gray level; and These are the preset overexposure sensitivity coefficient and the preset underexposure sensitivity coefficient, used to control the extent to which overexposure and underexposure affect the correction results. Both are preset positive numbers, for example, both can be set to 50, but the specific values of the preset overexposure sensitivity coefficient and the preset underexposure sensitivity coefficient can be adjusted according to the camera, light source and the object being measured.
[0110] When the number of overexposed pixels increases, λ is greater than 1, and the corrected brightness value is higher than the base brightness. The system can then determine that the image is brighter than the base brightness and reduce the exposure accordingly. Conversely, when the number of underexposed pixels increases, λ is less than 1, and the corrected brightness value is lower than the base brightness. The system can then determine that the image is darker than the base brightness and increase the exposure accordingly. For example, if a chip solder joint shows a whitish area due to reflection, even if the base brightness is close to the target brightness, increasing the corrected brightness value can prompt the system to reduce the exposure. Conversely, if a defective area of a component is completely black, decreasing the corrected brightness value can prompt the system to increase the exposure. If both overexposure and underexposure exist simultaneously, the correction direction is determined by a weighted average of the two values using their corresponding sensitivity coefficients.
[0111] In one feasible implementation, the method provided in this application further includes: determining a first gray-level quantile value corresponding to a first preset quantile ratio and a second gray-level quantile value corresponding to a second preset quantile ratio based on the gray-level histogram of the image to be tested; determining the gray-level distribution span of the image to be tested based on the difference between the first gray-level quantile value and the second gray-level quantile value; determining the photometric reliability based on the gray-level distribution span, and performing weighted fusion of the brightness-corrected base brightness and the preset target brightness based on the photometric reliability to obtain the current feedback brightness; wherein the photometric reliability increases with the increase of the gray-level distribution span.
[0112] Considering that directly using the maximum and minimum grayscale values might affect the calculation results due to noise, dead pixels, or highly reflective pixels, this embodiment utilizes the effective dynamic range to determine the reliability of the current image's brightness calculation result. Specifically, the first preset quantile ratio is set to 95%, and the second preset quantile ratio is set to 5%. The 95th percentile grayscale value is then determined based on the grayscale histogram. and the 5th percentile gray value .in, This represents the grayscale value corresponding to a cumulative pixel ratio of 95%. This represents the grayscale value corresponding to when the cumulative pixel proportion reaches 5%. The grayscale distribution span (DR, Dynamic Range) can be expressed as: The grayscale distribution span, also known as the effective dynamic range, indicates how wide the grayscale range is actually occupied by most pixels in the image under test.
[0113] When the grayscale DR is large, it indicates that there is a significant grayscale difference between the bright and dark areas in the image. For example, weld points, defects, and the background can be distinguished in grayscale. In this case, the brightness value calculated from the image is relatively reliable. When the grayscale DR is small, it indicates that most pixels are squeezed into a narrow grayscale range. For example, in foggy scenes, uniform surfaces, or images of low-contrast components, slight changes in image brightness may mainly come from noise. In this case, if the exposure is adjusted directly based on the image, it is easy to cause frequent back-and-forth changes in parameters.
[0114] Specifically, the reliability of photometric measurements is denoted as... , can be represented as: ;in, A preset reference grayscale span is used to determine at what width the grayscale distribution can fully utilize the actual photometric results; for example, it can be set to 128 grayscale levels. Then, by taking the minimum value, the photometric reliability is limited to between 0 and 1, and the photometric reliability can increase as the grayscale distribution span increases.
[0115] Let the base brightness after brightness correction be... The preset target brightness is The current feedback brightness is The current feedback brightness can then be expressed as: ;when When the brightness is lower, the current feedback brightness is closer to the preset target brightness, thereby reducing erroneous adjustments caused by noise in low-contrast images; when When =1, the base brightness after brightness correction is fully adopted. This allows for normal adherence to the actual brightness when image information is sufficient, and reduces the adjustment range when image grayscale is too concentrated, resulting in more stable exposure control.
[0116] Please refer to Figure 2 After obtaining the feedback brightness, the exposure adjustment direction and adjustment range can be further determined based on the difference between the feedback brightness and the target brightness. To avoid the problems of excessive adjustment times, over-adjustment, or insufficient response speed in traditional fixed-step adjustment methods, this application embodiment can further combine the relationship between exposure changes and brightness changes in the historical adjustment process to predict the brightness response trend after the exposure parameter changes, and dynamically determine the exposure adjustment amount based on the prediction results. Correspondingly, in a feasible embodiment, determining the exposure adjustment amount based on the brightness error includes: obtaining the historical exposure value and historical feedback brightness corresponding to at least two iterations respectively; determining the brightness response gradient relative to the exposure value based on the exposure value change and feedback brightness change between two adjacent iterations; and predicting the predicted exposure adjustment amount required to make the current feedback brightness reach the preset target brightness based on the brightness error and the response gradient.
[0117] In this embodiment, online gradient estimation can be used to estimate the impact of exposure value changes on feedback brightness based on the actual image acquisition results after the two most recent consecutive adjustments. Specifically, the historical data corresponding to the (k-1)th iteration is denoted as... The current data corresponding to the k-th iteration is denoted as .in, and These represent the exposure values used in the two iterations. and These represent the feedback brightness of the images corresponding to the two iterations, respectively.
[0118] Response gradient It can be represented as: Here, the response gradient represents approximately how much the feedback brightness changes for every unit change in exposure value. For example, if the exposure value increases by 0.5 and the feedback brightness increases by 20, the response gradient is 40, meaning that for every 1 increase in exposure value, the feedback brightness increases by approximately 40 gray levels. To reduce gradient jumps caused by image noise or accidental reflections, the response gradients obtained consecutively can be smoothed to obtain a smoothed gradient. .
[0119] Let the preset target brightness be The current feedback brightness is Then predict the amount of exposure adjustment. It can be represented as:
[0120] ;
[0121] in, This indicates how much exposure value needs to be increased or decreased to reach the target brightness. The darker the current image is than the target brightness, the more the prediction tends to increase the exposure; the brighter the current image is than the target brightness, the more the prediction tends to decrease the exposure. Therefore, this embodiment can directly use the actual brightness changes of the camera, light source, and the current object under test in the previous two adjustments to predict the next adjustment range. Compared to adjusting step-by-step with a fixed step size, this reduces the number of adjustments and reduces the possibility of exceeding the target brightness in a single adjustment. When two adjacent exposure values are the same or the difference is too small, the current gradient calculation result can be omitted to avoid abnormal prediction values due to an excessively small divisor.
[0122] In one feasible embodiment, determining the response gradient of brightness relative to exposure value includes: calculating the ratio of the change in feedback brightness to the change in exposure value between two adjacent iterations to obtain the current gradient estimate; when the change in exposure value is less than a preset change threshold, or when the current gradient estimate exceeds a preset gradient range, determining the preset default gradient as the current gradient estimate; and using an exponential moving average method to fuse the current gradient estimate with historical smoothed gradients to obtain the response gradient.
[0123] In this embodiment, the current gradient estimate is first calculated using the exposure values and feedback brightness from two adjacent iterations, i.e., the change in feedback brightness is divided by the change in exposure value. This gradient represents approximately how much the image feedback brightness changes for every unit change in exposure value. To avoid mistaking image noise for brightness response when parameters remain almost unchanged, the gradient is calculated when the difference between two adjacent exposure values satisfies... If the current ratio is not used, the preset default gradient will be used instead. This is used as the current gradient estimate. This is a preset threshold for determining whether two exposure values are essentially the same. If the calculated current gradient estimate is negative, too large, or too small, exceeding the preset range, it indicates that the calculated current gradient estimate may be affected by reflections, vibrations, noise, or that the parameters have not yet taken effect. In this case, the preset default gradient will be used instead.
[0124] More specifically, to avoid sudden gradient changes caused by a single anomalous image, an exponential moving average (EMA) can be used for smoothing: ;in, This is the current gradient estimate. The historical smooth gradient from the previous iteration, In response to the gradient, This is the smoothing factor, with a value between 0 and 1; for example, it can be set to 0.6. Smoothing Factor This allows the current results to reference the latest images more, while retaining some historical results, thus avoiding drastic changes in exposure adjustment.
[0125] Under an approximately linear optical response, the brightness B can be approximated by 2. EV Proportional, therefore the default gradient is acceptable. When the reference luminance B=128, This indicates that a 1-unit change in exposure value will result in an estimated change of approximately 89 gray levels in the feedback brightness. By replacing the specific numerical anomalies of the current gradient estimate with default values and using EMA-based smoothing, subsequent exposure adjustments can be made more stable.
[0126] In one feasible implementation, determining the exposure adjustment amount based on the brightness error further includes: determining the predicted brightness corresponding to the current iteration based on the feedback brightness, response gradient, and exposure value change corresponding to the previous iteration; determining the prediction error based on the difference between the predicted brightness and the current feedback brightness, and determining the prediction confidence based on the prediction error; determining a conservative exposure adjustment amount based on the brightness ratio between the current feedback brightness and the preset target brightness; and weightedly fusing the predicted exposure adjustment amount and the conservative exposure adjustment amount based on the prediction confidence to obtain the exposure adjustment amount; wherein the prediction confidence decreases as the prediction error increases.
[0127] In one feasible implementation, we can first check whether the response gradient obtained in the previous iteration can accurately describe the relationship between exposure changes and image brightness changes. Let the feedback brightness of the previous iteration be... The smooth gradient of the previous iteration is The change in exposure value between the current iteration and the previous iteration is Then the predicted brightness of the current iteration It can be represented as: This expression can be understood as estimating the brightness that the current image should achieve based on the brightness of the previous image and how much the current exposure value has changed. For example, if the previous feedback brightness was 100 and the smoothing gradient was 40, and the current exposure value increased by 0.5, then the predicted feedback brightness for this round is 120.
[0128] Compare the predicted brightness with the current actual feedback brightness. By comparing the results, the prediction error can be obtained. : ; Indicates the first The prediction error corresponding to each iteration is used to represent the difference between the brightness predicted according to the historical brightness response relationship and the actual brightness measured this time. Indicates the first The current feedback brightness is calculated after the actual image to be measured is acquired in the next iteration; Indicates the first Before the next iteration begins, based on the feedback brightness of the previous iteration, the historical local response gradient, and the... The feedback brightness is predicted by the change in exposure value in the next iteration relative to the previous iteration; symbol This indicates taking the absolute value. The smaller the prediction error, the closer the previously estimated gradient is to the actual response of the current camera, light source, and object being measured. In this case, the predicted exposure adjustment amount based on the gradient can be used more often. The larger the prediction error, the more likely the image in this round is affected by factors such as local reflections, changes in object position, light source fluctuations, image noise, or camera parameters that have not yet stabilized. In this case, the reliability of the predicted exposure adjustment amount is not high.
[0129] More specifically, the prediction confidence level is denoted as , can be represented as: ;in, This represents the prediction confidence level corresponding to the current iteration, used to indicate the degree to which the predicted exposure adjustment amount is adopted when adjusting the exposure. The value can be limited to between 0 and 1. Indicates the first The prediction error corresponding to each iteration is the absolute value of the difference between the current actual feedback brightness and the brightness predicted based on the historical response relationship. This represents the preset error, which is a pre-set positive number used to specify at what level the prediction error increases before the adoption of the prediction results needs to be significantly reduced. This indicates the preset minimum confidence level, used to limit the minimum value of the prediction confidence level; This indicates that the larger of the two values within the parentheses is selected. When the prediction error is small, Approaching 1; as the prediction error increases, Gradually decrease.
[0130] At the same time, it can be based on the current feedback brightness. With preset target brightness The brightness ratio between them determines the conservative exposure adjustment amount: ;in, To conservatively adjust the exposure amount, This is a preset protection value greater than 0, used to prevent situations where calculation is impossible when the feedback brightness is 0. The conservative exposure adjustment amount can be calculated directly based on the ratio of the target brightness to the current brightness, without relying on the current gradient. Therefore, it is more reliable when the gradient calculation is inaccurate. For example, if the target brightness is higher than the current feedback brightness, the calculation result is positive, indicating that the exposure needs to be increased; if the target brightness is lower than the current feedback brightness, the calculation result is negative, indicating that the exposure needs to be decreased.
[0131] Final exposure adjustment It can be represented as: ;in, This is the predicted exposure adjustment amount obtained based on the brightness error and response gradient. When the actual brightness is close to the predicted brightness, the proportion of the predicted exposure adjustment amount is increased to quickly approach the target brightness; when the difference between the two is large, the proportion of the conservative exposure adjustment amount is increased to avoid excessive adjustment at once, which could cause the image to change directly from dark to bright, or from bright to dark. Therefore, exposure control can both utilize historical responses to speed up adjustments and automatically reduce adjustment risks when predictions are inaccurate.
[0132] In one feasible implementation, to avoid using a fixed exposure limit each time, the maximum allowable exposure adjustment range for the current round can be dynamically determined based on the magnitude of the current brightness error. Let the... The brightness error of the next iteration is The maximum allowable exposure adjustment range in this round is Then it can be expressed as: ;in, The basic limit is used to specify the basic adjustment range when the brightness is already close to the target brightness; for example, it can be set to 0.5EV. This is a preset reference error used to measure whether the current brightness error is a small or large error. For example, for an 8-bit grayscale image, it can be set to 64 gray levels. It represents the absolute value of the difference between the current feedback brightness and the preset target brightness. Therefore, regardless of whether the image is too bright or too dark, the limiting size is determined according to the degree of deviation from the target brightness.
[0133] To avoid the calculated limit being too small, resulting in slow adjustment speed, or the limit being too large, causing sudden parameter changes, you can also... Limited to a preset range, for example: ;in, This indicates a range limitation process: if the calculated result is less than 0.2EV, it is taken as 0.2EV; if it is greater than 0.2EV, it is taken as 2.0EV; if it falls within this range, the original calculation result is maintained. Subsequently, the exposure adjustment amount calculated in this round is limited to... to between.
[0134] For example, when =0.5EV When there are 64 gray levels, if the current brightness error is 10 gray levels, then The value is approximately 0.58 EV. At this point, smaller increments should be used for fine-tuning to avoid excessive adjustments at once. If the brightness error is 50 gray levels, then... Approximately 0.89 EV; if the brightness error reaches 128 gray levels, then At approximately 1.50 EV, a larger adjustment range is allowed, allowing the image to approach the target brightness more quickly.
[0135] Therefore, compared to always using a fixed ±1.0EV limit, this implementation automatically reduces the adjustment range when the error is small, avoiding repeated changes in the image between being too bright and too dark; when the error is large, it automatically widens the adjustment range, avoiding excessive iterations due to only being able to make small adjustments each time. At the same time, by setting an upper limit of 2.0EV, it can prevent excessively large single jumps in exposure time, camera gain, or light source brightness.
[0136] like Figure 3 As shown, after determining the exposure adjustment amount, it is necessary to further convert the exposure adjustment amount into an actual executable hardware parameter adjustment amount. The automatic exposure control in this embodiment comprehensively considers the influence of camera exposure time, light source brightness, and analog gain on image brightness and image quality, and makes reasonable allocations based on the adjustment characteristics of different parameters.
[0137] Correspondingly, in one feasible implementation, at least one of the camera exposure time, analog gain, and light source brightness is adjusted based on the exposure adjustment amount, including: determining a candidate exposure time based on the exposure adjustment amount; when the candidate exposure time is within a preset exposure time range, adjusting the camera exposure time to bear the exposure adjustment amount; when the candidate exposure time exceeds the preset exposure time range, adjusting the camera exposure time to the corresponding exposure time boundary, and adjusting the light source brightness based on the remaining adjustment amount not borne by the camera exposure time; when both the camera exposure time and the light source brightness reach the corresponding parameter boundaries, adjusting the analog gain based on the remaining adjustment amount not borne by the camera exposure time and the light source brightness.
[0138] Specifically, the exposure adjustment can be allocated sequentially to camera exposure time, light source brightness, and analog gain, following the principle of prioritizing signal-to-noise ratio (SNR). The SNR model used can be expressed as: Among them, T exp For camera exposure time, This is an analog gain factor, for example, a camera gain control value. Divide by 1024 to get F; F is the response coefficient of the sensor received signal to the change in light source brightness, which is used to represent the degree of influence of the change in light source brightness on the effective incident light signal. For example, it can be obtained by changing the light source brightness and calibrating according to the feedback brightness change relationship. The standard deviation of sensor readout noise is used to represent the influence of fixed noise generated during the sensor's electronic readout process. The specific value can be determined according to the actual camera model, and can be 3 to 5DN (Digital Number, which represents the digital grayscale count unit output by the image sensor after analog-to-digital conversion). Indicates the readout noise variance; The shot noise coefficient represents the proportion of noise caused by the randomness of photons. It can be determined based on the characteristic parameters of the image sensor or through noise measurement results under different exposure conditions.
[0139] Under this model, for Taking the partial derivative with respect to the exposure time, we get: That is, under otherwise unchanged conditions, increasing the exposure time can improve the signal-to-noise ratio. Under common operating conditions, while increasing the analog gain can improve image brightness, it also amplifies sensor readout noise; therefore, the effect on improving the signal-to-noise ratio is usually less than that of increasing the exposure time. Increasing the light source brightness increases the amount of incident light before the sensor receives the signal and does not directly amplify readout noise. Therefore, in this embodiment, the exposure time is adjusted first, followed by the light source brightness, and finally the analog gain is used.
[0140] Specifically, let the current exposure time be... Exposure adjustment amount is Then the candidate exposure time T new It can be represented as: ;
[0141] If T new Within the preset exposure time range [T min ,T max Within this range, the exposure time is directly adjusted to T. new The light source brightness and analog gain remain constant. If Tnew exceeds this range, the exposure time is set to the corresponding boundary. For example, T... new >T max At that time, set the exposure time to T. max Remaining adjustment amount for: ;
[0142] When T new <T min At the same time, the exposure time can be set to T in the same way. min And calculate the remaining adjustment amount in the negative direction.
[0143] The remaining adjustment amount can be converted into a change in light source brightness: ;in, and These are the current light source brightness and the adjusted light source brightness, respectively. and These are the lower and upper limits of light source brightness, respectively; This indicates the remaining exposure adjustment not covered by the camera's exposure time; This represents the range of equivalent exposure values corresponding to adjusting the light source from its lowest to its highest brightness; round indicates rounding, and clamp indicates limiting the result to an acceptable range.
[0144] When the adjusted light source brightness reaches the corresponding parameter boundary, based on the actual equivalent exposure change borne by the light source, from... Subtracting this adjustment amount from the total amount yields the second remaining adjustment amount that is still incomplete. Then adjust the analog gain: ;in, and These are the current analog gain and the adjusted analog gain, respectively. These are the preset minimum and maximum gains, respectively. Compared to the traditional method of allocating only between exposure time and gain, this embodiment uses light source brightness as a second adjustment parameter. When the exposure time is limited by motion blur, detection beat, or parameter upper limit, brightness is compensated by increasing the actual incident light amount first. Gain is only enabled when neither exposure time nor light source brightness can be adjusted further, thereby reducing image noise amplification caused by excessive gain.
[0145] Still referencing Figure 3 In another feasible implementation, or based on the above parameter allocation method, to further improve the adaptability of joint adjustment of camera exposure parameters and light source parameters, the actual response relationship between changes in camera exposure value and changes in light source brightness to feedback brightness can be analyzed separately, establishing exposure response gradients and light source response gradients, and determining the camera exposure value adjustment amount and light source brightness adjustment amount respectively based on the current brightness error. Therefore, this application embodiment further establishes exposure response gradients and light source response gradients by analyzing the actual response relationship between changes in exposure value and changes in light source brightness to feedback brightness, and dynamically allocates adjustment amounts in two directions according to the current brightness error, so that exposure parameters and light source parameters can change in synergy. Correspondingly, in a feasible implementation, the method further includes: modeling the current feedback brightness as a function of camera exposure value and light source brightness; keeping the light source brightness constant and changing the camera exposure value in the first type of iteration, determining the exposure response gradient based on the change in feedback brightness and the change in camera exposure value; keeping the camera exposure value constant and changing the light source brightness in the second type of iteration, determining the light source response gradient based on the change in feedback brightness and the change in light source brightness; and determining the camera exposure value adjustment amount and the light source brightness adjustment amount respectively based on the exposure response gradient, the light source response gradient, and the brightness error.
[0146] In this embodiment, the current feedback brightness B is considered as the result of the combined effect of the camera exposure value EV and the light source brightness L, i.e., B = h(EV, L); where EV is used to uniformly represent the equivalent exposure level formed by the camera exposure time and camera gain, L is the light source brightness control value, used to represent the current output brightness of the external light source; h() represents the correspondence between the camera exposure value, the light source brightness, and the feedback brightness, which can be estimated by the image brightness change before and after parameter changes during actual iteration. Changes in either the camera exposure value or the light source brightness may cause the image to become brighter or darker. If both are changed simultaneously and the brightness change is observed, it will be difficult to determine which parameter specifically caused the brightness change. Therefore, this embodiment uses an alternating perturbation method to estimate the influence of the two parameters on the brightness separately.
[0147] In the first type of iteration, keeping the light source brightness L constant, only changing the camera exposure value EV, the exposure response gradient is obtained based on the feedback changes in brightness and exposure value before and after this adjustment: ;in, This represents the exposure response gradient, used to indicate approximately how much the feedback brightness changes when the camera exposure value changes by one unit, assuming the light source brightness remains constant. Indicates the current feedback brightness; Indicates the camera exposure value; This indicates the rate of change of the feedback brightness relative to the camera's exposure value; This represents the change in feedback brightness between two adjacent related iterations; This represents the change in camera exposure value between two consecutive related iterations. In actual control processes, the value obtained from a finite number of iterations can be used. An approximate estimate is made of the rate of change.
[0148] The exposure response gradient represents the approximate change in feedback brightness for every unit change in camera exposure value. In the second type of iteration, keeping the camera exposure value constant and only changing the light source brightness, the light source response gradient is obtained based on the changes in feedback brightness and light source brightness. : ;in, This represents the light source response gradient, used to indicate approximately how much the feedback brightness changes when the light source brightness changes by one control unit while the camera exposure value remains constant. Indicates the light source brightness control value; This indicates the rate of change of the feedback brightness relative to the brightness of the light source; This represents the change in light source brightness between two consecutive related iterations.
[0149] The light source response gradient represents approximately how much the feedback brightness changes for every unit change in the light source brightness. For example, the light source brightness can be fixed and the exposure value adjusted in odd-numbered iterations, while the exposure value can be fixed and the light source brightness adjusted in even-numbered iterations.
[0150] To reduce gradient jumps caused by image noise, local reflections, or light source fluctuations, the following can be done: and Perform exponential moving average smoothing.
[0151] Let the preset target brightness be B. t The current feedback brightness is B. c Then the brightness error e is: e = B t -B c ;
[0152] Based on whether the camera exposure time and light source brightness are close to their respective parameter boundaries, the brightness error is allocated to the exposure value and the light source brightness. Let the exposure value bear the proportion of the error. The proportion of error borne by the light source brightness is If the sum of the two is 1, then the corresponding adjustment amount is... It can be represented as: ;
[0153] Here, `round` indicates that the light source brightness adjustment is converted into an integer level that the light source controller can execute. This setting can be used when the camera exposure time has not yet reached the parameter limits. =1.0、 =0.0, mainly adjusted through the exposure value; when the exposure time reaches the boundary, it can be set to... =0.3、 =0.7, so that most of the brightness error is borne by the light source; when both the exposure time and the light source brightness reach the boundary, the remaining adjustment can continue to be achieved by changing the exposure value corresponding to the camera gain.
[0154] For example, if the chip solder joint image is too dark, and there is still room to increase the exposure time, the exposure time can be extended first; if the detection cycle limits the exposure time and cannot be increased further, the light source brightness should be increased; when the light source also reaches its limit, the camera gain should be increased. By separately measuring the actual impact of the exposure value and the light source brightness on the image brightness, and then calculating how much each should be adjusted, the repeated trial and error caused by the mutual influence of the two parameters can be reduced, allowing the image to approach the target brightness more quickly.
[0155] Please refer to Figure 4 , Figure 4 This is a schematic flowchart of another automatic exposure control method according to an embodiment of this application. More specifically, please refer to the following algorithm flow:
[0156]
[0157] In the above process, `exp_time` represents the camera exposure time, and `exp_min` and `exp_max` represent the minimum and maximum exposure times allowed by the camera, respectively. Setting the exposure time to the middle of the allowed range during initialization avoids starting with an exposure that is too short or too long. `a_gain` represents the camera gain, and `gain_min` represents the minimum allowed gain. Using a lower gain during initialization can reduce the premature amplification of image noise. `light` represents the light source brightness control value, and `light_min` and `light_max` represent the minimum and maximum allowed brightness of the light source, respectively. An intermediate value between these two can be used during initialization.
[0158] EV(exp_time, a_gain) represents the conversion of exposure time and camera gain into a uniform exposure value. As an example, the exposure value can be expressed as: ;in, For reference exposure time, This is used as the reference gain. After this processing, although the exposure time and gain have different units, they can both be expressed as changes in the exposure value, making it easy to calculate how much exposure needs to be increased or decreased in this round. `g_smooth` represents the current smoothing gradient, indicating approximately how much the feedback brightness changes for each unit change in the exposure value. A preset default gradient `g_default` can be used during initialization. In the case of an approximately linear response, the brightness is related to 2... EV Approximately proportional, therefore, with a reference brightness of 128, the default gradient can be set to: In other words, when there are no historical images available for calculation in the initial stage, it can be temporarily assumed that a change of one unit in the exposure value results in a change of approximately 88.7 gray levels in the feedback brightness.
[0159] In each iteration, the light source brightness, exposure time, and camera gain for the current round are first sent to the light source and camera. After these parameters take effect, the image to be tested is acquired. If image acquisition fails, it can be re-acquired a preset number of times. Only after successfully acquiring the image to be tested is the feedback brightness calculated and the historical exposure values, historical feedback brightness, and gradient updated to avoid failed or empty images from interfering with subsequent calculations.
[0160] brightness represents the current feedback brightness obtained using the aforementioned histogram-based photometric method, target represents the preset target brightness, and error represents the brightness error between the two. (Using:) When error is positive, it means the current image is too dark; when error is negative, it means the current image is too bright.
[0161] `iter` represents the current iteration number, `min_iterations` represents the minimum number of iterations that should be completed before stopping the adjustment, and `tolerance` represents the allowable brightness deviation. When the iteration number reaches `min_iterations` and the absolute value of the brightness error does not exceed `tolerance`, the current image can be considered to have reached the preset brightness requirement, and the current exposure time, camera gain, and light source brightness are returned.
[0162] To determine whether the gradient prediction is accurate, we can use the brightness from the previous round of feedback. Based on the historical smooth gradient and the change in exposure value in this round, first predict the brightness of the current round of feedback: ;
[0163] Where g_history is the existing historical smooth gradient when entering this round. This represents the camera exposure value corresponding to the current iteration; This represents the camera exposure value corresponding to the previous iteration; This indicates the change in exposure value compared to the previous round. Prediction error. Represented as: ;
[0164] If the actual feedback brightness is close to the predicted brightness, it means that the historical gradient can accurately reflect the response relationship between the current camera, light source and the object under test; if the two differ significantly, it may be due to changes in the position of the object under test, changes in the reflection of the solder joint, fluctuations in the light source, or noise in the image.
[0165] Prediction confidence can be expressed as: ;in, This indicates the preset confidence error, which specifies at what level the prediction error should significantly reduce the adoption of the prediction results; This indicates the preset minimum confidence level, used to avoid completely discarding the prediction results. The smaller the prediction error, the closer the confidence is to 1; the larger the prediction error, the lower the confidence.
[0166] When the change in exposure value between two adjacent iterations is significant enough, the current gradient can be calculated based on the actual change in exposure and the actual change in brightness. : ;in, This is a preset threshold for exposure value changes. When... When the exposure parameters are essentially unchanged between two adjacent exposure rounds, the small difference in image brightness is more likely due to noise. Directly calculating the ratio can easily result in an overly large or undersized gradient. Therefore, a preset default gradient can be used instead. If the calculated value is... If the value is negative or significantly exceeds the preset gradient range, the result can be considered unreliable, and this should be used... Replacement.
[0167] To avoid sudden gradient changes caused by an anomalous image, an exponential moving average is used for smoothing. ;in, Indicates the first The current smooth gradient obtained in the next iteration; Indicates the first The current original gradient estimate is calculated based on the change in exposure value and the change in feedback brightness in the next iteration; This represents the historical smoothed gradient obtained in the previous iteration; This is the smoothing factor, ranging from 0 to 1, for example, it can be set to 0.6. This setting means that the new gradient result accounts for 60%, and the previous smoothed gradient accounts for 40%, which can follow the changes in the current imaging state without causing large jumps due to reflections or noise in a single image.
[0168] Based on the smooth gradient, the predicted exposure adjustment amount can be calculated. : ; This indicates the preset target brightness; this adjustment amount uses the results of the most recent rounds of actual adjustments to directly predict how much exposure value needs to be changed to approach the target brightness.
[0169] At the same time, a conservative exposure adjustment amount can be calculated based on the ratio of the current feedback brightness to the target brightness. : ;in, This is a preset protection value greater than 0, used to prevent calculation failures when the feedback brightness is 0. The conservative exposure adjustment amount does not depend on the gradient; although the adjustment speed may be slower, it is more reliable when gradient prediction is inaccurate.
[0170] The final exposure adjustment is obtained by combining the two adjustment amounts: When the prediction error is small, more predictive exposure adjustment is used to make the image approach the target brightness more quickly; when the prediction error is large, more conservative exposure adjustment is used to avoid adjusting too much at once.
[0171] To avoid using a large step size when the brightness is close to the target, the maximum exposure adjustment range for this round is dynamically determined based on the current brightness error: ;in, This indicates the base limit, which can be set to, for example, 0.5 EV; This indicates the preset reference error; for example, for an 8-bit grayscale image, it can be set to 64 gray levels. This indicates the brightness error between the current feedback brightness and the preset target brightness; `clamp` indicates that the calculation result is limited to between 0.2 EV and 2.0 EV. Subsequently, the final exposure adjustment is limited to: Therefore, when the brightness error is small, a smaller step size is used for fine-tuning to reduce the image from changing back and forth between being too bright and too dark; when the brightness error is large, a larger step size is allowed to make the image approach the target brightness more quickly.
[0172] SNROptimalApply indicates that the exposure adjustment amount is allocated according to the signal-to-noise ratio requirements and the range of device parameters. The configuration should at least include the exposure time range, gain range, light source brightness range, maximum allowable exposure time, and detection cycle requirements. In practice, the desired exposure change can be achieved first by adjusting the exposure time. If the exposure time is limited by motion blur or the acquisition cycle, then the light source brightness can be adjusted. When neither exposure time nor light source brightness can be adjusted further, the remaining exposure can be compensated for with camera gain. This reduces noise amplification caused by excessive gain.
[0173] Under a set of exemplary test or simulation conditions, when the initial feedback brightness is 50 and the preset target brightness is 128, the two differ significantly. Using traditional PID control or fixed-step iteration, approximately 5 to 8 adjustments are typically required. However, using the predictive control method described in this application, the response gradient can be calculated after obtaining the first two exposure values and feedback brightness, and the subsequent adjustment range can be directly predicted accordingly, thus typically requiring only 2 to 3 adjustments.
[0174] When the initial feedback brightness is 100 and the preset target brightness is 128, the brightness error is considered moderate. Traditional PID control or fixed-step iterative methods typically require about 3 to 5 adjustments, while the predictive control method of this application typically requires about 1 to 2 adjustments. When the initial feedback brightness is 120 and the preset target brightness is 128, the current image is already quite close to the target brightness. Traditional methods typically still require 2 to 3 small-step adjustments, while the predictive control method of this application can approach the target brightness after only one adjustment.
[0175] When an image exhibits noise fluctuations with a standard deviation of approximately 5 gray levels, traditional control methods may require repeated adjustments due to changes in brightness measured each time, typically requiring about 5 to 10 iterations. The embodiments of this application utilize exponential moving averages to smooth the gradient and reduce the prediction confidence based on the prediction error, thereby reducing the impact of a single noisy image on the adjustment result, typically requiring about 3 to 5 iterations.
[0176] It is understandable that the number of iterations mentioned above is used to illustrate the adjustment trend of different control methods and does not limit the number of iterations required for each automatic exposure control. The actual number of iterations will also be affected by factors such as camera response speed, light source stabilization time, the reflectivity of the object being measured, image noise, and preset brightness tolerance. Overall, after obtaining an effective gradient in the first iteration, predictive control can directly adjust the exposure parameters to a position close to the target brightness in subsequent iterations, thus reducing the number of repeated trial and error adjustments in typical cases.
[0177] The above describes an automatic exposure control method provided by an embodiment of this application. The following will describe the apparatus for performing the above-described automatic exposure control method. Please refer to... Figure 5 , Figure 5 This is a schematic diagram of an automatic exposure control device provided in an embodiment of this application. Figure 5 As shown, the automatic exposure control device includes:
[0178] The image acquisition module 501 is used to acquire the image to be tested captured by the camera under the current camera exposure parameters and current light source parameters;
[0179] The histogram generation module 502 is used to convert the image to be tested into a grayscale image and generate a grayscale histogram based on the number of pixels corresponding to each grayscale level in the grayscale image.
[0180] The brightness feature extraction module 503 is used to determine the histogram skewness, gray mean, gray median, overexposed pixel ratio and underexposed pixel ratio of the image to be tested based on the gray histogram.
[0181] The basic brightness determination module 504 is used to determine the fusion weights corresponding to the gray mean and gray median respectively based on the histogram skewness, and to fuse the gray mean and gray median based on the fusion weights to obtain the basic brightness.
[0182] The feedback brightness determination module 505 is used to correct the basic brightness based on the overexposed pixel ratio and the underexposed pixel ratio to obtain the feedback brightness of the image to be tested.
[0183] The exposure adjustment module 506 is used to determine the brightness error based on the feedback brightness and the preset target brightness, and to determine the exposure adjustment amount based on the brightness error.
[0184] The exposure parameter adjustment module 507 is used to adjust at least one of the camera exposure time parameter, camera gain parameter and light source brightness parameter based on the exposure adjustment amount and re-acquire the test image until the re-acquired test image meets the preset convergence condition.
[0185] Optionally, the brightness feature extraction module is specifically used for: determining the gray-level mean, gray-level standard deviation, and gray-level cumulative distribution based on the pixel probabilities corresponding to each gray-level in the gray-level histogram; determining the histogram skewness based on the gray-level mean and gray-level standard deviation, and determining the gray-level median based on the gray-level cumulative distribution; accumulating the pixel probabilities whose gray-level values are greater than or equal to a preset high gray-level threshold based on the gray-level histogram to obtain the proportion of overexposed pixels; and accumulating the pixel probabilities whose gray-level values are less than or equal to a preset low gray-level threshold to obtain the proportion of underexposed pixels; wherein the preset high gray-level threshold and the preset low gray-level threshold are determined based on at least one of the image bit depth, black level, and saturation gray-level value of the image to be tested.
[0186] Optionally, the basic brightness determination module is specifically used to: determine the first fusion weight corresponding to the grayscale median based on the ratio of the absolute value of the histogram skewness to the preset reference skewness; and determine the second fusion weight corresponding to the grayscale mean based on the first fusion weight, wherein the sum of the first fusion weight and the second fusion weight is one, and the first fusion weight increases as the absolute value of the histogram skewness increases.
[0187] Optionally, the feedback brightness determination module is specifically used to: determine the brightness correction coefficient based on the overexposed pixel ratio, the underexposed pixel ratio, the preset overexposed sensitivity coefficient, and the preset underexposed sensitivity coefficient; and use the brightness correction coefficient to correct the base brightness so that when the overexposed pixel ratio increases, the corrected brightness value increases relative to the base brightness, and when the underexposed pixel ratio increases, the corrected brightness value decreases relative to the base brightness.
[0188] Optionally, the feedback brightness determination module is specifically used for: determining, based on the grayscale histogram of the image to be tested, a first grayscale quantile value corresponding to a first preset quantile ratio and a second grayscale quantile value corresponding to a second preset quantile ratio; determining the grayscale distribution span of the image to be tested based on the difference between the first grayscale quantile value and the second grayscale quantile value; determining the photometric reliability based on the grayscale distribution span, and performing a weighted fusion of the brightness-corrected base brightness and the preset target brightness based on the photometric reliability to obtain the current feedback brightness; wherein, the photometric reliability increases with the increase of the grayscale distribution span.
[0189] Optionally, the exposure adjustment amount determination module is specifically used to: obtain the historical exposure value and historical feedback brightness corresponding to at least two iterations respectively; determine the response gradient of brightness relative to the exposure value based on the change in exposure value and the change in feedback brightness between two adjacent iterations; and predict the predicted exposure adjustment amount required to make the current feedback brightness reach the preset target brightness based on the brightness error and the response gradient.
[0190] Optionally, the exposure adjustment determination module is specifically used to: calculate the ratio of the feedback brightness change to the exposure value change between two adjacent iterations to obtain the current gradient estimate; when the exposure value change is less than a preset change threshold, or the current gradient estimate exceeds a preset gradient range, determine the preset default gradient as the current gradient estimate; and use an exponential moving average method to fuse the current gradient estimate with the historical smoothed gradient to obtain the response gradient.
[0191] Optionally, the exposure adjustment amount determination module is specifically used for: determining the predicted brightness corresponding to the current iteration based on the feedback brightness, response gradient, and exposure value change corresponding to the previous iteration; determining the prediction error based on the difference between the predicted brightness and the current feedback brightness, and determining the prediction confidence based on the prediction error; determining the conservative exposure adjustment amount based on the brightness ratio between the current feedback brightness and the preset target brightness; and weightedly fusing the predicted exposure adjustment amount and the conservative exposure adjustment amount based on the prediction confidence to obtain the exposure adjustment amount; wherein the prediction confidence decreases as the prediction error increases.
[0192] Optionally, the exposure parameter adjustment module is specifically used for: determining a candidate exposure time based on the exposure adjustment amount; when the candidate exposure time is within the preset exposure time range, adjusting the camera exposure time to handle the exposure adjustment amount; when the candidate exposure time exceeds the preset exposure time range, adjusting the camera exposure time to the corresponding exposure time boundary, and adjusting the light source brightness based on the remaining adjustment amount not handled by the camera exposure time; when both the camera exposure time and the light source brightness reach the corresponding parameter boundaries, adjusting the analog gain based on the remaining adjustment amount not handled by the camera exposure time and the light source brightness.
[0193] Optionally, the exposure parameter adjustment module is specifically used for: modeling the current feedback brightness as a function of the camera exposure value and the light source brightness; keeping the light source brightness constant and changing the camera exposure value in the first type of iteration, and determining the exposure response gradient based on the change in feedback brightness and the change in camera exposure value; keeping the camera exposure value constant and changing the light source brightness in the second type of iteration, and determining the light source response gradient based on the change in feedback brightness and the change in light source brightness; and determining the camera exposure value adjustment amount and the light source brightness adjustment amount based on the exposure response gradient, the light source response gradient, and the brightness error, respectively.
[0194] This application also provides an electronic device in its embodiments. (See reference...) Figure 6 The diagram illustrates a structural schematic of an electronic device suitable for implementing the automatic exposure control method in the embodiments of this application. The electronic device in the embodiments of this application may include, but is not limited to, fixed terminals such as mobile phones, laptops, personal digital assistants (PDAs), tablet computers, desktop computers, etc. Figure 6 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0195] like Figure 6As shown, the electronic device may include a processing unit 601, such as a central processing unit (CPU) or a graphics processing unit (GPU). The processing unit 601 can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 602 or programs loaded from storage device 608 into random access memory (RAM) 603. When the electronic device is powered on, RAM 603 also stores various programs and data required for the operation of the electronic device. The processing unit 601, ROM 602, and RAM 603 are interconnected via bus 604. Input / output (I / O) interface 605 is also connected to bus 604.
[0196] Typically, the following devices can be connected to I / O interface 605: input devices 606 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 607 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 608 including, for example, memory cards, hard drives, etc.; and communication devices 609. Communication device 609 allows electronic devices to exchange data via wireless or wired communication with other devices. Although Figure 6 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown. More or fewer devices may be implemented or have instead.
[0197] This application also provides a computer program product including computer-readable instructions, which, when executed on an electronic device, cause the electronic device to implement any of the automatic exposure control methods provided in this application.
[0198] This application also provides a computer-readable storage medium carrying one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any of the automatic exposure control methods provided in this application.
[0199] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the accompanying drawings of the device embodiments provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.
[0200] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, training equipment, or network device, etc.) to execute the methods of the various embodiments of this application.
[0201] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.
[0202] A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this application is generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions may be transmitted from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line, DSL) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disk, hard disk, magnetic tape); optical media, such as Digital Versatile Disc (DVD); or semiconductor storage media, such as Solid-State Drive (SSD), etc.
Claims
1. An automatic exposure control method, characterized in that, include: Acquire the image to be tested captured by the camera under the current camera exposure parameters and current light source parameters; The image to be tested is converted into a grayscale image, and a grayscale histogram is generated based on the number of pixels corresponding to each grayscale level in the grayscale image. Based on the grayscale histogram, determine the histogram skewness, grayscale mean, grayscale median, overexposed pixel ratio, and underexposed pixel ratio of the image to be tested. The fusion weights corresponding to the mean gray level and the median gray level are determined based on the histogram skewness, and the mean gray level and the median gray level are fused based on the fusion weights to obtain the base brightness. The base brightness is corrected based on the overexposed pixel ratio and the underexposed pixel ratio to obtain the feedback brightness of the image under test; The brightness error is determined based on the feedback brightness and the preset target brightness, and the exposure adjustment amount is determined based on the brightness error. Based on the exposure adjustment amount, at least one of the camera exposure time parameter, camera gain parameter, and light source brightness parameter is adjusted and the test image is re-acquired until the re-acquired test image meets the preset convergence condition.
2. The method according to claim 1, characterized in that, The step of determining the histogram skewness, gray-level mean, gray-level median, overexposed pixel ratio, and underexposed pixel ratio of the image under test based on the gray-level histogram includes: Based on the pixel probability corresponding to each gray level in the gray histogram, the gray mean, gray standard deviation, and gray cumulative distribution are determined. The histogram skewness is determined based on the mean gray level and the standard deviation of gray level, and the median gray level is determined based on the cumulative distribution of gray level. Based on the grayscale histogram, the probability of pixels whose grayscale value is greater than or equal to a preset high grayscale threshold is accumulated to obtain the overexposed pixel ratio. The probability of pixels with grayscale values less than or equal to a preset low grayscale threshold is accumulated to obtain the underexposed pixel ratio; wherein, the preset high grayscale threshold and the preset low grayscale threshold are determined based on at least one of the image bit depth, black level and saturation grayscale value of the image to be tested.
3. The method according to claim 1, characterized in that, The step of determining the fusion weights corresponding to the mean and median gray levels of the image under test based on the histogram skewness includes: The first fusion weight corresponding to the grayscale median is determined based on the ratio of the absolute value of the histogram skewness to the preset reference skewness. The second fusion weight corresponding to the grayscale mean is determined based on the first fusion weight, wherein the sum of the first fusion weight and the second fusion weight is one, and the first fusion weight increases as the absolute value of the histogram skewness increases.
4. The method according to claim 1, characterized in that, The step of correcting the base brightness based on the overexposed pixel ratio and the underexposed pixel ratio includes: The brightness correction coefficient is determined based on the overexposed pixel ratio, the underexposed pixel ratio, the preset overexposed sensitivity coefficient, and the preset underexposed sensitivity coefficient. The base brightness is corrected using the brightness correction coefficient, such that when the proportion of overexposed pixels increases, the corrected brightness value increases relative to the base brightness, and when the proportion of underexposed pixels increases, the corrected brightness value decreases relative to the base brightness.
5. The method according to claim 1, characterized in that, The method further includes: Based on the grayscale histogram of the image to be tested, determine the first grayscale quantile value corresponding to the first preset quantile ratio and the second grayscale quantile value corresponding to the second preset quantile ratio. The grayscale distribution span of the image under test is determined based on the difference between the first grayscale quantile and the second grayscale quantile. The photometric reliability is determined based on the grayscale distribution span, and the base brightness after brightness correction and the preset target brightness are weighted and fused based on the photometric reliability to obtain the current feedback brightness; wherein, the photometric reliability increases as the grayscale distribution span increases.
6. The method according to claim 1, characterized in that, The step of determining the exposure adjustment amount based on the brightness error includes: Obtain the historical exposure value and historical feedback brightness corresponding to at least two iterations; The response gradient of brightness relative to the exposure value is determined based on the change in exposure value and the change in feedback brightness between two adjacent iterations; Based on the brightness error and the response gradient, predict the amount of exposure adjustment required to bring the current feedback brightness to the preset target brightness.
7. The method according to claim 6, characterized in that, Determining the response gradient of brightness relative to the exposure value includes: Calculate the ratio of the change in feedback brightness to the change in exposure value between two adjacent iterations to obtain the current gradient estimate; When the change in the exposure value is less than a preset change threshold, or when the current gradient estimate exceeds a preset gradient range, the preset default gradient is determined as the current gradient estimate. The current gradient estimate is fused with the historical smoothed gradient using an exponential moving average method to obtain the response gradient.
8. The method according to claim 6, characterized in that, The step of determining the exposure adjustment amount based on the brightness error further includes: The predicted brightness for the current iteration is determined based on the feedback brightness, response gradient, and exposure value change corresponding to the previous iteration. The prediction error is determined based on the difference between the predicted brightness and the current feedback brightness, and the prediction confidence level is determined based on the prediction error. Based on the brightness ratio between the current feedback brightness and the preset target brightness, a conservative exposure adjustment amount is determined; Based on the prediction confidence level, the predicted exposure adjustment amount and the conservative exposure adjustment amount are weighted and fused to obtain the exposure adjustment amount; wherein, the prediction confidence level decreases as the prediction error increases.
9. The method according to claim 1, characterized in that, The adjustment of at least one of the camera exposure time, analog gain, and light source brightness based on the exposure adjustment amount includes: The candidate exposure time is determined based on the exposure adjustment amount; When the candidate exposure time is within the preset exposure time range, the exposure adjustment amount is handled by adjusting the camera exposure time. When the candidate exposure time exceeds the preset exposure time range, the camera exposure time is adjusted to the corresponding exposure time boundary, and the light source brightness is adjusted according to the remaining adjustment amount not borne by the camera exposure time. When both the camera exposure time and the light source brightness reach the corresponding parameter boundaries, the analog gain is adjusted based on the remaining adjustment amount not borne by the camera exposure time and the light source brightness.
10. The method according to claim 1, characterized in that, The method further includes: The current feedback brightness is modeled as a function of the camera exposure value and the light source brightness; In the first type of iteration, the brightness of the light source is kept constant while the camera exposure value is changed, and the exposure response gradient is determined based on the feedback brightness change and the camera exposure value change. In the second type of iteration, the camera exposure value is kept constant while the light source brightness is changed, and the light source response gradient is determined based on the feedback brightness change and the light source brightness change. Based on the exposure response gradient, the light source response gradient, and the brightness error, the camera exposure value adjustment amount and the light source brightness adjustment amount are determined respectively.
