Surface defect detection method and system based on feature extraction and sparse representation
By employing feature extraction and sparse representation methods, this approach addresses the reliance on manually labeled data in existing technologies, enabling real-time and accurate defect detection and classification on industrial production lines. It is applicable to industrial surface defect detection in diverse scenarios.
Patent Information
- Application Number
- CN202311250049.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-25
- Publication Date
- 2026-02-03
- Estimated Expiration
- 2043-09-25
AI Technical Summary
Existing defect detection technologies require a large amount of manually labeled data and are difficult to implement quickly and accurately in industrial production for defect detection, location and classification, especially in environments with changing scenarios.
This paper adopts a feature extraction and sparse representation-based approach. It extracts image features through a deep convolutional neural network, optimizes and sparsely encodes them using dictionary learning methods in sparse representation, calculates defect scores and performs post-processing to achieve defect detection, localization and classification.
It reduces the reliance on manually labeled data, enables real-time and accurate defect detection and classification on industrial production lines, and is suitable for industrial surface defect detection in various scenarios, with high efficiency, accuracy and robustness.
Smart Images

Figure CN117314855B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of defect detection technology, and more specifically, to a surface defect detection method and system based on feature extraction and sparse representation. Background Technology
[0002] In industrial production and manufacturing processes, defect detection and identification are crucial. The presence of defects can lead to decreased product quality, safety hazards, and production line downtime, causing significant losses to enterprises. Therefore, efficient and accurate defect detection and location are essential for ensuring product quality and production efficiency. Furthermore, defect classification helps enterprises quickly identify and resolve the problems caused by defects, thereby safeguarding the company's interests.
[0003] In recent years, image processing and analysis-based defect detection technologies have made significant progress. These technologies utilize digital image acquisition equipment to obtain image data of product surfaces and then perform defect detection through image processing and analysis algorithms. However, traditional image processing-based defect detection methods still face some challenges and limitations in practical applications.
[0004] Currently, many defect detection models rely on target detection technologies, especially deep learning-based methods such as YOLO (You Only Look Once) and Faster R-CNN (Region-based Convolutional Neural Networks). While these technologies can efficiently detect and locate defects, they require a large amount of labeled data to train the network model. In industrial applications with varying scenarios, the high cost of manually labeled data, high yield rates in industrial production, and the scarcity of defect samples prevent the widespread application of these technologies.
[0005] Therefore, how to make full use of the effective features extracted by deep neural networks to quickly and accurately detect, locate and classify defects is an urgent problem to be solved.
[0006] Chinese patent document CN115880209A discloses a surface defect detection system for steel plates, comprising: a dataset module for acquiring steel plate surface image data and preprocessing the image data to form an image dataset; a training module for training a defect detection model based on a Faster R-CNN object detection model using the acquired image dataset, and optimizing it specifically for the morphological features and size of steel plate defects; and an inference module for acquiring images of the steel plate production line transmitted from the dataset module at the edge side using the trained defect detection model and performing model inference. However, this patent document has shortcomings in that it requires a large amount of manually labeled data for training, and can only provide bounding rectangles of the defect area, failing to provide pixel-level detection results or accurately quantify the defect area, thus failing to solve the aforementioned problems.
[0007] Chinese patent document CN116228754A discloses a surface defect detection method based on deep learning and global differential information. The method includes: constructing a benchmark sample set and a normal training sample set from the training set of the original dataset; fitting a multivariate Gaussian distribution to the features of the benchmark sample set to obtain the mean and covariance corresponding to different patches on the sample images; calculating the Mahalanobis distance between the features of each sample in the normal training sample set and the corresponding mean and covariance fitted by the benchmark sample set to obtain a global differential information map; finally, fusing this map with the corresponding sample image representation from the normal training sample set to obtain the final input data; inputting this data into a segmentation network to output a defect score map; and constructing a loss function to train the network model. However, this patent document has a shortcoming: all its features are based on the assumption that they are generated by a multivariate Gaussian distribution, which is uncertain; and it can only detect and locate defects, not perform defect classification tasks, thus failing to solve the aforementioned problems. Summary of the Invention
[0008] To address the shortcomings of existing technologies, the purpose of this invention is to provide a surface defect detection method and system based on feature extraction and sparse representation.
[0009] A surface defect detection method based on feature extraction and sparse representation according to the present invention includes:
[0010] Step S1: Acquire image data of the target surface and perform preprocessing;
[0011] Step S2: Use a deep convolutional neural network to extract features from the image data to obtain a feature map;
[0012] Step S3: Train the image data, refine and optimize the extracted features, and learn the dictionary;
[0013] Step S4: Based on the dictionary, perform sparse coding on the features of the image data, and calculate the defect score and reconstruction error;
[0014] Step S5: Obtain the defect fraction map based on the reconstruction error, perform post-processing on the defect fraction map, and obtain the defect detection result.
[0015] Preferably, step S1 includes the following sub-steps:
[0016] Step S1.1: Use a digital image acquisition device to acquire image data of the target surface, and perform image correction according to preset parameters;
[0017] Step S1.2: Preprocess the corrected image data, including scaling, cropping, and regularization, to obtain image data that can be processed by the convolutional neural network.
[0018] Preferably, step S2 includes the following sub-steps:
[0019] Step S2.1: Use a deep convolutional neural network to extract multi-scale features from the image data. Input the image data into the pre-trained convolutional neural network and use the output of multiple convolutional blocks in the convolutional neural network as feature maps.
[0020] Step S2.2: Fuse the feature maps output by different convolutional blocks; the fusion includes: using interpolation to scale feature maps with a resolution less than a preset value to be equal to the feature map with the highest resolution; and stitching the feature maps output by multiple convolutional blocks along the channel dimension to obtain the final feature map.
[0021] Preferably, step S3 includes the following sub-steps:
[0022] Step S3.1: Extract the feature map according to the channel dimension as a feature vector;
[0023] Step S3.2: Use the dictionary learning method in sparse representation to optimize and refine the features and generate a dictionary.
[0024] Preferably, step S4 includes the following sub-steps:
[0025] Step S4.1: The dictionary performs sparse representation and reconstruction on the feature vector to obtain the sparse coding vector of the feature vector, and calculates the reconstruction error;
[0026] Step S4.2: Arrange the reconstruction errors according to the relative positions of the feature vectors in the feature map to form a reconstruction error map;
[0027] Step S4.3: Obtain the defect score based on the sparse coding vector and the transformation matrix obtained during dictionary learning; arrange the defect scores according to the relative positions of the feature vectors in the feature map to form a defect score map.
[0028] Preferably, step S5 includes the following sub-steps:
[0029] Step S5.1: Take the maximum value in the defect score map as the defect score of the image data to be tested; set a threshold τ. When the defect score is less than the threshold τ, it is determined that there is no defect in the image to be tested, and the detection result is output; when the defect score is greater than the threshold τ, it is determined that there is a defect in the image to be tested, and step S5.2 is executed.
[0030] Step S5.2: Scale the defect fraction map to the same resolution as the image to be tested, and obtain the defect region after binary segmentation;
[0031] Step S5.3: Based on the defect areas obtained in step S5.2, calculate the pixel coordinates of all defect areas to obtain the position of the defect in the image under test; based on the position of the received image under test coverage area in the entire product, calculate the position of the defect in the entire product.
[0032] Step S5.4: Based on the defect area obtained in step S5.2, count the number of pixels in the defect area; combine the image to be tested and the size ratio of the area it covers to the product to calculate the size of the defect.
[0033] Step S5.5: Based on the defect area obtained in step S5.2 and the set threshold τ, if a defect area exists and there is a defect score in the area that is greater than the threshold τ, then the category with the largest defect score is the defect category of the area; if all defect scores in the defect area are lower than the threshold τ, then it is determined to be an unknown category defect.
[0034] A surface defect detection system based on feature extraction and sparse representation according to the present invention includes:
[0035] Module M1: Acquires image data of the target surface and performs preprocessing;
[0036] Module M2: Uses a deep convolutional neural network to extract features from image data to obtain feature maps;
[0037] Module M3: Training image data, refining and optimizing the extracted features, and learning to obtain a dictionary;
[0038] Module M4: Based on the dictionary, sparsely encodes the features of the image data and calculates the defect score and reconstruction error;
[0039] Module M5: Obtains a defect fraction map based on the reconstruction error, performs post-processing on the defect fraction map, and obtains the defect detection results.
[0040] Preferably, module M1 includes the following sub-modules:
[0041] Module M1.1: Uses digital image acquisition equipment to acquire image data of the target surface and performs image correction according to preset parameters;
[0042] Module M1.2: Preprocesses the corrected image data, including scaling, cropping, and regularization, to obtain image data that can be processed by the convolutional neural network.
[0043] Preferably, module M2 includes the following sub-modules:
[0044] Module M2.1: Uses a deep convolutional neural network to extract multi-scale features from image data. The image data is input into a pre-trained convolutional neural network, and the output of multiple convolutional blocks in the convolutional neural network is used as a feature map.
[0045] Module M2.2: Fusion of feature maps output by different convolutional blocks; the fusion includes: using interpolation to scale feature maps with resolutions lower than a preset value to be equal to the feature map with the highest resolution; and concatenating feature maps output by multiple convolutional blocks according to the channel dimension to obtain the final feature map.
[0046] Preferably, module M3 includes the following sub-modules:
[0047] Module M3.1: Extracts the feature map as a feature vector according to the channel dimension;
[0048] Module M3.2: Uses dictionary learning methods in sparse representation to optimize and refine features and generate a dictionary.
[0049] Preferably, module M4 includes the following sub-modules:
[0050] Module M4.1: The dictionary performs sparse representation and reconstruction of the feature vectors to obtain the sparse encoded vectors of the feature vectors and calculates the reconstruction error;
[0051] Module M4.2: Arranges the reconstruction errors according to the relative positions of the feature vectors in the feature map to form a reconstruction error map;
[0052] Module M4.3: Based on the sparse coding vector and the transformation matrix obtained during dictionary learning, the defect scores are obtained; the defect scores are arranged according to the relative positions of the feature vectors in the feature map to form a defect score map.
[0053] Preferably, module M5 includes the following sub-modules:
[0054] Module M5.1: Take the maximum value in the defect score map as the defect score of the image data to be tested; set a threshold τ, when the defect score is less than the threshold τ, determine that there is no defect in the image to be tested and output the detection result; when the defect score is greater than the threshold τ, determine that there is a defect in the image to be tested and execute step S5.2.
[0055] Module M5.2: Scales the defect fraction map to the same resolution as the image under test, and obtains the defect region after binary segmentation;
[0056] Module M5.3: Based on the defect areas obtained from module M5.2, calculate the pixel coordinates of all defect areas to obtain the position of the defect in the image under test; based on the position of the received image under test coverage area in the entire product, calculate the position of the defect in the entire product.
[0057] Module M5.4: Based on the defect area obtained from module M5.2, count the number of pixels in the defect area; combine the image to be tested and the size ratio of the area it covers to the product to calculate the size of the defect;
[0058] Module M5.5: Based on the defect area obtained from module M5.2 and the set threshold τ, if a defect area exists and there is a defect score in the area that is greater than the threshold τ, then the category with the highest defect score is the defect category of the area; if all defect scores in the defect area are lower than the threshold τ, then it is determined to be an unknown category defect.
[0059] Compared with the prior art, the present invention has the following beneficial effects:
[0060] 1. The method and system provided by this invention do not require a large amount of manual data annotation. They can detect the location, size and type of defects simultaneously with only a small number of defect-free data samples for training, which reduces costs, improves work efficiency and has good generalization and practicality.
[0061] 2. The method and system provided by this invention treat defects as a rare anomaly for detection, and can simultaneously complete the tasks of defect detection, location, quantification and classification. It can also distinguish unseen defect categories and can be widely applied in the field of industrial surface defect detection with diverse scenarios.
[0062] 3. The method and system provided by this invention can be easily deployed on industrial production lines and simultaneously possess real-time performance, accuracy, and robustness.
[0063] Other beneficial effects of the present invention will be explained in detail through the introduction of specific technical features and technical solutions in specific embodiments. Those skilled in the art should be able to understand the beneficial technical effects brought about by these technical features and technical solutions through the introduction of these technical features and technical solutions. Attached Figure Description
[0064] Other features, objects, and advantages of the present invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:
[0065] Figure 1 This is a flowchart of the surface defect detection method based on feature extraction and sparse representation in this embodiment. Detailed Implementation
[0066] The present invention will now be described in detail with reference to specific embodiments. These embodiments will help those skilled in the art to further understand the present invention, but do not limit the invention in any way. It should be noted that those skilled in the art can make several changes and improvements without departing from the concept of the present invention. These all fall within the protection scope of the present invention.
[0067] Reference Figure 1 As shown, a surface defect detection method based on feature extraction and sparse representation includes:
[0068] First, image data of the target surface is acquired using a digital image acquisition device, and image correction is performed according to preset parameters. The corrected image data undergoes preprocessing including scaling, cropping, and regularization to obtain image data that can be processed by a convolutional neural network.
[0069] Next, a deep convolutional neural network is used to extract multi-scale features from the image data. The image data is then input into the pre-trained convolutional neural network, and the outputs of multiple convolutional blocks in the convolutional neural network are used as feature maps. Then, the feature maps output by different convolutional blocks are fused together, and the feature maps output by multiple convolutional blocks are concatenated according to the channel dimension to obtain the final feature map.
[0070] The specific operation of fusion is as follows: using interpolation, feature maps with a resolution smaller than a preset value are scaled to be equal to the feature map with the highest resolution.
[0071] Feature maps are extracted based on the channel dimension and used as feature vectors. Dictionary learning methods in sparse representation are used to optimize and refine the features to generate a dictionary.
[0072] First, the features of the image data are sparsely encoded, and the defect score and reconstruction error are calculated. Then, the reconstruction errors are arranged according to the relative positions of the feature vectors in the feature map to form a reconstruction error map.
[0073] In the sparse coding vector and dictionary learning process, the transformation matrix is obtained first, followed by the defect score. The defect scores are arranged according to the relative positions of the feature vectors in the feature map to form a defect score map. The maximum value in the defect score map is taken as the defect score of the image data to be tested, and a threshold τ is set. When the defect score is less than the threshold τ, it is determined that there is no defect in the image to be tested, and the detection result is output; when the defect score is greater than the threshold τ, it is determined that there is a defect in the image to be tested, and the defect score map is scaled to the same resolution as the image to be tested, and the defect region is obtained after binary segmentation.
[0074] Calculate the pixel coordinates of all defective regions to obtain the location of the defect in the image under test. Based on the location of the area covered by the received image under test within the entire product, the location of the defect within the entire product is then calculated.
[0075] The size of the defect is calculated by counting the number of pixels in the defective area and combining this with the size ratio of the image under test and the area of the product it covers.
[0076] Finally, based on the defect area and the set threshold τ, if a defect area exists and there is a defect score in that area that is greater than the threshold τ, then the category with the highest defect score is the defect category of that area; if all defect scores in the defect area are lower than the threshold τ, then it is determined to be an unknown category defect.
[0077] The above are basic embodiments of the present invention. The technical solution of the present invention will be further described below through a preferred embodiment.
[0078] Reference Figure 1 As shown, a high-speed CMOS camera is used to acquire high-resolution surface image data on the production line. The image data is transmitted to the camera controller via cable, where image correction is performed according to preset parameters to obtain corrected image data. Correction can employ gamma correction or PRUNC correction.
[0079] Next, the corrected image data is preprocessed, including scaling, cropping, and regularization.
[0080] We can obtain image data I that can be processed by a convolutional neural network, with dimensions of 3*W*H. Here, 3 represents the number of channels, and W and H represent the horizontal and vertical resolutions, respectively.
[0081] Specifically, scaling involves adjusting the image size by shrinking or enlarging it to fit the network's input requirements. Interpolation methods can be used to redistribute the image's pixel values to the new dimensions, ensuring the image has uniform size in both width and height.
[0082] The cropping operation involves selecting the region of interest from the image and removing the unwanted parts.
[0083] Cropping allows you to focus on a target area within an image and remove surrounding background or other irrelevant information. Cropping helps extract and preserve key features from an image while reducing irrelevant noise or interference.
[0084] Regularization is an operation that normalizes image data to give it similar statistical properties. Common regularization methods include normalizing the pixel values of an image to a range of 0 to 1, or standardizing using the mean and variance. Regularization can help reduce the differences between image data and improve the stability of the model.
[0085] Then, a deep convolutional neural network is used to extract multi-scale features. The image data is input into a pre-trained convolutional neural network, such as the ResNet series or lightweight networks like ShuffleNet. The outputs of multiple convolutional blocks in the convolutional neural network are taken as feature maps. For example, feature map F1 from the first convolutional block is taken, with dimensions C1*W1*H1; feature map F2 from the second convolutional block is taken, with dimensions C2*W2*H2. Here, C1 and C2 represent the number of feature maps and the number of channels, respectively; W1 and W2 represent the horizontal resolution of the feature maps, and H1 and H2 represent the vertical resolution of the feature maps. Generally, in deep convolutional neural networks, the resolution of shallow features is greater than that of deep features, i.e., W1 > W2 and H1 > H2.
[0086] To achieve the fusion of feature maps output by different convolutional blocks: First, the resolution of the feature map with smaller resolution is scaled up to be equal to that of the feature map with the largest resolution by interpolation. Then, the feature maps output by multiple convolutional blocks are spliced together according to the channel dimension to obtain the final feature map F, which has a size of C*W1*H1, where C=C1+C2.
[0087] The obtained feature map is extracted along the channel dimension and used as the feature vector y. i y i ∈R C Each image yields a feature map F, which can generate W1*H1 feature vectors. Each feature vector corresponds to a small region in the image data, thus dividing the image into W1*H1 small image blocks with some overlap.
[0088] Next, the dictionary learning method in sparse representation is used to optimize and refine the features to generate a dictionary.
[0089] Specifically, the feature vectors obtained from the training data are used as the training dataset Y = [y1y2,…,y]. m ]∈R C×m Meanwhile, let the dictionary D = [d1d2, ..., d... m ]∈R C×pLet X = [x1, x2, ..., xn] be the sparse representation vector matrix of the training data. m ]∈R p ×m .
[0090] Describe the dictionary learning process as st||x i ||0≤T0i=1,2,…,m.
[0091] Here, μ is a number greater than zero, F represents the Frobenius norm, and the optimization problem is solved using an optimization algorithm to obtain a dictionary D and a transformation matrix C. A separate dictionary is constructed for each class of feature vectors, with n-1 defect types, plus one class of no defects, for a total of n classes, i.e., n dictionaries are learned; H is the class label matrix of the training samples.
[0092] During testing, the same operations described above are applied to the image data to be tested to obtain the feature vector y. i y i ∈R C and the sparse encoding vector x of the feature vector i x i ∈R p And calculate the reconstruction error e i .
[0093] The reconstruction errors are arranged according to the relative positions of the feature vectors in the feature map to form a reconstruction error map. Its size is n*W1*H1, where n is the number of label categories. The defect score map S is obtained by calculating the reconstruction error map, and its size is n*W1*H1, where n represents the number of defect types (n-1), plus one no-defect category, for a total of n label categories.
[0094] Based on the sparse coding vector x i And the transformation matrix C yields y i Defect score l i The calculation formula is l i =Cx i ∈R n .
[0095] Similarly, the defect scores are arranged according to the relative positions of the feature vectors in the feature map to form a defect score map S with a size of n*W1*H1, where n represents the number of defect types n-1. In addition, there is a no-defect category, for a total of n categories of labels.
[0096] Finally, the maximum value s in the defect score map S is... maxThe defect score is used as the defect score of the image data to be tested, and a threshold t is set. When the defect score is less than the threshold, it is determined that there is no defect in the image to be tested, and the detection result is output. When the defect score is greater than the threshold, it is determined that there is a defect in the image to be tested. The defect score map is scaled to the same resolution as the image to be tested, and then binary segmentation is performed on it to obtain the defect region.
[0097] After calculating the pixel coordinates of all defective areas, the location of the defect in the image under test is obtained. Simultaneously, the location of the area covered by the image under test within the entire product can also be received, allowing for the calculation of the defect's location within the entire product.
[0098] The size of the defect is calculated by counting the number of pixels in the defective area and combining this with the size ratio of the image to be tested and the area of the product it covers.
[0099] Based on the set threshold τ, if a defective region exists, and there is a defect score in that region that is greater than the threshold τ, then the category with the highest defect score is the defect category of that region; if the defect scores of all defective regions are lower than the threshold τ, then they are determined to be defects of unknown category.
[0100] The present invention also provides a surface defect detection system based on feature extraction and sparse representation. The surface defect detection system based on feature extraction and sparse representation can be implemented by executing the process steps of the surface defect detection method based on feature extraction and sparse representation. That is, those skilled in the art can understand the surface defect detection method based on feature extraction and sparse representation as a preferred embodiment of the surface defect detection system based on feature extraction and sparse representation.
[0101] Specifically, a surface defect detection system based on feature extraction and sparse representation includes:
[0102] Module M1: Acquires image data of the target surface and performs preprocessing;
[0103] Module M2: Uses a deep convolutional neural network to extract features from image data to obtain feature maps;
[0104] Module M3: Training image data, refining and optimizing the extracted features, and learning to obtain a dictionary;
[0105] Module M4: Based on the dictionary, sparsely encodes the features of the image data and calculates the defect score and reconstruction error;
[0106] Module M5: Obtains a defect fraction map based on the reconstruction error, performs post-processing on the defect fraction map, and obtains the defect detection results.
[0107] The module M1 includes the following sub-modules:
[0108] Module M1.1: Uses digital image acquisition equipment to acquire image data of the target surface and performs image correction according to preset parameters;
[0109] Module M1.2: Preprocesses the corrected image data, including scaling, cropping, and regularization, to obtain image data that can be processed by the convolutional neural network.
[0110] Preferably, module M2 includes the following sub-modules:
[0111] Module M2.1: Uses a deep convolutional neural network to extract multi-scale features from image data. The image data is input into a pre-trained convolutional neural network, and the output of multiple convolutional blocks in the convolutional neural network is used as a feature map.
[0112] Module M2.2: Fusion of feature maps output by different convolutional blocks; the fusion includes: using interpolation to scale feature maps with resolutions lower than a preset value to be equal to the feature map with the highest resolution; and concatenating feature maps output by multiple convolutional blocks according to the channel dimension to obtain the final feature map.
[0113] The module M3 includes the following sub-modules:
[0114] Module M3.1: Extracts the feature map as a feature vector according to the channel dimension;
[0115] Module M3.2: Uses dictionary learning methods in sparse representation to optimize and refine features and generate a dictionary.
[0116] The module M4 includes the following sub-modules:
[0117] Module M4.1: The dictionary performs sparse representation and reconstruction of the feature vectors to obtain the sparse encoded vectors of the feature vectors and calculates the reconstruction error;
[0118] Module M4.2: Arranges the reconstruction errors according to the relative positions of the feature vectors in the feature map to form a reconstruction error map;
[0119] Module M4.3: Based on the sparse coding vector and the transformation matrix obtained during dictionary learning, the defect scores are obtained; the defect scores are arranged according to the relative positions of the feature vectors in the feature map to form a defect score map.
[0120] The module M5 includes the following sub-modules:
[0121] Module M5.1: Take the maximum value in the defect score map as the defect score of the image data to be tested; set a threshold τ, when the defect score is less than the threshold τ, determine that there is no defect in the image to be tested and output the detection result; when the defect score is greater than the threshold τ, determine that there is a defect in the image to be tested and execute step S5.2.
[0122] Module M5.2: Scales the defect fraction map to the same resolution as the image under test, and obtains the defect region after binary segmentation;
[0123] Module M5.3: Based on the defect areas obtained from module M5.2, calculate the pixel coordinates of all defect areas to obtain the position of the defect in the image under test; based on the position of the received image under test coverage area in the entire product, calculate the position of the defect in the entire product.
[0124] Module M5.4: Based on the defect area obtained from module M5.2, count the number of pixels in the defect area; combine the image to be tested and the size ratio of the area it covers to the product to calculate the size of the defect;
[0125] Module M5.5: Based on the defect area obtained from module M5.2 and the set threshold τ, if a defect area exists and there is a defect score in the area that is greater than the threshold τ, then the category with the highest defect score is the defect category of the area; if all defect scores in the defect area are lower than the threshold τ, then it is determined to be an unknown category defect.
[0126] Specific embodiments of the present invention have been described above. It should be understood that the present invention is not limited to the specific embodiments described above, and those skilled in the art can make various changes or modifications within the scope of the claims, which do not affect the essence of the present invention. Unless otherwise specified, the embodiments and features described in this application can be arbitrarily combined with each other.
Claims
1. A surface defect detection method based on feature extraction and sparse representation, characterized in that, include: Step S1: Acquire image data of the target surface and perform preprocessing; Step S2: Use a deep convolutional neural network to extract features from the image data to obtain a feature map; Step S3: Train the image data, refine and optimize the extracted features, and learn the dictionary; Step S4: Based on the dictionary, perform sparse coding on the features of the image data, and calculate the defect score and reconstruction error; Step S5: Obtain the defect fraction map based on the reconstruction error, perform post-processing on the defect fraction map, and obtain the defect detection results; Step S4 includes the following sub-steps: Step S4.1: The dictionary performs sparse representation and reconstruction on the feature vector to obtain the sparse coding vector of the feature vector, and calculates the reconstruction error; Step S4.2: Arrange the reconstruction errors according to the relative positions of the feature vectors in the feature map to form a reconstruction error map; Step S4.3: Obtain the defect score based on the sparse coding vector and the transformation matrix obtained during dictionary learning; The defect scores are arranged according to the relative positions of the feature vectors in the feature map to form a defect score map; Step S5 includes the following sub-steps: Step S5.1: Take the maximum value in the defect score map as the defect score of the image data to be tested; set a threshold τ, and when the defect score is less than the threshold τ, determine that there is no defect in the image to be tested and output the detection result; When the defect score is greater than the threshold τ, it is determined that there is a defect in the image to be tested, and step S5.2 is executed; Step S5.2: Scale the defect fraction map to the same resolution as the image to be tested, and obtain the defect region after binary segmentation; Step S5.3: Based on the defect areas obtained in step S5.2, calculate the pixel coordinates of all defect areas to obtain the position of the defect in the image under test; based on the position of the received image under test coverage area in the entire product, calculate the position of the defect in the entire product. Step S5.4: Based on the defect area obtained in step S5.2, count the number of pixels in the defect area; combine the image to be tested and the size ratio of the area it covers to the product to calculate the size of the defect. Step S5.5: Based on the defect area obtained in step S5.2 and the set threshold τ, if a defect area exists and there is a defect score in the area that is greater than the threshold τ, then the category with the largest defect score is the defect category of the area; if all defect scores in the defect area are lower than the threshold τ, then it is determined to be an unknown category defect.
2. The surface defect detection method based on feature extraction and sparse representation according to claim 1, characterized in that, Step S1 includes the following sub-steps: Step S1.1: Use a digital image acquisition device to acquire image data of the target surface, and perform image correction according to preset parameters; Step S1.2: Preprocess the corrected image data, including scaling, cropping, and regularization, to obtain image data that can be processed by the convolutional neural network.
3. The surface defect detection method based on feature extraction and sparse representation according to claim 1, characterized in that, Step S2 includes the following sub-steps: Step S2.1: Use a deep convolutional neural network to extract multi-scale features from the image data. Input the image data into the pre-trained convolutional neural network and use the output of multiple convolutional blocks in the convolutional neural network as feature maps. Step S2.2: Fuse the feature maps output by different convolutional blocks; the fusion includes: using interpolation to scale feature maps with a resolution less than a preset value to be equal to the feature map with the highest resolution; The feature maps output from multiple convolutional blocks are concatenated along the channel dimension to obtain the final feature map.
4. The surface defect detection method based on feature extraction and sparse representation according to claim 1, characterized in that, Step S3 includes the following sub-steps: Step S3.1: Extract the feature map according to the channel dimension as a feature vector; Step S3.2: Use the dictionary learning method in sparse representation to optimize and refine the features and generate a dictionary.
5. A system for implementing the surface defect detection method based on feature extraction and sparse representation as described in any one of claims 1-4, characterized in that, include: Module M1: Acquires image data of the target surface and performs preprocessing; Module M2: Uses a deep convolutional neural network to extract features from image data to obtain feature maps; Module M3: Training image data, refining and optimizing the extracted features, and learning to obtain a dictionary; Module M4: Based on the dictionary, sparsely encodes the features of the image data and calculates the defect score and reconstruction error; Module M5: Obtains a defect fraction map based on the reconstruction error, performs post-processing on the defect fraction map, and obtains the defect detection results.
6. A surface defect detection system based on feature extraction and sparse representation according to claim 5, characterized in that, The module M1 Includes the following sub-modules: Module M1.1: Uses digital image acquisition equipment to acquire image data of the target surface and performs image correction according to preset parameters; Module M1.2: Preprocesses the corrected image data, including scaling, cropping, and regularization, to obtain image data that can be processed by the convolutional neural network.
7. A surface defect detection system based on feature extraction and sparse representation according to claim 5, characterized in that, The module M2 Includes the following sub-modules: Module M2.1: Uses a deep convolutional neural network to extract multi-scale features from image data. The image data is input into a pre-trained convolutional neural network, and the output of multiple convolutional blocks in the convolutional neural network is used as a feature map. Module M2.2: Fusion of feature maps output from different convolutional blocks; the fusion includes: using interpolation to scale feature maps with resolutions smaller than a preset value to be equal to the feature map with the highest resolution; The feature maps output from multiple convolutional blocks are concatenated along the channel dimension to obtain the final feature map.
8. A surface defect detection system based on feature extraction and sparse representation according to claim 5, characterized in that, The module M3 includes the following sub-modules: Module M3.1: Extracts the feature map as a feature vector according to the channel dimension; Module M3.2: Uses dictionary learning methods in sparse representation to optimize and refine features and generate a dictionary.
Citation Information
Patent Citations
Surface defect detection system and method suitable for steel plate, equipment and medium
CN115880209A
Surface defect detection method based on deep learning and global difference information
CN116228754A
Infrastructure surface defect detection method based on deep learning and sparse representation model
CN114612453A
Surface defect identification system and method and storage medium thereof
CN115170490A