Film material surface treatment defect detection method and system based on image recognition
By using grayscale distribution entropy value and direction gradient analysis technology in the detection of surface defects of membrane materials, the local area size is dynamically adjusted and abnormal pixel points are identified, which solves the problems of insufficient recognition rate and missed detection of defect detection in the prior art, and achieves higher detection accuracy and stability.
Patent Information
- Application Number
- CN202510356082.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-25
- Publication Date
- 2025-04-25
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing membrane surface defect detection methods have shortcomings in the quantization of grayscale distribution and complex defect morphology treatment, resulting in insufficient recognition rate, many false detection and missed detection phenomena, affecting the accuracy and reliability of the detection.
By collecting the surface images of the film material, counting the grayscale level frequency, calculating the entropy value of the grayscale distribution, dynamically adjusting the size of the local area, analyzing the changes in the grayscale gradient, distinguishing defects and background areas, extracting pixel directions, evaluating the degree of direction gradient deviation, identifying abnormal pixel points, and generating boundary detection results of the defect area.
It improves the sensitivity and adaptability of surface defect detection of membrane materials, enhances the clarity of boundary feature recognition, improves the accuracy and stability of detection results, and reduces false detection and missed detection.
Smart Images

Figure CN119887755A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of film material image processing, and in particular to a film material surface processing defect detection method and system based on image recognition. Background Art
[0002] The field of film material image processing technology involves the use of computer vision and image analysis methods to detect and evaluate the surface characteristics of thin film materials. It can quickly and accurately perform quality control without contacting the material and is widely used in the film material production and evaluation process in the optical, electronic, energy and medical industries.
[0003] Among them, the film surface treatment defect detection method uses image processing technology to identify and classify surface defects generated by thin film materials during production or processing. The method uses image analysis technology such as edge detection and texture analysis to identify surface defects, thereby helping to improve the efficiency and accuracy of product quality control, and ensure that the final product meets high quality requirements by real-time monitoring of the quality of the film material on the production line.
[0004] Existing technologies mainly rely on edge detection and texture analysis in film surface defect detection, lacking fine quantitative processing of grayscale distribution, which may lead to insufficient recognition rate of subtle defects. The fixed area size division method cannot adapt to complex defect distribution, and is prone to false detection or missed detection, especially when the area boundary is irregular. The feature extraction of the defect area boundary relies on a single segmentation algorithm, which makes it difficult to accurately distinguish the boundary from the background, affecting the accuracy of subsequent detection. Existing methods fail to conduct in-depth analysis of pixel directional gradient changes in the defect area, and have limited processing capabilities for complex defect morphology, which may lead to misjudgment of abnormal pixels or blurred boundaries, ultimately affecting the reliability of the detection results. These deficiencies lead to bottlenecks in efficiency and accuracy in the quality control process, which cannot fully meet high quality standards and may have an adverse impact on the timely adjustment of production and processing links. Summary of the invention
[0005] The purpose of the present invention is to solve the shortcomings existing in the prior art and to propose a film surface treatment defect detection method and system based on image recognition.
[0006] In order to achieve the above object, the present invention adopts the following technical solution: a film surface treatment defect detection method based on image recognition, comprising the following steps: S1: Collect the surface image of the film material, count the frequency of gray levels in the gray image, obtain the gray distribution information of the surface image of the film material, divide the surface image of the film material into multiple local areas of the same size, calculate the gray distribution entropy value in each local area, and generate the analysis results of the local area of the surface of the film material; S2: Based on the analysis result of the local area of the film material surface, the local areas marked as potential defect objects are sorted according to the grayscale distribution entropy value, the grayscale gradient change in the local area of each potential defect object is analyzed, and the size of the local area of the potential defect object is dynamically adjusted to obtain an adjusted local area image of the film material surface; S3: Based on the adjusted local area image of the film material surface, the screened defect area is processed to distinguish the defect area from the background area, and the pixel direction is obtained from the boundary features of the defect area to obtain the defect feature analysis result of the film material surface; S4: Based on the analysis results of the surface defects of the film material, the deviation degree of the directional gradient of each pixel point in the defect area from the mean of the directional gradient distribution of the entire area is evaluated, and the abnormal pixel points that deviate from the mean of the directional gradient distribution are identified to obtain the boundary detection results of the surface defect area of the film material.
[0007] As a further solution of the present invention, the step of acquiring the grayscale distribution of the film material surface image is specifically as follows: S111: collecting a film material surface image, extracting color information of each pixel in the film material surface image and performing brightness conversion to generate grayscale data of the film material surface image; S112: Based on the grayscale data of the film surface image, the formula is used: ; Calculate gray level Relative frequency of occurrence in the entire film surface image , count the gray level frequency and obtain the gray distribution information of the film surface image; in, is the gray level in the image The total number of occurrences, is the total number of pixels in the image, is the Laplace smoothing parameter.
[0008] As a further solution of the present invention, the steps for obtaining the analysis results of the local area of the membrane surface are specifically as follows: S121: Based on the grayscale distribution information of the film material surface image, the film material surface image is divided into a plurality of local areas of the same size according to a preset fixed size, and pixel range information of the local areas is generated; S122: Based on the pixel range information of the local area, the formula is used: ; Calculate the Grayscale distribution entropy value of local area , get the grayscale distribution entropy value information; in, is the index of gray level, is the total number of gray levels, yes The logarithm of ; S123: Compare the grayscale distribution entropy value information of each local area with a preset distribution threshold, mark the area above the threshold as a potential defect object, and generate a local area analysis result of the film material surface.
[0009] As a further solution of the present invention, the step of acquiring the adjusted local area image of the film surface is specifically as follows: S211: based on the analysis result of the local area of the film material surface, extract the grayscale distribution entropy value of the local area marked as the potential defect object, sort the grayscale distribution entropy values in descending order, record the sorting results, and obtain the entropy value sorting list; S212: Based on the entropy value sorting list, the formula is used: ; Calculate the pixel Grayscale gradient amplitude at coordinate , get the change amplitude value of gray gradient; in, It is the grayscale change rate of the pixel in the horizontal direction, that is, the x direction. It is the grayscale change rate of the pixel in the vertical direction, that is, the y direction; S213: According to the grayscale gradient change amplitude value, by obtaining the grayscale gradient change of each pixel in the local area and comparing it with the preset grayscale gradient change threshold, combined with the priority of the entropy value sorting list, the size of each potential defect local area is dynamically adjusted to generate an adjusted local area image of the membrane surface.
[0010] As a further solution of the present invention, the steps for obtaining the analysis results of the surface defects of the film material are specifically as follows: S311: based on the defective area screened in the adjusted local area image of the film surface, extracting the gray value of each pixel in the defective area, statistically analyzing the gray distribution, dividing the defective part and the background part according to a preset gray segmentation threshold, and obtaining a segmented binary image; S312: Based on the segmented binary image, extract the boundary information of the defective part by scanning pixel by pixel, count the distribution, morphology and change characteristics of the boundary, and analyze the shape, curvature and complexity of the boundary to obtain the boundary characteristics of the defective area; S313: Based on the boundary features of the defect area, the directional information of each pixel is obtained through the directional distribution and geometric characteristics of the defect area, and the film surface defect feature analysis results are generated.
[0011] As a further solution of the present invention, the step of obtaining the deviation degree evaluation result is specifically as follows: S411: based on the analysis result of the surface defect characteristics of the film material, obtaining the directional gradient information of each pixel in the defect area, integrating it into one-dimensional data, performing normal distribution fitting, and generating fitting results of directional gradient trend and fluctuation degree; S412: Based on the fitting results of the directional gradient trend and fluctuation degree, the deviation degree of each directional gradient value from the distribution mean is analyzed, and the deviation degree is standardized into a Z score, abnormal pixel points are screened, and a deviation degree evaluation result is generated.
[0012] As a further solution of the present invention, the step of obtaining the boundary detection result of the defective area on the surface of the film material is specifically as follows: S421: Based on the deviation degree evaluation result, the formula is used: ; Calculate smoothed coordinates The pixel value at , and obtain the Gaussian smoothing result; in, is the relative position in the Gaussian kernel The weight value of is the relative position in the original image The pixel value of is the relative position index of the Gaussian kernel, is the radius of the Gaussian kernel, are the coordinates of the currently processed pixel in the image; S422: Based on the Gaussian smoothing result, determine the change of the grayscale gradient by scanning pixel by pixel, record the pixel coordinates of the gradient change, connect the pixel coordinates to form a continuous boundary contour, and obtain the boundary detection result of the defect area on the surface of the film material.
[0013] A film material surface treatment defect detection system based on image recognition, the film material surface treatment defect detection system based on image recognition is used to execute the above-mentioned film material surface treatment defect detection method based on image recognition, the system comprises: The image acquisition module collects the surface image of the film material, converts the image into a grayscale image, counts the frequency of each grayscale level in the grayscale image, and generates grayscale distribution information; The local analysis module divides the film material surface image into a plurality of local areas of the same size based on the grayscale distribution information, calculates the grayscale distribution entropy value of each area, and generates a local area analysis result of the film material surface; The defect location module sorts the areas marked as potential defects by grayscale distribution entropy value based on the analysis results of the local area of the film material surface, analyzes the grayscale gradient change of each area, dynamically adjusts the area size, and obtains an adjusted local area image of the film material surface; The feature extraction module analyzes the screened defect area based on the adjusted local area image of the film surface, distinguishes the defect and the background area, extracts the pixel direction from the boundary feature of the defect area, and obtains the defect feature analysis result of the film surface; The boundary assessment module evaluates the degree of deviation of the directional gradient of each pixel point in the defect area from the mean value of the directional gradient distribution of the entire area based on the analysis results of the surface defect characteristics of the film material, identifies abnormal pixels, and generates boundary detection results of the surface defect area of the film material.
[0014] Compared with the prior art, the advantages and positive effects of the present invention are: In the present invention, by converting the surface image of the film material into a grayscale image and counting the grayscale frequency, fine grayscale distribution information is obtained, the preliminary regional division of the surface image is achieved, and the positioning accuracy of potential defects is improved. The grayscale distribution entropy value of the local area is used as a defect assessment indicator, combined with a preset distribution threshold to accurately mark the potential defect area, effectively improving the sensitivity of defect detection. By analyzing the grayscale gradient change amplitude, adjusting the size of the defect area and optimizing the defect range, the false detection problem caused by the fixed area size is overcome and the adaptability is enhanced. In the defect area, based on grayscale segmentation technology and boundary feature extraction, the boundary between the defect area and the background area is refined to enhance the clarity of boundary feature recognition. The directional gradient distribution of the defect area is fitted with a normal distribution, the degree of pixel deviation is quantified, abnormal pixels are accurately identified, and the detection error is reduced through Gaussian smoothing to improve the stability of boundary detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 It is a schematic diagram of the workflow of the present invention; Figure 2 A flow chart of obtaining the grayscale distribution of the film material surface image according to the present invention; Figure 3 A flow chart of obtaining the analysis results of a local area on the surface of a membrane material according to the present invention; Figure 4 A flow chart of obtaining an adjusted local area image of a film material surface according to the present invention; Figure 5 A flow chart of obtaining the analysis results of the surface defects of the film material according to the present invention; Figure 6 A flow chart for obtaining deviation evaluation results for the present invention; Figure 7 The present invention is a flow chart for obtaining boundary detection results of defective areas on the surface of a film material. DETAILED DESCRIPTION
[0016] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0017] In the description of the present invention, it should be understood that the terms "length", "width", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, in the description of the present invention, "multiple" means two or more, unless otherwise clearly and specifically defined.
[0018] See also Figure 1 The present invention provides a technical solution: a method for detecting film surface treatment defects based on image recognition, comprising the following steps: S1: Collecting a film material surface image, converting a colored film material surface image into a grayscale image, and counting the frequency of grayscale levels in the grayscale image to obtain grayscale distribution information of the film material surface image, dividing the film material surface image into multiple local areas of the same size, calculating the grayscale distribution entropy value in each local area, and comparing the grayscale distribution entropy value with a preset distribution threshold, marking the local area exceeding the distribution threshold as a potential defect object, and generating a local area analysis result of the film material surface; S2: Based on the analysis results of the local area of the film surface, the local areas marked as potential defect objects are sorted according to the grayscale distribution entropy value. By calculating the change amplitude of the grayscale gradient, the grayscale gradient change in the local area of each potential defect object is analyzed. The grayscale gradient change amplitude is compared with the preset grayscale gradient change threshold. With reference to the grayscale distribution entropy value sorting, the size of the local area of the potential defect object is dynamically adjusted, and the defective area of the potential defect object is screened to obtain the adjusted local area image of the film surface; S3: Based on the adjusted local area image of the film surface, the maximum inter-class variance method is used to process the screened defect area, and the grayscale of the defect area is segmented to distinguish the defect area from the background area, extract the boundary features of the defect area, obtain the pixel direction from the boundary features of the defect area, and obtain the defect feature analysis results of the film surface; S4: Based on the analysis results of the defect characteristics of the film surface, the directional gradient distribution of the pixels in the defect area is fitted with a normal distribution, and the Z score is used to evaluate the degree of deviation of the directional gradient of each pixel point in the defect area from the mean of the directional gradient distribution of the entire area, and the deviation degree evaluation result is obtained. According to the deviation degree evaluation result, the abnormal pixel points that deviate from the mean of the directional gradient distribution are identified, and the abnormal pixel points are Gaussian smoothed to obtain the boundary detection result of the defect area on the surface of the film material; The analysis results of local areas on the membrane surface include a list of identified potential defect areas, a list of grayscale distribution entropy values for each potential defect area, and abnormal markings after comparison with the distribution threshold. The adjusted local area image on the membrane surface includes the grayscale gradient change and the adjusted area size, the grayscale gradient value of the sorted potential defect objects, and the selected defect area. The analysis results of defect features on the membrane surface include the grayscale segmentation data of the defect area, the extracted boundary feature parameters, and detailed information on the pixel direction and amplitude within the defect area. The boundary detection results of defect areas on the membrane surface include the normal distribution parameters for the directional gradient distribution, the Z score value of each pixel after evaluation, and the image features after Gaussian smoothing.
[0019] See also Figure 2 , the steps for obtaining the grayscale distribution of the film surface image are as follows: S111: collecting a film material surface image, extracting color information of each pixel in the film material surface image and performing brightness conversion to generate grayscale data of the film material surface image; The process of collecting the surface image of the membrane material includes loading the color image file through image processing tools such as MATLAB or OpenCV. The common formats are TIFF, JPEG or BMP, converting the color image into a data matrix, and then processing the image by grayscale. The brightness value of the color pixel is extracted to generate the grayscale value. The characteristic texture and details of the membrane surface can be highlighted by adjusting the ratio of the color channel during the grayscale process. At the same time, dynamic adjustment is made according to the overall brightness of the image to optimize the detail performance. A histogram is generated for the processed grayscale image to check whether the grayscale distribution is uniform. If it is too dark or too bright, the grayscale range is stretched to improve the contrast. The processed grayscale image will be stored as a single-channel file for subsequent analysis. If the grayscale image quality is found to be poor, the direction of the acquisition light source can be adjusted or re-acquired to ensure that the surface details are clear and complete.
[0020] S112: Based on the grayscale data of the film surface image, the formula is: ; Calculate gray level Relative frequency of occurrence in the entire film surface image , count the gray level frequency and obtain the gray distribution information of the film surface image; in, The value range is usually from 0 to 255. The number of pixels corresponding to each gray level is determined by counting the gray values of the image pixels. is the gray level in the image The total number of occurrences is obtained by traversing the pixel values of the entire image. is the total number of pixels in the image, indicating the number of all pixels in the image, is the Laplace smoothing parameter, which indicates the smoothing factor introduced in the grayscale statistics to prevent the low-frequency grayscale probability from being zero. It is determined through experiments or data analysis. For example, a set of samples containing a variety of defective and non-defective images is selected, and statistics are performed on different The smoothing effect of the grayscale distribution of the image under the value is finally selected to reduce noise interference and retain feature information at the same time. The experiment includes: setting the grayscale frequency threshold , if the frequency of occurrence of a gray level satisfies: , then the gray level is defined as a low-frequency gray level. Low-frequency gray levels tend to have a probability of zero in traditional probability statistics due to their small number of occurrences, which may mask some tiny but critical defect areas in actual detection. The smoothing factor introduced in low-frequency gray level statistics is used to prevent the low-frequency gray level probability from being zero, thereby avoiding missing these areas.
[0021] If the grayscale image of the film surface is 100×100 pixels, the total number of pixels , pixel count at gray level 150 . Set the grayscale frequency threshold to The initial value of the Laplace smoothing parameter is 00. Calculate the smoothing probability of gray level 150 And determine whether the Laplace smoothing parameters need to be adjusted.
[0022] Compute the unsmoothed frequency of gray level 150: ; The result is less than the gray frequency threshold Therefore, it is judged that the gray level 150 belongs to the low-frequency gray level, and Laplace smoothing processing needs to be introduced.
[0023] Compute the frequency after Laplace smoothing: ; It represents the smoothing probability of gray level 150 in the gray image of the entire film surface, that is, the relative frequency of gray level 150. After Laplace smoothing, this value represents the importance of gray level 150 in the image, avoiding the influence of low frequency or no gray level on the analysis. By counting the frequency of each gray level, specifically including the relative frequency of each gray level , which reflects the distribution characteristics of each gray level in the image.
[0024] See also Figure 3 , the specific steps for obtaining the analysis results of the local area of the membrane surface are: S121: Based on the grayscale distribution information of the film material surface image, the film material surface image is divided into a plurality of local areas of the same size according to a preset fixed size, and pixel range information of the local areas is generated; The process of dividing the film surface image into multiple local areas of the same size can be achieved by using the image processing tool MATLAB, which supports image segmentation and regional analysis. First, the grayscale film image is imported into MATLAB, and the image is evenly divided into multiple local areas according to a rectangular grid by presetting a fixed segmentation size, such as 10×10 pixels. The software automatically calculates the total number of pixels in the image and the pixel range of each grid. For example, for a 100×100 image, a grid of 10 rows and 10 columns is segmented, and the pixel range of each area is (0, 0)-(9, 9), (10, 0)-(19, 9), etc. MATLAB is used to assign a unique number to each local area and generate a boundary coordinate table of the area.
[0025] S122: Based on the pixel range information of the local area, the formula is used: ; Calculate the Grayscale distribution entropy value of local area , get the grayscale distribution entropy value information; in, It is the index of the gray level, which represents a gray value in the gray value range from 0 to 255. is the total number of gray levels, usually 256 (gray levels range from 0 to 255), yes The logarithm of is calculated using the natural logarithm and is used as the contribution value in the entropy formula.
[0026] For the first local region (region 1): total number of pixels , the smoothed probability of gray level 150 , assuming the smoothed probability of gray level 200 , the probability of the remaining gray levels is 0.
[0027] Entropy calculation: ; Take the natural logarithm: ; ; For the second local area (area 2): total number of pixels , assuming the smoothed probability of gray level 100 , the smoothed probability of gray level 250 , the probability of the remaining gray levels is 0 (the probability of the remaining gray levels is not considered).
[0028] Entropy calculation: ; Take the natural logarithm: ; ; S123: comparing the grayscale distribution entropy value information of each local area with a preset distribution threshold, marking the area above the threshold as a potential defect object, and generating a local area analysis result of the film material surface; Compare the grayscale distribution entropy value of each local area with the preset distribution threshold Compare and judge whether it is a potential defect area. Through analysis, the entropy value of area 1 Entropy values of region 1 and region 2 Both are higher than the set distribution threshold. Therefore, both area 1 and area 2 are marked as potential defect areas. Based on the comparison results, a list of analysis results of local areas on the surface of the film material is generated, and the number, entropy value and marking status of each local area are recorded. The analysis results are as follows: Area 1: The entropy value is 0.141, which is higher than the threshold and marked as a potential defect. Area 2: The entropy value is 0.138, which is higher than the threshold and marked as a potential defect. The results show that by calculating the entropy value and comparing the threshold, areas with complex grayscale distribution can be effectively identified, which may have surface defects.
[0029] See also Figure 4 , the steps for acquiring the adjusted local area image of the membrane surface are as follows: S211: based on the analysis results of the local area of the film material surface, extract the grayscale distribution entropy value of the local area marked as the potential defect object, sort the grayscale distribution entropy values in descending order, record the sorting results, and obtain the entropy value sorting list; The local areas marked as potential defect objects are sorted according to the grayscale distribution entropy value. This process involves quantitatively comparing the entropy value of each marked area to ensure the accuracy of the defect detection priority and processing order. The specific operation is to first extract the entropy value of each local area from the generated list of analysis results of local areas on the surface of the film material, such as the entropy value of area 1 is 0.141, and the entropy value of area 2 is 0.138. Subsequently, these entropy values are input into the sorting algorithm, such as using a quick sort or merge sort method, to ensure that they can be quickly and effectively arranged in order from high to low, so as to give priority to areas with high entropy values, which are more complex in grayscale distribution and more likely to hide more serious defects. The sorted order will directly affect the subsequent grayscale gradient analysis and further inspection and processing of potential defect areas, ensuring that attention is paid to those areas that are most likely to have significant defects first.
[0030] S212: Sort the list based on entropy value, using the formula: ; Calculate the pixel Grayscale gradient amplitude at coordinate , get the change amplitude value of gray gradient; in, It is the grayscale change rate of the pixel in the horizontal direction, that is, the x direction, indicating the grayscale value The difference in the x direction is processed using the Sobel operator to obtain the grayscale gradient of each pixel in the x direction. It is the grayscale change rate of the pixel in the vertical direction, that is, the y direction, indicating the grayscale value The difference in the y direction, is the symbol for partial derivative, which is used to express the rate of change of a function of multiple variables with respect to one of the variables.
[0031] For example, if the horizontal gradient of a pixel is , the vertical gradient is .
[0032] Calculate the gradient magnitude: ; ; The results show that the pixels Grayscale gradient amplitude at coordinate for .
[0033] S213: According to the grayscale gradient change amplitude value, by obtaining the grayscale gradient change of each pixel in the local area, and comparing it with the preset grayscale gradient change threshold, combined with the priority of the entropy value sorting list, dynamically adjusting the size of each potential defect local area, and generating an adjusted local area image of the film surface; According to the calculated gray gradient amplitude and the preset gray gradient change threshold For comparison, the grayscale gradient amplitude value Significantly above the threshold , indicating that there is a significant grayscale change in the local area, which may correspond to protrusions, depressions or other physical defects on the surface of the film material. Referring to the sorting of grayscale distribution entropy values, the areas with higher entropy values are analyzed first, such as area 1 (entropy value is 0.141) is determined as the priority analysis object. During the analysis process, the gradient change of area 1 is statistically analyzed by MATLAB, and the pixels whose local gradient amplitude exceeds the threshold are regarded as high gradient points to generate a high gradient point distribution map of the area. This distribution map is used to determine the spatial distribution range of local gradient changes. If the high gradient points are distributed more concentratedly in the local area, the boundary of the local area is dynamically reduced, and the target area is concentrated in the range with higher defect probability; if the high gradient points are distributed more dispersedly, the area range is expanded to ensure that all potential defects are included. For example, in area 1, it is calculated that the high gradient points are mainly distributed in the central part, and the concentration range is about 50% of the original area. Based on this result, the area boundary is dynamically adjusted, and the original 10×10 local area is adjusted to a 5×5 range to reduce the analysis interference of redundant areas. In region 2 (entropy value is 0.138), the distribution of high gradient points is relatively scattered, so the region is expanded to cover a larger area of 15×15 to ensure comprehensive detection. Finally, after dynamic adjustment, MATLAB is used to output the adjusted local area images of the film surface containing more accurate defect information in regions 1 and 2. These adjusted images contain detailed distribution information of high gradient points in the region.
[0034] See also Figure 5 , the specific steps for obtaining the analysis results of the surface defects of the film material are as follows: S311: based on the defective area screened in the adjusted local area image of the film surface, extract the gray value of each pixel in the defective area, calculate the gray distribution, divide the defective part and the background part according to a preset gray segmentation threshold, and obtain a segmented binary image; The maximum inter-class variance method is used to process the screened defective areas. The grayscale of the defective areas is segmented. First, for the marked defective areas, MATLAB is used to extract the grayscale value of each pixel in the area, and the grayscale histogram is statistically calculated. The histogram shows the distribution frequency of the grayscale value in the area. Then the grayscale segmentation function in MATLAB (such as graythresh) is called to analyze the grayscale value of the pixels inside the marked area. The optimal grayscale segmentation threshold inside the area is determined by calculating the inter-class variance of the grayscale histogram. The segmentation process is only for the marked defective area, not the entire image. Finally, the threshold is used to divide the pixels in the defective area into two parts, one is the defective core area, and the other is the background area (the non-core part of the defective area). These segmented results are displayed in a binary image, the pixel value of the core area is set to 1, and the background part is set to 0. The segmentation results are stored in image and data formats for subsequent boundary feature extraction. Through this method, the core part and the secondary part in the marked defective area can be effectively distinguished.
[0035] S312: Based on the segmented binary image, extract the boundary information of the defective part by scanning pixel by pixel, count the distribution, morphology and change characteristics of the boundary, and analyze the shape, curvature and complexity of the boundary to obtain the boundary characteristics of the defective area; The binary image generated by grayscale segmentation uses OpenCV's boundary extraction (such as the findContours method) to obtain the boundary information of the core defect area. The specific operation is to scan the binary image pixel by pixel, determine the set of boundary points of each closed area, and output it in the form of pixel coordinates. Then, by counting the position and distribution of these boundary points, the basic morphological features of the edge, such as boundary length, boundary smoothness, etc., are extracted. Furthermore, the local changes of each boundary point are analyzed, and the local curvature information is extracted by fitting the curve of the boundary point to describe the curvature of the boundary. The analysis of contour complexity is completed by comparing the boundary length and the area of the area. The complexity of the boundary is evaluated by the total number of boundary points, and the compactness of its shape is calculated in combination with the area of the closed area. These boundary features are stored as structured data files (such as CSV or JSON format) and superimposed on the original image in the form of visual graphics to display key boundary features.
[0036] S313: Based on the boundary features of the defect area, the directional information of each pixel is obtained through the directional distribution and geometric characteristics of the defect area, and the film surface defect feature analysis results are generated; The pixel direction is obtained from the boundary features of the defect area to extract the analysis results of the surface defect features of the film material. First, the cv2.Sobel function in OpenCV is used to process the boundary of the defect area that has been determined. This function can calculate the horizontal and vertical gradients of the image boundary pixels to obtain the direction information of each boundary pixel. By synthesizing the horizontal and vertical gradients, a direction vector is calculated for each pixel, indicating the maximum direction of the grayscale change of the pixel. Next, the horizontal and vertical components of the gradient are converted into angles through cv2.phase to obtain the direction angle of each pixel. These angle values reflect the local geometric direction of the defect boundary and help understand the characteristics of the defect morphology. In addition, the statistical analysis of the angle distribution can further reveal the overall structural arrangement and pattern of the defect area, such as whether there is a specific texture or arrangement tendency.
[0037] See also Figure 6 , the specific steps for obtaining the deviation degree assessment results are as follows: S411: Based on the analysis results of the surface defects of the film material, the directional gradient information of each pixel in the defect area is obtained, and after being integrated into one-dimensional data, normal distribution fitting is performed on it to generate fitting results of directional gradient trend and fluctuation degree; First, MATLAB is used to extract the directional gradient value of each pixel in the defect area. These gradient values are calculated by horizontal and vertical gradient components. After all gradient values are sorted into a one-dimensional data set, the data is fitted with a normal distribution using MATLAB's statistical tools. The mean and standard deviation of the directional gradient distribution are calculated through the fitting process. These two indicators reflect the concentration trend and fluctuation degree of the directional gradient of the entire defect area. After the fitting is completed, the probability density curve of the gradient distribution is generated and visualized, and the mean, standard deviation and fitting curve parameters are saved.
[0038] S412: Based on the fitting results of the directional gradient trend and the fluctuation degree, the deviation degree of each directional gradient value from the distribution mean is analyzed, and the deviation degree is standardized into a Z score, abnormal pixel points are screened, and a deviation degree evaluation result is generated; By reading the fitted distribution mean and standard deviation, the directional gradient value of each pixel is normalized. The gradient value is subtracted from the distribution mean and divided by the standard deviation to obtain the Z score of the pixel. Subsequently, the Z scores of all pixels are calculated according to the set anomaly detection threshold (such as ) to classify and mark the pixels that meet the conditions as abnormal pixels. After the classification is completed, MATLAB is used to superimpose the abnormal pixels on the original defect area image to generate a color image with abnormal pixels marked, and the coordinates of the abnormal pixels and their corresponding Z score list are output at the same time.
[0039] See also Figure 7, the specific steps for obtaining the boundary detection results of the defective area on the surface of the film material are: S421: Based on the deviation assessment results, the formula is used: ; Calculate smoothed coordinates The pixel value at , and obtain the Gaussian smoothing result; in, Used to replace the original pixel value and represent the result after Gaussian smoothing. Indicates the neighborhood is the center and the radius is All pixels are weighted and accumulated. is the relative position in the Gaussian kernel The weight value describes the weight of the Gaussian distribution at this point. The Gaussian kernel weight is obtained by the following formula: , is the standard deviation of the Gaussian distribution, which determines the strength of smoothing and is determined by experimental optimization. Preserve more details, larger Enhance the smoothing effect and determine the appropriate value by analyzing the treatment effect of the film surface defect samples. It is the base of the natural logarithm and the core of the exponential decay part in the Gaussian distribution formula. It is used to describe the characteristic that the farther the pixel position is from the center, the lower the weight value. is the relative position in the original image The pixel value represents the grayscale value of each pixel in the neighborhood, and the grayscale value of the corresponding coordinate is directly read from the image. is the relative position index of the Gaussian kernel, describing the displacement relative to the center pixel, for example and are the horizontal and vertical offsets respectively, is the radius of the Gaussian kernel, which determines the size of the neighborhood. For example express The nuclear range, are the coordinates of the currently processed pixel in the image.
[0040] For example, if a The pixels in the neighborhood are processed, and the Gaussian kernel weights and original pixel grayscale values are as follows: Gaussian kernel weights: , original pixel gray value Calculate the center pixel Smoothed value of : Multiply the grayscale value at the corresponding position by the weight and sum them: ; ; Smoothed pixel grayscale value , reducing the abnormal fluctuations caused by isolated noise points (such as the influence of grayscale value 105).
[0041] S422: Based on the Gaussian smoothing result, the change of the grayscale gradient is determined by scanning pixel by pixel, the coordinates of the pixel points where the gradient changes significantly are recorded, and the coordinates of the pixel points are connected to form a continuous boundary contour to obtain the boundary detection result of the defect area on the surface of the film material; Based on the pixel values at each coordinate after smoothing, the boundary detection of the defective area on the surface of the film material is performed. First, the smoothed image data is read, and the area where the grayscale value changes in the image is scanned pixel by pixel. Specifically, the grayscale gradient change value of the pixels in the neighborhood is compared to determine whether the pixel is at the boundary position. For each pixel, its gradient value can be calculated by the difference in the grayscale values of the pixels in the neighborhood. The area with a larger gradient usually corresponds to the boundary of the surface defect of the film material. In order to determine the specific position of the boundary pixel, the coordinates of the pixel points whose gradient values are significantly higher than the preset threshold are recorded by row-by-row and column-by-column scanning, and a continuous boundary contour is formed based on these coordinates. By optimizing the scanning range and threshold setting, the accuracy and stability of boundary detection can be improved. The detected boundary information is stored as a set of coordinate points and can be superimposed on the original image for visualization, which is convenient for checking the accuracy of the boundary extraction result. Finally, the boundary detection result is saved in the form of structured data, including the coordinates of each boundary pixel and the gradient characteristics of its neighborhood.
[0042] The film material surface treatment defect detection system based on image recognition is used to execute the above-mentioned film material surface treatment defect detection method based on image recognition. The system includes: The image acquisition module collects the surface image of the film material, converts the image into a grayscale image, counts the frequency of each grayscale level in the grayscale image, and generates grayscale distribution information; The local analysis module divides the film surface image into multiple local areas of the same size based on the grayscale distribution information, calculates the grayscale distribution entropy value of each area, and generates the analysis results of the local area of the film surface; The defect location module sorts the grayscale distribution entropy values of the areas marked as potential defects based on the analysis results of the local area of the film surface, analyzes the grayscale gradient changes of each area, dynamically adjusts the area size, and obtains the adjusted local area image of the film surface; The feature extraction module analyzes the screened defect area based on the adjusted local area image of the film surface, distinguishes the defect and background area, extracts the pixel direction from the boundary features of the defect area, and obtains the defect feature analysis results of the film surface; The boundary assessment module is based on the analysis results of the surface defect characteristics of the film material, evaluates the degree of deviation of the directional gradient of each pixel in the defect area from the mean of the directional gradient distribution of the entire area, identifies abnormal pixels, and generates boundary detection results for the surface defect area of the film material.
[0043] The above are only preferred embodiments of the present invention and are not intended to limit the present invention in other forms. Any technician familiar with the profession may use the technical contents disclosed above to change or modify them into equivalent embodiments with equivalent changes and apply them to other fields. However, any simple modification, equivalent change and modification made to the above embodiments based on the technical essence of the present invention without departing from the technical solution of the present invention still falls within the protection scope of the technical solution of the present invention.
Claims
1. A film surface treatment defect detection method based on image recognition, characterized in that: The following steps are involved: Collect the surface image of the film material, count the frequency of gray levels in the gray image, obtain the gray distribution information of the surface image of the film material, divide the surface image of the film material into multiple local areas of the same size, calculate the gray distribution entropy value in each local area, and generate the analysis results of the local area of the surface of the film material; Based on the analysis result of the local area of the film material surface, the local areas marked as potential defect objects are sorted according to the grayscale distribution entropy value, the grayscale gradient change in the local area of each potential defect object is analyzed, and the size of the local area of the potential defect object is dynamically adjusted to obtain an adjusted local area image of the film material surface; Based on the adjusted local area image of the film material surface, the screened defect area is processed to distinguish the defect area from the background area, and the pixel direction is obtained from the boundary features of the defect area to obtain the film material surface defect feature analysis result; Based on the analysis results of the surface defect characteristics of the film material, the deviation degree of the directional gradient of each pixel point in the defect area from the directional gradient distribution mean of the entire area is evaluated, and abnormal pixel points that deviate from the directional gradient distribution mean are identified to obtain the boundary detection results of the defect area on the surface of the film material.
2. The film surface treatment defect detection method based on image recognition according to claim 1 is characterized in that: The steps for obtaining the grayscale distribution of the film surface image are specifically as follows: Collect the film material surface image, extract the color information of each pixel in the film material surface image and convert the brightness to generate the grayscale data of the film material surface image; Based on the grayscale data of the film surface image, the formula is used: ; Calculate gray level Relative frequency of occurrence in the entire film surface image , count the gray level frequency and obtain the gray distribution information of the film surface image; in, is the gray level in the image The total number of occurrences, is the total number of pixels in the image, is the Laplace smoothing parameter.
3. The film surface treatment defect detection method based on image recognition according to claim 2 is characterized in that: The steps for obtaining the analysis results of the local area of the membrane surface are specifically as follows: Based on the grayscale distribution information of the film material surface image, the film material surface image is divided into a plurality of local areas of the same size according to a preset fixed size, and pixel range information of the local areas is generated; Based on the pixel range information of the local area, the formula is adopted: ; Calculate the Grayscale distribution entropy value of local area , get the grayscale distribution entropy value information; in, is the index of gray level, is the total number of gray levels, yes The logarithm of ; The grayscale distribution entropy value information of each local area is compared with a preset distribution threshold, and the area above the threshold is marked as a potential defect object, and the analysis result of the local area of the film material surface is generated.
4. The method for detecting film surface treatment defects based on image recognition according to claim 3, characterized in that: The steps for acquiring the adjusted local area image of the film surface are specifically as follows: Based on the analysis results of the local area of the film material surface, extract the grayscale distribution entropy value of the local area marked as the potential defect object, sort the grayscale distribution entropy values in order from high to low, record the sorting results, and obtain the entropy value sorting list; Based on the entropy value sorted list, the formula is adopted: ; Calculate the pixel Grayscale gradient amplitude at coordinate , get the change amplitude value of gray gradient; in, It is the grayscale change rate of the pixel in the horizontal direction, that is, the x direction. It is the grayscale change rate of the pixel in the vertical direction, that is, the y direction; According to the grayscale gradient change amplitude value, by obtaining the grayscale gradient change of each pixel point in the local area and comparing it with the preset grayscale gradient change threshold, combined with the priority of the entropy value sorting list, the size of each potential defect local area is dynamically adjusted to generate an adjusted local area image of the membrane surface.
5. The method for detecting film surface treatment defects based on image recognition according to claim 4, characterized in that: The steps for obtaining the analysis results of the surface defects of the film material are specifically as follows: Based on the defective area screened in the adjusted local area image of the film material surface, the grayscale value of each pixel in the defective area is extracted, the grayscale distribution is statistically analyzed, and the defective part and the background part are divided according to a preset grayscale segmentation threshold to obtain a segmented binary image; Based on the segmented binary image, the boundary information of the defective part is extracted by scanning pixel by pixel, the distribution, morphology and change characteristics of the boundary are counted, and the shape, curvature and complexity of the boundary are analyzed to obtain the boundary characteristics of the defective area; Based on the boundary features of the defect area, the directional information of each pixel is obtained through the directional distribution and geometric characteristics of the defect area to generate a film material surface defect feature analysis result.
6. The method for detecting film surface treatment defects based on image recognition according to claim 5, characterized in that: The steps for obtaining the deviation degree evaluation result are specifically as follows: Based on the analysis results of the surface defect characteristics of the film material, the directional gradient information of each pixel in the defect area is obtained, and after being integrated into one-dimensional data, normal distribution fitting is performed to generate fitting results of the directional gradient trend and fluctuation degree; Based on the fitting results of the directional gradient trend and fluctuation degree, the deviation degree of each directional gradient value from the distribution mean is analyzed, and the deviation degree is standardized into a Z score, abnormal pixels are screened, and a deviation degree evaluation result is generated.
7. The film surface treatment defect detection method based on image recognition according to claim 6 is characterized in that: The steps for obtaining the boundary detection result of the defect area on the surface of the film material are specifically as follows: Based on the deviation evaluation results, the formula is used: ; Calculate smoothed coordinates The pixel value at , and obtain the Gaussian smoothing result; in, is the relative position in the Gaussian kernel The weight value of is the relative position in the original image The pixel value of is the relative position index of the Gaussian kernel, is the radius of the Gaussian kernel, are the coordinates of the currently processed pixel in the image; Based on the Gaussian smoothing result, the change of the grayscale gradient is determined by scanning pixel by pixel, the coordinates of the pixel points where the gradient changes are recorded, and the coordinates of the pixel points are connected to form a continuous boundary contour to obtain the boundary detection result of the defective area on the surface of the film material.
8. The film surface treatment defect detection system based on image recognition is characterized by: According to the method for detecting film surface treatment defects based on image recognition according to any one of claims 1 to 7, the system comprises: The image acquisition module collects the surface image of the film material, converts the image into a grayscale image, counts the frequency of each grayscale level in the grayscale image, and generates grayscale distribution information; The local analysis module divides the film material surface image into a plurality of local areas of the same size based on the grayscale distribution information, calculates the grayscale distribution entropy value of each area, and generates a local area analysis result of the film material surface; The defect location module sorts the areas marked as potential defects by grayscale distribution entropy value based on the analysis results of the local area of the film material surface, analyzes the grayscale gradient change of each area, dynamically adjusts the area size, and obtains an adjusted local area image of the film material surface; The feature extraction module analyzes the screened defect area based on the adjusted local area image of the film surface, distinguishes the defect and the background area, extracts the pixel direction from the boundary feature of the defect area, and obtains the defect feature analysis result of the film surface; The boundary assessment module evaluates the degree of deviation of the directional gradient of each pixel point in the defect area from the mean value of the directional gradient distribution of the entire area based on the analysis results of the surface defect characteristics of the film material, identifies abnormal pixels, and generates boundary detection results of the surface defect area of the film material.
Citation Information
Patent Citations
PCB apparent defect automatic detection system and method based on image
CN107389701A
Production quality detection method suitable for chip circuit board
CN114926463A
Road quality identification and detection method
CN115457041A
Surface defect identification method based on anti-creeping insulating material
CN116309561A
Soldering tin defect intelligent detection method and system based on machine vision
CN119205636A
Cited By
Stain detection method for fresh egg cleaning
CN120259310A
Photovoltaic module defect detection method and system based on image recognition
CN120807422A
A photovoltaic module defect detection method and system based on image recognition
CN120807422B
Non-woven fabric surface defect detection method and system
CN120807498A
Methods and systems for detecting surface defects in nonwoven fabrics
CN120807498B