Background grayscale detection method, storage medium, computer equipment and program product

By fitting Gaussian peaks to the grayscale histogram of dark-field images, the problem of inaccurate background grayscale extraction in traditional methods is solved, achieving efficient and automatic background grayscale detection and improving image analysis accuracy and detection efficiency.

CN120852800AActive Publication Date: 2025-10-28BEIJING OPTOKO MICROELECTRONICS TECH CO LTD
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202511094277.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-05
Publication Date
2025-10-28
Estimated Expiration
2045-08-05

AI Technical Summary

Technical Problem

Traditional background grayscale extraction methods are difficult to adapt to complex and varied dark-field image backgrounds, resulting in low image analysis accuracy and low automated detection efficiency.

Method used

By acquiring the grayscale histogram of the dark field image, performing Gaussian peak fitting, selecting the final Gaussian curve, and combining sliding window and smoothing processing, the background grayscale range is automatically determined.

Benefits of technology

It improves the accuracy and robustness of background grayscale detection in dark-field images, reduces manual intervention, and enhances detection efficiency and adaptability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120852800A_ABST
    Figure CN120852800A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image processing, in particular to a background grayscale detection method, a storage medium, computer equipment and a program product. According to the background gray level detection method, Gaussian fitting of different Gaussian peak numbers is carried out on a to-be-fitted interval through combination of gray level histogram analysis and Gaussian fitting, one Gaussian curve is selected as a final Gaussian curve, and the minimum mean value of the final Gaussian curve is selected as a central value of a background gray level range. According to the method, the change of gray level distribution in a complex image can be well coped with, the accuracy of the detected background gray level range is ensured, the background gray level range is prevented from deviating towards a high gray level area and interfering other bright parts in the image, automatic detection of the background gray level can be achieved, manual intervention is not needed, and the detection efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing technology, and in particular to a background grayscale detection method, storage medium, computer equipment, and program product. Background Technology

[0002] Dark-field imaging is widely used in fields such as optical microscopy, electron microscopy, and semiconductor industrial inspection because it can highlight weak scattering or minute structural features of samples. However, dark-field images often exhibit non-uniform background grayscale distribution. This non-uniformity may stem from factors such as non-uniformity of the light source, stray light from the optical system, or sensor noise. This non-uniformity can interfere with the extraction and analysis of target features, especially in quantitative measurements or automated inspections, potentially leading to data bias or misjudgment.

[0003] Traditional background grayscale extraction methods, such as global thresholding and mean filtering, often struggle to effectively handle complex and variable dark-field image backgrounds. For example, when background grayscale exhibits gradient changes or local fluctuations, simple filtering methods may fail to accurately separate the background from the target signal. Furthermore, morphological or polynomial fitting-based methods have high computational complexity, making them unsuitable for real-time processing. Therefore, this paper aims to develop an efficient and accurate dark-field image background grayscale extraction method to improve image analysis accuracy and automated detection efficiency. Summary of the Invention

[0004] To address the technical problem of low accuracy in extracting background grayscale from dark-field images, this invention provides a background grayscale detection method, storage medium, computer equipment, and program product.

[0005] The solution to the technical problem of this invention is to provide a background grayscale detection method, a storage medium, a computer device, and a program product.

[0006] Preferably, it includes the following steps: Acquire a dark field image, count the frequency of each gray level in the dark field image, and draw a gray level histogram with the horizontal axis representing the gray level and the vertical axis representing the frequency. Scan the grayscale histogram from low grayscale levels to high grayscale levels to determine the first data interval in which the frequency first increases and then decreases with the change of grayscale level, and use this data interval as the interval to be fitted. Gaussian fitting with different numbers of Gaussian peaks is performed on the interval to be fitted to obtain the fitted Gaussian curve, and one of the Gaussian curves is selected as the final Gaussian curve. Obtain the mean and standard deviation of each Gaussian peak in the final Gaussian curve, select the smallest mean as the center value, and determine the background grayscale range based on the center value and the preset error range.

[0007] Preferably, Gaussian fitting with different numbers of Gaussian peaks is performed on the interval to be fitted, and one of the Gaussian curves is selected as the final Gaussian curve, including the following steps: For the interval to be fitted, start with single-peak Gaussian fitting, gradually increase the number of Gaussian peaks and perform multiple fittings, and calculate the coefficient of determination or root mean square error of each Gaussian fitting. The number of peaks whose coefficient of determination is closest to 1 or the number of peaks with the smallest root mean square error is selected as the final number of peaks for Gaussian fitting, and the corresponding Gaussian curve is taken as the final Gaussian curve.

[0008] Preferably, the frequency of occurrence of each gray level in the dark field image is statistically analyzed, including the following steps: Determine the number of gray levels in a dark field image Obtain the total number of pixels in the vertical direction of the dark field image. and the total number of pixels in the horizontal direction ; According to the formula Obtain the frequency of occurrence of each gray level; in, Indicates grayscale level as The frequency of pixel occurrence, and These represent the coordinates of the dark field image in the vertical and horizontal directions, respectively. coordinates The grayscale level of a pixel. Let Kronecker function be used when It is 1 if it is true, otherwise it is 0.

[0009] Preferably, the grayscale histogram is scanned from low grayscale levels to high grayscale levels to determine the first data interval in which the frequency first increases and then decreases with the change of grayscale level, and this data interval is used as the interval to be fitted, including the following steps: The grayscale histogram is smoothed to obtain a smoothed histogram; Set a sliding window of preset width, slide it through the smooth histogram from low gray level to high gray level with a fixed step size, and calculate the cumulative frequency in each window; When the cumulative frequency value first shows a trend of increasing and then decreasing, obtain the maximum value point within the current window; Search forward and backward simultaneously from the maximum value point to obtain the nearest maximum value point; Obtain the monotonicity inflection point corresponding to the maximum point. and Calculate gray levels frequency within The frequency set output is then used as the interval to be fitted.

[0010] Preferably, the final Gaussian curve is as follows: ,in, Indicates grayscale level as At that time, the prediction frequency of the final Gaussian curve, This indicates the number of Gaussian peaks in the final Gaussian curve. Let be the peak height of the i-th Gaussian peak. Let be the mean of the i-th Gaussian peak. Let be the standard deviation of the i-th Gaussian peak.

[0011] Preferably, the background grayscale range is ,in For the determined center value, Let be the standard deviation corresponding to the central value, and .

[0012] Preferably, the interval to be fitted is fitted with Gaussian curves using the least squares method or the expectation-maximization algorithm.

[0013] To solve the above-mentioned technical problems, the present invention provides another technical solution as follows: a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the above-mentioned background grayscale detection method.

[0014] To solve the above-mentioned technical problems, the present invention provides another technical solution as follows: a computer device, including a storage device, a processor, and a computer program stored in the storage device, wherein the processor executes the computer program to implement the above-mentioned background grayscale detection method.

[0015] To solve the above-mentioned technical problems, the present invention provides another technical solution as follows: a computer program product, on which a computer program is stored, which, when executed by a processor, implements the above-mentioned background grayscale detection method.

[0016] Compared with the prior art, the background grayscale detection method, storage medium, computer equipment, and program product provided by the present invention have the following beneficial effects: 1. The automatic background grayscale detection method for dark-field images of the present invention, by combining grayscale histogram analysis and Gaussian fitting, can better cope with the changes in grayscale distribution in complex images, effectively distinguish between background and foreground, improve the accuracy and robustness of background grayscale detection in dark-field images, and the method can realize automatic detection of background grayscale without manual intervention, thus improving detection efficiency. Specifically, firstly, a dark-field image is acquired, and the frequency of each gray level in the dark-field image is statistically analyzed to create a gray-level histogram with gray level on the horizontal axis and frequency on the vertical axis. This visually reflects the distribution and changing trends of different gray levels in the dark-field image, providing crucial information for subsequent analysis. Secondly, the gray-level histogram is scanned from low to high gray levels to identify the first data interval where the frequency first increases and then decreases with gray level. This data interval is used as the fitting interval. This step focuses on the main distribution range of the background, reducing interference from high-gray-level target areas and background noise on background detection. Then, Gaussian fitting with different numbers of Gaussian peaks is performed on the fitting interval to obtain the fitted Gaussian curve. The process involves several steps. First, a Gaussian curve is selected as the final Gaussian curve. This step decomposes the complex gray-level distribution into multiple simple Gaussian components, adapting to different gray-level distributions in the image, reducing fitting errors, and fitting a background gray-level curve that better matches the gray-level histogram distribution, further improving detection accuracy. Second, the mean and standard deviation of each Gaussian peak in the final Gaussian curve are obtained, and the smallest mean is selected as the center value. The background gray-level range is then determined based on the center value and a preset error range. This step, selecting the smallest mean as the center value, accurately locates the main area with the lowest gray level in the image, thus accurately defining the background area and avoiding the background gray-level range shifting to higher gray-level areas and interference from other brighter parts of the image.

[0017] 2. The background grayscale detection method of this invention starts with single-peak Gaussian fitting and gradually increases the number of Gaussian peaks for multiple fittings, adaptively selecting the most suitable model to fit the data. If the data distribution is complex, multiple peaks can better capture the characteristics of the data; if the data distribution is simple, a single peak is sufficient. Simultaneously, by calculating and comparing the coefficient of determination or root mean square error, it can be ensured that a Gaussian curve with a good fit is selected, avoiding the risks of overfitting and underfitting.

[0018] 3. The background grayscale detection method of the present invention provides a specific formula for calculating the grayscale frequency, which can automatically calculate and generate a grayscale histogram, reduce manual intervention, and improve detection efficiency.

[0019] 4. The background grayscale detection method of this invention provides specific steps for determining the fitting interval, employing a combination of sliding window, smoothing processing, and dynamic search, which can adapt to different types of dark-field images. Smoothing processing effectively removes noise and can more clearly and reliably identify the trend of grayscale changes. Setting a sliding window allows for a comprehensive analysis of the entire grayscale histogram, reducing noise interference and accurately identifying the first increasing-then-decreasing trend in the global grayscale histogram.

[0020] 5. The background grayscale detection method of this invention provides a specific formula for the Gaussian curve, which can automatically analyze the grayscale changes of the image background without manual intervention. This can greatly reduce the error of manual detection and improve detection efficiency.

[0021] 6. The background grayscale detection method of the present invention has a background grayscale range of: ,in For the determined center value, The standard deviation is the value corresponding to the center value. That is, the preset error range, and It can automatically adjust the preset error range according to the characteristics of different dark field images, thereby adapting to various different image data, detecting and outputting a suitable background grayscale range, and improving the adaptability, versatility and efficiency of the detection method.

[0022] 7. The background grayscale detection method of the present invention effectively fits the Gaussian curve by using the least squares method or the expectation-maximization algorithm, thereby enhancing the robustness of the detection method and ensuring that the obtained Gaussian curve is highly consistent with the distribution of background grayscale in the actual dark field image.

[0023] 8. The present invention also provides a computer-readable storage medium, which has the same beneficial effects as the background grayscale detection method described above, and will not be elaborated here.

[0024] 9. The present invention also provides a computer device that has the same beneficial effects as the background grayscale detection method described above, which will not be elaborated here.

[0025] 10. The present invention also provides a computer program product that has the same beneficial effects as the background grayscale detection method described above, which will not be elaborated here. Attached Figure Description

[0026] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0027] Figure 1 This is a flowchart of steps S1 to S4 of the background grayscale detection method provided in the first embodiment of the present invention.

[0028] Figure 2 This is a flowchart of steps S31 to S32 of the background grayscale detection method provided in the first embodiment of the present invention.

[0029] Figure 3 This is a flowchart of steps S11 to S12 of the background grayscale detection method provided in the first embodiment of the present invention.

[0030] Figure 4 This is a flowchart of steps S21 to S25 of the background grayscale detection method provided in the first embodiment of the present invention.

[0031] Figure 5 This is a flowchart showing step S26 replacing step S25 in the background grayscale detection method provided in the first embodiment of the present invention.

[0032] Figure 6 This is a 12-bit dark field image provided in the first embodiment of the present invention.

[0033] Figure 7 This is the grayscale histogram obtained in the first embodiment of the present invention.

[0034] Figure 8 This is the histogram portion of the interval to be fitted obtained in the first embodiment of the present invention.

[0035] Figure 9 This is a three-peak Gaussian fitted image obtained in the first embodiment of the present invention.

[0036] Figure 10 This is the background area image detected in the first embodiment of the present invention.

[0037] Figure 11 This is a schematic diagram of the framework of the storage medium provided in the second embodiment of the present invention.

[0038] Figure 12 This is a schematic diagram of the framework of a computer device provided in the third embodiment of the present invention.

[0039] Figure 13 This is a schematic diagram of the framework of the computer program product provided in the fourth embodiment of the present invention.

[0040] Explanation of reference numerals in the attached diagram: 1. Storage media; 2. Computer equipment; 3. Computer program products; 10. Computer program; 20. Memory; 21. Processor; 22. Computer program; 30. Computer program. Detailed Implementation

[0041] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0042] The terms “vertical,” “horizontal,” “left,” “right,” “up,” “down,” “upper left,” “upper right,” “lower left,” “lower right,” “lower left,” “lower right,” and similar expressions used in this article are for illustrative purposes only.

[0043] Please see Figure 1 The first embodiment of the present invention provides a background grayscale detection method, comprising the following steps: Step S1: Acquire the dark field image, count the frequency of each gray level in the dark field image, and draw a gray level histogram with the horizontal axis representing the gray level and the vertical axis representing the frequency. Step S2: Scan the grayscale histogram from low grayscale levels to high grayscale levels to determine the first data interval in which the frequency first increases and then decreases with the change of grayscale level, and use this data interval as the interval to be fitted. Step S3: Perform Gaussian fitting on the interval to be fitted with different numbers of Gaussian peaks to obtain the fitted Gaussian curves, and select one of the Gaussian curves as the final Gaussian curve. Step S4: Obtain the mean and standard deviation of each Gaussian peak in the final Gaussian curve, select the smallest mean as the center value, and determine the background grayscale range based on the center value and the preset error range.

[0044] Optionally, the dark field image in step S1 is a single-channel image, or a single-channel grayscale image obtained by converting a multi-channel image.

[0045] Understandably, this method, by combining gray-level histogram analysis and Gaussian fitting, can effectively handle variations in gray-level distribution in complex images. Step S1 uses the gray-level histogram to provide global gray-level distribution information for dark-field images; Step S2 then progressively filters from the overall to the local level, effectively eliminating interference from non-background information such as targets and noise, obtaining the region to be fitted, and ensuring that background analysis focuses on the core area; Step S3 uses Gaussian fitting to accurately model the gray-level distribution of the background; Step S4 determines the background gray-level range through quantization, thereby effectively distinguishing between background and foreground, improving the accuracy and robustness of background gray-level detection in dark-field images. Furthermore, this method can achieve automatic background gray-level detection without manual intervention and with relatively low computational cost, improving detection efficiency.

[0046] Specifically, in step S1, a gray-level histogram is generated by statistically analyzing the gray levels of the dark-field image, which can intuitively reflect the distribution of different gray levels in the image. It should be understood that dark-field images usually contain high noise, and this step can help identify the characteristics of the gray-level distribution in the dark field, especially the gray-level difference between the background and the foreground, providing an objective data basis for subsequent steps.

[0047] In step S2, the background region of a dark-field image typically has a lower grayscale level and a higher percentage of pixels. Therefore, the low grayscale region of the grayscale histogram will show a clear trend of first increasing and then decreasing. Scanning from low grayscale to high grayscale allows for priority identification of the low grayscale region. Acquiring the first data interval where the frequency changes with grayscale level first increases and then decreases avoids interference from subsequent high grayscale regions, such as targets, reflections, or noise. This ensures that the region to be fitted only contains the core grayscale distribution of the background.

[0048] In step S3, Gaussian fitting with different numbers of Gaussian peaks is performed on the region to be fitted. This can decompose the complex gray-level distribution into multiple simple Gaussian components, which can adapt to the distribution of different gray levels in the image, reduce fitting errors, and fit a background gray-level curve that is more consistent with the gray-level histogram distribution, thereby further improving the detection accuracy.

[0049] For example, if the dark field image is formed by ideal dark field imaging, its frequency changes with gray level according to the first data interval of the first data interval of the first increase followed by a decrease, and a single-peak Gaussian fitting can be selected. If there are situations such as uneven background illumination, which cause the frequency to change with gray level according to the first data interval of the first data interval of the first increase followed by a decrease, that is, the first trend of the first increase followed by a decrease in the gray level histogram shows multiple peaks, broad peaks, multiple shoulders, or asymmetrical tails, a multi-peak Gaussian fitting can be selected.

[0050] In step S4, selecting the smallest mean as the center value accurately locates the main region with the lowest gray level in the image, thus accurately defining the background region and avoiding the background gray level range shifting to higher gray level regions and interference from other brighter parts of the image. For ease of calculation, the selected mean and standard deviation can be rounded down, or only one or two decimal places can be retained.

[0051] Preferably, in step S3, a bimodal or trimodal Gaussian fit is performed on the interval to be fitted to avoid overfitting.

[0052] Further reading Figure 2 In step S3, Gaussian fitting with different numbers of Gaussian peaks is performed on the interval to be fitted, and one of the Gaussian curves is selected as the final Gaussian curve. This includes the following steps: Step S31: For the interval to be fitted, start with single-peak Gaussian fitting, gradually increase the number of Gaussian peaks and perform multiple fittings, and calculate the coefficient of determination or root mean square error of each Gaussian fitting. Step S32: Select the number of peaks with the coefficient closest to 1 or the number of peaks with the smallest root mean square error as the final number of peaks for Gaussian fitting, and use the corresponding Gaussian curve as the final Gaussian curve.

[0053] Understandably, in step S31, by progressively increasing the number of Gaussian peaks in the fit from single-peak to multi-peak, the most suitable Gaussian model can be adaptively selected for fitting. If the data distribution is complex, multiple peaks can better capture the characteristics of the data; if the data distribution is simple, a single peak is sufficient.

[0054] Understandably, the gray levels of the background in a dark-field image are often not simply linear or uniformly distributed, but rather contain multiple peaks. In step S32, selecting the final Gaussian curve by determining the coefficients or root mean square error helps to find the Gaussian model with the best fit, find the most suitable background gray range, and avoid the risks of overfitting and underfitting.

[0055] Please continue reading. Figure 3 In step S1, the frequency of occurrence of each gray level in the dark field image is statistically analyzed, including the following steps: Step S11: Determine the number of gray levels in the dark field image. Obtain the total number of pixels in the vertical direction of the dark field image. and the total number of pixels in the horizontal direction ; Step S12: According to the formula Obtain the frequency of occurrence of each gray level.

[0056] Formula 1 is: .

[0057] in, Indicates grayscale level as The frequency of pixel occurrence, and These represent the vertical and horizontal coordinates of the dark field image, respectively. for The gray level of the pixel at coordinates. Let Kronecker function be used when The value is 1 if the condition is met, and 0 otherwise. The size of the dark field image is... , The value range is [0, M-1]. The value range is [0, N-1].

[0058] For example, if the dark field image in step S11 is 8 bits, then the number of gray levels... If it is a 16-bit dark field image, then the number of gray levels... .

[0059] Understandably, this method provides a specific formula for calculating the frequency of gray levels. This allows for automatic calculation using the formula, and the software program can then generate a grayscale histogram based on the calculation results, reducing manual intervention and improving detection efficiency.

[0060] Please continue reading. Figure 4 In step S2, the grayscale histogram is scanned from low grayscale levels to high grayscale levels to determine the first data interval in which the frequency first increases and then decreases with the change of grayscale level, and this data interval is used as the interval to be fitted, including the following steps: Step S21: Smooth the grayscale histogram to obtain a smoothed histogram; Step S22: Set a sliding window of a preset width, slide it through the smooth histogram from low gray level to high gray level with a fixed step size, and calculate the cumulative frequency in each window; Step S23: When the cumulative frequency value first shows a trend of increasing and then decreasing, obtain the maximum value point within the current window; Step S24: Search forward and backward simultaneously from the maximum value point to obtain the nearest maximum value point; Step S25: Obtain the monotonicity inflection point corresponding to the maximum point. and Calculate gray levels frequency within The frequency set output is used as the interval to be fitted.

[0061] Understandably, the method of obtaining the fitting interval in steps S21 to S25 can effectively avoid the interference of noise, ensure that the first data interval in which the frequency first increases and then decreases with the change of gray level is located, and further improve the accuracy of background detection.

[0062] Specifically, in step S21, smoothing the grayscale histogram can effectively remove noise and obtain a smoother and more stable grayscale histogram, ensuring that subsequent trend analysis is more stable and reliable.

[0063] In steps S22 and S23, by setting a sliding window of a preset width, the cumulative frequency within the window is traversed from low grayscale to high grayscale levels. This process determines the first data interval where the frequency first increases and then decreases with the change in grayscale level. This method can reflect the overall trend of a local area and, compared to single-point frequency, can more stably capture trend changes, avoiding misjudgments due to minor local fluctuations.

[0064] The maximum value within the window in step S23 may not be a local maximum. Therefore, in step S4, the true maximum point is further searched to accurately locate the peak value, providing an accurate center for determining the interval to be fitted in the subsequent step S25.

[0065] In step S25, with the point of maximum value as the center, the first monotonicity inflection point is searched in both the low gray level direction and the high gray level direction. and This method accurately obtains the region to be fitted. By searching for monotonicity inflection points to obtain the region, it adaptively matches the true distribution characteristics of the background gray levels, ensuring that the complete features of the background peaks are included in the region, without omitting peak details or including irrelevant gray levels. Furthermore, this method can identify the trend changes in the distribution of background gray levels in real time and dynamically adjust the boundaries of the region to be fitted, avoiding problems such as the region being too narrow due to background fluctuations and missing some background, or the region being too wide and including foreground.

[0066] Optionally, at the search for maximum points and monotonicity inflection points and When encountering a plateau region, the starting point, ending point, or midpoint of the plateau region can be selected as the maximum value point and the monotonicity inflection point. and .

[0067] Understandably, in this embodiment, the preset width of the sliding window and the fixed step size of the sliding window movement are not specifically limited. Appropriate preset widths and fixed step sizes can be selected based on the specific grayscale histogram. However, it should be noted that if the preset width is too small, it may not accurately capture trends; if the preset range is too large, it may contain multiple trends.

[0068] Optionally, the fixed step size of the sliding window is 1, that is, the sliding window moves one gray level at a time.

[0069] Further, please refer to Figure 5 Step S25 can be replaced with: Step S26: Using the maximum point as the center, extend forward and backward by a fixed step size to form the interval to be fitted.

[0070] Understandably, using the fixed step size extension method in step S26 to obtain the interval to be fitted reduces the analysis process of the gray-level histogram trend, significantly reducing the computational load and meeting real-time requirements. At the same time, small local fluctuations caused by noise may be misjudged as monotonicity inflection points; using a fixed step size avoids noise interference and ensures the stability of the interval boundaries.

[0071] Optionally, if the background grayscale distribution of the dark-field image is complex, fluctuates greatly, or has varying peak widths, the method of searching for monotonicity inflection points in step S25 can be preferred to obtain the fitting interval. If the background grayscale distribution of the dark-field image is stable, the noise is controllable, and high efficiency is required, the method of extending the fixed step size in step S26 can be preferred to obtain the fitting interval.

[0072] Understandably, in this embodiment, the range of the fixed step size extending forward and backward in step S26 is not specifically limited. It can be adjusted according to the specific grayscale histogram, or the most suitable step size can be found through dynamic adjustment to obtain the optimal fitting interval.

[0073] Furthermore, in step S3, the final Gaussian curve obtained is as follows: .

[0074] in, Indicates grayscale level as At that time, the prediction frequency of the final Gaussian curve, This indicates the number of Gaussian peaks in the final Gaussian curve. Let be the peak height of the i-th Gaussian peak. Let be the mean of the i-th Gaussian peak. Let be the standard deviation of the i-th Gaussian peak.

[0075] Furthermore, in step S4, the background grayscale range is... ,in To determine the mean value as the central value, Let be the standard deviation corresponding to the central value, and .

[0076] Understandably, This refers to the preset error range in step S4. The K value can be automatically adjusted according to the characteristics of different dark-field images, thereby adjusting the preset error range to adapt to various image data, detect and output a suitable background grayscale range, and improve the adaptability, versatility and efficiency of the detection method.

[0077] Preferably, the value of K is 1 / 2.

[0078] Furthermore, using the least squares method or the expectation-maximization algorithm to perform Gaussian fitting on the region to be fitted to obtain a Gaussian curve can enhance the robustness of the detection method and ensure that the obtained Gaussian curve is highly consistent with the distribution of background grayscale in the actual dark field image.

[0079] As a concrete example, please refer to Figures 6 to 10 , Figure 6 To obtain a 12-bit dark field image, the number of gray levels... 4096. According to the formula The frequency of gray levels in this dark field image was statistically analyzed to obtain the following results: Figure 7 The grayscale histogram is shown. The maximum point 104 is obtained as the center value according to the methods in steps S21-S24, and the grayscale range [94, 115] is obtained according to the method in step S26. As the interval to be fitted Figure 8 The image shows the histogram of the region to be fitted. For this region, we started with a single-peak Gaussian fit, gradually increasing the number of Gaussian peaks for multiple fitting attempts. Calculations and comparisons showed that when the number of Gaussian peaks was 3, the coefficient of determination was 0.9991, the closest to 1 among all simulations, and the root mean square error was 410.47, the smallest among all simulations. Therefore, the Gaussian curve with 3 Gaussian peaks was selected as the final Gaussian curve. Figure 9 The image shows the fitted Gaussian curve when the number of Gaussian peaks is 3. The mean and standard deviation of the three Gaussian peaks in this final Gaussian curve are then obtained, with the smallest mean being [value missing]. The corresponding standard deviation is For ease of calculation, this mean is... Round to one decimal place, standard deviation Retain two decimal places and take K as 1 / 2 to determine the background grayscale range as 102.1±1.4. Figure 10 This image, which detects the background region based on the background grayscale range, has high accuracy.

[0080] Please see Figure 11 The second embodiment of the present invention provides a computer-readable storage medium 1 on which a computer program 10 is stored, which implements the background grayscale detection method described above when executed by a processor.

[0081] Understandably, the computer-readable storage medium 1 of this embodiment has the same beneficial effects as the background grayscale detection method described above, and will not be repeated here.

[0082] Please see Figure 12 The third embodiment of the present invention provides a computer device 2, including a storage 20, a processor 21 and a computer program 22 stored on the storage 20. The processor 21 executes the computer program 22 to implement the background grayscale detection method described above.

[0083] Understandably, the computer device 2 in this embodiment has the same beneficial effects as the background grayscale detection method described above, and will not be elaborated here.

[0084] Please see Figure 13The fourth embodiment of the present invention provides a computer program product 3, on which a computer program 30 is stored. When the computer program 30 is executed by a processor, it implements the background grayscale detection method described above.

[0085] Understandably, the computer program product 3 of this embodiment has the same beneficial effects as the background grayscale detection method described above, and will not be elaborated here.

[0086] In the embodiments provided by this invention, it should be understood that "B corresponding to A" means that B is associated with A, and B can be determined based on A. However, it should also be understood that determining B based on A does not mean determining B solely based on A; B can also be determined based on A and / or other information.

[0087] It should be understood that the phrase "one embodiment" or "an embodiment" throughout the specification means that a specific feature, structure, or characteristic related to the embodiment is included in at least one embodiment of the invention. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Those skilled in the art should also recognize that the embodiments described in the specification are optional embodiments, and the actions and modules involved are not necessarily essential to the invention.

[0088] In various embodiments of the present invention, it should be understood that the sequence number of each process does not necessarily imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0089] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It is particularly important to note that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0090] Compared with the prior art, the background grayscale detection method, storage medium, computer equipment, and program product provided by the present invention have the following beneficial effects: 1. The automatic background grayscale detection method for dark-field images of the present invention, by combining grayscale histogram analysis and Gaussian fitting, can better cope with the changes in grayscale distribution in complex images, effectively distinguish between background and foreground, improve the accuracy and robustness of background grayscale detection in dark-field images, and the method can realize automatic detection of background grayscale without manual intervention, thus improving detection efficiency. Specifically, firstly, a dark-field image is acquired, and the frequency of each gray level in the dark-field image is statistically analyzed to create a gray-level histogram with gray level on the horizontal axis and frequency on the vertical axis. This visually reflects the distribution and changing trends of different gray levels in the dark-field image, providing crucial information for subsequent analysis. Secondly, the gray-level histogram is scanned from low to high gray levels to identify the first data interval where the frequency first increases and then decreases with gray level. This data interval is used as the fitting interval. This step focuses on the main distribution range of the background, reducing interference from high-gray-level target areas and background noise on background detection. Then, Gaussian fitting with different numbers of Gaussian peaks is performed on the fitting interval to obtain the fitted Gaussian curve. The process involves several steps. First, a Gaussian curve is selected as the final Gaussian curve. This step decomposes the complex gray-level distribution into multiple simple Gaussian components, adapting to different gray-level distributions in the image, reducing fitting errors, and fitting a background gray-level curve that better matches the gray-level histogram distribution, further improving detection accuracy. Second, the mean and standard deviation of each Gaussian peak in the final Gaussian curve are obtained, and the smallest mean is selected as the center value. The background gray-level range is then determined based on the center value and a preset error range. This step, selecting the smallest mean as the center value, accurately locates the main area with the lowest gray level in the image, thus accurately defining the background area and avoiding the background gray-level range shifting to higher gray-level areas and interference from other brighter parts of the image.

[0091] 2. The background grayscale detection method of this invention starts with single-peak Gaussian fitting and gradually increases the number of Gaussian peaks for multiple fittings, adaptively selecting the most suitable model to fit the data. If the data distribution is complex, multiple peaks can better capture the characteristics of the data; if the data distribution is simple, a single peak is sufficient. Simultaneously, by calculating and comparing the coefficient of determination or root mean square error, it can be ensured that a Gaussian curve with a good fit is selected, avoiding the risks of overfitting and underfitting.

[0092] 3. The background grayscale detection method of the present invention provides a specific formula for calculating the grayscale frequency, which can automatically calculate and generate a grayscale histogram, reduce manual intervention, and improve detection efficiency.

[0093] 4. The background grayscale detection method of this invention provides specific steps for determining the fitting interval, employing a combination of sliding window, smoothing processing, and dynamic search, which can adapt to different types of dark-field images. Smoothing processing effectively removes noise and can more clearly and reliably identify the trend of grayscale changes. Setting a sliding window allows for a comprehensive analysis of the entire grayscale histogram, reducing noise interference and accurately identifying the first increasing-then-decreasing trend in the global grayscale histogram.

[0094] 5. The background grayscale detection method of this invention provides a specific formula for the Gaussian curve, which can automatically analyze the grayscale changes of the image background without manual intervention. This can greatly reduce the error of manual detection and improve detection efficiency.

[0095] 6. The background grayscale detection method of the present invention has a background grayscale range of: ,in For the determined center value, The standard deviation is the value corresponding to the center value. That is, the preset error range, and It can automatically adjust the preset error range according to the characteristics of different dark field images, thereby adapting to various different image data, detecting and outputting a suitable background grayscale range, and improving the adaptability, versatility and efficiency of the detection method.

[0096] 7. The background grayscale detection method of the present invention effectively fits the Gaussian curve by using the least squares method or the expectation-maximization algorithm, thereby enhancing the robustness of the detection method and ensuring that the obtained Gaussian curve is highly consistent with the distribution of background grayscale in the actual dark field image.

[0097] 8. The present invention also provides a computer-readable storage medium, which has the same beneficial effects as the background grayscale detection method described above, and will not be elaborated here.

[0098] 9. The present invention also provides a computer device that has the same beneficial effects as the background grayscale detection method described above, which will not be elaborated here.

[0099] 10. The present invention also provides a computer program product that has the same beneficial effects as the background grayscale detection method described above, which will not be elaborated here.

[0100] The foregoing has provided a detailed description of a background grayscale detection method, storage medium, computer device, and program product disclosed in the embodiments of the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention. Any modifications, equivalent substitutions, and improvements made within the principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A background grayscale detection method, characterized in that: Includes the following steps: Acquire a dark field image, count the frequency of each gray level in the dark field image, and draw a gray level histogram with the horizontal axis representing the gray level and the vertical axis representing the frequency. Scan the grayscale histogram from low grayscale levels to high grayscale levels to determine the first data interval in which the frequency first increases and then decreases with the change of grayscale level, and use this data interval as the interval to be fitted. Gaussian fitting with different numbers of Gaussian peaks is performed on the interval to be fitted to obtain the fitted Gaussian curve, and one of the Gaussian curves is selected as the final Gaussian curve. Obtain the mean and standard deviation of each Gaussian peak in the final Gaussian curve, select the smallest mean as the center value, and determine the background grayscale range based on the center value and the preset error range.

2. The background grayscale detection method as described in claim 1, characterized in that: Perform Gaussian fitting on the region to be fitted with different numbers of Gaussian peaks to obtain fitted Gaussian curves, and select one of the Gaussian curves as the final Gaussian curve, including the following steps: For the interval to be fitted, start with single-peak Gaussian fitting, gradually increase the number of Gaussian peaks and perform multiple fittings, and calculate the coefficient of determination or root mean square error of each Gaussian fitting. The number of peaks whose coefficient of determination is closest to 1 or the number of peaks with the smallest root mean square error is selected as the final number of peaks for Gaussian fitting, and the corresponding Gaussian curve is taken as the final Gaussian curve.

3. The background grayscale detection method as described in claim 1, characterized in that: The frequency of occurrence of each gray level in the dark field image is statistically analyzed, including the following steps: Determine the number of gray levels in a dark field image Obtain the total number of pixels in the vertical direction of the dark field image. and the total number of pixels in the horizontal direction ; According to the formula Obtain the frequency of occurrence of each gray level; in, Indicates grayscale level as The frequency of pixel occurrence, coordinates The grayscale level of a pixel. Let Kronecker function be used when It is 1 if it is true, otherwise it is 0.

4. The background grayscale detection method as described in claim 3, characterized in that: The grayscale histogram is scanned from low grayscale levels to high grayscale levels to determine the first data interval in which the frequency first increases and then decreases with the change of grayscale level, and this data interval is used as the interval to be fitted, including the following steps: The grayscale histogram is smoothed to obtain a smoothed histogram; Set a sliding window of preset width, slide it through the smooth histogram from low gray level to high gray level with a fixed step size, and calculate the cumulative frequency in each window; When the cumulative frequency value first shows a trend of increasing and then decreasing, obtain the maximum value point within the current window; Search forward and backward simultaneously from the maximum value point to obtain the nearest maximum value point; Obtain the monotonicity inflection point corresponding to the maximum point. and Calculate gray levels frequency within The frequency set output is then used as the interval to be fitted.

5. The background grayscale detection method as described in claim 1, characterized in that: The final Gaussian curve is specifically as follows: ,in, Indicates grayscale level as At that time, the prediction frequency of the final Gaussian curve, This indicates the number of Gaussian peaks in the final Gaussian curve. Let be the peak height of the i-th Gaussian peak. Let be the mean of the i-th Gaussian peak. Let be the standard deviation of the i-th Gaussian peak.

6. The background grayscale detection method as described in claim 5, characterized in that: The background grayscale range is ,in For the determined center value, Let be the standard deviation corresponding to the central value, and .

7. The background grayscale detection method as described in claim 1, characterized in that: Gaussian curves are obtained by performing Gaussian fitting on the interval to be fitted using the least squares method or the expectation-maximization algorithm.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by the processor, it implements the background grayscale detection method as described in any one of claims 1-7.

9. A computer device, comprising a storage unit, a processor, and a computer program stored in the storage unit, characterized in that: The processor executes the computer program to implement the background grayscale detection method as described in any one of claims 1-7.

10. A computer program product having a computer program stored thereon, characterized in that: When the computer program is executed by the processor, it implements the background grayscale detection method as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Method for identifying sea ship of SAR (Synthetic Aperture Radar) image

    CN108734111A

  • Line scan image quality improvement method based on feature model establishment and gamma gray correction

    CN109447915A

  • An industrial CT artifact correction method

    CN109712212A

  • Airport pavement anomaly detection method based on machine vision

    CN114821314A

  • PCB welding spot defect detection method

    CN115311301A