Cover film surface defect detection method based on machine vision
By iteratively optimizing the segmentation threshold in the Otsu algorithm and combining fitting curves and clustering techniques, the problem of traditional methods being insufficiently adaptable to noise and multiple defect types is solved, and a higher precision of the surface defect detection of the covering film is achieved.
Patent Information
- Application Number
- CN202411795060.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-09
- Publication Date
- 2025-01-07
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the detection of surface defects of the cover film, the traditional Otsu algorithm is sensitive to noise and cannot adapt to multiple defect types, resulting in inaccurate segmentation effect and ineffective identification of defects on the cover film.
In the iterative update process of Otsu algorithm, the segmentation threshold is gradually optimized, and the quantization values of the scratch segmentation coefficient and segmentation effect are calculated using the fitting curve and clustering technology, and the optimal segmentation threshold is selected for image segmentation to improve the detection accuracy.
Effectively reduce noise interference, enhance the ability to distinguish multiple defect types, improve image segmentation accuracy and accuracy of detection results, and ensure that defect detection results on the surface of the covering film are more accurate and reliable.
Smart Images

Figure CN119273684A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and specifically to a method for detecting surface defects of a covering film based on machine vision. Background Art
[0002] Covering film is often used in many fields such as laptop battery protection, light strips, and circuit protection. As a protective material, it can not only effectively resist physical damage, environmental factors and chemical corrosion, but also protect internal electronic components. It also plays a key role in improving product aesthetics and extending product life. In the production process of covering film, surface scratches are a common defect type, so scratch detection has become a crucial step in quality inspection.
[0003] With the continuous development of modern industrial inspection technology, the existing technology usually uses machine vision technology for defect detection, specifically to obtain the surface image of the object to be inspected, and then use the traditional Otsu algorithm for image segmentation. This algorithm is to find a fixed grayscale threshold, and divide the image into defect areas and normal areas according to the comparison result between the grayscale value of the pixel point and the fixed grayscale threshold. For example, the Chinese patent document with the existing authorization announcement number CN110827309B discloses a method for segmenting the appearance defects of polarizers based on superpixels: loading the defective image of the polarizer to be segmented; graying; performing superpixel segmentation on the defective image of the polarizer; extracting the grayscale features of the superpixels; using the Otsu algorithm to calculate the grayscale threshold; merging the superpixels according to the optimal segmentation threshold to obtain the final segmentation result.
[0004] However, the traditional OSTU algorithm (Otsu algorithm) using the above scheme has exposed many limitations when detecting defects on the surface of the covering film. On the one hand, it is extremely sensitive to noise, and noise interference in the actual detection environment is difficult to avoid, which makes it easy to confuse noise pixels with defective pixels, thereby affecting the accuracy of defect detection and failing to accurately locate the real defect area. On the other hand, the Otsu algorithm relies solely on grayscale information and is difficult to cope with the diversity of surface defect types of covering films. Different types of defects, such as scratches, spots, holes, etc., each have unique grayscale characteristics and change rules. Scratches present continuous grayscale gradients, and spots are reflected as significant differences in local grayscale, and the single grayscale threshold determined by the Otsu algorithm cannot flexibly adapt to these differences. This results in poor segmentation when detecting covering films with multiple defects at the same time, unclear definition of defective areas, some defects being missed, and some normal areas being misjudged as defects. Both aspects will affect the accuracy of defect detection results. Summary of the invention
[0005] In order to solve the problem that when performing defect detection on the surface of a covering film, the threshold segmentation method of the Otsu algorithm that only relies on grayscale information is easily affected by noise and cannot adapt to the segmentation requirements of various defect types, resulting in inaccurate image segmentation results and inability to effectively identify defects, the present invention proposes a covering film surface defect detection method based on machine vision, including: Get the surface image of the covering film, update the segmentation threshold through multiple iterations according to the Otsu algorithm, and after each iteration the threshold is updated: The surface image is segmented into a scratch area and a normal area using the current segmentation threshold, and all pixels in the scratch area are clustered into multiple categories; Get the fitting curve of the positions of all pixels in each category and calculate the scratch segmentation coefficient of the current segmentation threshold , is the number of categories, For the The absolute value of the difference between the mean grayscale value of the pixel points of each category and the standard grayscale value, is the natural exponential function, For the The average Euclidean distance from the pixel points of each category to the fitting curve, wherein the standard gray value is the average gray value of the standard surface image of the covering film collected in advance; Calculate the quantitative value of the segmentation effect of the current segmentation threshold , is the difference between the scratch area and the normal area under the current segmentation threshold; After the entire iterative update is completed, the segmentation threshold corresponding to the maximum quantization value is selected as the optimal segmentation threshold, the surface image is segmented using the optimal segmentation threshold, and the detection result of the scratch defect is determined based on the segmentation result.
[0006] The above technical solution is that in the iterative process of the Otsu algorithm to find the optimal segmentation threshold that maximizes the inter-class variance based on the global grayscale information of the image, each time the threshold is updated, the image segmentation effect is re-evaluated, and a more suitable threshold for the current image can be gradually approached, reducing the segmentation error caused by inaccurate single threshold setting. After each iterative update, the image is divided into two types of areas, and the possible scratch range is preliminarily located. Clustering the pixels in the scratch area helps to mine the structural information inside the scratch. Different clusters may correspond to different parts of the scratch, different shape characteristics or different degrees of defect performance, so as to more accurately characterize the scratch characteristics, rather than simply treating the scratch as a whole area. The position distribution trend of the pixel points of each category can be described by fitting the curve, and the degree of deviation from the ideal scratch shape (represented by the fitting curve) can be measured. The scratch segmentation coefficient is calculated by comprehensively considering the grayscale difference and the position deviation degree, which can comprehensively evaluate the fit between the scratch area determined under the current segmentation threshold and the ideal scratch characteristics (standard grayscale and expected shape). Furthermore, the quantified value of the segmentation effect of the current segmentation threshold is obtained. This quantified value takes into account both the macroscopic separation of the scratch area and the normal area and the rationality of the internal features of the scratch area, and can comprehensively quantify and evaluate the segmentation quality. Finally, after iteration and quantitative evaluation, the threshold corresponding to the maximum quantized value is the optimal choice for the segmentation effect of the current covering film surface image after comprehensive consideration of various factors. The final segmentation using this optimal segmentation threshold can obtain the most accurate division of the scratch area and the normal area. The scratch defect detection result is determined based on this accurate segmentation result, which can improve the accuracy and reliability of the detection and provide a reliable basis for subsequent work such as covering film quality evaluation.
[0007] Preferably, the method for obtaining the difference between the scratch area and the normal area under the current segmentation threshold is: For any pixel point in the scratch area or normal area, record the cumulative number of times the pixel point is divided into the scratch area in the current and previous iterations, and take the maximum value of all scratch segmentation coefficients corresponding to the cumulative number as the historical maximum scratch segmentation coefficient of the pixel point; Taking the pixels contained in the scratch area and the normal area as one class, the inter-class variance value of the historical maximum scratch segmentation coefficient of all pixels contained in the scratch area and the historical maximum segmentation coefficient of all pixels contained in the normal area is calculated. The inter-class variance value is used as the difference between the scratch area and the normal area under the current segmentation threshold.
[0008] The above technical solution records the cumulative number of times each pixel is divided into the scratch area in the current and previous iterations, and selects the maximum value of all scratch segmentation coefficients as the historical maximum scratch segmentation coefficient. This method makes full use of the historical data in the iteration process. It not only focuses on the result of one division under the current segmentation threshold, but also integrates the association between each pixel and the scratch area in multiple iterations, making the evaluation of pixel characteristics more comprehensive and in-depth. The inter-class variance can reflect the degree of discreteness or difference between two types of data (here refers to the historical maximum segmentation coefficient of the pixels in the scratch area and the normal area). In this way, we can intuitively understand the degree of difference between the scratch area and the normal area based on the historical segmentation situation under the current segmentation threshold, which provides a quantitative and representative indicator for evaluating the segmentation effect.
[0009] Preferably, the method for determining the detection result of the scratch defect based on the segmentation result is: The scratch segmentation coefficient of the optimal segmentation threshold is calculated based on the segmentation result of the optimal segmentation threshold. If the scratch segmentation coefficient is less than or equal to the preset scratch segmentation coefficient threshold, there is no scratch defect on the surface of the covering film. If the scratch segmentation coefficient is greater than the preset scratch segmentation coefficient threshold, there is a scratch defect on the surface of the covering film, and the scratch area is a scratch defect.
[0010] The above technical solution uses the best segmentation threshold to segment the image and then calculates the scratch segmentation coefficient to determine the defect. The best segmentation threshold is determined after comprehensively considering various features of the image, regional differences and other factors. The scratch segmentation coefficient calculated based on this threshold can more accurately reflect the difference between the scratch features in the image and the normal area. This means that the detection result is not simply based on a single parameter judgment, but is closely linked to the optimization process of the entire image segmentation, which improves the fit between the detection result and the actual situation of the image.
[0011] Preferably, the method of segmenting the surface image into the scratch area and the normal area using the current segmentation threshold is: The pixels in the surface image whose grayscale values are greater than the current segmentation threshold are taken as scratch pixels to form a scratch area, and the pixels whose grayscale values are less than or equal to the current segmentation threshold are taken as normal pixels to form a normal area.
[0012] Preferably, the updating of the segmentation threshold through multiple iterations according to the Otsu algorithm is iteratively updated in an ascending order based on the grayscale values in the grayscale histogram of the surface image.
[0013] Preferably, before clustering all the pixels in the scratch area into multiple categories, the following operations are performed: A corresponding binary mask image is generated for the scratch area, and a dot multiplication operation is performed with the surface image to obtain a surface image containing only the grayscale values of the pixels in the scratch area. The grayscale values of the pixels in the normal area are all 0.
[0014] The above technical solution can accurately focus the analysis on the scratch area, which is the part that needs the most attention. This operation can effectively eliminate the interference of normal areas, so that subsequent processing of the scratch area (such as clustering operations) can be more purely carried out around the characteristics of the scratch itself.
[0015] Preferably, the method for obtaining the fitting curve of the positions of all pixel points of each category is: With the upper left corner of the surface image as the origin, the horizontal rightward direction as the positive direction, and the vertical downward direction as the positive axis direction, a coordinate system is constructed to obtain the position of each pixel point. The position of the pixel point of each category is fitted using the least squares method to obtain the fitting curve.
[0016] The above technical solution is based on the pixel distribution trend accurately described by the fitting curve. When subsequently calculating various parameters related to scratches (such as the average Euclidean distance from the pixels of each category to the fitting curve, etc.), it can more accurately reflect the relationship between the pixels and the ideal shape of the scratch (represented by the fitting curve).
[0017] Preferably, the clustering is performed based on an iterative self-organizing clustering algorithm.
[0018] The iterative self-organizing clustering algorithm adopted in the above technical solution can automatically discover the inherent structure and pattern from the data. In the context of surface defect detection of covering films, the distribution of pixels in the scratch area may present various complex situations, such as scratches of different lengths, widths, and directions, as well as possible scratch intersections and overlaps. Through the iterative self-organizing clustering algorithm, they can be automatically divided into different categories based on features such as the similarity between pixels, thereby revealing the potential structural information inside the scratch area.
[0019] The present invention has the following effects: The present invention adopts an adaptive threshold mechanism, which can dynamically adjust the threshold according to the local or global features of the image, effectively reduce the interference of noise on the segmentation result, comprehensively consider the various characteristic information of scratch defects, enhance the ability to distinguish specific types of defects, and through iterative optimization and feedback mechanism, continuously adjust the segmentation threshold according to the segmentation result, gradually improve the segmentation accuracy, and finally obtain an optimal segmentation threshold, thereby improving the accuracy of the threshold segmentation result, making the defect detection result of the covering film surface more accurate and reliable. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] By reading the following detailed description with reference to the accompanying drawings, the above and other objects, features and advantages of the exemplary embodiments of the present invention will become readily understood. In the accompanying drawings, several embodiments of the present invention are shown in an exemplary and non-limiting manner, and the same or corresponding reference numerals represent the same or corresponding parts, wherein: Figure 1 It is a schematic flow chart of the method of the present invention; Figure 2 It is a schematic diagram of the method flow of step S2 of the present invention. DETAILED DESCRIPTION
[0021] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0022] The specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0023] Reference Figure 1 The method for detecting surface defects of a covering film based on machine vision provided by the present invention comprises steps S1 to S3: S1: Acquire a surface image of the covering film.
[0024] The surface image of the covering film is collected. During the image collection process, the lighting environment is strictly controlled, and a uniformly distributed and stable light source, such as a professional shadowless lamp system, is used to illuminate the covering film from a specific angle, thereby minimizing the shadows and highlights caused by uneven lighting and ensuring the details and clarity of the image. At the same time, by adjusting the polarization direction of the light source and installing a polarizing filter in front of the camera lens, the reflected light that may be generated on the surface of the covering film is effectively suppressed to avoid interference with the subsequent image analysis process.
[0025] After acquiring the surface image of the covering film, it is subjected to grayscale processing to convert the color surface image into a grayscale image, so the "surface image" referred to below is the result after the grayscale processing.
[0026] S2: The optimal segmentation threshold is obtained by optimizing the process of iteratively updating the segmentation threshold of the Otsu algorithm.
[0027] Otsu algorithm is a classic image threshold segmentation method. Its basic principle is to traverse all possible segmentation thresholds, which are used to segment the image, and calculate the inter-class variance of the pixel values of the two types of pixels in the image foreground (target) and background under each segmentation threshold. The pixel value that maximizes the inter-class variance is determined as the segmentation threshold, thereby dividing the image into two parts: the target and the background. It can be seen that using Otsu algorithm to determine the segmentation threshold is a process of continuously iteratively updating the segmentation threshold.
[0028] In the present invention, the segmentation threshold is updated through multiple iterations according to the Otsu algorithm, and the grayscale values in the grayscale histogram of the surface image are iteratively updated in order from small to large. Therefore, the grayscale histogram of the surface image is first obtained, and the horizontal coordinate of the grayscale histogram is all the grayscale values in the surface image, and the total coordinate is the number of pixels corresponding to each grayscale value.
[0029] The iterative update process is as follows: first select the minimum grayscale value in the grayscale histogram as the segmentation threshold, divide all pixels into two categories, and calculate the inter-class variance value. Then use the second smallest grayscale value as the segmentation threshold, divide all pixels into two categories, and calculate the inter-class variance value. This process is repeated until the maximum grayscale value is used as the segmentation threshold, all pixels are divided into two categories, and the corresponding inter-class variance value is obtained. The entire process of iteratively updating the segmentation threshold is completed.
[0030] This step optimizes the iterative update of the segmentation threshold of the Otsu algorithm to obtain the optimal segmentation threshold. Specifically, after each iterative update of the threshold, the following operations are performed: S21: Segment the surface image into a scratch area and a normal area using the current segmentation threshold.
[0031] For any pixel in the surface image, if the grayscale value of the pixel is greater than the current segmentation threshold, the pixel is regarded as a scratch pixel. If the grayscale value of the pixel is less than or equal to the current segmentation threshold, the pixel is regarded as a normal pixel. Ultimately, all scratch pixels constitute the scratch area, and all normal pixels constitute the normal area.
[0032] According to the division method of this scheme, the area where scratches may exist can be located quickly and effectively in the surface image, achieving the preliminary positioning of the scratch defects and providing an approximate range for further accurate identification of the scratch defects.
[0033] S22: Cluster all pixels in the scratch area into multiple categories.
[0034] First, use a binary mask to focus on the scratch area features: Generate a binary mask image corresponding to the scratch area and perform a dot multiplication operation with the original grayscale image, which can accurately extract the grayscale values corresponding to the pixels in the scratch area, while the grayscale values of the pixels in the normal area become 0 after this operation. In other words, the new image obtained through such an operation is like masking all parts of the original surface image except the scratch area, and only highlights the grayscale of the scratch area, so that the pixels in the scratch area can be further analyzed and processed more focusedly, such as clustering operations, etc., which can reduce the interference of the normal area on the subsequent analysis of scratch-related features.
[0035] The core significance of this operation is to focus the analysis on the scratch area itself, eliminating the interference of other non-scratch areas in the image, so that subsequent processing and analysis can be more purely carried out around the characteristics of the scratch area. For example, in a complex cover film surface image, there may be a variety of background information, noise, and pixels in other normal areas. This method can effectively focus on the pixels related to the scratch, providing a clear and targeted data foundation for in-depth exploration of the specific characteristics of the scratch.
[0036] Next, DBSCAN (Iterative Self-Organizing) clustering is used to mine the internal structure of the scratch area: The clustering radius is set to 1 and the minimum number of points is set to 3. These two values are empirical values and can be selected according to actual conditions, which gives the scheme strong flexibility and adaptability. For example, for images of cover films with dense and small scratches, it may be necessary to appropriately reduce the clustering radius and adjust the minimum number of points to obtain a more refined clustering result. For images with relatively sparse and large scratches, the clustering radius and other parameters can be increased accordingly to ensure that the overall structure and characteristics of the scratches can be accurately captured.
[0037] The DBSCAN clustering algorithm is selected to cluster the pixels in the scratch area based on the grayscale value because the algorithm has certain advantages in processing data with spatial distribution characteristics. It can automatically discover different clustering structures in the data based on the continuity and approximation of the coordinates and grayscale values of the pixel points, without the need to specify the number of clusters in advance. In the context of scratch detection on the cover film surface, different scratches may have different shapes, lengths, widths, and internal grayscale changes. DBSCAN clustering can divide these pixels with similar characteristics (continuous and approximate coordinates, continuous and approximate grayscale values) into different clustering categories, thereby mining the potential structural information inside the scratch area, which helps to understand the composition and characteristics of the scratches more comprehensively and carefully.
[0038] After clustering, the pixels in the scratch area are divided into multiple clusters. Each cluster is a category, and each category contains several scratch pixels. By performing cluster analysis on the pixels in the scratch area, based on the two key factors of the coordinate position of the pixel points in the image and their grayscale value, those pixels that are coherent and close in coordinates, and have smooth grayscale value changes and are close to each other, are divided into the same category.
[0039] The result of this division is that all the pixels in each category correspond to a scratch area that appears to be continuous in the image. In other words, through this clustering method, the complex scratch area can be subdivided according to its intrinsic coordinates and grayscale value characteristics, so that each subdivided part (i.e. each category) can more accurately represent a relatively independent and continuous scratch part, which helps to more deeply understand the specific form, structure and distribution of the scratch, and provide a more detailed basis for subsequent accurate evaluation of scratch defects.
[0040] S23: Obtain the fitting curve of the positions of all pixel points of each category, and calculate the scratch segmentation coefficient of the current segmentation threshold.
[0041] The coordinate system is constructed with the upper left corner of the surface image as the origin, the horizontal right direction as the positive direction, and the vertical downward direction as the positive axis direction to obtain the position of each pixel. Since scratches usually appear in an elongated shape, the least squares method is used to fit the positions of all pixels in each category to obtain a fitting curve, and the average value of the Euclidean distance from all pixels in this category to the fitting curve is calculated, because the distribution of pixels inside the elongated scratch area should be closer to a certain curve. If the average value of the Euclidean distance is smaller, it means that all pixels in this category are more consistent with the elongated shape characteristics in spatial distribution, so it can be inferred that the clustering result is more likely to be a real scratch area, which helps to accurately identify the scratch morphology and improve the accuracy of scratch detection.
[0042] At the same time, the scratch area and the normal area will have different grayscale values due to differences in material and structure. The difference between the mean grayscale value of all pixels in each category and the standard grayscale value (the average grayscale value of the standard surface image of the cover film collected in advance) is calculated. The greater the difference, the more significant the distinction between the scratch area and the normal area, which means the more accurate the scratch area segmentation. If the difference is smaller, it means that the grayscale difference between this area and the normal area is not large, the abnormality detection effect is not obvious, and it is difficult to determine as a clear scratch area.
[0043] In summary, by comprehensively considering the above two aspects, the scratch segmentation coefficient of the current segmentation threshold is calculated from the two aspects of shape and grayscale:
[0044] In the formula, is the number of categories, For the The absolute value of the difference between the mean grayscale value of the pixel points of each category and the standard grayscale value, is the natural exponential function, For the The average Euclidean distance from the pixel points of each category to the fitting curve, and the standard gray value is the average gray value of the standard surface image of the covering film collected in advance.
[0045] In this formula, The smaller the The more the pixel points of a category conform to the scratch characteristics, the better the segmentation effect of the current segmentation threshold is for the pixel points of this category. Therefore, the scratch segmentation coefficient of the current segmentation threshold is larger. Therefore, the negative correlation function is used to map the relationship between the two.
[0046] In this formula, The smaller the The smaller the difference between the grayscale value of the pixel point of each category and the standard grayscale value, the less obvious the segmentation effect of the current segmentation threshold is. The larger the value is, the better the segmentation effect of the current segmentation threshold is. and It is a positive correlation.
[0047] In summary, the larger the scratch segmentation coefficient, the better the segmentation result of the current segmentation threshold. However, in actual situations, there may be extremely obvious or insignificant differences between the scratch area and the normal area, which will have different effects on the scratch segmentation coefficient and the final segmentation result. For example, when the difference is extremely obvious, it may be relatively easy to obtain a larger segmentation coefficient and a better segmentation result, but when the difference is extremely insignificant, it may be difficult to accurately segment the scratch, resulting in an unsatisfactory segmentation coefficient and poor segmentation results.
[0048] S24: Evaluate the segmentation effect of the current segmentation threshold and calculate the quantitative value of the segmentation effect.
[0049] Generally, the size of the scratch segmentation coefficient can reflect the segmentation effect of the scratch. When the scratch segmentation coefficient is larger, it means that the current segmentation result for the scratch is better. However, there are different situations in practice, that is, the degree of difference between the scratch area and the normal area is different, specifically: When the difference between the scratch area and the normal area is extremely obvious, the segmentation threshold will have a large change space. However, in this case, the change of the segmentation threshold will not have a significant impact on the segmentation result of the scratch area, that is, the segmentation result is relatively stable and will not have obvious deviations due to the fluctuation of the segmentation threshold.
[0050] When the difference between the scratched area and the normal area is extremely insignificant, the situation becomes more complicated. If the segmentation threshold is slightly reduced, although the scratched area can be segmented, a large number of mis-segmentations will occur at the same time, which will further affect the segmentation effect of the entire cover film surface image, causing the overall segmentation quality to decline.
[0051] Therefore, we further combine the scratch segmentation coefficient of the current segmentation threshold and the difference between the scratch area and the normal area under the current segmentation threshold to construct a function for evaluating the segmentation effect of the current segmentation threshold:
[0052] In the formula, is the quantitative value of the segmentation effect of the current segmentation threshold, is the difference between the scratch area and the normal area under the current segmentation threshold, is the scratch segmentation coefficient of the current segmentation threshold.
[0053] in, The method to obtain is: For any pixel in the scratch area or normal area, record the cumulative number of times the pixel is divided into the scratch area during the current and previous iterations, and take the maximum value of all scratch segmentation coefficients corresponding to the cumulative number as the historical maximum scratch segmentation coefficient of the pixel. For example, for pixel A, the number of iterations it has experienced is 10, and 6 of these 10 times it has been divided into the scratch area. Obtain the 6 scratch segmentation coefficients corresponding to these 6 iterations as the historical scratch segmentation coefficients of pixel A, and select the maximum value among these 6 scratch segmentation coefficients as the historical maximum scratch segmentation coefficient of pixel A.
[0054] The pixels in the scratch area and the normal area are taken as one class, and the inter-class variance of the historical maximum scratch segmentation coefficient of all pixels in the scratch area and the historical maximum segmentation coefficient of all pixels in the normal area is calculated. The inter-class variance is used as the difference between the scratch area and the normal area under the current segmentation threshold. .
[0055] If S is larger, it means that the segmentation threshold corresponding to the scratch segmentation coefficient D generates less noise in the segmentation result, the segmentation effect of the segmentation threshold corresponding to the scratch segmentation coefficient D is better, the more obvious the scratch area is, and the more conducive it is to the scratch detection of the cover film. If S is smaller, it means that the segmentation effect of the segmentation threshold corresponding to the scratch segmentation coefficient D is not good, and a lot of interference noise is generated in the segmentation result. Therefore, the introduction of This is equivalent to a secondary analysis of D.
[0056] In summary, this formula integrates the difference between the scratch area and the normal area The scratch segmentation coefficient D provides a comprehensive and effective quantitative method for evaluating the segmentation effect of the segmentation threshold, which is specifically reflected in the following aspects: From the perspective of overall evaluation, multiplying the two key factors into one formula can comprehensively consider the impact of different aspects on the segmentation effect and avoid the one-sidedness of single indicator evaluation. S reflects the discreteness or distinguishability of the scratch area and the normal area at the level of the historical maximum scratch segmentation coefficient of the pixel point, while D directly reflects the accuracy of the current segmentation threshold for the scratch segmentation. The Z value obtained by multiplying the two can intuitively give a comprehensive quantitative result of the segmentation effect, which is convenient for comparison and screening under different threshold settings, and quickly determines the optimal segmentation threshold, which improves the efficiency and accuracy of determining the segmentation threshold in the scratch detection algorithm.
[0057] From the perspective of scratch area highlighting and noise suppression, a larger The value means that there is a significant difference between the scratch area and the normal area at the level of the historical maximum scratch segmentation coefficient, which indirectly indicates that under the current segmentation threshold, the characteristics of the scratch area can be better distinguished from the normal area and less noise is generated. Because if there is more noise interference, the boundary between the scratch area and the normal area will be blurred, causing the S value to decrease. A larger D value itself represents a better scratch segmentation effect, so when both S and D are large, the Z value increases, indicating that the scratch area in the segmentation result is clearly identifiable and less affected by noise. This is of great significance for accurately locating and identifying scratches on the cover film, and can effectively improve the accuracy and reliability of scratch detection and reduce the occurrence of misjudgments and missed judgments.
[0058] From the perspective of iterative optimization, during the iteration process, S is determined by calculating the historical maximum scratch segmentation coefficient of each pixel, so that the algorithm can make full use of the information of the previous iteration, and continuously adjust and optimize to improve the accuracy of the segmentation of the scratch area and the normal area. As the iteration proceeds, the change in the S value can reflect the improvement in the stability and accuracy of the algorithm's segmentation area. Combined with the change in the D value, the effectiveness of the entire segmentation process can be better monitored, and possible problems can be discovered and corrected in a timely manner. For example, when the S value suddenly becomes smaller or the D value fluctuates abnormally, the algorithm parameters can be adjusted in a targeted manner or the data processing process can be re-examined, thereby promoting the continuous iterative evolution of the entire scratch detection in a better direction.
[0059] Through the above steps S21 to S24, each segmentation threshold will obtain a quantized value of the segmentation effect. After the entire iterative update is completed, the segmentation threshold corresponding to the maximum quantized value of the segmentation effect is selected as the optimal segmentation threshold.
[0060] Through the above series of optimization measures for the iterative update of the segmentation threshold process of the Otsu algorithm, an optimal segmentation threshold that can accurately distinguish scratch areas from normal areas in complex covering film surface images is finally determined. This threshold will serve as a key parameter for subsequent image precise segmentation and defect detection.
[0061] S3: Segment the surface image using the optimal segmentation threshold, and perform defect detection based on the segmentation results.
[0062] The surface image is segmented using the optimal segmentation threshold as follows: For any pixel in the surface image, if the grayscale value of the pixel is greater than the optimal segmentation threshold, the pixel is regarded as a scratch pixel; if the grayscale value of the pixel is less than or equal to the optimal segmentation threshold, the pixel is regarded as a normal pixel. Finally, a scratch area composed of scratch pixels and a normal area composed of normal pixels are obtained.
[0063] The scratch segmentation coefficient is an important indicator to measure the segmentation effect. It is calculated based on the segmentation algorithm and data, and its size is related to the accuracy and obviousness of the segmentation of the scratch area.
[0064] The method for defect detection based on the segmentation results is: According to the method in step S2, the scratch segmentation coefficient of the best segmentation threshold is calculated based on the segmentation result of the best segmentation threshold. The scratch segmentation coefficient threshold is preset to 10, which is an empirical value and can be adjusted according to actual conditions.
[0065] If the scratch segmentation coefficient of the optimal segmentation threshold is less than or equal to 10, the segmentation result is likely to be some scratch-like illusions caused by noise or other non-scratch factors, or some misjudgment of the normal area by the segmentation algorithm. Because if it is a real scratch, according to the previous segmentation effect evaluation system, its scratch segmentation coefficient should be large enough to reflect the obvious difference in segmentation features between the scratch area and the normal area. Therefore, it is determined that there is no scratch defect on the surface of the cover film.
[0066] If the scratch segmentation coefficient of the optimal segmentation threshold is greater than 10, it means that the segmentation algorithm can well distinguish the scratch area from the normal area. At this time, the segmented scratch area is considered to be the location of the scratch defect, because this area shows sufficiently obvious scratch characteristics during the segmentation process. For example, in the calculation process of the scratch segmentation coefficient, through the comprehensive consideration of the inter-class variance value (difference) of the historical maximum scratch segmentation coefficient of the pixel point and the scratch segmentation coefficient, it is determined that this area is significantly different from the normal area, which meets the characteristics of the scratch defect area. Therefore, it is determined that there is a scratch defect on the surface of the covering film.
[0067] In summary, the present invention continuously optimizes the process of iteratively calculating the segmentation threshold through steps S1 to S3, comprehensively considers a variety of characteristic factors related to scratches, and does not simply rely on a single threshold judgment, thereby reducing the interference of noise on the results to a certain extent. At the same time, because the calculation process combines the gray value, position distribution and other characteristics unique to scratch defects, it can better meet the segmentation needs of defects such as scratches, improve the accuracy of the threshold segmentation results, and effectively identify scratch defects on the surface of the cover film.
[0068] In the description of this specification, "multiple" or "several" means at least two, such as two, three or more, etc., unless otherwise clearly and specifically defined.
[0069] Although this specification has shown and described a number of embodiments of the present invention, it will be apparent to those skilled in the art that such embodiments are provided by way of example only. Those skilled in the art will conceive of many modifications, changes and alternatives without departing from the ideas and spirit of the present invention. It should be understood that in the practice of the present invention, various alternatives to the embodiments of the present invention described herein may be employed.
Claims
1. A method for detecting surface defects of a covering film based on machine vision, characterized in that: include: Get the surface image of the covering film, update the segmentation threshold through multiple iterations according to the Otsu algorithm, and after each iteration the threshold is updated: The surface image is segmented into a scratch area and a normal area using the current segmentation threshold, and all pixels in the scratch area are clustered into multiple categories; Get the fitting curve of the positions of all pixels in each category and calculate the scratch segmentation coefficient of the current segmentation threshold , is the number of categories, For the The absolute value of the difference between the mean grayscale value of the pixel points of each category and the standard grayscale value, is the natural exponential function, For the The average Euclidean distance from the pixel points of each category to the fitting curve, wherein the standard gray value is the average gray value of the standard surface image of the covering film collected in advance; Calculate the quantitative value of the segmentation effect of the current segmentation threshold , is the difference between the scratch area and the normal area under the current segmentation threshold; After the entire iterative update is completed, the segmentation threshold corresponding to the maximum quantization value is selected as the optimal segmentation threshold, the surface image is segmented using the optimal segmentation threshold, and the detection result of the scratch defect is determined based on the segmentation result.
2. The method for detecting surface defects of a covering film based on machine vision according to claim 1, characterized in that: The method for obtaining the difference between the scratch area and the normal area under the current segmentation threshold is: For any pixel point in the scratch area or normal area, record the cumulative number of times the pixel point is divided into the scratch area in the current and previous iterations, and take the maximum value of all scratch segmentation coefficients corresponding to the cumulative number as the historical maximum scratch segmentation coefficient of the pixel point; Taking the pixels contained in the scratch area and the normal area as one class, the inter-class variance value of the historical maximum scratch segmentation coefficient of all pixels contained in the scratch area and the historical maximum segmentation coefficient of all pixels contained in the normal area is calculated. The inter-class variance value is used as the difference between the scratch area and the normal area under the current segmentation threshold.
3. The method for detecting surface defects of a covering film based on machine vision according to claim 1, characterized in that: The method for determining the detection result of scratch defects based on the segmentation result is: The scratch segmentation coefficient of the optimal segmentation threshold is calculated based on the segmentation result of the optimal segmentation threshold. If the scratch segmentation coefficient is less than or equal to the preset scratch segmentation coefficient threshold, there is no scratch defect on the surface of the covering film. If the scratch segmentation coefficient is greater than the preset scratch segmentation coefficient threshold, there is a scratch defect on the surface of the covering film, and the scratch area is a scratch defect.
4. The method for detecting surface defects of a covering film based on machine vision according to claim 1, characterized in that: The method of segmenting the surface image into the scratch area and the normal area using the current segmentation threshold is: The pixels in the surface image whose grayscale values are greater than the current segmentation threshold are taken as scratch pixels to form a scratch area, and the pixels whose grayscale values are less than or equal to the current segmentation threshold are taken as normal pixels to form a normal area.
5. The method for detecting surface defects of a covering film based on machine vision according to claim 1, characterized in that: The segmentation threshold is updated through multiple iterations according to the Otsu algorithm, and the grayscale values in the grayscale histogram of the surface image are updated iteratively in an ascending order.
6. The method for detecting surface defects of a covering film based on machine vision according to claim 1, characterized in that: Before clustering all the pixels in the scratch area into multiple categories, the following operations are performed: A corresponding binary mask image is generated for the scratch area, and a dot multiplication operation is performed with the surface image to obtain a surface image containing only the grayscale values of the pixels in the scratch area. The grayscale values of the pixels in the normal area are all 0.
7. The method for detecting surface defects of a covering film based on machine vision according to claim 1, characterized in that: The method to obtain the fitting curve of the positions of all pixels of each category is: With the upper left corner of the surface image as the origin, the horizontal rightward direction as the positive direction, and the vertical downward direction as the positive axis direction, a coordinate system is constructed to obtain the position of each pixel point. The position of the pixel point of each category is fitted using the least squares method to obtain the fitting curve.
8. The method for detecting surface defects of a covering film based on machine vision according to claim 1, characterized in that: The clustering is performed based on an iterative self-organizing clustering algorithm.
Citation Information
Patent Citations
A method for segmenting appearance defects in polarizers based on superpixels
CN110827309B
Cited By
PCM plate quality inspection system
CN119804327A
Drug production quality informatization management and control method and system
CN119809460A
Storage tank body defect detection method and system based on image processing
CN120318257A
Part image processing method and system based on multi-camera computer vision
CN120355656A
Optical module packaging material defect detection method
CN120355706A