Glass mold surface defect automatic detection method based on image processing
By adaptively adjusting the MSRCR algorithm and combining the defect severity and confidence level of pixels, an adaptive gain constant is obtained, which solves the problems of uneven illumination and interference from reflective areas in the surface inspection of glass molds, and achieves higher detection accuracy and detail clarity.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHANGSHU WEIHENG MOLD MFG
- Filing Date
- 2026-03-27
- Publication Date
- 2026-04-28
AI Technical Summary
In existing technologies, the detection accuracy of glass mold surface defects is reduced due to uneven illumination and confusion between reflective areas and defect edge gradients, especially affecting the detection rate of minute defects.
An adaptively adjusted MSRCR algorithm is adopted. By obtaining the degree of defect, first-level confidence and second-level confidence of each pixel, and combining them with the preset color recovery parameter range, an adaptive gain constant is obtained to enhance the color recovery of defective areas in the image and suppress the over-enhancement of reflective areas.
It significantly improves the accuracy of surface defect detection in glass molds, clearly presents details such as cracks and scratches, reduces noise and artifacts, obtains reasonable enhanced images, and improves detection results.
Smart Images

Figure CN121937448A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of defect detection technology, and more specifically to an automatic detection method for surface defects of glass molds based on image processing. Background Technology
[0002] In the glass mold manufacturing process, accurate detection of surface defects is crucial and directly affects the quality of glass products. However, in actual industrial settings, due to complex and variable lighting conditions such as uneven illumination, strong light reflection, and shadow interference, as well as the complex reflected light caused by the material properties of the mold surface, the acquired images of the glass mold surface often suffer from low contrast, blurred details, and color distortion. These problems make it difficult to clearly present defect features, posing significant challenges to subsequent automated defect detection. Therefore, there is an urgent need for an image enhancement method specifically designed for the characteristics of glass mold surface images to improve image quality, clearly present defect features, and provide a reliable image foundation for the automated detection of glass mold surface defects.
[0003] The MSR with Color Restoration (MSRCR) algorithm, through multi-scale Retinex processing, effectively removes the effects of uneven illumination, highlighting subtle defects and texture details on the mold surface. This results in an enhanced image that clearly presents structural features while maintaining natural and realistic colors, thus better assisting in the detection of surface defects in glass molds. Therefore, this approach is chosen to enhance the acquired mold images. However, the standard MSRCR algorithm uses globally fixed color restoration parameters. While this improves the overall clarity of the glass mold image, it over-enhances reflective areas. The original average brightness of reflective areas is approximately 200 gray levels, but after enhancement, it reaches 240 gray levels, causing a surge in local standard deviation. Meanwhile, the enhancement of defect areas is limited. This compression of the dynamic range of both leads to a significant increase in the overlap of gray-level features, resulting in a strong random response in the gradient space of reflective areas. This causes confusion with the gradient of defect edges, simultaneously affecting the detection rate of minute defects and severely impacting detection accuracy. Summary of the Invention
[0004] To address the aforementioned technical problems, the present invention aims to provide an automatic detection method for surface defects in glass molds based on image processing. The specific technical solution adopted is as follows: One embodiment of the present invention provides an automatic detection method for surface defects of glass molds based on image processing, the method comprising: Acquire a grayscale image of the surface of the glass mold and take any pixel in the grayscale image as the target pixel; obtain the degree of defect of the target pixel based on the pixels in its eight neighborhoods; Obtain the connected components and branch points of each connected component in the grayscale image; obtain the first-level confidence score of the target pixel based on the area of the connected component to which the target pixel belongs, the aspect ratio of the minimum bounding rectangle, the number of connected components at the branch point, the aspect ratio of the minimum bounding rectangle of each connected component at the branch point, the mean curvature of the edge pixels of the connected component to which the target pixel belongs, and the local edge distribution of the target pixel. Starting from the center of the connected region to which the target pixel belongs, traverse the pixels in each set direction to obtain the pixel sequence corresponding to each set direction; obtain the second-level confidence of the target pixel based on the entropy of the gradient direction angle and the standard deviation of gray level of each pixel in the connected region to which the target pixel belongs, the gray level gradient of each pixel in the pixel sequence, and the difference in the entropy values of the gray co-occurrence matrix of the two windows centered on the target pixel and the center of the largest connected region. The adaptive gain constant of the target pixel is obtained based on the degree of defect severity, first-level confidence, second-level confidence, and the gain constant range in the preset color restoration parameters; the adaptive gain constant of each pixel is combined with the MSRCR algorithm to obtain an enhanced image of the glass mold surface; the enhanced image is used to detect surface defects of the glass mold.
[0005] Preferably, the degree of defect of the target pixel is obtained based on the pixels in the eight-neighborhood of the target pixel, including: The difference between the maximum gray value of the target pixel and the gray value of the target pixel, and the difference between the gray value of the target pixel and the minimum gray value of the target pixel and the gray value of the target pixel in its eight neighboring areas, are obtained. The maximum of the two differences is normalized to obtain the degree of defect of the target pixel.
[0006] Preferably, the first-level confidence score of the target pixel is obtained based on the area of the connected component to which the target pixel belongs, the aspect ratio of the minimum bounding rectangle, the number of connected components at the branch point, the aspect ratio of the minimum bounding rectangle of each connected component at the branch point, the mean curvature of the edge pixels of the connected component to which the target pixel belongs, and the local edge distribution of the target pixel, including: The branch connected component feature is obtained by adding the number of connected components at the branch points of the connected component to the average aspect ratio of the minimum bounding rectangle of each connected component. A window is constructed with the target pixel as the center, and the ratio of the number of edge pixels on the longest edge in the window to the total number of edge pixels in the window is recorded as the edge continuity feature. The first-level confidence of the target pixel is obtained by multiplying and normalizing the inverse of the area of the connected component to the target pixel, the aspect ratio of the minimum bounding rectangle, the branch connected component feature, the inverse of the average curvature of the edge pixels of the connected component to the target pixel, and the edge continuity feature.
[0007] Preferably, the secondary confidence level of the target pixel is obtained based on the entropy of the gradient direction angle and the standard deviation of gray level of each pixel within the connected component to which the target pixel belongs, the gray level gradation of pixels in each pixel sequence, and the difference in entropy values of the gray-level co-occurrence matrices of two windows centered on the target pixel and the center of the largest connected component, including: Fitting the grayscale values of pixels in a pixel sequence corresponding to a given direction yields the fitting slope and the fitted grayscale value of each pixel in the sequence. Adding the mean of the absolute differences between the grayscale values of each pixel in the pixel sequence corresponding to the given direction and the fitted grayscale values to the hyperparameters, and then taking the reciprocal, yields the first gradient feature corresponding to that given direction. The absolute difference between the fitting slope of the pixel sequence corresponding to a given direction and the mean of the fitting slopes of all pixel sequences corresponding to given directions is taken as the second gradient feature for that given direction. The first gradient feature corresponding to each given direction is then obtained. The local gradient feature is obtained by multiplying the mean of the first gradient feature, the mean of the second gradient feature corresponding to each set direction, and the number of non-zero fitting slopes in the fitting slopes of the pixel sequence corresponding to each set direction. This product is then multiplied by the standard deviation of the gray values of each pixel in the connected region to which the target pixel belongs, and the reciprocal is obtained. The second-level confidence of the target pixel is obtained by multiplying the reciprocal of the entropy of the gradient direction angle of each pixel in the connected region to which the target pixel belongs, the local gradient feature, and the absolute value of the difference between the entropy values of the gray-level co-occurrence matrices of the two windows centered on the target pixel and the center of the largest connected region, and then normalizing the result.
[0008] Preferably, the adaptive gain constant of the target pixel is obtained based on the degree of defect obviousness, first-level confidence level, second-level confidence level, and the gain constant range in the preset color restoration parameters, including: The defect confidence of the target pixel is obtained by multiplying its first-level confidence and second-level confidence. The adaptive gain constant of the target pixel is obtained based on its defect confidence, defect severity, and the range of gain constants in the preset color restoration parameters.
[0009] Preferably, the adaptive gain constant of the target pixel is obtained based on the defect confidence level, defect severity, and the gain constant range in the preset color recovery parameters, including: The difference between the upper and lower limits of the gain constant range in the preset color restoration parameters is used as the adjustment base value. The adjustment base value, the defect confidence of the target pixel, and the normalized value of the reciprocal of the defect severity of the target pixel are multiplied to obtain the adjustment amplitude corresponding to the target pixel. The sum of the lower limit of the gain constant range and the adjustment amplitude corresponding to the target pixel is the adaptive gain constant of the target pixel.
[0010] The embodiments of the present invention have at least the following beneficial effects: This application acquires a grayscale image of the surface of a glass mold and takes any pixel in the grayscale image as a target pixel; the degree of defect significance of the target pixel is obtained based on the pixels in the eight neighborhoods of the target pixel, and the degree of defect significance is obtained by analyzing the local grayscale change features; furthermore, the first-level confidence of the target pixel is obtained based on the area of the connected region to which the target pixel belongs, the aspect ratio of the minimum bounding rectangle, the number of connected regions at the branch point, the aspect ratio of the minimum bounding rectangle of each connected region at the branch point, the mean curvature of the edge pixels of the connected region to which the target pixel belongs, and the local edge distribution of the target pixel; then, the entropy of the gradient direction angle and the standard deviation of grayscale of each pixel in the connected region to which the target pixel belongs, the grayscale gradient of the pixels in each pixel sequence, and the degree of defect significance are obtained based on the target pixel's grayscale change features. The second-order confidence level of the target pixel is obtained by comparing the entropy values of the gray-level co-occurrence matrices of two windows centered on the pixel and the center of the largest connected region. This is combined with the local morphological features, statistical and texture features of each pixel to eliminate interference factors and further obtain the confidence level that it belongs to a real defect region. Finally, the adaptive gain constant of the target pixel is obtained based on the defect severity, first-order confidence level, second-order confidence level, and the gain constant range in the preset color restoration parameters. This is then combined with the MSRCR algorithm to obtain an enhanced image of the glass mold surface. This significantly enhances the color restoration of high-defect areas, making details such as cracks and scratches clearer, while weakening the color restoration of low-defect areas. This avoids noise or artifacts caused by over-enhancement, resulting in a more reasonable enhanced image. The enhanced image is then used to detect surface defects in the glass mold, improving detection accuracy. Attached Figure Description
[0011] To more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, 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.
[0012] Figure 1 A flowchart of an automatic detection method for surface defects of glass molds based on image processing, provided in an embodiment of the present invention. Detailed Implementation
[0013] To further illustrate the technical means and effects adopted by the present invention to achieve its intended purpose, the following, in conjunction with the accompanying drawings and preferred embodiments, details the specific implementation, structure, features, and effects of an image processing-based automatic detection method for surface defects in glass molds proposed according to the present invention. In the following description, different "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. Furthermore, specific features, structures, or characteristics in one or more embodiments can be combined in any suitable form.
[0014] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.
[0015] The following description, in conjunction with the accompanying drawings, details the specific scheme of the automatic detection method for surface defects of glass molds based on image processing provided by the present invention.
[0016] Example: The main application scenario of this invention is as follows: When performing defect detection on the surface of glass molds, it is necessary to use the MSRCR algorithm to enhance the image data of the surface of the glass molds. In order to adapt to the characteristics of the surface of the glass molds, this application performs pixel-level adaptive adjustment of the color recovery parameters in the traditional MSRCR algorithm, thereby improving the accuracy of surface defect detection of glass molds.
[0017] Please see Figure 1 The diagram illustrates a flowchart of an automatic detection method for surface defects in glass molds based on image processing, provided by an embodiment of the present invention. The method includes the following steps: Step S1: Obtain a grayscale image of the surface of the glass mold and take any pixel in the grayscale image as the target pixel; obtain the degree of defect of the target pixel based on the pixels in the eight neighborhoods of the target pixel.
[0018] Before performing surface defect detection on glass molds, it is necessary to first acquire images of the corresponding surfaces of each mold. After the glass mold production is completed, it is placed on a glass mold image acquisition device, which consists of a high-definition industrial camera and a supplementary light. When the glass mold is detected to be placed under the image acquisition device, the industrial camera acquires and collects the surface image corresponding to the current mold.
[0019] After obtaining the image of the surface of the current glass mold, it can be converted to grayscale to obtain a grayscale image of the surface of the glass mold. Then, the next step of analysis can be carried out. For ease of explanation, any pixel in the grayscale image is taken as the target pixel.
[0020] When defects exist on the surface of a glass mold, the defective area typically exhibits contrast with the surrounding background, meaning there are localized grayscale variations. Therefore, the degree of defect visibility is first calculated by analyzing the local grayscale fluctuations of each pixel. Consequently, the degree of defect visibility of the target pixel is obtained based on the pixels within its eight-neighborhood.
[0021] Specifically, the difference between the maximum gray value of the target pixel and the gray value of the target pixel, as well as the difference between the gray value of the target pixel and the minimum gray value of the target pixel and the gray value of the target pixel and the gray value of the target pixel and the target pixel, are obtained. The maximum of the two differences is taken and normalized to obtain the degree of defect of the target pixel.
[0022] The specific calculation model for the degree of defect noticeability of target pixels is as follows: , Where Ai represents the degree of defect noticeability of the i-th pixel in the grayscale image, which is also the degree of defect noticeability of the target pixel. and These represent the maximum and minimum gray values of the pixels within the eight neighboring pixels of the target pixel, respectively. This represents the difference between the maximum and minimum grayscale values of the eight neighboring pixels of the target pixel and the target pixel's grayscale value. The larger of these two values is taken as the local grayscale fluctuation level of the target pixel. The larger the difference, the higher the grayscale fluctuation level, meaning the more obvious the defect. Therefore, the enhancement effect should be appropriately reduced when enhancing the target pixel. Similarly, the degree of defect obviousness of each pixel in a grayscale image can be obtained. `norm` represents the normalization function.
[0023] After obtaining the degree of defect severity for each pixel, it is necessary to further integrate the local morphological texture features and statistical gradient features of the pixels. Since the smooth surface of the glass mold easily forms reflective areas, these areas also exhibit local grayscale changes. Enhancing these areas would interfere with subsequent defect detection. Therefore, it is necessary to further integrate the local morphological texture features and statistical gradient features of the pixels, calculating their morphological-based first-level confidence and statistical gradient-based second-level confidence respectively. This effectively suppresses reflective interference and comprehensively determines the defect confidence of each pixel.
[0024] Step S2: Obtain the connected components and branch points of each connected component in the grayscale image; obtain the first-level confidence level of the target pixel based on the area of the connected component to which the target pixel belongs, the aspect ratio of the minimum bounding rectangle, the number of connected components at the branch point, the aspect ratio of the minimum bounding rectangle of each connected component at the branch point, the mean curvature of the edge pixels of the connected component to which the target pixel belongs, and the local edge distribution of the target pixel.
[0025] To differentiate between scratches, cracks, and other defects on the surface of glass molds and reflective interference, an analysis of local morphological characteristics is conducted first. First, cracks typically have a large aspect ratio, while reflective areas may be more circular or irregularly shaped but with a smaller aspect ratio, and their area is generally smaller. Second, cracks on the glass surface generally exhibit a spiderweb-like distribution, meaning that any crack has other connected regions intersecting with it, and the aspect ratio of these connected regions is similar to that of the connected region to which the target data point belongs—both have a large aspect ratio. Furthermore, glass cracks typically have relatively gentle curves (elongated), while reflective edges show greater curvature changes (spotted). Finally, cracks usually have good continuity; even with minor fractures, relatively long continuous edge segments may still form within the local window. Therefore, in cracked areas, the proportion of continuous edge length to the total number of edge pixels is high. In contrast, reflective interference, due to drastic brightness changes, may produce many short and broken edges with shorter continuous edge lengths and a relatively larger number of edge pixels, resulting in a smaller ratio.
[0026] Therefore, the first step is to obtain the connected components and branch points of each connected component in the grayscale image. The connected component acquisition methods are as follows: All edges in the image are obtained using the Canny edge detection algorithm; a two-pass scanning method is used, where the first pass marks pixel connectivity, and the second pass merges equivalent labels to generate independent connected components; skeletonization is used to refine complex connected components while preserving the centerline structure; branch points are located using Harris corner detection or intersection counting (number of pixels in 8-neighborhood > 3) to obtain the branch points of the connected components, thereby segmenting the main connected component and branch connected components; finally, the connected component to which the target pixel belongs is obtained.
[0027] Furthermore, the first-level confidence level of the target pixel is obtained based on the area of the connected region to which the target pixel belongs, the aspect ratio of the minimum bounding rectangle, the number of each connected region at the branch point, the aspect ratio of the minimum bounding rectangle of each connected region at the branch point, the mean curvature of the edge pixels of the connected region to which the target pixel belongs, and the local edge distribution of the target pixel.
[0028] Specifically, the branch connected component feature is obtained by adding the number of connected components at the branch points of the connected component to the average aspect ratio of the minimum bounding rectangle of each connected component; a window is constructed with the target pixel as the center, and the ratio of the number of edge pixels on the longest edge in the window to the number of all edge pixels in the window is recorded as the edge continuity feature; the first-level confidence of the target pixel is obtained by multiplying the inverse of the area of the connected component to the target pixel, the aspect ratio of the minimum bounding rectangle, the branch connected component feature, the inverse of the average curvature of the edge pixels of the connected component to the target pixel, and the edge continuity feature, and then normalizing.
[0029] The specific model for calculating the first-level confidence score of a target pixel is as follows: , Where Bi represents the first-level confidence score of the i-th pixel, which is also the first-level confidence score of the target pixel; Li and Wi are the length and width of the minimum bounding rectangle of the connected component to which the target pixel belongs, respectively. denoted by , represents the aspect ratio of the minimum bounding rectangle of the connected region to which the target pixel belongs. A larger aspect ratio indicates a higher likelihood of it being a crack edge. Si represents the area of the connected region to which the target pixel belongs. A smaller area better matches the characteristic of a smaller crack area. Di represents the number of connected regions at each branch point of the connected region to which the target pixel belongs. A larger number of connected regions better matches the spiderweb distribution characteristic of cracks on the glass surface. Lij and Wij represent the length and width of the minimum bounding rectangle of the j-th connected region at each branch point of the connected region to which the target pixel belongs, respectively. Let be the aspect ratio of the minimum bounding rectangle of the j-th connected component. The mean value is the average aspect ratio of the minimum bounding rectangles of the connected components at the branch points of the connected component to which the target pixel belongs. The larger the mean value, the more it matches the spiderweb-like slender structure characteristics of cracks on the glass surface. The branch connected component features are represented by: Qi, which represents the mean curvature of all edge pixels in the connected component to which the target pixel belongs; the smaller the mean, the more it matches the smooth, elongated crack feature of the glass mold surface; li represents the number of edge pixels on the longest edge within the window centered on the target pixel; and zi represents the total number of edge pixels within the window. For edge continuity features, a window of size n*n (n=15) is used. Edge detection is performed within the window to obtain all edge pixels. Then, an edge tracking algorithm is used to obtain the length of the longest edge within the window (the number of edge pixels on the longest edge), which is also the length of the longest connected edge. The ratio of the number of edge pixels on the longest edge to the total number of edge pixels within the window is then calculated. The larger the ratio, the better the continuity of the edges within the window, and the more it conforms to the continuous characteristics of crack edges. `norm` is the normalization function.
[0030] Similarly, the corresponding first-level confidence level can be obtained for each pixel.
[0031] Step S3: Starting from the center of the connected region to which the target pixel belongs, traverse the pixels in each set direction to obtain the pixel sequence corresponding to each set direction; obtain the secondary confidence level of the target pixel based on the entropy of the gradient direction angle and the standard deviation of gray level of each pixel in the connected region to which the target pixel belongs, the gray level gradient of each pixel in the pixel sequence, and the difference in the entropy value of the gray co-occurrence matrix of the two windows centered on the target pixel and the center of the largest connected region.
[0032] The above steps obtained the first-level confidence score of the target pixel. To further distinguish between defects and reflective areas, it is necessary to combine statistical and texture features for analysis. First, the gradient direction of the crack edge has strong directional consistency, that is, most gradient directions are perpendicular to the crack direction. Therefore, the gradient direction distribution is concentrated and the entropy value is low. The gradient direction of reflective interference may be randomly distributed (because the edge direction of reflective spots is different), and the entropy value is high. Second, cracks usually appear as dark lines with low and relatively uniform contrast. Therefore, the local gray-scale change of cracks is small and there is no gray-scale distribution feature. In contrast, reflective interference areas often have obvious brightness attenuation, resulting in drastic local gray-scale changes. That is, the local gray-scale gradient feature is shown from the midpoint to the surrounding area, and the gray-scale standard deviation in the area is large. Therefore, this feature is derived from the features of reflective areas. At the same time, the introduction of cracks increases the structural information of local areas (because cracks are a new structure), resulting in a large difference between local texture and background texture (which may increase or decrease depending on the regularity of the crack). Reflective interference is mainly a change in brightness and does not significantly change the local information structure. Therefore, the difference between local texture and background texture is small.
[0033] First, starting from the center of the connected component to which the target pixel belongs, pixels are traversed sequentially in each predetermined direction to obtain the pixel sequence corresponding to each predetermined direction. The pixel characteristics of reflective and defective areas differ as the target pixel radiates outwards. Therefore, starting from the center of the connected component to which the target pixel belongs, pixels are traversed sequentially in each predetermined direction to obtain the pixel sequence corresponding to each predetermined direction. The pixel sequences corresponding to each predetermined direction are then analyzed. During the traversal, the traversal deadline in each predetermined direction is reaching the boundary of the connected component to which the target pixel belongs, and the order of the pixels in the pixel sequence is the traversal order. Preferably, in this application, the predetermined directions are any four directions, such as 0 degrees, 90 degrees, 180 degrees, and 270 degrees.
[0034] Furthermore, the secondary confidence level of the target pixel is obtained based on the entropy of the gradient direction angle of each pixel in the connected region to which the target pixel belongs, the standard deviation of gray level, the gray level gradation of each pixel in the pixel sequence, and the difference in the entropy values of the gray level co-occurrence matrices of two windows centered on the target pixel and the center of the largest connected region.
[0035] Specifically, the grayscale values of pixels in a pixel sequence corresponding to a given direction are fitted to obtain the fitting slope of the pixel sequence and the fitted grayscale value of each pixel in the pixel sequence; the mean of the absolute values of the differences between the grayscale values of each pixel in the pixel sequence corresponding to the given direction and the fitted grayscale values are added to the hyperparameters, and the reciprocal is taken to obtain the first gradient feature corresponding to the given direction; the absolute value of the difference between the fitting slope of the pixel sequence corresponding to the given direction and the mean of the fitting slopes of all pixel sequences corresponding to the given directions is taken as the second gradient feature of the given direction; the set-direction corresponding to each given direction is obtained. The product of the mean of the first gradient feature, the mean of the second gradient feature corresponding to each set direction, and the number of non-zero fitting slopes in the fitting slopes of the pixel sequence corresponding to each set direction is multiplied by the standard deviation of the gray values of each pixel in the connected region to which the target pixel belongs, and the reciprocal is obtained to obtain the local gradient feature; the reciprocal of the entropy of the gradient direction angle of each pixel in the connected region to which the target pixel belongs, the local gradient feature, and the absolute value of the difference between the entropy values of the gray co-occurrence matrices of the two windows centered on the target pixel and the center of the largest connected region are multiplied by the product and normalized to obtain the second-level confidence of the target pixel.
[0036] The specific calculation model for the second-order confidence score of the target pixel is as follows: , Where Ci represents the second-order confidence score of the i-th pixel (target pixel); Sti represents the entropy of the gradient direction angle of each pixel within the connected domain to which the target pixel belongs (the acquisition of the gradient direction angle is a current technique and will not be elaborated here). The smaller the entropy, the more it matches the concentrated distribution of gradient directions at the edge of the crack defect; θi represents the standard deviation of the grayscale values of each pixel within the connected domain to which the target pixel belongs. The larger the standard deviation, the more it matches the characteristic of more drastic grayscale changes in the reflective area; Xsi represents the number of non-zero fitting slopes in the fitting slopes of the pixel sequence corresponding to each set direction. The more slopes, the more it matches the gradual change characteristics of the reflective area; Xik represents the fitting slope of the pixel sequence corresponding to the k-th set direction; Xi represents the mean of the fitting slopes of the pixel sequences corresponding to all set directions; and |Xik-Xi| represents the second gradual change feature of the k-th set direction. ε represents the mean of the second gradient feature in each set direction. The smaller the second gradient feature value, the more similar the gradient features in each direction, and the more it conforms to the gradient feature of reflection from the center of the area outwards. ε is a hyperparameter, a constant to prevent the denominator from being 0. Pik represents the mean of the absolute values of the differences between the grayscale values of each pixel in the pixel sequence corresponding to the k-th set direction and the fitted grayscale values. The higher the degree of fit between the fitted value and the actual value, the smaller this mean value. The first gradient feature is represented by sum(K); the number of directions is defined by sum(K); Shi and Sh represent the entropy values of the gray-level co-occurrence matrix of the window centered on the target pixel and the gray-level co-occurrence matrix of the window centered on the center of the largest connected region in the image, respectively. The larger the absolute value of the difference, the more consistent it is with the texture features of the cracked area of the glass mold, which is a new structure distinct from the texture features of the background area. Preferably, the window size is n*n (n=15). norm is the normalization function.
[0037] Similarly, the second-order confidence level of each pixel in the image can be obtained.
[0038] Step S4: Obtain the adaptive gain constant of the target pixel based on the degree of defect obviousness, first-level confidence, second-level confidence, and the gain constant range in the preset color recovery parameters; use the adaptive gain constant of each pixel in combination with the MSRCR algorithm to obtain an enhanced image of the glass mold surface; use the enhanced image to detect surface defects of the glass mold.
[0039] The above obtains the defect severity, first-level confidence, and second-level confidence of any pixel in the grayscale image. Further, the adaptive gain constant of the target pixel is obtained based on the defect severity, first-level confidence, and second-level confidence of the target pixel, as well as the gain constant range in the preset color restoration parameters.
[0040] First, the first-level confidence score and the second-level confidence score of the target pixel are fused together, that is, the first-level confidence score and the second-level confidence score of the target pixel are multiplied together to obtain the defect confidence score of the target pixel.
[0041] Then, the adaptive gain constant of the target pixel is obtained based on the defect confidence level, defect severity, and the gain constant range in the preset color recovery parameters.
[0042] Specifically, the difference between the upper and lower limits of the gain constant range in the preset color restoration parameters is obtained as the adjustment base value; the adjustment base value, the defect confidence of the target pixel, and the normalized value of the reciprocal of the defect severity of the target pixel are multiplied to obtain the adjustment amplitude corresponding to the target pixel; the sum of the lower limit of the gain constant range and the adjustment amplitude corresponding to the target pixel is the adaptive gain constant of the target pixel.
[0043] The specific calculation model for the adaptive gain constant of the target pixel is as follows: , Where βi represents the adaptive gain constant in the color restoration parameters of the i-th pixel (target pixel) (because the gain constant β in the color restoration parameters can directly amplify the effect of the color restoration factor, specifically enhancing the local contrast between the defective area and the background. At the same time, by controlling the adjustment range (such as 40-50), color oversaturation or noise amplification can be avoided, achieving an adaptive scene optimization effect. Therefore, this scheme chooses to adaptively adjust β); βmin represents the lower limit of the gain constant range. This represents the adjustment of the base value, which is the difference between the upper and lower limits of the gain constant range in the preset color restoration parameters, i.e., βmax - βmin; Zi is the defect confidence of the target pixel, and Ai is the degree of defect obviousness of the target pixel. The adaptive gain constant of the target pixel is determined by both the defect confidence and the degree of defect obviousness. This prevents obvious defects from being over-enhanced and distorted, while further enhancing less obvious defects. Similarly, the adaptive gain constant of each pixel in the grayscale image can be obtained.
[0044] Next, after obtaining the adaptive gain constant corresponding to each pixel, the MSRCR algorithm can be continued to complete the image enhancement of the surface of the glass mold, and the enhanced image is obtained, which is recorded as the enhanced image.
[0045] Subsequently, the Canny edge detection algorithm is employed to accurately locate the edge contours of defects in the enhanced image. Simultaneously, the gray-level co-occurrence matrix is used to extract texture features, such as contrast and correlation, comprehensively reflecting the surface texture information of the defects. Next, to reduce data dimensionality and computational load, Principal Component Analysis (PCA) is used to reduce the dimensionality of the extracted features, retaining the most representative principal components. Then, a classification model is constructed using Support Vector Machines (SVM). Pre-labeled training data for defect types is input into the model. The SVM learns the feature distribution patterns of different defect types by finding the optimal separating hyperplane in high-dimensional space. After training, the features of the current enhanced image are input into the model. The SVM classifies and judges the defect type based on its learning, outputting the defect type. Combined with image coordinate information, the defect location is determined, ultimately achieving automated and accurate detection of surface defects in glass molds.
[0046] It should be noted that the order of the above embodiments of the present invention is merely for descriptive purposes and does not represent the superiority or inferiority of the embodiments. Furthermore, the above description focuses on specific embodiments of this specification. Additionally, the processes depicted in the accompanying drawings do not necessarily require a specific or sequential order to achieve the desired results. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0047] The various embodiments in this specification are described in a progressive manner. The same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on describing the differences from other embodiments.
[0048] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. An automatic detection method for surface defects in glass molds based on image processing, characterized in that, The method includes: Acquire a grayscale image of the surface of the glass mold and take any pixel in the grayscale image as the target pixel; obtain the degree of defect of the target pixel based on the pixels in its eight neighborhoods; Obtain the connected components and branch points of each connected component in the grayscale image; obtain the first-level confidence score of the target pixel based on the area of the connected component to which the target pixel belongs, the aspect ratio of the minimum bounding rectangle, the number of connected components at the branch point, the aspect ratio of the minimum bounding rectangle of each connected component at the branch point, the mean curvature of the edge pixels of the connected component to which the target pixel belongs, and the local edge distribution of the target pixel. Starting from the center of the connected region to which the target pixel belongs, traverse the pixels in each set direction to obtain the pixel sequence corresponding to each set direction; obtain the second-level confidence of the target pixel based on the entropy of the gradient direction angle and the standard deviation of gray level of each pixel in the connected region to which the target pixel belongs, the gray level gradient of each pixel in the pixel sequence, and the difference in the entropy values of the gray co-occurrence matrix of the two windows centered on the target pixel and the center of the largest connected region. The adaptive gain constant of the target pixel is obtained based on the degree of defect severity, first-level confidence, second-level confidence, and the gain constant range in the preset color restoration parameters; the adaptive gain constant of each pixel is combined with the MSRCR algorithm to obtain an enhanced image of the glass mold surface; the enhanced image is used to detect surface defects of the glass mold.
2. The automatic detection method for surface defects of glass molds based on image processing according to claim 1, characterized in that, The degree of defect in obtaining the target pixel based on the pixels in the eight neighborhoods of the target pixel includes: The difference between the maximum gray value of the target pixel and the gray value of the target pixel, and the difference between the gray value of the target pixel and the minimum gray value of the target pixel and the gray value of the target pixel in its eight neighboring areas, are obtained. The maximum of the two differences is normalized to obtain the degree of defect of the target pixel.
3. The automatic detection method for surface defects of glass molds based on image processing according to claim 1, characterized in that, The process of obtaining the first-level confidence score of the target pixel based on the area of the connected component to which the target pixel belongs, the aspect ratio of the minimum bounding rectangle, the number of connected components at the branch point, the aspect ratio of the minimum bounding rectangle of each connected component at the branch point, the mean curvature of the edge pixels of the connected component to which the target pixel belongs, and the local edge distribution of the target pixel includes: The branch connected component feature is obtained by adding the number of connected components at the branch points of the connected component to the average aspect ratio of the minimum bounding rectangle of each connected component. A window is constructed with the target pixel as the center, and the ratio of the number of edge pixels on the longest edge in the window to the total number of edge pixels in the window is recorded as the edge continuity feature. The first-level confidence of the target pixel is obtained by multiplying and normalizing the inverse of the area of the connected component to the target pixel, the aspect ratio of the minimum bounding rectangle, the branch connected component feature, the inverse of the average curvature of the edge pixels of the connected component to the target pixel, and the edge continuity feature.
4. The automatic detection method for surface defects of glass molds based on image processing according to claim 1, characterized in that, The method of obtaining the secondary confidence level of the target pixel based on the entropy of the gradient direction angle and the standard deviation of gray level of each pixel in the connected region to which the target pixel belongs, the gray level gradation of each pixel in the pixel sequence, and the difference in the entropy values of the gray-level co-occurrence matrices of two windows centered on the target pixel and the center of the largest connected region includes: Fitting the grayscale values of pixels in a pixel sequence corresponding to a given direction yields the fitting slope and the fitted grayscale value of each pixel in the sequence. Adding the mean of the absolute differences between the grayscale values of each pixel in the pixel sequence corresponding to the given direction and the fitted grayscale values to the hyperparameters, and then taking the reciprocal, yields the first gradient feature corresponding to that given direction. The absolute difference between the fitting slope of the pixel sequence corresponding to a given direction and the mean of the fitting slopes of all pixel sequences corresponding to given directions is taken as the second gradient feature for that given direction. The first gradient feature corresponding to each given direction is then obtained. The local gradient feature is obtained by multiplying the mean of the first gradient feature, the mean of the second gradient feature corresponding to each set direction, and the number of non-zero fitting slopes in the fitting slopes of the pixel sequence corresponding to each set direction. This product is then multiplied by the standard deviation of the gray values of each pixel in the connected region to which the target pixel belongs, and the reciprocal is obtained. The second-level confidence of the target pixel is obtained by multiplying the reciprocal of the entropy of the gradient direction angle of each pixel in the connected region to which the target pixel belongs, the local gradient feature, and the absolute value of the difference between the entropy values of the gray-level co-occurrence matrices of the two windows centered on the target pixel and the center of the largest connected region, and then normalizing the result.
5. The automatic detection method for surface defects of glass molds based on image processing according to claim 1, characterized in that, The process of obtaining the adaptive gain constant of the target pixel based on the severity of the defect, the first-level confidence level, the second-level confidence level, and the gain constant range in the preset color restoration parameters includes: The defect confidence of the target pixel is obtained by multiplying its first-level confidence and second-level confidence. The adaptive gain constant of the target pixel is obtained based on its defect confidence, defect severity, and the range of gain constants in the preset color restoration parameters.
6. The automatic detection method for surface defects of glass molds based on image processing according to claim 5, characterized in that, The step of obtaining the adaptive gain constant of the target pixel based on the defect confidence level, defect severity, and the gain constant range in the preset color restoration parameters includes: The difference between the upper and lower limits of the gain constant range in the preset color restoration parameters is used as the adjustment base value. The adjustment base value, the defect confidence of the target pixel, and the normalized value of the reciprocal of the defect severity of the target pixel are multiplied to obtain the adjustment amplitude corresponding to the target pixel. The sum of the lower limit of the gain constant range and the adjustment amplitude corresponding to the target pixel is the adaptive gain constant of the target pixel.