A defect detection method based on image segmentation and completion

Through image segmentation and completion technology, the impact of industrial product surface interference factors on defect detection is solved, the detection performance is improved, and the adaptability to complex situations is improved.

CN118447015BActive Publication Date: 2024-10-15ARTIFICIAL INTELLIGENCE RES INST OF HEFEI COMPREHENSIVE NAT SCI CENT (ANHUI ARTIFICIAL INTELLIGENCE LAB) +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410875598.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-02
Publication Date
2024-10-15
Estimated Expiration
2044-07-02

AI Technical Summary

Technical Problem

Existing defect detection methods are difficult to effectively locate defects when dealing with concave and convex patterns or other obstructions on the surface of industrial products, and are affected by interference factors, resulting in a decline in detection performance.

Method used

A method based on image segmentation and completion is used to separate, segment and fuse industrial product surface images to generate interference area masks, and use defect-free images and random masks to train the image completion model to eliminate interference areas and return to normal Texture for defect detection.

Benefits of technology

It effectively eliminates the influence of industrial product surface interference factors on defect detection, improves the model's adaptability to complex and special situations, and improves the accuracy of defect detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118447015B_ABST
    Figure CN118447015B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of defect detection technology, and discloses a defect detection method based on image segmentation and completion, including: collecting a surface image of an industrial product to be detected, and separating the surface image into three channels; segmenting the images of the three channels respectively to obtain masks of interference areas under the three channels; fusing the masks under the three channels to obtain masks of interference areas in the surface image; using defect-free surface images and randomly generated masks to train an image completion model; inputting the collected surface image of the industrial product and the mask into the trained image completion model to complete the interference area in the surface image; and performing defect detection on the completed surface image through the defect detection model. The present invention effectively eliminates the influence of interference factors on the surface of industrial products on the defect detection effect through the segmentation and completion methods, and improves the adaptability of the model to complex and special situations of the surface images of industrial products.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of defect detection, and in particular to a defect detection method based on image segmentation and completion. Background Art

[0002] Defect detection is an important part of the industrial product production process, and it plays a huge role in quality inspection. With the development of computer vision technology, industrial product defect detection methods based on various image processing technologies are emerging in an endless stream.

[0003] At present, common defect detection methods have excellent performance when processing industrial product surfaces with a single texture background. However, when there are bumps or other obstructions on the surface of industrial products, they are often interfered by these factors and cannot locate the defects well. Areas with interference factors do not belong to the scope of surface defect detection. By completing them with background textures, the impact on defect detection tasks can be eliminated and the performance of defect detection models can be improved. Summary of the invention

[0004] In order to solve the technical problem that defect detection results are affected by interference areas on the surface of industrial products, the present invention provides a defect detection method based on image segmentation and completion.

[0005] In order to solve the above technical problems, the present invention adopts the following technical solutions:

[0006] A defect detection method based on image segmentation and completion performs defect detection after segmenting and completing interference areas in an industrial product surface image; the method comprises the following steps:

[0007] Step 1: Collect the surface image of the industrial product to be inspected , and separating the surface image into three channel images, namely an R channel image, a G channel image and a B channel image;

[0008] Step 2: Segment the R channel image, the G channel image, and the B channel image respectively to obtain the masks of the interference area under the three channels;

[0009] Step 3: Fuse the masks under the three channels to obtain the surface image The mask of the interference area in the middle;

[0010] Step 4: Use a surface image of a defect-free industrial product and randomly generated masks to train the image completion model so that the image completion model can learn the characteristics of the surface texture of industrial products;

[0011] Step 5: Take the surface image of the industrial product collected in step 1 The mask obtained in step 3 is input into the trained image completion model to complete the surface image. The interference area in the image is completed and restored to a normal area consistent with the surface texture of the industrial product;

[0012] Step 6: Use the defect detection model to complete the surface image Perform defect detection and obtain defect detection results.

[0013] Furthermore, in step 2, when segmenting the R channel image, the G channel image, and the B channel image, the following steps are performed on the images of each channel:

[0014] Step 2A, construct an undirected graph according to the pixel value of each pixel of the image; in the undirected graph, each node represents a pixel of the image; the similarity between the pixels corresponding to the two nodes connected by each edge is used as the weight of the edge;

[0015] Step 2B, will have The undirected graph of nodes is represented as a weight matrix , the elements in the weight matrix ,in, To connect nodes and nodes The weight of the edge; solve the graph segmentation problem, divide the undirected graph into two subgraphs, so that the overall cost of the segmentation is minimized, and the segmentation vector is obtained. and the two sub-graphs after segmentation;

[0016] Step 2C, select the background and foreground in the two sub-images, and add a mask to the foreground part;

[0017] Step 2D: Repeat step 2B to step 2C until the set maximum number of segmentations is reached or the minimum overall cost of the segmentation exceeds the set threshold.

[0018] Furthermore, in step 2A, the similarity between the pixels corresponding to the two nodes connected by each edge is used as the weight of the edge, specifically including:

[0019] ;

[0020] To connect nodes and nodes The edge weight of Respectively pixels and The pixel value of a pixel, Respectively pixels and The position of the pixel in the image; and is an adjustable correction parameter, is the distance threshold considering the similarity of pixels, is the two-norm.

[0021] Furthermore, in step 2B, the graph segmentation problem is solved by dividing the undirected graph into two subgraphs so as to minimize the overall cost of the segmentation and obtain the segmentation vector And the two sub-graphs after segmentation, specifically including:

[0022] The complete set of all nodes in the undirected graph Divide into subsets and subset , defining the overall cost function of segmentation for:

[0023] ;

[0024] represents the sum of the weights of the edges removed by the split, Representation Subset With the complete works The degree of correlation, Representation Subset With the complete works Degree of association:

[0025] ;

[0026] ;

[0027] ;

[0028] For generalized eigenvalue systems Solve, where is the weight matrix, is a diagonal matrix, Elements in , eigenvalue The corresponding eigenvector is the segmentation vector ; The segmentation vector obtained by solution Take the mean of all elements of to get the segmentation value , remove all the values ​​less than The edges of the undirected graph are divided into subgraphs and subgraph .

[0029] Furthermore, the image completion model includes an encoder and a decoder; step 4 specifically includes the following steps:

[0030] Step 4A: Surface image The pixel values ​​of the parts covered by the mask are set to zero to obtain the image to be processed. ; The position information of the mask on the image is recorded as mask information ;

[0031] Step 4B: Image to be processed Perform convolution, and then perform matrix dot multiplication of the convolution result and its own projection on the GELU activation function to obtain image features :

[0032] ;

[0033] in, is convolution, is the GELU activation function;

[0034] Step 4C: Image Features After passing through an encoder consisting of four coding blocks, downsampling is performed between every two coding blocks, and finally the features of the surface image at four different scales are obtained. , , and ; and , , and Set up in different levels from top to bottom;

[0035] Step 4D: The features obtained in step 4C , , and Connect layer by layer and pass through a decoder consisting of three decoding blocks to obtain the final features. At the beginning, each time it is upsampled once, then connected with the previous layer features and passed through a decoding block;

[0036] Step 4E: Map the output of the decoder to the final completed surface image through deconvolution.

[0037] Compared with the prior art, the beneficial technical effects of the present invention are:

[0038] The present invention effectively eliminates the influence of interference factors on the surface of industrial products on the defect detection effect through segmentation and completion methods, and improves the adaptability of the model to complex and special situations of industrial product surface images. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 Schematic diagram of the structure of the image completion model in the present invention; Figure 1In the figure, Conv is the convolution operation, GELU is the GELU activation function, and MPD represents the pixel shuffle downsampling of the integrated mask information.

[0040] Figure 2 Schematic diagram of the composite structure of the present invention; each composite structure is composed of two feedforward neural networks (FFN) and an attention module (SCAL) located between the two feedforward neural networks; for the channel self-attention branch of the attention module, LN is layer normalization, Q, K and V are respectively the query matrix, key matrix and value matrix obtained by projection and convolution transformation of the input features; for the spatial activation branch, AP is average pooling, f and g are both convolution modules with a convolution kernel size of 3×3, , and They represent matrix addition, cross product, and dot product respectively. DETAILED DESCRIPTION

[0041] A preferred embodiment of the present invention is described in detail below with reference to the accompanying drawings.

[0042] The defect detection method based on image segmentation and completion in this embodiment includes the following steps:

[0043] Step 1: Collect the surface image of the industrial product to be inspected, and obtain the images of the R channel, G channel, and B channel respectively.

[0044] Step 1 specifically includes the following steps:

[0045] Step 1A: Adjust the position of the camera in the shooting equipment, and shoot a total of 6 images of the surface of a single industrial product from different positions and angles to ensure that any part of the surface of the industrial product appears in at least one image; the size of the collected surface images is 2048×4500 pixels.

[0046] Step 1B: Divide each 2048×4500 pixel surface image into 16 equal parts to obtain a 512×1125 pixel surface image.

[0047] Step 1C: Perform channel separation on the surface image of 512×1125 pixels obtained in step 1B to obtain an R channel image, a G channel image, and a B channel image.

[0048] Step 2: Segment the R channel image, G channel image and B channel image respectively to obtain the mask of the interference area under each channel.

[0049] Step 2 specifically includes:

[0050] For each channel image, perform the following steps:

[0051] Step 2A: construct an undirected graph based on the pixel value of each pixel in the image. Each node represents a pixel, and each edge represents the similarity between the pixels corresponding to the two nodes it connects. This embodiment adopts a similarity calculation method that integrates pixel values ​​and pixel positions. pixels and The similarity between pixels is used as the connection node and nodes The edge weight of The calculation formula is:

[0052] ;

[0053] For the pixels and The pixel value of a pixel, For the pixels and The position of a pixel in the entire image, that is, the horizontal and vertical coordinates of the pixel; and is an adjustable correction parameter, is the distance threshold considering the similarity of pixels, is the two-norm. In the actual calculation process of this embodiment, take , , .

[0054] Step 2B: Split the undirected graph obtained in step 2A as follows:

[0055] For the full set of all nodes Divide into subsets and subset Segmentation, defining the overall cost function of segmentation for:

[0056] ;

[0057] definition represents the sum of the weights of the edges removed by the split, Representation Subset With the complete works The degree of correlation, Representation Subset With the complete works The degree of correlation between them is expressed as:

[0058] ;

[0059] ;

[0060] ;

[0061] For generalized eigenvalue systems Solve. is the weight matrix, is a diagonal matrix, Elements in , the second smallest eigenvalue The corresponding eigenvector is the segmentation vector . Then the segmentation vector obtained is The mean of all elements of , remove all the values ​​less than The edges of the undirected graph are divided into subgraphs and subgraph .

[0062] Step 2C: In two subgraphs and Select the background and foreground from the image, and add the foreground part to the mask. In this embodiment, the image containing at most the surface A corner sub-image is used as the foreground. If both sub-images contain surface images If there are two corners of the image, the sub-image with a smaller area is selected as the foreground.

[0063] Step 2D: For the background part in step 2C (denoted as ), recalculate the weight matrix :

[0064] ;

[0065] Delete all rows and columns where all elements are 0 to get a new weight matrix , which is used to calculate the next segmentation. Repeat the above process of segmenting the image, judging the foreground and background, and updating the mask until the maximum number of segmentations is reached, or the minimum overall cost of the segmentation exceeds the set threshold. In this embodiment, the maximum number of segmentations is 3, and the overall cost threshold of the segmentation is 0.15.

[0066] Step 3: Fuse the masks to obtain the surface image In this embodiment, the mask of the three channels is superimposed to calculate the surface image mask.

[0067] Step 4: Use the surface image of defect-free industrial products and the randomly generated mask to train the image completion model so that the image completion model can fully learn the characteristics of the surface texture of industrial products. The image completion model processes the surface image and mask information as follows:

[0068] Step 4A: Set the pixel values ​​of the part of the surface image covered by the mask to zero to obtain the image to be processed ; The position information of the mask on the image is recorded as mask information .

[0069] Step 4B: Image to be processed Perform the original convolution, and then perform matrix dot multiplication on the convolution result and its own projection on the GELU activation function to obtain the image features :

[0070] ;

[0071] in For a convolution with a kernel size of 3×3 and a convolution step size of 1, the expression of the GELU activation function is , It is the input of GELU activation function.

[0072] Step 4C: Image Features After passing through an encoder consisting of four coding blocks, downsampling is performed between every two coding blocks, and finally the features of the image at four different scales are obtained. , , and .

[0073] Specifically, the downsampling operation in this embodiment adopts pixel shuffle downsampling (MPD) with integrated mask information. Step 4C specifically includes: image features First input into the first encoding block to get the features , for the features Perform pixel shuffling and downsampling of comprehensive mask information to obtain downsampled features ; Downsample the features Input into the second encoding block to get the features , for the features Perform pixel shuffling and downsampling of comprehensive mask information to obtain downsampled features ; Downsample the features Input into the third encoding block to get the features , for the features Perform pixel shuffling and downsampling of comprehensive mask information to obtain downsampled features ; Downsample the features Input into the fourth encoding block to get the feature .feature The output of the last coding block does not need to be downsampled, but upsampled and then Concatenate and use as input to the first decoding block.

[0074] Pixel shuffling and downsampling of comprehensive mask information, including:

[0075] The size of image features and mask information is , , They are image features The height and width of ; The feature , , Unified as a feature , for multi-channel features and mask information , perform the following processing:

[0076] First, use a 3×3 convolution kernel The characteristics Projection is a feature with half the number of channels , then and Perform pixel shuffling downsampling , get the mask information after downsampling and Features :

[0077] ; ;

[0078] The downsampled mask information and Features Perform channel-wise connections to keep the mask position consistent during downsampling and retain as much valid information as possible:

[0079] ;

[0080] ;

[0081] ;

[0082] in , and The operators represent channel-wise slicing, channel-wise concatenation, and modulo operations, respectively. and Mask information and Features No. slices, the calculated size is , the number of channels is Connection characteristics , Represents the field of real numbers.

[0083] Finally, a 3×3 convolution kernel is used For connection features Encode and output downsampled features :

[0084] .

[0085] Downsampling features Including downsampled features , , .

[0086] Step 4D: The features obtained in step 4C , , and Connect layer by layer and pass through a decoder consisting of three decoding blocks to obtain the final features. At the beginning, a pixel shuffle upsampling is performed to ensure that the size is consistent with the features to be connected later, and then it is connected with the features of the previous layer and passed through a decoding block.

[0087] Step 4E: Map the output of the decoder to the final completed image through 3×3 deconvolution.

[0088] Step 5: Input the industrial product surface image collected in step 1 and the mask obtained in step 3 into the image completion model trained in step 4, complete the interference area in the surface image, and restore it to a normal area consistent with the background texture.

[0089] In the encoder and decoder of this embodiment, the encoder includes four encoding blocks, and the decoder includes three decoding blocks. Each encoding block and decoding block is composed of a plurality of composite structures connected together; Figure 1 As shown, in this embodiment, the four encoding blocks include 4, 6, 6, and 8 composite structures in sequence; the three decoding blocks include 6, 6, and 4 composite structures in sequence. Each composite structure includes two feedforward neural networks (FFNs) and an attention module located between them. The structure of the feedforward neural network is similar to the structure corresponding to the operation in step 4B, and the key features are extracted through deep convolution and GELU activation function. The output of each composite structure is:

[0090] ;

[0091] in is a feed-forward neural network, is the attention module.

[0092] This embodiment uses the spatially activated attention module (SCAL) as a component of the composite structure. For the input feature of the attention module ,The attention module processes it through two branches.

[0093] The processing process of the channel self-attention branch is:

[0094] ;

[0095] ;

[0096] ;

[0097] in is the intermediate output, Normalize the layer. is a learnable parameter, and the query matrix , the bond matrix , value matrix , , , They represent the depthwise convolution with a kernel size of 3×3 used to calculate Q, K, and V, respectively. , , denote the linear projections used to calculate Q, K, and V, respectively. represents transpose, is a linear projection, is a depthwise convolution with a kernel size of 3×3, is the channel attention function, is the softmax function.

[0098] Spatial activation branch pair features After average pooling, two convolutional layers with a kernel size of 3×3 are used to extract attention, and then the global attention matrix is ​​generated by upsampling. , which is used to weight the output of the channel self-attention branch:

[0099] ;

[0100] ;

[0101] in For upsampling, and Both are convolution layers with a convolution kernel size of 3×3. The spatial activation branch generates the global attention matrix, which is multiplied by the output of the channel self-attention branch, and then a convolution kernel of size 1×1 is used to generate the global attention matrix. Projection is the output of the attention module .

[0102] In the process of training the image completion model, this embodiment adopts a loss function that integrates multiple evaluation indicators, including the loss function for evaluating the overall reconstruction effect. , style loss , Perceptual Feature Loss and combat loss The final loss function is It is expressed as:

[0103] ;

[0104] The weights of each loss component during actual training are as follows: , , , .

[0105] Step 6: The completed image has eliminated the influence of the interference area, and the defects in the completed image are detected using the defect detection method based on YOLOv5. It is divided into:

[0106] Step 6A: In this embodiment, the YOLOv5 model is used as a defect detection model; the surface images of industrial products with no interference areas and defects are collected, and the positions of defect boxes and the types of defects are manually marked to form supervised learning data. The data is divided into a training set and a validation set, and input into the YOLOv5 model, and the maximum number of iterations is set to 300 for training.

[0107] Step 6B: Input the completed surface image obtained in step 5 into the trained YOLOv5 model to obtain a standard defect detection result with defect box, defect type and confidence.

[0108] It is obvious to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential features of the present invention. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-limiting, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention, and any reference numerals in the claims should not be regarded as limiting the claims involved.

[0109] In addition, it should be understood that although this specification is described in terms of implementation methods, not every implementation method contains only one independent technical solution. This narrative method of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation methods that can be understood by those skilled in the art.

Claims

1. A defect detection method based on image segmentation and completion, which performs defect detection after segmenting and completing the interference area in the surface image of the industrial product; characterized in that: The following steps are involved: Step 1: Collect the surface image of the industrial product to be inspected , and separating the surface image into three channel images, namely an R channel image, a G channel image and a B channel image; Step 2: Segment the R channel image, the G channel image, and the B channel image respectively to obtain the masks of the interference area under the three channels; Step 3: Fuse the masks under the three channels to obtain the surface image The mask of the interference area in the middle; Step 4: Use a surface image of a defect-free industrial product and randomly generated masks to train the image completion model so that the image completion model can learn the characteristics of the surface texture of industrial products; Step 5: Take the surface image of the industrial product collected in step 1 The mask obtained in step 3 is input into the trained image completion model to complete the surface image. The interference area in the image is completed and restored to a normal area consistent with the surface texture of the industrial product; Step 6: Use the defect detection model to complete the surface image Perform defect detection and obtain defect detection results; The image completion model includes an encoder and a decoder; step 4 specifically includes the following steps: Step 4A: Surface image The pixel values ​​of the parts covered by the mask are set to zero to obtain the image to be processed. ; The position information of the mask on the image is recorded as mask information ; Step 4B: Image to be processed Perform convolution, and then perform matrix dot multiplication of the convolution result and its own projection on the GELU activation function to obtain image features : ; in, is convolution, is the GELU activation function; Step 4C: Image Features After passing through an encoder consisting of four coding blocks, downsampling is performed between every two coding blocks, and finally the features of the surface image at four different scales are obtained. , , and ; and , , and Set up in different levels from top to bottom; Step 4D: The features obtained in step 4C , , and Connect layer by layer and pass through a decoder consisting of three decoding blocks to obtain the final features. At the beginning, each pixel is shuffled and upsampled, then connected with the previous layer features and passed through a decoding block; Step 4E, mapping the output result of the decoder into the final completed surface image through deconvolution; The downsampling adopts pixel shuffling downsampling with comprehensive mask information ; Step 4C specifically includes: image features First input into the first encoding block to get the features , for the features Perform pixel shuffling and downsampling of comprehensive mask information to obtain downsampled features ; Downsample the features Input into the second encoding block to get the features , for the features Perform pixel shuffling and downsampling of comprehensive mask information to obtain downsampled features ; Downsample the features Input into the third encoding block to get the features , for the features Perform pixel shuffling and downsampling of comprehensive mask information to obtain downsampled features ; Downsample the features Input into the fourth encoding block to get the feature ;feature is the output of the last encoding block, which is upsampled and then Connect as input to the first decoding block; Pixel shuffling and downsampling of comprehensive mask information, including: The size of image features and mask information is , , They are image features The height and width of ; The feature , , Unified as a feature , for multi-channel features and mask information , perform the following processing: First, use the convolution kernel The characteristics Projection is a feature with half the number of channels , then and Perform pixel shuffling downsampling , get the mask information after downsampling and Features : ; ; The downsampled mask information and Features Perform channel-wise connections to keep the mask position consistent during downsampling: ; ; ; in , and The operators represent channel-wise slicing, channel-wise concatenation, and modulo operations, respectively. Features No. slices, Mask information No. slices, , the calculated size is , the number of channels is Connection characteristics , represents the field of real numbers; Finally, use the convolution kernel For connection features Encode and output downsampled features : ; Downsampling features Including downsampled features , , .

2. The defect detection method based on image segmentation and completion according to claim 1, characterized in that: In step 2, when segmenting the R channel image, the G channel image, and the B channel image, the following steps are performed on the images of each channel: Step 2A, construct an undirected graph according to the pixel value of each pixel of the image; in the undirected graph, each node represents a pixel of the image; the similarity between the pixels corresponding to the two nodes connected by each edge is used as the weight of the edge; Step 2B, will have The undirected graph of nodes is represented as a weight matrix , the elements in the weight matrix ,in, To connect nodes and nodes The weight of the edge; solve the graph segmentation problem, divide the undirected graph into two subgraphs, so that the overall cost of the segmentation is minimized, and the segmentation vector is obtained. and the two sub-graphs after segmentation; Step 2C, select the background and foreground in the two sub-images, and add a mask to the foreground part; Step 2D: Repeat step 2B to step 2C until the set maximum number of segmentations is reached or the minimum overall cost of the segmentation exceeds the set threshold.

3. The defect detection method based on image segmentation and completion according to claim 2, characterized in that: In step 2A, the similarity between the pixels corresponding to the two nodes connected by each edge is used as the weight of the edge, which specifically includes: ; To connect nodes and nodes The edge weight of Node The corresponding pixel and nodes The corresponding pixel The pixel value of Pixels and pixels Position in the image; and is an adjustable correction parameter, is the distance threshold considering the similarity of pixels, is the two-norm.

4. The defect detection method based on image segmentation and completion according to claim 2, characterized in that: In step 2B, the graph segmentation problem is solved by dividing the undirected graph into two subgraphs so as to minimize the overall cost of the segmentation and obtain the segmentation vector And the two sub-graphs after segmentation, specifically including: The complete set of all nodes in the undirected graph Divide into subsets and subset , defining the overall cost function of segmentation for: ; represents the sum of the weights of the edges removed by the split, Representation Subset With the complete works The degree of correlation, Representation Subset With the complete works Degree of association: ; ; ; For generalized eigenvalue systems Solve, where is the weight matrix, is a diagonal matrix, Elements in , eigenvalue The corresponding eigenvector is the segmentation vector ; The segmentation vector obtained by solution Take the mean of all elements of to get the segmentation value , remove all the values ​​less than The edges of the undirected graph are divided into subgraphs and subgraph .