Defect scoring method and apparatus based on contrast and area, device, and medium
Patent Information
- Application Number
- CN202611256101.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-19
- Publication Date
- 2026-09-18
AI Technical Summary
然而这种阶梯式卡控方法在实际应用中面临明显的局限性,一方面,该方法需要针对每个指标分别设置多个阈值参数,当存在多个判定等级时,所需设置的参数量成倍增加,导致计算量大且现场工程师的调试工作量复杂
通过构建由对比度和面积共同确定的单一直线作为缺陷评判基准线,将每个疑似缺陷的对比度和面积信息转化为该缺陷到基准线的距离值,再依据距离值落入的分数区间赋予单缺陷评分,实现了从二维指标到一维评分的统一量化转换,使得评分结果直观易懂,便于质检人员理解和调试。仅设定最小对比度阈值及其对应的最小面积阈值、最大对比度阈值及其对应的最小面积阈值共四个基础参数即可完成整条评判基准线的构建,相比于传统阶梯式卡控所需的数十个独立阈值,减少了参与计算的参数,也减少了现场调试的工作量。此外,由于缺陷评判基准线在对比度与面积之间建立了连续的线性映射关系,评分结果在对比度与面积组合变化时保持一致的单调性,避免了阶梯式阈值设定中相邻等级之间判定结果不一致的逻辑问题,提升了缺陷评分结果的可靠性和一致性。
Smart Images

Figure CN122780293A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of defect detection technology, and in particular to a defect scoring method, apparatus, device and storage medium based on contrast and area. Background Technology
[0002] In the field of industrial visual inspection, defect scoring is a crucial method for product defect assessment. Currently, the commonly used defect control method in industry is a tiered parameter setting approach. This involves setting multiple threshold levels for various indicators such as defect area, length, width, and contrast. Defects are graded by comparing each indicator with the threshold level. However, this tiered control method faces significant limitations in practical applications. Firstly, it requires setting multiple threshold parameters for each indicator. When multiple assessment levels exist, the number of parameters required increases exponentially, leading to high computational complexity and complicated debugging work for field engineers. Secondly, when different defect scores need to be output, additional combination rules satisfying various defect area, length, and width conditions are required, further increasing the complexity of parameter configuration. Furthermore, because there is no inherent logical connection between the thresholds of different indicators, logical contradictions can easily arise between different levels of assessment results. For example, a defect might meet a second-level threshold for area but only a first-level threshold for contrast, making it difficult to determine its final assessment level.
[0003] Therefore, how to improve the reliability and consistency of defect scoring results while reducing the number of parameters has become a technical problem that urgently needs to be solved in this field. Summary of the Invention
[0004] In view of the above, this application provides a defect scoring method, apparatus, device and storage medium based on contrast and area, the purpose of which is to solve the above technical problems.
[0005] In a first aspect, this application provides a defect scoring method based on contrast and area, the method comprising: Obtain the original image corresponding to the object to be detected, and perform binarization processing on the original image to obtain the binarized image of the object to be detected; Defect regions are extracted from the binarized image to obtain a set of suspected defects of the object to be detected. Each suspected defect in the set of suspected defects has defect information, which includes the contrast of the defect region and the area of the defect region. Based on the preset minimum contrast threshold and the minimum area threshold corresponding to the minimum contrast threshold, and the preset maximum contrast threshold and the maximum area threshold corresponding to the maximum contrast threshold, a defect evaluation baseline is constructed. Based on the defect evaluation baseline and the contrast and area corresponding to each suspected defect, calculate the distance value from each suspected defect to the defect evaluation baseline. Each suspected defect is assigned a corresponding single defect score based on the preset single score range in which the distance value from each suspected defect to the defect evaluation baseline falls; Based on the single defect score corresponding to each suspected defect, the defect score value of the object to be inspected is determined.
[0006] Secondly, this application provides a defect scoring device based on contrast and area, the defect scoring device based on contrast and area comprising: Preprocessing module: Used to acquire the original image corresponding to the object to be detected, and to perform binarization processing on the original image to obtain the binarized image of the object to be detected; Extraction module: used to extract defect regions from the binarized image to obtain a set of suspected defects of the object to be detected, wherein each suspected defect in the set of suspected defects has defect information, including the contrast of the defect region and the area of the defect region; Construction module: used to construct a defect evaluation baseline based on the preset minimum contrast threshold and the minimum area threshold corresponding to the minimum contrast threshold, and the preset maximum contrast threshold and the maximum area threshold corresponding to the maximum contrast threshold. Calculation module: Used to calculate the distance from each suspected defect to the defect assessment baseline based on the defect assessment baseline and the contrast and area corresponding to each suspected defect; Assignment module: Used to assign a corresponding single defect score to each suspected defect based on the preset single score range in which each suspected defect falls from the distance value from the defect judgment baseline; Scoring module: Used to determine the defect score of the object to be inspected based on the single defect score corresponding to each suspected defect.
[0007] Thirdly, this application provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; When a processor executes a program stored in memory, it implements the steps of the defect scoring method based on contrast and area as described in any embodiment of the first aspect.
[0008] Fourthly, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of the defect scoring method based on contrast and area as described in any embodiment of the first aspect.
[0009] The technical solutions provided in this application have the following advantages compared with the prior art: By constructing a single straight line defined by contrast and area as the defect evaluation baseline, the contrast and area information of each suspected defect is converted into a distance value from the baseline. A score is then assigned to each defect based on the score range within which the distance value falls. This achieves a unified quantitative conversion from two-dimensional indicators to one-dimensional scoring, making the scoring results intuitive and easy for quality inspectors to understand and adjust. The entire evaluation baseline can be constructed by setting only four basic parameters: the minimum contrast threshold and its corresponding minimum area threshold, and the maximum contrast threshold and its corresponding minimum area threshold. Compared to the dozens of independent thresholds required by traditional tiered control, this reduces the number of parameters involved in the calculation and the workload of on-site debugging. Furthermore, because the defect evaluation baseline establishes a continuous linear mapping relationship between contrast and area, the scoring results maintain consistent monotonicity when the combination of contrast and area changes. This avoids the logical problem of inconsistent judgment results between adjacent levels in tiered threshold settings, improving the reliability and consistency of defect scoring results. Attached Figure Description
[0010] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0011] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 This is a flowchart illustrating a preferred embodiment of the defect scoring method based on contrast and area in this application; Figure 2 This is a schematic image of the object to be detected with a defect score of 0 in an embodiment of this application. Figure 3 This is a schematic image of the object to be detected with a defect score of 4 in an embodiment of this application. Figure 4 This is a schematic image of the object to be detected with a defect score of 1 in an embodiment of this application. Figure 5 This is a schematic diagram of a preferred embodiment of the defect scoring device based on contrast and area according to this application; Figure 6 This is a schematic diagram of a preferred embodiment of the electronic device of this application; The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0013] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application. All other embodiments obtained by those skilled in the art based on the embodiments in this application without inventive effort are within the scope of protection of this application.
[0014] It should be noted that the use of terms such as "first" and "second" in this application is for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of those features. Furthermore, the technical solutions of the various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. If the combination of technical solutions is contradictory or impossible to implement, such a combination of technical solutions should be considered non-existent and not within the scope of protection claimed in this application.
[0015] Reference Figure 1 The diagram shown is a flowchart illustrating an embodiment of the defect scoring method based on contrast and area according to this application. The method is executed by an electronic device, which can be implemented by a software system and / or a hardware system. The defect scoring method based on contrast and area includes: Step S10: Obtain the original image corresponding to the object to be detected, and perform binarization processing on the original image to obtain the binarized image of the object to be detected; Step S20: Extract the defect region from the binarized image to obtain a set of suspected defects of the object to be detected. Each suspected defect in the set of suspected defects has defect information, which includes the contrast of the defect region and the area of the defect region. Step S30: Construct a defect evaluation baseline based on the preset minimum contrast threshold and the minimum area threshold corresponding to the minimum contrast threshold, and the preset maximum contrast threshold and the maximum area threshold corresponding to the maximum contrast threshold. Step S40: Based on the defect evaluation baseline and the contrast and area corresponding to each suspected defect, calculate the distance value from each suspected defect to the defect evaluation baseline; Step S50: Assign a corresponding single defect score to each suspected defect based on the preset single score range in which the distance value from each suspected defect to the defect evaluation baseline falls; Step S60: Determine the defect score value of the object to be inspected based on the single defect score corresponding to each suspected defect.
[0016] This application's embodiments are applicable to the quantitative evaluation of internal defects in lenses in industrial vision inspection scenarios. As a core component of an optical imaging system, the surface quality of a lens directly affects image sharpness and optical performance. Internal lens defects can include dust particles, bubbles, scratches, coating flaws, etc., on or inside the lens surface. These defects appear in the image as areas with grayscale differences compared to the surrounding lens background. In practical applications of industrial vision inspection, quality inspectors typically consider both the contrast and size of defects when evaluating lens quality. Contrast reflects the visibility of the defect, while size reflects its physical footprint. Under the same contrast conditions, a larger defect size indicates a higher product defect grade, and vice versa.
[0017] Traditional defect control methods employ a tiered parameter setting, requiring multiple threshold levels for defect area, length, width, and contrast, followed by graded judgments. This multi-parameter combination approach is not only complex to debug, but also necessitates configuring various combinations of conditions when different levels of scores are required, significantly increasing the workload for on-site engineers. Furthermore, lens surfaces possess light-transmitting and curvature characteristics; defects at different locations exhibit varying contrast due to different light incidence angles. Defects in edge regions are often more difficult to capture clearly than those of the same size in the center region, yet edge defects have a more significant impact on the image quality at the lens edges. Therefore, a scoring mechanism that uniformly considers defect contrast and area is needed to meet the specific requirements of lens inspection. Based on these reasons, this application constructs a baseline for judging defect severity by combining two indicators: defect contrast and defect area. By calculating the distance of each defect to this baseline, the severity of the defect is quantified, thereby achieving continuous defect scoring output with a small number of parameters. This not only adapts to the differentiated evaluation needs of defects in different areas of the lens but also significantly simplifies on-site debugging.
[0018] Specifically, the process involves acquiring the original image of the object to be inspected and performing binarization on it to obtain a binarized image of the object. The object can be a single optical lens in a lens module or a lens assembly composed of multiple lenses. In the actual inspection process, an image acquisition device captures a surface image of the object. For light-transmitting elements like lenses, backlighting or coaxial illumination is typically used to enhance the visibility of internal defects, resulting in a grayscale image. During binarization, pixels in the original image are divided into foreground and background categories based on a preset segmentation threshold. Foreground pixels correspond to areas where defects may exist, while background pixels correspond to normal or light-transmitting areas on the lens surface. After binarization, the original image is converted into a binarized image containing both foreground and background pixel values. The binarized image retains the position and shape information of all candidate defect areas in the original image while removing redundant grayscale details.
[0019] Defect regions are extracted from the binarized image to obtain a set of suspected defects in the object to be detected. Each suspected defect in this set has defect information, including the contrast and area of the defect region. Foreground connected regions in the binarized image are candidate defect regions. By performing connected component analysis on the binarized image, all independent foreground connected regions can be identified, with each region corresponding to a suspected defect. After extracting each connected region, the defect information for each suspected defect is calculated. The area is obtained by counting the number of foreground pixels within the connected region, and the contrast is calculated based on the difference between the average gray value of the pixels within the connected region and the average gray value of the surrounding background pixels. Since the lens surface is a light-transmitting medium, the gray value of the defect region usually appears as a dark or bright spot relative to the surrounding transparent background. Therefore, the contrast calculation can effectively characterize the degree of prominence of the defect relative to the clean lens surface.
[0020] Based on preset minimum contrast thresholds and their corresponding minimum area thresholds, and preset maximum contrast thresholds and their corresponding minimum area thresholds, a defect evaluation baseline is constructed. Specifically, in a two-dimensional coordinate system with contrast as the horizontal axis and area as the vertical axis, there are two key coordinate points. The horizontal coordinate of the first coordinate point is the preset minimum contrast threshold, and the vertical coordinate is the minimum area threshold corresponding to that minimum contrast threshold. The horizontal coordinate of the second coordinate point is the preset maximum contrast threshold, and the vertical coordinate is the minimum area threshold corresponding to that maximum contrast threshold. The straight line connecting these two coordinate points is the defect evaluation baseline.
[0021] The physical meaning of the defect assessment baseline is that for defects falling on one side of the baseline, the combination of contrast and area is considered within the acceptable or minor defect range. For defects falling on the other side of the baseline, the combination of contrast and area is considered to exceed acceptable limits, indicating a higher degree of defect severity. For lens inspection, the minimum contrast threshold can be set based on the reflectivity and transmittance characteristics of the lens coating surface. Lenses with different coating processes have varying abilities to reveal small defects. The maximum contrast threshold reflects the maximum acceptable defect contrast in the lens manufacturing process. A linear equation can be uniquely determined through these two preset endpoints. This equation can be expressed as a linear combination of contrast and area variables equal to zero, where the coefficients are uniquely determined by the coordinate values of the two endpoints. Constructing this baseline requires only two sets of threshold parameters, significantly reducing the number of parameters compared to the numerous parameters required by traditional stepped control methods.
[0022] After obtaining the defect assessment baseline, the distance from each suspected defect to the baseline is calculated based on the baseline and the contrast and area corresponding to each suspected defect. Specifically, in a two-dimensional space composed of contrast and area, each suspected defect is mapped to a coordinate point, where the x-coordinate is the contrast of the defect area and the y-coordinate is the area of the defect area. Since the defect assessment baseline is a straight line in space, the vertical distance from the coordinate point corresponding to each suspected defect to this line can be calculated using the point-to-line distance formula. The sign of this vertical distance reflects which side of the baseline the coordinate point is on, while the absolute value of the distance reflects the degree to which the defect deviates from the baseline; a larger absolute value indicates a higher degree of defect severity. For lens inspection, defects in edge areas typically exhibit lower contrast in the image due to the skewed angle of incident light, thus requiring a larger area in the assessment baseline to be judged as a serious defect. This aligns with the actual judgment logic of lens optical design. Therefore, the contrast and area of each suspected defect are transformed into a unified quantitative indicator, namely, the distance from the defect to the baseline. The distance from a suspected defect to the defect assessment baseline can be expressed by the following formula:
[0023] in, d i Let represent the distance from the i-th suspected defect to the defect evaluation baseline, T represent the total number of suspected defects in the suspected defect set, M represent the first linear coefficient (i.e., the coefficient of the contrast variable), N represent the second linear coefficient (i.e., the coefficient of the area variable), and P represent the constant term. c i This represents the contrast of the i-th suspected defect. a iLet represent the area of the region where the i-th suspected defect is located.
[0024] Each suspected defect is assigned a single-item score based on the distance value from its origin to the defect assessment baseline falling within a preset single-item score interval. The preset single-item score interval divides the range of distance values into multiple consecutive segments, each segment corresponding to a score value. In practical applications, the number of score intervals and the boundary values of each interval can be preset according to the severity level requirements of lens quality inspection. When the distance value of a suspected defect falls within a certain score interval, the score corresponding to that distance value is the single-item defect score. This single-item defect score directly reflects the severity of the individual defect; a higher score indicates that the defect deviates further from the baseline, i.e., the defect is more severe. It should be noted that the division of score intervals can be adjusted according to different lens models or different quality standards. Furthermore, the distance value and the preset single-item score interval can be expressed by the following formula:
[0025] in, d i This represents the distance from the i-th suspected defect to the defect evaluation baseline. score This represents the single defect score for the i-th suspected defect.
[0026] The defect score of the object to be inspected is determined based on the single defect score corresponding to each suspected defect. Specifically, when the object to be inspected contains only a single suspected defect, the single defect score of that suspected defect is directly used as the defect score of the object to be inspected. When the object to be inspected contains multiple suspected defects, the single defect scores of all suspected defects need to be considered comprehensively to determine the final defect score.
[0027] In one optional implementation, the maximum value among all suspected single defect scores can be used as the defect score of the object to be inspected. That is, the severity of the lens defect is considered to be determined by the most serious single defect. This approach is consistent with the veto logic in lens quality inspection.
[0028] In another optional implementation, when all individual defects have scores within the acceptable range but the number of defects exceeds one, a comprehensive distance value can be calculated based on the contrast and area of each suspected defect. This comprehensive distance value is then mapped to a comprehensive score, which is used as the defect score of the object to be inspected. This approach reflects the cumulative effect of multiple defects. For example, although individual dust particles on a lens surface are very small, the cumulative effect of multiple dust particles can still affect the lens's transmittance and image quality. The defect score of the object to be inspected is a quantified value that can be used for defect level determination, product sorting, or quality statistics.
[0029] This embodiment transforms defect scoring into quantifiable numerical output, eliminating the need for quality inspectors to deal with numerous independent threshold parameters. Parameter configuration only requires setting two sets of threshold points, reducing the total number of parameters compared to the multiple threshold parameters required by traditional tiered control methods, thus reducing the workload of model changeover and debugging in lens production lines. By unifying the two related indicators of contrast and area into a single linear model for evaluation, the logical conflicts and inconsistencies caused by setting multiple independent thresholds in traditional methods are avoided. In practical applications, the defect evaluation baseline can directly correspond to the optical design requirements of the lens; that is, the minimum and maximum contrast thresholds can be flexibly set according to the lens's coating reflection characteristics and the user's sensitivity requirements for visible defects, allowing the scoring standard to adapt to the differences in optical performance of different lens models. This embodiment also considers the special physical properties of lenses as light-transmitting elements, including the contrast attenuation of edge defect imaging due to surface curvature, the modulation effect of different coating processes on defect imaging capabilities, and the cumulative effect of multiple small defects on transmittance—all unique to lens inspection. Compared to directly applying defect detection methods for other opaque industrial parts to lens inspection, this embodiment can more accurately reflect the true optical impact of lens defects.
[0030] In one embodiment, extracting the defect region from the binarized image to obtain a set of suspected defects in the object to be detected includes: Perform connected component analysis on the binarized image to extract all connected components in the binarized image, and obtain the initial defect region set of the binarized image. Each initial defect region in the initial defect region set has location information and geometric parameters. The location information includes the coordinates of the region center of the initial defect region in the binarized image, and the geometric parameters include the region area, the length of the bounding rectangle, and the width of the bounding rectangle. Based on the image center coordinates of the binarized image and the region center coordinates of each initial defect region, calculate the radial distance from each initial defect region to the image center coordinates; Based on the radial distance of each initial defect region, the shape correction coefficient corresponding to each initial defect region is determined, and the area of the initial defect region is weighted and corrected using the shape correction coefficient to obtain the corrected area corresponding to each initial defect region. Based on the corrected area, circumscribed rectangle length, and circumscribed rectangle width of each initial defect region, initial defect regions with a corrected area less than a preset area threshold, a circumscribed rectangle length less than a preset length threshold, or a circumscribed rectangle width less than a preset width threshold are removed. The remaining initial defect regions are then used as suspected defects of the object to be detected, resulting in a set of suspected defects.
[0031] Connected component analysis is performed on the binarized image to extract all connected components, resulting in an initial set of defect regions. Each initial defect region in this set possesses location information and geometric parameters. The location information includes the coordinates of the region's center in the binarized image, while the geometric parameters include the region area, the length of the bounding rectangle, and the width of the bounding rectangle. Connected component analysis scans each pixel in the binarized image, marking adjacent foreground pixels with the same pixel value as the same connected component, thus aggregating scattered pixels into physically meaningful regions. During the marking process, the statistical attributes of each connected component are recorded simultaneously. The region area is obtained by counting the number of foreground pixels within the connected component; the length and width of the bounding rectangle are obtained by calculating the span of the minimum bounding rectangle of the connected component in the row and column directions of the image, respectively; and the region center coordinates are obtained by calculating the mean of the coordinates of all pixels within the connected component.
[0032] For lens images, since lenses are circular components, the effective area of the lens in the image is usually circular or elliptical. When extracting connected components, the image region to be analyzed can be limited according to the contour position of the effective area of the lens, extracting only the connected components within the effective area of the lens, thus avoiding including irrelevant areas on the image border or clamping device in the initial defect region set. After connected component analysis, all candidate regions are organized into an initial defect region set, where each element carries the location information and geometric parameters required for subsequent screening.
[0033] Based on the image center coordinates of the binarized image and the region center coordinates of each initial defect region, the radial distance from each initial defect region to the image center coordinates is calculated. Specifically, the image center coordinates are taken as the midpoint of the binarized image in both the row and column directions. For lens images, the optical center of the lens and the geometric center of the image are ideally almost coincident, so using the image center coordinates as a reference point is reasonable. For situations where the lens is not perfectly centered in certain acquisition scenarios, the position of the lens's optical center can be pre-determined through edge detection or circular fitting, and then this position can be used as a reference point instead of the image center coordinates for calculation. The radial distance is calculated using the Euclidean distance formula, which is the sum of the square of the difference between the row coordinates of the region center and the row coordinates of the image center, and the square of the difference between the column coordinates of the region center and the column coordinates of the image center, and then the square root is taken.
[0034] This radial distance reflects the initial location of the defect area on the lens. A smaller distance indicates that the area is closer to the lens center, while a larger distance indicates that the area is closer to the lens edge. For the lens edge region, due to the inherent distortion effects of the optical system and the influence of the skewed angle of incident light, defects may undergo shape stretching or area expansion during imaging. The pixel area of the same physical defect in the edge region may differ significantly from that in the center region. Therefore, introducing the radial distance as a positional parameter before screening allows subsequent area correction to be differentiated based on the specific location of the area on the lens.
[0035] After obtaining the radial distance of each initial defect region, a shape correction coefficient is determined based on the radial distance of each initial defect region. The area of each initial defect region is then weighted and corrected using this shape correction coefficient to obtain the corrected area for each initial defect region. The shape correction coefficient is a monotonically non-decreasing function of the radial distance. In one optional implementation, the shape correction coefficient is equal to one plus the square of the radial distance divided by a preset proportional constant. This ensures that the correction coefficient for regions closer to the lens center is close to one, maintaining a relatively constant area, while the correction coefficient for regions farther from the lens edge is greater than one, resulting in an appropriately enlarged area.
[0036] Multiplying the shape correction factor by the original area of the initial defect region yields the corrected area. This corrected area eliminates the area measurement deviation caused by optical distortion at the lens edge, allowing defects at different radial positions to be screened and judged based on a unified physical size standard. This shape correction factor is specifically designed for lens light-transmitting element detection because defects at the lens edge often have a greater impact on image quality than defects of the same size in the center region. Through position-related area magnification correction, edge region defects achieve higher pass sensitivity during screening.
[0037] Based on the corrected area, circumscribed rectangle length, and circumscribed rectangle width of each initial defect region, initial defect regions with a corrected area smaller than a preset area threshold, a circumscribed rectangle length smaller than a preset length threshold, or a circumscribed rectangle width smaller than a preset width threshold are removed. The remaining initial defect regions are considered as suspected defects in the object to be inspected, resulting in a set of suspected defects. The preset area threshold, preset length threshold, and preset width threshold correspond to the minimum size limits on the lens that can be considered valid defects. These thresholds are preset according to the quality specifications of the lens product. When the corrected area of an initial defect region after position-weighted correction is less than the preset area threshold, it indicates that the region is still smaller than the minimum size that can be considered a defect even after area magnification correction, and should be removed as noise or a non-substantial flaw. Similarly, when the circumscribed rectangle length or width is less than the corresponding preset length threshold or preset width threshold, it indicates that the region is too small in a certain dimension and does not meet the basic morphological characteristics of a lens defect, and should also be removed.
[0038] The three screening criteria use an OR logic relationship: an initial defect region is removed if it meets any one of the following three conditions: the corrected area is less than a preset area threshold, the length of the circumscribed rectangle is less than a preset length threshold, or the width of the circumscribed rectangle is less than a preset width threshold. Only initial defect regions that simultaneously meet all three threshold conditions are retained as suspected defects. After this triple screening, the retained initial defect regions constitute the suspected defect set for subsequent scoring calculations.
[0039] By introducing radial distance and shape correction coefficients, defects located at the lens edge achieve a screening pass rate comparable to defects of the same size in the central region due to the appropriate enlargement of the correction area. This avoids the situation where edge defects are missed due to undersized area measurements caused by optical distortion. Simultaneously, by jointly screening based on the correction area, the length of the circumscribed rectangle, and the width of the circumscribed rectangle, pseudo-defect connected regions caused by image noise, coating textures, or processing marks can be effectively eliminated, ensuring a high degree of authenticity in the suspected defect set and improving the accuracy and reliability of lens defect detection.
[0040] In one embodiment, the step of constructing a defect evaluation baseline based on a preset minimum contrast threshold and a minimum area threshold corresponding to the minimum contrast threshold, and a preset maximum contrast threshold and a maximum area threshold corresponding to the maximum contrast threshold, includes: Obtain the preset minimum contrast threshold, the minimum area threshold corresponding to the minimum contrast threshold, the preset maximum contrast threshold, and the minimum area threshold corresponding to the maximum contrast threshold; The first coordinate point is generated based on the minimum contrast threshold and the minimum area threshold corresponding to the minimum contrast threshold, and the second coordinate point is generated based on the maximum contrast threshold and the minimum area threshold corresponding to the maximum contrast threshold. Based on the first and second coordinate points, a straight line equation passing through the first and second coordinate points is generated, and the straight line equation is used as the baseline for defect evaluation.
[0041] The minimum and maximum contrast thresholds define the range of contrast values relevant to lens defect assessment. The minimum contrast threshold is typically set as the lowest contrast level at which a lens surface defect can be reliably identified by the human eye or image acquisition system. Grayscale fluctuations below this threshold are considered background noise and not treated as defects. The maximum contrast threshold is set as the maximum contrast value that may occur during lens manufacturing. Defects exceeding this contrast range, regardless of size, should be considered serious defects. The minimum area threshold corresponding to the minimum contrast threshold refers to the area of the defect region reaching this threshold when the contrast is equal to the minimum contrast threshold. Defects smaller than this threshold, even if just identifiable, are considered to have negligible impact on lens image quality. The minimum area threshold corresponding to the maximum contrast threshold refers to the area of the defect region reaching this threshold when the contrast is equal to the maximum contrast threshold. Because defects corresponding to the maximum contrast threshold are very noticeable, even small areas can have a visible impact on image quality. Therefore, this area threshold is usually set much smaller than the minimum area threshold corresponding to the minimum contrast threshold.
[0042] A first coordinate point is generated based on the minimum contrast threshold and the corresponding minimum area threshold. A second coordinate point is generated based on the maximum contrast threshold and the corresponding minimum area threshold. Specifically, in a two-dimensional coordinate system with contrast as the horizontal axis and area as the vertical axis, the horizontal coordinate of a coordinate point represents the contrast value, and the vertical coordinate represents the area value. Therefore, the horizontal coordinate of the first coordinate point is the minimum contrast threshold, and the vertical coordinate is the corresponding minimum area threshold. This coordinate point represents the lower limit of the defect evaluation baseline, i.e., the minimum area required to determine the existence of a defect under the lowest identifiable contrast condition. The horizontal coordinate of the second coordinate point is the maximum contrast threshold, and the vertical coordinate is the corresponding minimum area threshold. This coordinate point represents the upper limit of the defect evaluation baseline, i.e., the minimum area required to determine the existence of a defect under the highest contrast condition. Since the defect contrast on the lens surface usually decreases as the distance between the defect and the lens center increases, the setting of the minimum and maximum contrast thresholds also needs to consider the defect contrast distribution characteristics at different locations within the entire field of view of the lens, so that the constructed evaluation baseline is applicable throughout the entire effective area of the lens. Once the two coordinate points are generated, the positions of the two endpoints of the defect evaluation baseline in the coordinate system are determined.
[0043] Based on the first and second coordinate points, a straight line equation passing through these two points is generated, and this equation serves as the baseline for defect evaluation. Specifically, in a two-dimensional coordinate system, there is one and only one straight line passing through two known points. The slope of this line is determined by the ratio of the difference between the ordinates and the abscissas of the two coordinate points. The intercept of the line is obtained by substituting the slope and the coordinate value of any given point into the straight line equation. This straight line equation can be expressed as a general form where the linear combination of the contrast variable and the area variable equals zero, where the coefficients of the contrast variable and the area variable, as well as the constant term, are uniquely determined by the coordinate values of the first and second coordinate points.
[0044] In terms of the physical meaning of lens inspection, this defect evaluation baseline represents the critical area value corresponding to each contrast value within the range from the lowest to the highest contrast. When the combined coordinate point of a defect's contrast and area falls on one side of the baseline, it indicates that the severity of the defect is lower than or equal to the critical level represented by the baseline. Conversely, when the coordinate point falls on the other side of the baseline, it indicates that the severity of the defect is higher than the critical level represented by the baseline. This defect evaluation baseline transforms the originally discrete, step-like multi-level threshold judgment into a continuous, single linear judgment model, fundamentally simplifying the quantitative assessment process of defect severity.
[0045] A complete evaluation baseline can be uniquely determined using the coordinates of two endpoints, significantly reducing the number of parameters involved in the calculation. The defect evaluation baseline establishes a continuous linear mapping between contrast and area, ensuring that any contrast value between the minimum and maximum contrast has a corresponding critical area reference value, avoiding the logical contradiction of inconsistent judgment results between adjacent levels in discrete threshold settings. For the specific needs of lens inspection, the positions of the two endpoint coordinates can be flexibly adjusted according to the lens's coating reflection characteristics and imaging quality requirements, allowing the evaluation baseline to adapt to the differences in optical performance of different lens models, exhibiting good versatility and scalability.
[0046] In one embodiment, calculating the distance from each suspected defect to the defect assessment baseline based on the defect assessment baseline and the contrast and area corresponding to each suspected defect includes: Obtain the first linear coefficient, the second linear coefficient, and the constant term in the linear equation of the defect evaluation baseline; For each suspected defect, the product of the contrast corresponding to the suspected defect and the first linear coefficient, the product of the area corresponding to the suspected defect and the second linear coefficient, and the constant term are added to obtain the numerator corresponding to the suspected defect. Divide the numerator by the square root of the sum of the squares of the first and second linear coefficients to obtain the distance from the suspected defect to the defect assessment baseline.
[0047] Each suspected defect has two attribute values: contrast and area. In the contrast-area two-dimensional coordinate system, the suspected defect is uniquely mapped to a coordinate point, and the defect evaluation baseline is a straight line passing through the two endpoint coordinates. The distance from this coordinate point to this straight line is a geometric quantity that can comprehensively reflect the degree of deviation in both contrast and area dimensions. The larger the distance value, the greater the degree to which the defect exceeds the baseline threshold in terms of contrast or area, that is, the more serious the defect.
[0048] The defect assessment baseline is expressed by the equation of a straight line passing through the first and second coordinate points. The general form of this equation can be written as: the first straight line coefficient multiplied by the contrast variable plus the second straight line coefficient multiplied by the area variable plus a constant term equals zero. For example, when the slope-intercept equation of the defect assessment baseline is expressed as: area equals slope multiplied by contrast plus intercept, it can be transformed into its general form by rearranging terms. In this case, the first straight line coefficient equals the negative of the slope, the second straight line coefficient equals one, and the constant term equals the negative of the intercept. As another example, when constructing the general equation directly using the coordinates of the two endpoints, the first straight line coefficient equals the ordinate of the second coordinate point minus the ordinate of the first coordinate point; the second straight line coefficient equals the abscissa of the first coordinate point minus the abscissa of the second coordinate point; and the constant term equals the abscissa of the second coordinate point multiplied by the ordinate of the first coordinate point minus the abscissa of the first coordinate point multiplied by the ordinate of the second coordinate point. The first straight line coefficient, the second straight line coefficient, and the constant term together determine the position and orientation of the defect assessment baseline in the coordinate system and are the three necessary parameters for calculating the distance from a point to a line. In the lens inspection scenario, since different lens models correspond to different defect evaluation baselines, it is necessary to obtain the first linear coefficient, second linear coefficient, and constant term corresponding to the current baseline at the beginning of each inspection process. For lenses of the same model in the same batch, this set of parameters remains unchanged.
[0049] For each suspected defect, the numerator is obtained by adding the product of the contrast corresponding to the suspected defect and the first linear coefficient, the product of the area corresponding to the suspected defect and the second linear coefficient, and a constant term. In the formula for calculating the distance from a point to a line, the numerator is calculated by multiplying the abscissa of the point by the first linear coefficient, the ordinate by the second linear coefficient, and then adding a constant term. In the coordinate system of this embodiment, the abscissa corresponds to the contrast of the suspected defect, and the ordinate corresponds to the area of the suspected defect. Therefore, multiplying the contrast of the suspected defect by the first linear coefficient yields the first product term, multiplying the area of the suspected defect by the second linear coefficient yields the second product term, and then adding the first product term, the second product term, and the constant term. The sign of the numerator reflects which side of the defect evaluation baseline the suspected defect coordinate point is located on; a positive value indicates the coordinate point is on one side of the baseline, and a negative value indicates the coordinate point is on the other side. The absolute value of the numerator reflects the absolute degree of deviation of the coordinate point from the baseline. For lens inspection, a zero numerator indicates that the contrast and area combination of the suspected defect falls exactly on the baseline, indicating a critical state. A positive numerator with a larger absolute value indicates a more severe defect. A negative numerator indicates that the severity of the defect is below the critical level represented by the baseline. For defects located at different radial positions within the lens, as long as the numerator corresponding to their contrast and area combinations is the same, it means they deviate from the baseline to the same degree and will be assigned the same distance value.
[0050] Dividing the numerator by the square root of the sum of the squares of the first and second linear coefficients yields the distance from the suspected defect to the defect assessment baseline. The denominator of the point-to-line distance formula is the square root of the sum of the squares of the first and second linear coefficients. This denominator is a positive number determined solely by the coefficients of the linear equation, and it takes the same value for all suspected defects on the same defect assessment baseline. Dividing the numerator by this denominator gives the quotient, which is the vertical distance from the suspected defect to the defect assessment baseline. This distance is a dimensionless value that comprehensively reflects the degree to which the defect deviates from the baseline in both contrast and area dimensions. Compared to the simple numerator, the distance value eliminates the scale effect caused by different linear equation coefficients, making the distance values corresponding to baselines with different slopes or positions comparable. The calculation of this distance value involves only multiplication and addition operations, resulting in high computational efficiency, making it suitable for rapid processing of a large number of suspected defects on real-time production lines in industrial vision inspection. Since the distance value directly reflects the degree to which the defect deviates from the evaluation baseline and corresponds directly to the subsequent scoring interval division, the scoring results are interpretable.
[0051] In one embodiment, determining the defect score value of the object to be inspected based on the single defect score corresponding to each suspected defect includes: If any single defect score meets the preset out-of-standard judgment condition, then the single defect score corresponding to the out-of-standard judgment condition is taken as the defect score value of the object to be tested. If none of the individual defect scores meet the preset criteria for exceeding the standard, the comprehensive distance value is calculated based on the contrast and area of all suspected defects. The defect score of the object to be inspected is determined based on the preset comprehensive score range into which the comprehensive distance value falls.
[0052] When the number of suspected defects is zero, it means that no defective areas meeting the minimum concern standard were found on the surface of the object to be inspected. In this case, the defect score of the object to be inspected can be directly determined to be zero. When the number of suspected defects is one, the single defect score of that suspected defect is the defect score of the object to be inspected. When the number of suspected defects is multiple, it is necessary to comprehensively consider the individual scores of multiple defects and the overall impact of the number of defects on product quality. There are two typical judgment scenarios in this case. The first scenario is that at least one of the multiple defects has a high single defect score, which has reached the threshold for direct non-compliance. In this case, according to the veto principle commonly used in lens quality inspection, the score of the defect that exceeds the threshold should be used as the final score. The second scenario is that the single defect scores of all defects do not meet the threshold for non-compliance. That is, each individual defect is within the acceptable range when judged in isolation. However, when multiple defects exist on the same lens surface at the same time, their cumulative effect may have a non-negligible impact on the optical performance of the lens. Therefore, it is necessary to combine the contrast and area information of multiple defects to calculate a comprehensive distance value, and then map this comprehensive distance value to a comprehensive score as the final score.
[0053] Specifically, the system determines whether any suspected defect's single-defect score meets a preset out-of-standard judgment condition. If so, the single-defect score that meets the out-of-standard judgment condition is used as the defect score value of the object to be inspected. The out-of-standard judgment condition refers to a pre-set scoring threshold. When the single-defect score of a suspected defect reaches or exceeds this threshold, it indicates that the severity of the defect has exceeded the acceptable range, and the lens should be judged as a non-conforming product. In practical applications, the out-of-standard judgment condition can be flexibly set according to the quality level of the lens product. For example, setting a score of four as the out-of-standard judgment condition means that any lens with a single-defect score of four is directly judged as non-conforming. In lens quality inspection scenarios, lens imaging quality is highly sensitive to a single significant defect. A noticeable scratch or bubble is enough to cause visible defects in the lens image. Even if other areas of the lens are completely clean, the impact of this defect cannot be compensated for. Therefore, once any defect that meets the out-of-standard judgment condition is detected, there is no need to comprehensively consider other defects; the score of this defect can be directly used as the final defect score output for the lens.
[0054] When all individual defect scores fail to meet the preset criteria for exceeding the limit, meaning each suspected defect score is within an acceptable range, it is necessary to further determine the number of suspected defects. If all individual defect scores fail to meet the criteria for exceeding the limit and the number of suspected defects is one, then the score of the single suspected defect is taken as the defect score of the object to be inspected. In this case, since the lens has only one defect and its score has not yet reached the criteria for exceeding the limit, it indicates that the severity of the defect is within an acceptable range. Therefore, this individual defect score directly reflects the severity of the lens defect, and no additional comprehensive calculation is required.
[0055] If all individual defect scores fail to meet the preset criteria for exceeding the standard and the number of suspected defects is greater than one, then a comprehensive distance value is calculated based on the contrast and area of all suspected defects. The comprehensive distance value is a composite index calculated by aggregating the contrast and area information of all suspected defects. Its calculation method is logically similar to the calculation of the distance from a single defect to the baseline, but the processing object is expanded from a single defect to the entirety of all defects.
[0056] The calculation of the comprehensive distance value based on the contrast and area of all suspected defects includes: Obtain the first linear coefficient, the second linear coefficient, and the constant term in the linear equation of the defect evaluation baseline; For each suspected defect in the suspected defect set, the product of the contrast corresponding to the suspected defect and the first straight line coefficient and the product of the area of the region and the second straight line coefficient are added to obtain the single straight line substitution value corresponding to the suspected defect. The sum of the individual line values corresponding to all suspected defects in the suspected defect set is obtained by substituting the values into the line values. After adding the sum of the substituted values to the constant term, divide by the square root of the sum of the squares of the first and second linear coefficients to obtain the overall distance value from the defect assessment baseline to all suspected defects.
[0057] The overall distance value, in its physical sense, represents the combined deviation of all suspected defects from the evaluation baseline. When multiple minor defects exist on the lens surface, although the individual linear values of each defect may not exceed the standard when substituted into the distance formula individually, the sum of all defect linear values before calculating the distance may result in a higher overall distance value, reflecting the cumulative degradation effect of multiple defects. The overall distance value is expressed by the formula:
[0058] Where D represents the comprehensive distance value, T represents the total number of all suspected defects in the suspected defect set, M represents the first linear coefficient (i.e., the coefficient of the contrast variable), N represents the second linear coefficient (i.e., the coefficient of the area variable), and P represents the constant term. c i This represents the contrast of the i-th suspected defect. a i Let represent the area of the region where the i-th suspected defect is located.
[0059] After obtaining the comprehensive distance value, the defect score of the object to be inspected is determined based on the preset comprehensive score interval into which the comprehensive distance value falls. The preset comprehensive score interval divides the range of comprehensive distance values into multiple consecutive intervals, each corresponding to a comprehensive score value. The physical meaning of the comprehensive score value is similar to that of the single defect score, but it represents the severity level of multiple defects as a whole. When the comprehensive distance value falls into a certain comprehensive score interval, the comprehensive score corresponding to that comprehensive distance value is the defect score value of the object to be inspected. It should be noted that the preset comprehensive score interval and the aforementioned preset single-item score interval can use the same interval boundary values, or different interval boundary values can be used depending on the actual distribution of the comprehensive distance values; this is not limited here.
[0060] In another scenario, if one of the three suspected defects scores three points, thus meeting the preset criteria for exceeding the limit, then the three-point single defect score is directly used as the final defect score output for the lens, without needing to calculate the overall distance value.
[0061] For the situation where all defects do not exceed the standard but the number of defects is more than one, the method aggregates the contrast and area information of multiple defects as a whole through a comprehensive distance value, so that the cumulative effect of multiple tiny defects can be effectively captured, which avoids the one-sidedness of the traditional method that only focuses on the single largest defect and ignores the influence of the number of defects. The calculation of the comprehensive distance value adopts the same baseline and coefficients as the aforementioned single defect distance value calculation, which ensures the internal consistency of the scoring system, so that the single defect scoring and comprehensive scoring can be connected and compared with each other under the same framework. According to the actual requirements of lens detection, it can fully cover various application scenarios of lens defect scoring, and has good adaptability and reliability.
[0062] In one embodiment, the method further comprises: Mapping the defect score value of the object to be detected into the correspondence between preset score intervals and defect levels for matching, and determining the defect level corresponding to the object to be detected, wherein the correspondence between the score intervals and defect levels includes a plurality of score intervals, and each score interval corresponds to one defect level.
[0063] Obtaining a defect score value of the object to be detected, wherein the magnitude of the defect score value reflects the severity of defects on the surface of the object to be detected, and a higher score indicates a more severe defect.
[0064] Mapping the defect score value of the object to be detected into the correspondence between preset score intervals and defect levels for matching, and determining the defect level corresponding to the object to be detected, wherein the correspondence between score intervals and defect levels includes a plurality of score intervals, and each score interval corresponds to one defect level. The correspondence between preset score intervals and defect levels is a predefined mapping rule, which divides the numerical range of defect scores into several continuous intervals, and each interval corresponds to one defect level respectively. In an optional implementation, defect levels are sequentially divided into level 0, level 1, level 2, level 3 and level 4 according to the severity from low to high, which can respectively correspond to no defect or extremely slight, slight defect, moderate defect, severe defect and scrapped grade. In another optional implementation, defect levels can be divided into four grades: high-quality product, qualified product, reworkable product and scrapped product according to product quality standards. Comparing the numerical value with the upper and lower boundaries of each score interval one by one, determining which score interval the numerical value falls into, and then taking out the defect level corresponding to the score interval as the defect level of the object to be detected according to the correspondence between the score interval and the defect level.
[0065] Refer to Figure 2 , which is an image of an object to be detected with a defect score of 0 in an embodiment of the present application, Figure 3 which is an image of an object to be detected with a defect score of 4 in an embodiment of the present application, Figure 4is an image of an object to be detected with a defect score of 1 in the embodiment of the present application.
[0066] After determining the defect level corresponding to the object to be detected, the defect level can also be output after being associated with the image of the object to be detected. Output methods include marking different levels with different colors on the display interface of the detection system, storing defect level data in a database for subsequent retrospective query, or sending the defect level as a sorting signal to an automated production line actuator to complete automatic product classification.
[0067] Referring Figure 5 , it is a schematic diagram of functional modules of the defect scoring apparatus 100 based on contrast and area according to the present application.
[0068] According to the implemented functions, the defect scoring apparatus 100 based on contrast and area includes a preprocessing module 110, an extraction module 120, a construction module 130, a calculation module 140, an assignment module 150 and a scoring module 160. The above modules can also be referred to as units, which refer to a series of computer program segments that can be executed by a processor of an electronic device and can implement fixed functions, and are stored in the memory of the electronic device.
[0069] In this embodiment, the functions of each module / unit are as follows: Preprocessing module: configured to acquire an original image corresponding to an object to be detected, and perform binarization processing on the original image to obtain a binarized image of the object to be detected; Extraction module: configured to extract defect regions from the binarized image to obtain a set of suspected defects of the object to be detected, wherein each suspected defect in the set of suspected defects has defect information, and the defect information includes the contrast of the defect region and the area of the defect region; Construction module: configured to construct a defect evaluation reference line according to a preset minimum contrast threshold and a minimum area threshold corresponding to the minimum contrast threshold, as well as a preset maximum contrast threshold and a maximum area threshold corresponding to the maximum contrast threshold; Calculation module: configured to calculate the distance value from each suspected defect to the defect evaluation reference line according to the defect evaluation reference line and the contrast and area corresponding to each suspected defect; Assignment module: configured to assign a corresponding single defect score to each suspected defect according to a preset single score interval into which the distance value from each suspected defect to the defect evaluation reference line falls; Scoring module: configured to determine a defect score value of the object to be detected according to the single defect score corresponding to each suspected defect.
[0070] The specific implementation of the defect scoring apparatus based on contrast and area of the present application is substantially the same as the specific implementation of the above defect scoring method based on contrast and area, and will not be repeated herein.
[0071] Reference Figure 6 The diagram shown is a schematic representation of a preferred embodiment of the electronic device of this application.
[0072] The electronic device includes a processor 111, a communication interface 112, a memory 113, and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114. The memory 113 is used to store computer programs, such as a defect scoring program based on contrast and area; Figure 6 Only an electronic device having a processor 111, a communication interface 112, a memory 113 and a communication bus 114 is shown. However, it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.
[0073] In one embodiment of this application, when the processor 111 executes the program stored in the memory 113, it implements the defect scoring method based on contrast and area provided in any of the foregoing method embodiments, including: Obtain the original image corresponding to the object to be detected, and perform binarization processing on the original image to obtain the binarized image of the object to be detected; Defect regions are extracted from the binarized image to obtain a set of suspected defects of the object to be detected. Each suspected defect in the set of suspected defects has defect information, which includes the contrast of the defect region and the area of the defect region. Based on the preset minimum contrast threshold and the minimum area threshold corresponding to the minimum contrast threshold, and the preset maximum contrast threshold and the maximum area threshold corresponding to the maximum contrast threshold, a defect evaluation baseline is constructed. Based on the defect evaluation baseline and the contrast and area corresponding to each suspected defect, calculate the distance value from each suspected defect to the defect evaluation baseline. Each suspected defect is assigned a corresponding single defect score based on the preset single score range in which the distance value from each suspected defect to the defect evaluation baseline falls; Based on the single defect score corresponding to each suspected defect, the defect score value of the object to be inspected is determined.
[0074] For a detailed explanation of the above steps, please refer to the flowchart of the above embodiment of the defect scoring method based on contrast and area.
[0075] Furthermore, this application also proposes a computer-readable storage medium that is both non-volatile and volatile. This computer-readable storage medium is any one or any combination of several of the following: hard disk, multimedia card, SD card, flash memory card, SMC, read-only memory (ROM), erasable programmable read-only memory (EPROM), portable compact disc read-only memory (CD-ROM), USB memory, etc. The computer-readable storage medium includes a data storage area and a program storage area. The program storage area stores a defect scoring program based on contrast and area. When executed by a processor, the defect scoring program based on contrast and area performs the following operations: Obtain the original image corresponding to the object to be detected, and perform binarization processing on the original image to obtain the binarized image of the object to be detected; Defect regions are extracted from the binarized image to obtain a set of suspected defects of the object to be detected. Each suspected defect in the set of suspected defects has defect information, which includes the contrast of the defect region and the area of the defect region. Based on the preset minimum contrast threshold and the minimum area threshold corresponding to the minimum contrast threshold, and the preset maximum contrast threshold and the maximum area threshold corresponding to the maximum contrast threshold, a defect evaluation baseline is constructed. Based on the defect evaluation baseline and the contrast and area corresponding to each suspected defect, calculate the distance value from each suspected defect to the defect evaluation baseline. Each suspected defect is assigned a corresponding single defect score based on the preset single score range in which the distance value from each suspected defect to the defect evaluation baseline falls; Based on the single defect score corresponding to each suspected defect, the defect score value of the object to be inspected is determined.
[0076] The specific implementation of the computer-readable storage medium in this application is largely the same as the specific implementation of the defect scoring method based on contrast and area described above, and will not be repeated here.
[0077] It should be noted that the sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, apparatus, article, or method. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, apparatus, article, or method that includes that element.
[0078] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware simulation platforms. Of course, they can also be implemented by hardware, but in many cases the former is 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 storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device to execute the methods described in the various embodiments of this application.
[0079] The above are merely preferred embodiments of this application and do not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.
Claims
1. A contrast-to-area based defect scoring method, characterized by, The method includes: Obtain the original image corresponding to the object to be detected, and perform binarization processing on the original image to obtain the binarized image of the object to be detected; Defect regions are extracted from the binarized image to obtain a set of suspected defects of the object to be detected. Each suspected defect in the set of suspected defects has defect information, which includes the contrast of the defect region and the area of the defect region. Based on the preset minimum contrast threshold and the minimum area threshold corresponding to the minimum contrast threshold, and the preset maximum contrast threshold and the maximum area threshold corresponding to the maximum contrast threshold, a defect evaluation baseline is constructed. Based on the defect evaluation baseline and the contrast and area corresponding to each suspected defect, calculate the distance value from each suspected defect to the defect evaluation baseline; Each suspected defect is assigned a corresponding single defect score based on the preset single score range in which the distance value from each suspected defect to the defect evaluation baseline falls; Based on the single defect score corresponding to each suspected defect, the defect score value of the object to be inspected is determined.
2. The contrast and area based defect scoring method of claim 1, wherein, The extraction of defect regions from the binarized image yields a set of suspected defects in the object to be detected, including: Perform connected component analysis on the binarized image to extract all connected components in the binarized image, and obtain the initial defect region set of the binarized image. Each initial defect region in the initial defect region set has location information and geometric parameters. The location information includes the coordinates of the region center of the initial defect region in the binarized image, and the geometric parameters include the region area, the length of the bounding rectangle, and the width of the bounding rectangle. Based on the image center coordinates of the binarized image and the region center coordinates of each initial defect region, calculate the radial distance from each initial defect region to the image center coordinates; Based on the radial distance of each initial defect region, the shape correction coefficient corresponding to each initial defect region is determined, and the area of the initial defect region is weighted and corrected using the shape correction coefficient to obtain the corrected area corresponding to each initial defect region. Based on the corrected area, circumscribed rectangle length, and circumscribed rectangle width of each initial defect region, initial defect regions with a corrected area less than a preset area threshold, a circumscribed rectangle length less than a preset length threshold, or a circumscribed rectangle width less than a preset width threshold are removed. The remaining initial defect regions are then used as suspected defects of the object to be detected, resulting in a set of suspected defects.
3. The contrast and area based defect scoring method of claim 1, wherein, The step of constructing a defect evaluation baseline based on a preset minimum contrast threshold and its corresponding minimum area threshold, and a preset maximum contrast threshold and its corresponding maximum area threshold, includes: Obtain the preset minimum contrast threshold, the minimum area threshold corresponding to the minimum contrast threshold, the preset maximum contrast threshold, and the minimum area threshold corresponding to the maximum contrast threshold; The first coordinate point is generated based on the minimum contrast threshold and the minimum area threshold corresponding to the minimum contrast threshold, and the second coordinate point is generated based on the maximum contrast threshold and the minimum area threshold corresponding to the maximum contrast threshold. Based on the first and second coordinate points, a straight line equation passing through the first and second coordinate points is generated, and the straight line equation is used as the baseline for defect evaluation.
4. The contrast and area based defect scoring method of claim 1, wherein, The step of calculating the distance from each suspected defect to the defect evaluation baseline based on the defect evaluation baseline and the contrast and area corresponding to each suspected defect includes: Obtain the first linear coefficient, the second linear coefficient, and the constant term in the linear equation of the defect evaluation baseline; For each suspected defect, the product of the contrast corresponding to the suspected defect and the first linear coefficient, the product of the area corresponding to the suspected defect and the second linear coefficient, and the constant term are added to obtain the numerator corresponding to the suspected defect. Divide the numerator by the square root of the sum of the squares of the first and second linear coefficients to obtain the distance from the suspected defect to the defect assessment baseline.
5. The contrast and area based defect scoring method of claim 1, wherein, The step of determining the defect score value of the object to be inspected based on the single defect score corresponding to each suspected defect includes: If any single defect score meets the preset out-of-standard judgment condition, then the single defect score corresponding to the out-of-standard judgment condition is taken as the defect score value of the object to be tested. If none of the individual defect scores meet the preset criteria for exceeding the standard, the comprehensive distance value is calculated based on the contrast and area of all suspected defects. The defect score of the object to be inspected is determined based on the preset comprehensive score range into which the comprehensive distance value falls.
6. The contrast-to-area based defect scoring method of claim 5, wherein, The step of calculating the comprehensive distance value based on the contrast and area of all suspected defects includes: Obtain the first linear coefficient, the second linear coefficient, and the constant term in the linear equation of the defect evaluation baseline; For each suspected defect in the suspected defect set, the product of the contrast corresponding to the suspected defect and the first straight line coefficient and the product of the area of the region and the second straight line coefficient are added to obtain the single straight line substitution value corresponding to the suspected defect. The sum of the individual line values corresponding to all suspected defects in the suspected defect set is obtained by substituting the values into the line values. After adding the sum of the substituted values to the constant term, divide by the square root of the sum of the squares of the first and second linear coefficients to obtain the overall distance value from the defect assessment baseline to all suspected defects.
7. The defect scoring method based on contrast and area as described in claim 1, characterized in that, The method further includes: The defect score of the object to be tested is mapped to a preset correspondence between score intervals and defect levels for matching, thereby determining the defect level corresponding to the object to be tested. The correspondence between score intervals and defect levels includes multiple score intervals, and each score interval corresponds to a defect level.
8. A defect scoring device based on contrast and area, characterized in that, The device includes: Preprocessing module: Used to acquire the original image corresponding to the object to be detected, and to perform binarization processing on the original image to obtain the binarized image of the object to be detected; Extraction module: used to extract defect regions from the binarized image to obtain a set of suspected defects of the object to be detected, wherein each suspected defect in the set of suspected defects has defect information, including the contrast of the defect region and the area of the defect region; Construction module: used to construct a defect evaluation baseline based on the preset minimum contrast threshold and the minimum area threshold corresponding to the minimum contrast threshold, and the preset maximum contrast threshold and the maximum area threshold corresponding to the maximum contrast threshold. Calculation module: Used to calculate the distance from each suspected defect to the defect assessment baseline based on the defect assessment baseline and the contrast and area corresponding to each suspected defect; Assignment module: Used to assign a corresponding single defect score to each suspected defect based on the preset single score range in which each suspected defect falls from the distance value from the defect judgment baseline; Scoring module: Used to determine the defect score of the object to be inspected based on the single defect score corresponding to each suspected defect.
9. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; The processor, when executing a program stored in memory, implements the defect scoring method based on contrast and area as described in any one of claims 1 to 7.
10. 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 defect scoring method based on contrast and area as described in any one of claims 1 to 7.