Image defect region segmentation method and system based on multi-scale superpixel feature enhancement
Technical Field
The invention relates to the field of machine vision deep learning, in particular to an image defect region segmentation method and system based on multi-scale superpixel feature enhancement.
Background
Most of the surface defect detection based on deep learning at present is based on a supervised characterization learning method. The method for detecting the defects based on the characterization learning can be regarded as an application of a related classical network in the industrial field because the achieved target is completely consistent with the computer vision task.
The surface detection of industrial products in the industrial field is a key step for determining the quality of the products, and due to the influence of the processing environment, the processing technology and the like, the defects are irregular in shape, different in size and randomly distributed in positions, cannot be predicted in advance, and have unobvious defects (similar to the background), the traditional visual algorithm is difficult to consider various defects, and particularly, the unobvious defects have large missing detection.
The generalization capability of an additional measurement model can be effectively improved based on data-driven deep learning, whether a convolutional neural network can effectively extract defect features or not is a key factor for detecting defects, most of the conventional feature extraction methods are of a downsampling-upsampling network structure, the defect features are extracted through convolution and pooling, the downsampling process inevitably leads to loss of feature information, and the common convolution and pooling cannot fully extract the feature information. For low-contrast and unobvious defects, the difficulty in extracting defect features is a difficult problem in deep learning.
Chinese patent publication No. CN111445471A, published as 24/07/2020, discloses a method and apparatus for detecting surface defects of products based on deep learning and machine vision. The invention aims to provide a product surface defect detection method and device based on deep learning and machine vision. The technical scheme of the invention is as follows: a product surface defect detection method based on deep learning and machine vision is characterized in that: acquiring a surface image of a product to be detected in a line scanning mode of an industrial camera; performing defect characteristic pretreatment on the acquired image in real time, and quickly determining whether the surface image of the product to be detected has defects; identifying the severity of the defect and classifying the defect type of the image with the defect by using the trained deep convolutional neural network model; the trained deep convolutional neural network model is formed by performing transfer learning, transformation and training on a classical neural network model increment v 3. This patent also makes detection of low contrast, unobvious defects difficult to achieve due to the inability to adequately extract feature information.
Disclosure of Invention
The invention aims to provide an image defect region segmentation method based on multi-scale superpixel feature enhancement, which is suitable for detecting low contrast and multi-scale defects.
It is a further object of this invention to provide a system for image defect region segmentation based on multi-scale superpixel feature enhancement.
In order to solve the technical problems, the technical scheme of the invention is as follows:
a method for segmenting image defect regions based on multi-scale superpixel feature enhancement comprises the following steps:
s1: acquiring an image comprising a surface defect of a workpiece;
s2: preprocessing the image;
s3: extracting the characteristics of the preprocessed image;
s4: inputting the extracted features into an S2pNet network, wherein the S2pNet network outputs a super-pixel domain association mapping map under different scales, and the super-pixel domain association mapping map represents the relation between the internal pixel and the external pixel of the super-pixel;
s5: fusing and splicing the superpixel domain associated mapping maps under different scales and the feature layers of the segmentation network corresponding to the segmentation network for segmenting the image defect region;
s6: the segmentation network outputs the segmented defective regions.
Preferably, in the step S2, the image is preprocessed, specifically:
and carrying out image acquisition, preliminary setting of an image detection area and cutting on the image.
Preferably, in step S3, the feature extraction is performed on the preprocessed image, specifically:
extracting characteristic information of each pixel point in the preprocessed image, wherein the characteristic information comprises relative coordinate information (x, y) of the current pixel point, three-dimensional information (l, a, b) of the current pixel point in an LAB color space, gradient information h of the current pixel point and label information t of the current image, and taking a set (x, y, l, a, b, h, t) of all the information as the characteristic for describing each pixel point.
Preferably, in step S4, the extracted features are input into the S2pNet network, and the following processing is further performed on the extracted features:
subjecting the extracted features to mean pooling of different scales to obtain features f under different scales
αf
βf
ηThe down sampling multiples are respectively alpha, beta and eta, and the dimensions are respectively
Preferably, the dimension size of the super-pixel domain association map at different scales in the step S4 is
The first dimension is fixed to be 9, the first dimension represents that the current pixel point neighborhood comprises own 9 pieces of orientation information which are respectively upper left, upper right, left, center, right, lower left, lower right and lower right, and the value of each shop of the super pixel domain association mapping chart represents the correlation between the current super pixel and the 9 super pixels in the neighborhood.
Preferably, the S2pNet network trains a super-pixel neighborhood correlation model by using the extracted features, the super-pixel neighborhood correlation model outputs super-pixel neighborhood correlation mapping maps at different scales, and the training process of the super-pixel neighborhood correlation model is as follows:
for the feature with down-sampling multiple of alpha, first initialize one
S _ m matrix of, and
the characteristic region is subjected to weighted dot product calculation to obtain
Polymerization characteristic f of
0:
In the formula, H, W represents the length and width of an image, s _ m represents a super-pixel domain association mapping map to be learned, f represents an extracted image feature, and alpha represents a down-sampling multiple;
the image is obtained by redistributing the associated mapping map of the super pixel field
Is reconstructed feature f
rc:
Defining the similarity degree of the reconstructed features and the original features as the learning quality degree of the super-pixel neighborhood correlation model, and defining the Loss of the target functions_m:
Losss_m=|f0-frc|2
Updating reversely according to the target function until the target function is smaller than a threshold value, and finishing training;
and for the features with the down-sampling multiples of beta and eta, completing training by adopting the same method as the steps.
Preferably, in step S5, the super-pixel domain associated maps at different scales and the feature layers at the scales corresponding to the networks for segmenting the image defect region are fused and spliced, where the fused and spliced process is divided into fusion and splicing, and the fusion specifically includes:
fsi=λ*s_mi*fi+(1-λ)*fi,i∈(1,2,3)
in the formula (f)siAnd (3) representing the characteristic diagram after the ith fused superpixel incidence matrix, wherein lambda is a superparameter for adjusting the importance degree of the aggregated characteristic diagram and the original characteristic diagram.
Preferably, the splicing specifically is:
fout=up(up(up(fs3)+fs2)+fs1)
in the formula, up represents an up-sampling process, and '+' represents a splicing process of the feature map.
Preferably, the training of the segmentation network requires preprocessing of the workpiece image, the preprocessing includes movement of a program console and acquisition of images by a synchronous camera, and random inversion, contrast stretching and random center clipping of the input image.
An image defect region segmentation system based on multi-scale superpixel feature enhancement, comprising:
an image acquisition module for acquiring an image comprising a surface defect of a workpiece;
a pre-processing module for pre-processing the image;
the characteristic extraction module is used for extracting the characteristics of the preprocessed image;
the S2pNet module is used for inputting the extracted features into an S2pNet network, the S2pNet network outputs a super-pixel domain association mapping map under different scales, and the super-pixel domain association mapping map represents the relation between the internal and external pixels of the super-pixel;
the fusion splicing module is used for fusion splicing of the super-pixel domain associated mapping maps under different scales and the feature layers of the segmentation network corresponding to the scales for segmenting the image defect region;
and the output module outputs the well-segmented defect area by utilizing the segmentation network.
Compared with the prior art, the technical scheme of the invention has the beneficial effects that:
the invention utilizes the super-pixel priori knowledge of the S2pNet network learning image to extract the super-pixel priori knowledge under different scales and carries out multi-scale fusion with the coding characteristics of the segmentation network, so that the information of a characteristic layer is more compact, the characteristic points in the characteristic layer are mutually influenced, the characteristic information is enriched, the defect of insufficient supervision information of the weak supervision network is relieved, the information extraction of the weak supervision segmentation network to the image pixel in one order or even multiple orders is realized, and finally the segmentation network outputs a more precise prediction segmentation area.
Drawings
FIG. 1 is a schematic flow chart of the method of the present invention.
FIG. 2 is a block diagram of the system of the present invention.
Detailed Description
The drawings are for illustrative purposes only and are not to be construed as limiting the patent;
for the purpose of better illustrating the embodiments, certain features of the drawings may be omitted, enlarged or reduced, and do not represent the size of an actual product;
it will be understood by those skilled in the art that certain well-known structures in the drawings and descriptions thereof may be omitted.
The technical solution of the present invention is further described below with reference to the accompanying drawings and examples.
Example 1
The embodiment provides an image defect region segmentation method based on multi-scale superpixel feature enhancement, as shown in fig. 1, comprising the following steps:
s1: acquiring an image comprising a surface defect of a workpiece;
s2: preprocessing the image;
s3: extracting the characteristics of the preprocessed image;
s4: inputting the extracted features into an S2pNet network, wherein the S2pNet network outputs a super-pixel domain association mapping map under different scales, and the super-pixel domain association mapping map represents the relation between the internal pixel and the external pixel of the super-pixel;
s5: fusing and splicing the superpixel domain associated mapping maps under different scales and the feature layers of the segmentation network corresponding to the segmentation network for segmenting the image defect region;
s6: the segmentation network outputs the segmented defective regions.
In step S2, the image is preprocessed, specifically:
and carrying out image acquisition, preliminary setting of an image detection area and cutting on the image.
In step S3, feature extraction is performed on the preprocessed image, specifically:
extracting characteristic information of each pixel point in the preprocessed image, wherein the characteristic information comprises relative coordinate information (x, y) of the current pixel point, three-dimensional information (l, a, b) of the current pixel point in an LAB color space, gradient information h of the current pixel point and label information t of the current image, and taking a set (x, y, l, a, b, h, t) of all the information as the characteristic for describing each pixel point.
In step S4, the extracted features are input into the S2pNet network, and the following processing is further performed on the extracted features:
subjecting the extracted features to mean pooling of different scales to obtain features f under different scales
αf
βf
ηThe down sampling multiples are respectively alpha, beta and eta, and the dimensions are respectively
The dimension of the superpixel domain association map under different scales in the step S4 is
The super-pixel domain association model under multiple scales can extract longitudinal and transverse pixel relations, the first dimension is fixed to be 9, 9 azimuth information including the super-pixel domain association model per se in the neighborhood of the current pixel point is represented and respectively comprises upper left, upper right, left, center, right, lower left, lower right and lower right, the value of each store of the super-pixel domain association mapping map represents the correlation between the current super-pixel and the 9 super-pixels in the neighborhood, the larger the weight is, the larger the probability that the two super-pixels belong to the same category is, the smaller the weight is, the smaller the correlation between the two super-pixels is, and the probability of distributing labels of different categories is larger.
The S2pNet network is a convolutional neural network consisting of a plurality of convolutional layers, is a core part of an algorithm and is mainly responsible for training a neighborhood correlation model of internal-external pixels of the superpixel, and comprises the output definition of the network model and the training strategy design of the neighborhood correlation model of the superpixel; the S2pNet is a coding-de-coding network structure, and input and output channels are different but have the same size.
The S2pNet network trains a super-pixel neighborhood correlation model by using the extracted features, the super-pixel neighborhood correlation model outputs super-pixel neighborhood correlation mapping maps under different scales, and the training process of the super-pixel neighborhood correlation model is as follows:
for the feature with down-sampling multiple of alpha, first initialize one
S _ m matrix of, and
the characteristic region is subjected to weighted dot product calculation to obtain
Polymerization characteristic f of
0:
In the formula, H, W represents the length and width of an image, s _ m represents a super-pixel domain association mapping map to be learned, f represents an extracted image feature, and alpha represents a down-sampling multiple;
the image is obtained by redistributing the associated mapping map of the super pixel field
Is reconstructed feature f
rc:
Defining the similarity degree of the reconstructed features and the original features as the learning quality degree of the super-pixel neighborhood correlation model, and defining the Loss of the target functions_m:
Losss_m=|f0-frc|2
Updating reversely according to the target function until the target function is smaller than a threshold value, and finishing training;
and for the features with the down-sampling multiples of beta and eta, completing training by adopting the same method as the steps.
In step S5, fusion splicing is performed on the superpixel domain associated maps at different scales and the feature layers at the scales corresponding to the networks for segmenting the image defect region, where the fusion splicing includes fusion and splicing, and the fusion specifically includes:
fsi=λ*s_mi*fi+(1-λ)*fi,i∈(1,2,3)
in the formula (f)siAnd (3) representing the characteristic diagram after the ith fused superpixel incidence matrix, wherein lambda is a superparameter for adjusting the importance degree of the aggregated characteristic diagram and the original characteristic diagram.
The splicing specifically comprises the following steps:
fout=up(up(up(fs3)+fs2)+fs1)
in the formula, up represents an up-sampling process, and '+' represents a splicing process of the feature map.
The training of the segmentation network requires preprocessing of the workpiece image, including program console movement and synchronous camera image acquisition, random flipping, contrast stretching and random center clipping of the input image.
Example 2
The embodiment provides an image defect region segmentation system based on multi-scale superpixel feature enhancement, as shown in fig. 2, including:
an image acquisition module for acquiring an image comprising a surface defect of a workpiece;
a pre-processing module for pre-processing the image;
the characteristic extraction module is used for extracting the characteristics of the preprocessed image;
the S2pNet module is used for inputting the extracted features into an S2pNet network, the S2pNet network outputs a super-pixel domain association mapping map under different scales, and the super-pixel domain association mapping map represents the relation between the internal and external pixels of the super-pixel;
the fusion splicing module is used for fusion splicing of the super-pixel domain associated mapping maps under different scales and the feature layers of the segmentation network corresponding to the scales for segmenting the image defect region;
and the output module outputs the well-segmented defect area by utilizing the segmentation network.
The same or similar reference numerals correspond to the same or similar parts;
the terms describing positional relationships in the drawings are for illustrative purposes only and are not to be construed as limiting the patent;
it should be understood that the above-described embodiments of the present invention are merely examples for clearly illustrating the present invention, and are not intended to limit the embodiments of the present invention. Other variations and modifications will be apparent to persons skilled in the art in light of the above description. And are neither required nor exhaustive of all embodiments. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the claims of the present invention.