A mechanical surface defect segmentation and extraction method based on deep neural network
Through deep neural network combined with adaptive filtering and feature fusion, the problem of high false alarm rate in mechanical surface defect detection is solved, accurate identification and segmentation of mechanical surface defects is achieved, and detection efficiency is improved.
Patent Information
- Application Number
- CN202211731591.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-30
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2042-12-30
AI Technical Summary
The existing technology cannot automatically identify the original mechanical structure and the later defective structure during mechanical surface defect detection, resulting in a high false alarm rate and low detection efficiency.
A mechanical surface defect segmentation and extraction algorithm based on deep neural networks is used to process image noise through adaptive filtering windows, fuse color, texture and detail features, calculate the defect similarity matrix and diffuse it, to achieve automatic identification and segmentation of mechanical surface defects.
It improves the accuracy and efficiency of mechanical surface defect identification, reduces the false alarm rate, enhances the ability to express high-level semantic information, and achieves accurate identification of late-stage defects on the mechanical surface.
Smart Images

Figure CN116229059B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of mechanical surface defect segmentation, and in particular to a mechanical surface defect segmentation and extraction method based on a deep neural network. Background Art
[0002] Surface defect detection of industrial metal machinery parts is an important link in the workpiece production process. In the actual production process of various types of workpieces, the defects on the workpiece surface are mainly detected by manual screening, but this method has problems such as inaccurate detection results and low detection efficiency. Therefore, in order to ensure the surface quality of workpiece products, it is necessary to comprehensively improve the accuracy of the detection results and the detection rate. In recent years, with the rapid development of computer technology, intelligent detection technology based on deep learning has replaced manual detection technology, and the quality of metal machinery parts has been comprehensively improved in the process of reducing operating costs. However, this method cannot automatically identify the original structure of the machine and the later defective structure during the defect detection process, resulting in a high false alarm rate. In response to this problem, the present invention proposes a mechanical surface defect segmentation and extraction algorithm based on a deep neural network, which automatically distinguishes the original defect design and later defects of the mechanical surface, and improves the recognition accuracy of mechanical surface defects. Summary of the invention
[0003] In view of this, the present invention provides a mechanical surface defect segmentation and extraction algorithm based on deep neural network, the purpose of which is: 1) using an adaptively changing filter window to filter the collected surface area image of the machine to be inspected, to achieve targeted selection of filter windows of different specifications to remove different types of image noise, and to obtain defect feature vectors by fusing multiple types of feature vectors, by fusing color features, texture features and detail features, from the global and local perspectives of the image, by fusing low-level and mid-level features to effectively enhance the feature's ability to express high-level semantics, to obtain a fused feature vector that can better characterize the high-level semantic information of mechanical defects, and effectively identify mechanical defects. Surface late defects; 2) According to the similarity between the defect detection feature vector of the surface defect image of the machine to be detected and the defect feature vector of the same type of machine, the defect similarity matrix of the machine to be detected is obtained, and the defect similarity matrix is diffused to realize the measurement of the data manifold structure similarity between images. The diffusion process is to iterate the similarity weights between different images according to the image context relationship, traverse the defect similarity diffusion matrix, and calculate the maximum value of each row in the defect similarity diffusion matrix. If there is a maximum value greater than a preset threshold, the surface defect image of the machine to be detected corresponding to the row is marked as a defect extraction result, thereby realizing the defect segmentation and extraction of the machine surface.
[0004] To achieve the above object, the present invention provides a mechanical surface defect segmentation and extraction algorithm based on a deep neural network, comprising the following steps:
[0005] S1: collecting surface area images of different areas of the machine to be inspected, and preprocessing the collected surface area images to obtain preprocessed surface area images;
[0006] S2: construct a mechanical surface defect recognition model, input the preprocessed surface area image into the mechanical surface defect recognition model, and mark the original surface area image with defects identified as the mechanical surface defect image to be detected, so as to obtain a set of mechanical surface defect images to be detected;
[0007] S3: construct a set of surface defect images of different types of machinery, and use a feature extraction network to extract features from the surface defect images in the set of surface defect images to obtain a set of defect feature vectors of different types of machinery;
[0008] S4: extracting a defect detection feature vector of the surface defect image of the machine to be inspected by using a feature extraction network, and calculating the similarity between the defect detection feature vector and the defect feature vector of the same type of machine to obtain a defect similarity matrix of the machine to be inspected;
[0009] S5: Diffusion of the defect similarity matrix is performed to obtain a defect similarity diffusion matrix, and the defect similarity diffusion matrix is traversed to calculate the maximum value of each row in the defect similarity diffusion matrix. If there is a maximum value greater than a preset threshold, the surface defect image of the machine to be detected corresponding to the row is marked as a defect extraction result.
[0010] As a further improved algorithm of the present invention:
[0011] Optionally, in step S1, collecting surface area images of different areas of the machine to be inspected and preprocessing the collected surface area images include:
[0012] The surface area images of different areas of the machine to be inspected are collected by using a camera. The adjacent surface area images have an image overlap within 10%. The collected surface area images are:
[0013] {I i |i∈[1,n]}
[0014] in:
[0015] I i represents the i-th surface area image collected, and n represents the total number of surface area images collected;
[0016] The collected surface area image is preprocessed to obtain a preprocessed surface area image, wherein the surface area image I i The preprocessing process is:
[0017] S11: Surface area image I iGrayscale processing is performed, where the grayscale processing formula is:
[0018]
[0019] in:
[0020] R i (x,y),G i (x,y),B i (x,y) are image I i Medium Pixel I i (x,y) is the color value of the R, G, B color channels, pixel I i (x,y) represents image I i The pixel at row x and column y in g i (x,y) represents pixel I i Grayscale value of (x,y);
[0021] S12: Setting a filter window, wherein the initial size of the filter window is a 3×3 matrix and the maximum size is a 7×7 matrix;
[0022] S13: moving the filter window in the grayscale processed surface area image, with each movement range being 3 pixels;
[0023] S14: sorting all the pixels in the filter window according to the grayscale value, and recording the maximum grayscale value, the median grayscale value, and the minimum grayscale value of the pixels in the filter window;
[0024] S15: If the maximum grayscale value> the median grayscale value> the minimum grayscale value, then update the grayscale value of the center pixel in the filter window to the median grayscale value of the pixel in the filter window, and move the filter window; otherwise, determine whether the current filter window specification reaches the maximum specification. If it reaches the maximum specification, do not update the grayscale value of the center pixel in the filter window, and directly move the filter window. If it does not reach the maximum specification, add 2 to the rows and columns of the filter window, expand the filter window specification, and return to step S14;
[0025] S16: repeating steps S13-S15 until filtering is completed on the grayscale processed surface area image;
[0026] S17: traverse the surface area image after filtering, and take the average of the maximum grayscale value and the minimum grayscale value of the pixels in the surface area image as a binarization threshold;
[0027] S18: Segmenting the surface area image into foreground and background based on a binary threshold, and calculating average grayscale values of the foreground and background parts respectively, wherein pixels greater than the binary threshold are background pixels, pixels less than or equal to the binary threshold are foreground pixels, the foreground pixels constitute the foreground, and the background pixels constitute the background;
[0028] S19: If the average grayscale value of the foreground and background parts is equal to the binarization threshold, the iteration is terminated, and the surface area image after filtering is segmented into the foreground and the background using the binarization threshold to obtain the preprocessed surface area image I i ′ , otherwise the average grayscale value of the foreground and background parts is used as the binarization threshold after iteration, and the process returns to step S18.
[0029] Optionally, constructing a mechanical surface defect recognition model in step S2 includes:
[0030] A mechanical surface defect recognition model is constructed, wherein the constructed mechanical surface defect recognition model includes an input layer, a recognition layer and an output layer, wherein the input layer is used to receive the preprocessed surface area image, the recognition layer structure is a plurality of residual units, which are used to perform residual convolution processing on the preprocessed surface area image to obtain a corresponding feature map, and the output layer structure is a fully connected layer, which is used to receive the feature map and output the defect recognition result {0,1} of the feature map, wherein 0 indicates that there is no defect in the preprocessed surface area image, and 1 indicates that there is a defect in the preprocessed surface area image.
[0031] In an embodiment of the present invention, the training process of the constructed mechanical surface defect recognition model is:
[0032] Collect several sets of mechanical surface images and mark defects to form a training data set data, where mechanical surface images with defects are marked as 1 and mechanical surface images without defects are marked as 0;
[0033] Construct the training loss function Loss:
[0034]
[0035] in:
[0036] label v represents the real defect label of the mechanical surface image v in the training dataset data, It means that the machine surface image v in the training data set data is input into the model, and the defect recognition result output by the model;
[0037] Based on the training loss function, the Adams optimizer is used to optimize the parameters of the mechanical surface defect recognition model. The parameters to be optimized include the convolution kernel weights and bias parameters of the residual unit in the recognition layer, and the fully connected matrix in the output layer.
[0038] Optionally, in step S2, the preprocessed surface area image is input into a mechanical surface defect recognition model, and the corresponding original surface area image with the recognized defect is marked as a mechanical surface defect image to be detected, including:
[0039] The preprocessed surface area image is input into the mechanical surface defect recognition model. The mechanical surface defect recognition model outputs the defect recognition result of the image, and marks the corresponding original surface area image with the recognized defect as the mechanical surface defect image to be detected, wherein the original surface area image represents the surface area image that has not been preprocessed. If it is recognized that the preprocessed surface area image has defects, the original surface area image corresponding to the preprocessed surface area image is marked as the mechanical surface defect image to be detected, and a set of mechanical surface defect images to be detected is obtained:
[0040] {h j |j∈[1,m]}
[0041] in:
[0042] h j represents the jth image of the surface defect of the machine to be inspected, and m represents the total number of the surface defect images of the machine to be inspected;
[0043] Based on the mechanical surface defect recognition model, the pre-processed surface area image I′ i The process of defect identification is as follows:
[0044] S21: The input layer receives the preprocessed surface area image I′ i , and the preprocessed surface area image I′ i Input to the recognition layer;
[0045] S22: The recognition layer is based on L cascaded residual units to preprocess the surface area image I′ i Perform residual convolution to obtain the corresponding feature map, where the zth residual unit outputs the result q z The calculation formula is:
[0046] q z =W1(q z-1 )+ReLU[W3(q z-1 )]
[0047] in:
[0048] q z-1 represents the output result of the z-1th residual unit, and q0 represents the surface area image I′ after preprocessing i ;
[0049] W1(·) means that the input value is convolved with a convolution kernel of 1×1 pixel size, and W3(·) means that the input value is convolved with a convolution kernel of 3×3 pixel size;
[0050] ReLU(·) represents the activation function;
[0051] The output of the Lth residual unit is used as the feature map q L , and input the feature map into the output layer;
[0052] S23: The output layer uses the fully connected matrix to process the feature map to obtain the preprocessed surface area image I′ i The probability of a defect p(I′ i ):
[0053] p(I′ i )=W T q L
[0054] in:
[0055] W represents the fully connected matrix, and T represents the transpose;
[0056] If the probability p(I′ i ) is greater than the preset threshold, it means that the surface area image I′ after preprocessing i There is a defect, otherwise it means the surface area image I′ after preprocessing i There are no defects.
[0057] Optionally, in step S3, a surface defect image set of different types of machinery is constructed, and a feature extraction network is used to extract defect feature vectors from the surface defect images in the surface defect image set, including:
[0058] Construct a collection of surface defect images of different types of machinery:
[0059]
[0060] in:
[0061] k represents the mechanical type, represents a set of surface defect images of k types of machinery, represents the b-th surface defect image of the k-type machine, and B represents the total number of surface defect images of different types of machines; in the embodiment of the present invention, the collected surface defect images of different types of machines are surface area images with late defects;
[0062] The feature extraction network is used to extract defect feature vectors from the surface defect images in the surface defect images, wherein the feature extraction network includes a color feature extraction network, a texture feature extraction network and a detail feature extraction network. The surface defect images in the k-type mechanical corresponding surface defect image set are The defect feature vector extraction process is as follows:
[0063] S31: Extracting surface defect images using color feature extraction network Color characteristics
[0064]
[0065]
[0066]
[0067] in:
[0068] Representing surface defect images The color quantization result, Q R ,Q G ,Q B Represents the quantized values of the R, G, and B color channels, respectively, where the R color channel is quantized to [0, Q R -1], the G color channel is quantized to [0,Q G -1], the B color channel is quantized to [0,Q B -1], Ω represents the color space quantization result set {0,1,2,...,Q G Q R Q B -1};
[0069] Represent surface defect images Medium Pixels Color values in R, G, B color channels;
[0070] X and Y represent the surface defect images respectively. The total number of row pixels and column pixels;
[0071] S32: Extracting surface defect images using texture feature extraction network Texture features Texture feature extraction network for surface defect images Grayscale processing is performed, and the grayscale image after grayscale processing is divided into several grayscale image areas of the same size. The central pixel of each grayscale image area is selected, and the pixels in the grayscale image area with grayscale values greater than the central pixel are set to 1, and the remaining pixels are set to 0, and the central pixel is set to empty to obtain the binary code representation of each grayscale image area; the binary code representation is converted into a decimal code, and the decimal codes of all grayscale image areas are sorted according to the position of the grayscale image area to obtain the texture feature
[0072] S33: Extracting surface defect images using detail feature extraction network Detailed features The detail feature extraction algorithm is SIFT feature extraction algorithm;
[0073] S34: Splice and fuse the extracted features of different types to obtain a surface defect image The defect feature vector
[0074]
[0075] The defect feature vector set of different machines under machine type k is:
[0076]
[0077] in:
[0078] B represents the total number of surface defect images of different types of machinery.
[0079] Optionally, in step S4, the feature extraction network is used to extract features from the surface defect image of the machine to be inspected to obtain a defect detection feature vector, and the similarity between the defect detection feature vector and the defect feature vector of the same type of machine is calculated, including:
[0080] The feature extraction network is used to extract features of the mechanical surface defect images to be detected in the mechanical surface defect image set to be detected, and a defect detection feature vector is obtained, wherein the defect detection feature vector set corresponding to the mechanical surface defect image set to be detected is:
[0081] {f(h j )|j∈[1,m]}
[0082] in:
[0083] f(h j ) represents the defect detection feature vector corresponding to the surface defect image of the machine to be detected;
[0084] The machine type to be inspected is k′, and the defect feature vector set of different machines under machine type k′ is Calculate the similarity between the defect feature vector set of different machines under machine type k′ and any two feature vectors in the defect detection feature vector set, where the surface defect image h of the machine to be detected is j The corresponding defect detection feature vector f(h j )and Corresponding defect feature vector The similarity is The similarity calculation method is the cosine similarity calculation formula.
[0085] Optionally, in step S4, based on the similarity between the defect detection feature vector and the defect feature vector of the same type of machinery, a defect similarity matrix of the machinery to be inspected is formed, including:
[0086] Based on the similarity between the defect detection feature vector and the defect feature vector of the same type of machinery, the defect similarity matrix D of the machinery to be inspected is constructed:
[0087]
[0088] in:
[0089] k ′ Indicates the machine type to be tested. Indicates k ′ The b-th surface defect image of the type machine, b∈[1,B], k ′ ∈[1,K];
[0090] Represents the image h of the mechanical surface defect to be detected m The corresponding defect detection feature vector and The similarity of the corresponding defect feature vector, h m Represents the jth surface defect image of the machine to be inspected.
[0091] Optionally, in step S5, the defect similarity matrix is diffused to obtain a defect similarity diffusion matrix, including:
[0092] The defect similarity matrix D is diffused to obtain the defect similarity diffusion matrix, where the diffusion process of the defect similarity matrix D is:
[0093] S51: normalize the defect similarity matrix D to obtain the normalized defect similarity matrix D ′ :
[0094] D ′ =exp[(-D×D / σ 2 )]
[0095]
[0096] in:
[0097] It represents the δth maximum value of the jth row in the defect similarity matrix D, where δ is a random number of 1 or 2;
[0098] The normalized defect similarity matrix D ′ is a matrix with m rows and B columns;
[0099] S52: Initialize the transfer matrix U, where the transfer matrix U is a matrix with m rows and B columns:
[0100]
[0101] in:
[0102] U(j,b) represents the matrix element value of the jth row and bth column in the transfer matrix U, D ′ (j,b) represents the defect similarity matrix D ′ The matrix element value at the jth row and bth column in ;
[0103] D j ′ (max,δ ′ ) Defect similarity matrix D ′ The δth value of the jth row in ′ maximum value, ′ Set to 4;
[0104] S53: Initialize diffusion matrix ω0=U;
[0105] S54: setting the current iteration number of the diffusion matrix to t, and the initial value of t to 0;
[0106] S55: Iterate the diffusion matrix:
[0107] ω t+1 =Uω t U T
[0108] in:
[0109] ω t represents the diffusion matrix after the tth iteration;
[0110] S56: Compare ω before and after iteration t and ω t+1 The order of the matrix elements in each row is calculated, and the number of elements whose order changes in each row is recorded to obtain the average number of element order changes. where num jIndicates the number of elements whose order changes in row j;
[0111] S57: If the current average element sequence change number is less than the preset threshold, then ω t+1 As the defect similarity diffusion matrix, where ω t+1 is a matrix with m rows and B columns, and the jth row in the matrix represents the surface defect image h of the machine to be detected. m The similarity with the image of different surface defects of the same machine type, otherwise set t=t+1 and return to step S55.
[0112] Optionally, in step S5, the defect similarity diffusion matrix is traversed, and the maximum value of each row in the defect similarity diffusion matrix is calculated. If there is a maximum value greater than a preset threshold, the surface defect image of the machine to be detected corresponding to the row is marked as a defect extraction result, including:
[0113] The defect similarity diffusion matrix obtained by diffusion is traversed row by row, and the maximum value of each row in the defect similarity diffusion matrix is calculated. If there is a maximum value greater than a preset threshold, the surface defect image of the machine to be detected corresponding to the row is marked as a defect extraction result.
[0114] In order to solve the above problem, the present invention provides an electronic device, the electronic device comprising:
[0115] A memory storing at least one instruction;
[0116] Communication interface, enabling electronic equipment to communicate; and
[0117] A processor executes instructions stored in the memory to implement the above-mentioned mechanical surface defect segmentation and extraction algorithm based on deep neural network.
[0118] In order to solve the above problems, the present invention also provides a computer-readable storage medium, in which at least one instruction is stored. The at least one instruction is executed by a processor in an electronic device to implement the above-mentioned mechanical surface defect segmentation and extraction algorithm based on deep neural network.
[0119] Compared with the prior art, the present invention proposes a mechanical surface defect segmentation and extraction algorithm based on a deep neural network, which has the following advantages:
[0120] First, this scheme proposes a defect feature vector extraction method, which uses a feature extraction network to extract defect feature vectors from surface defect images in surface defect images, where the feature extraction network includes a color feature extraction network, a texture feature extraction network, and a detail feature extraction network. The surface defect images in the k-type mechanical corresponding surface defect image set The defect feature vector extraction process is as follows: Use the color feature extraction network to extract the surface defect image Color characteristics
[0121]
[0122]
[0123]
[0124] in: Representing surface defect images The color quantization result, Q R ,Q G ,Q B Represents the quantized values of the R, G, and B color channels, respectively, where the R color channel is quantized to [0, Q R -1], the G color channel is quantized to [0,Q G -1], the B color channel is quantized to [0,Q B -1], Ω represents the color space quantization result set {0,1,2,...,Q G Q R Q B -1}; Represent surface defect images Medium Pixels The color values in the R, G, and B color channels; X and Y represent the surface defect images respectively. The total number of row pixels and column pixels; use the texture feature extraction network to extract surface defect images Texture features Texture feature extraction network for surface defect images Grayscale processing is performed, and the grayscale image after grayscale processing is divided into several grayscale image areas of the same size. The central pixel of each grayscale image area is selected, and the pixels in the grayscale image area with grayscale values greater than the central pixel are set to 1, and the remaining pixels are set to 0, and the central pixel is set to empty to obtain the binary code representation of each grayscale image area; the binary code representation is converted into a decimal code, and the decimal codes of all grayscale image areas are sorted according to the position of the grayscale image area to obtain the texture feature Extracting surface defect images using detail feature extraction network Detailed features The detail feature extraction algorithm is the SIFT feature extraction algorithm; the extracted features of different types are spliced and fused to obtain the surface defect image The defect feature vector This solution uses an adaptively changing filter window to filter the collected surface area images of the machine to be inspected, and selects filter windows of different specifications to remove different types of image noise in a targeted manner. It also uses a multi-type feature vector fusion method to obtain a defect feature vector. By fusing color features, texture features, and detail features, from the global and local perspectives of the image, the low-level and mid-level features are fused to effectively enhance the feature's ability to express high-level semantics, and obtain a fused feature vector that can better characterize the high-level semantic information of mechanical defects, thereby effectively identifying late-stage defects on the mechanical surface.
[0125] At the same time, this scheme proposes a mechanical defect extraction process, by diffusing the defect similarity matrix D, to obtain the defect similarity diffusion matrix, wherein the diffusion process of the defect similarity matrix D is: normalizing the defect similarity matrix D to obtain the normalized defect similarity matrix D ′ :
[0126] D ′ =exp[(-D×D / σ 2 )]
[0127]
[0128] in: represents the δth maximum value of the jth row in the defect similarity matrix D, where δ is a random number of 1 or 2; the normalized defect similarity matrix D ′ is a matrix with m rows and B columns; initialize the transfer matrix U, where the transfer matrix U is a matrix with m rows and B columns:
[0129]
[0130] Where: U(j,b) represents the matrix element value of the jth row and bth column in the transfer matrix U, D ′ (j,b) represents the defect similarity matrix D ′ The matrix element value of the jth row and the bth column in D j ′ (max,δ ′ ) Defect similarity matrix D ′ The δth value of the jth row in ′ maximum value, ′ Set to 4; initialize the diffusion matrix ω0 = U; set the current iteration number of the diffusion matrix to t, and the initial value of t is 0; iterate the diffusion matrix:
[0131] ω t+1 =Uω t U T
[0132] Where: tRepresents the diffusion matrix after the tth iteration; compare ω before and after iteration t and ω t+1 The order of the matrix elements in each row is calculated, and the number of elements whose order changes in each row is recorded to obtain the average number of element order changes. where num j Indicates the number of elements whose order changes in the jth row; if the current average number of element order changes is less than the preset threshold, ω t+1 As the defect similarity diffusion matrix, where ω t+1 is a matrix with m rows and B columns, and the jth row in the matrix represents the surface defect image h of the machine to be detected. m The similarity with different surface defect images of the same type of machinery, otherwise let t = t + 1 and return to the iteration step. Traverse the defect similarity diffusion matrix obtained by diffusion row by row, and calculate the maximum value of each row in the defect similarity diffusion matrix. If there is a maximum value greater than the preset threshold, the surface defect image of the machinery to be detected corresponding to the row is marked as the defect extraction result. This scheme obtains the defect similarity matrix of the machinery to be detected based on the similarity between the defect detection feature vector of the surface defect image of the machinery to be detected and the defect feature vector of the same type of machinery, and diffuses the defect similarity matrix to realize the measurement of the data manifold structure similarity between images. The diffusion process is to iterate the similarity weights between different images according to the image context relationship, traverse the defect similarity diffusion matrix, and calculate the maximum value of each row in the defect similarity diffusion matrix. If there is a maximum value greater than the preset threshold, the surface defect image of the machinery to be detected corresponding to the row is marked as the defect extraction result, and the defect segmentation and extraction of the mechanical surface is realized. BRIEF DESCRIPTION OF THE DRAWINGS
[0133] Figure 1 A schematic diagram of a flow chart of a mechanical surface defect segmentation and extraction algorithm based on a deep neural network provided by an embodiment of the present invention;
[0134] Figure 2 A schematic diagram of the structure of an electronic device for implementing a mechanical surface defect segmentation and extraction algorithm based on a deep neural network provided by an embodiment of the present invention.
[0135] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0136] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0137] The embodiment of the present application provides a mechanical surface defect segmentation and extraction method based on a deep neural network. The execution subject of the mechanical surface defect segmentation and extraction algorithm based on a deep neural network includes but is not limited to at least one of the electronic devices such as a server and a terminal that can be configured to execute the algorithm provided in the embodiment of the present application. In other words, the mechanical surface defect segmentation and extraction algorithm based on a deep neural network can be executed by software or hardware installed on a terminal device or a server device, and the software can be a blockchain platform. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, etc.
[0138] Embodiment 1:
[0139] S1: collecting surface area images of different areas of the machine to be inspected, and preprocessing the collected surface area images to obtain preprocessed surface area images.
[0140] In the step S1, surface area images of different areas of the machine to be inspected are collected, and the collected surface area images are preprocessed, including:
[0141] The surface area images of different areas of the machine to be inspected are collected by using a camera. The adjacent surface area images have an image overlap within 10%. The collected surface area images are:
[0142] {I i |i∈[1,n]}
[0143] in:
[0144] I i represents the i-th surface area image collected, and n represents the total number of surface area images collected;
[0145] The collected surface area image is preprocessed to obtain a preprocessed surface area image, wherein the surface area image I i The preprocessing process is:
[0146] S11: Surface area image I i Grayscale processing is performed, where the grayscale processing formula is:
[0147]
[0148] in:
[0149] R i (x,y),G i (x,y),B i (x,y) are image I i Medium Pixel I i (x,y) is the color value of the R, G, B color channels, pixel Ii (x,y) represents image I i The pixel at row x and column y in g i (x,y) represents pixel I i Grayscale value of (x,y);
[0150] S12: Setting a filter window, wherein the initial size of the filter window is a 3×3 matrix and the maximum size is a 7×7 matrix;
[0151] S13: moving the filter window in the grayscale processed surface area image, with each movement range being 3 pixels;
[0152] S14: sorting all the pixels in the filter window according to the grayscale value, and recording the maximum grayscale value, the median grayscale value, and the minimum grayscale value of the pixels in the filter window;
[0153] S15: If the maximum grayscale value> the median grayscale value> the minimum grayscale value, then update the grayscale value of the center pixel in the filter window to the median grayscale value of the pixel in the filter window, and move the filter window; otherwise, determine whether the current filter window specification reaches the maximum specification. If it reaches the maximum specification, do not update the grayscale value of the center pixel in the filter window, and directly move the filter window. If it does not reach the maximum specification, add 2 to the rows and columns of the filter window, expand the filter window specification, and return to step S14;
[0154] S16: repeating steps S13-S15 until filtering is completed on the grayscale processed surface area image;
[0155] S17: traverse the surface area image after filtering, and take the average of the maximum grayscale value and the minimum grayscale value of the pixels in the surface area image as a binarization threshold;
[0156] S18: Segmenting the surface area image into foreground and background based on a binary threshold, and calculating average grayscale values of the foreground and background parts respectively, wherein pixels greater than the binary threshold are background pixels, pixels less than or equal to the binary threshold are foreground pixels, the foreground pixels constitute the foreground, and the background pixels constitute the background;
[0157] S19: If the average grayscale value of the foreground and background parts is equal to the binarization threshold, the iteration is terminated, and the surface area image after filtering is segmented into the foreground and the background using the binarization threshold to obtain the preprocessed surface area image I i ′ , otherwise the average grayscale value of the foreground and background parts is used as the binarization threshold after iteration, and the process returns to step S18.
[0158] S2: Construct a mechanical surface defect recognition model, input the preprocessed surface area image into the mechanical surface defect recognition model, and mark the original surface area image with defects identified as the mechanical surface defect image to be detected, so as to obtain a set of mechanical surface defect images to be detected.
[0159] The mechanical surface defect recognition model is constructed in step S2, including:
[0160] A mechanical surface defect recognition model is constructed, wherein the constructed mechanical surface defect recognition model includes an input layer, a recognition layer and an output layer, wherein the input layer is used to receive the preprocessed surface area image, the recognition layer structure is a plurality of residual units, which are used to perform residual convolution processing on the preprocessed surface area image to obtain a corresponding feature map, and the output layer structure is a fully connected layer, which is used to receive the feature map and output the defect recognition result {0,1} of the feature map, wherein 0 indicates that there is no defect in the preprocessed surface area image, and 1 indicates that there is a defect in the preprocessed surface area image.
[0161] In the step S2, the preprocessed surface area image is input into the mechanical surface defect recognition model, and the corresponding original surface area image with the recognized defect is marked as the mechanical surface defect image to be detected, including:
[0162] The preprocessed surface area image is input into the mechanical surface defect recognition model. The mechanical surface defect recognition model outputs the defect recognition result of the image, and marks the corresponding original surface area image with the recognized defect as the mechanical surface defect image to be detected, wherein the original surface area image represents the surface area image that has not been preprocessed. If it is recognized that the preprocessed surface area image has defects, the original surface area image corresponding to the preprocessed surface area image is marked as the mechanical surface defect image to be detected, and a set of mechanical surface defect images to be detected is obtained:
[0163] {h j |j∈[1,m]}
[0164] in:
[0165] h j represents the jth image of the surface defect of the machine to be inspected, and m represents the total number of the surface defect images of the machine to be inspected;
[0166] Based on the mechanical surface defect recognition model, the pre-processed surface area image I i ′ The process of defect identification is as follows:
[0167] S21: The input layer receives the preprocessed surface area image I i ′ , and the preprocessed surface area image Ii ′ Input to the recognition layer;
[0168] S22: The recognition layer is based on L cascaded residual units to preprocess the surface area image I i ′ Perform residual convolution to obtain the corresponding feature map, where the zth residual unit outputs the result q z The calculation formula is:
[0169] q z =W1(q z-1 )+ReLU[W3(q z-1 )]
[0170] in:
[0171] q z-1 represents the output result of the z-1th residual unit, and q0 represents the surface area image I after preprocessing i ′ ;
[0172] W1(·) means that the input value is convolved with a convolution kernel of 1×1 pixel size, and W3(·) means that the input value is convolved with a convolution kernel of 3×3 pixel size;
[0173] ReLU(·) represents the activation function;
[0174] The output of the Lth residual unit is used as the feature map q L , and input the feature map into the output layer;
[0175] S23: The output layer uses the fully connected matrix to process the feature map to obtain the preprocessed surface area image I i ′ The probability of a defect p(I i ′ ):
[0176] p(I i ′ )=W T q L
[0177] in:
[0178] W represents the fully connected matrix, and T represents the transpose;
[0179] If the probability p(I i ′ ) is greater than the preset threshold, it means that the surface area image I i ′ There is a defect, otherwise it means the surface area image I after preprocessing i′ There are no defects.
[0180] S3: Construct a set of surface defect images of different types of machinery, and use the feature extraction network to extract features of the surface defect images in the surface defect image set to obtain a set of defect feature vectors of different types of machinery.
[0181] In the step S3, a surface defect image set of different types of machinery is constructed, and a feature extraction network is used to extract defect feature vectors from the surface defect images in the surface defect image set, including:
[0182] Construct a collection of surface defect images of different types of machinery:
[0183]
[0184] in:
[0185] k represents the mechanical type, represents a set of surface defect images of k types of machinery, represents the bth surface defect image of the k-type machinery, and B represents the total number of surface defect images of different types of machinery;
[0186] The feature extraction network is used to extract defect feature vectors from the surface defect images in the surface defect images, wherein the feature extraction network includes a color feature extraction network, a texture feature extraction network and a detail feature extraction network. The surface defect images in the k-type mechanical corresponding surface defect image set are The defect feature vector extraction process is as follows:
[0187] S31: Extracting surface defect images using color feature extraction network Color characteristics
[0188]
[0189]
[0190]
[0191] in:
[0192] Representing surface defect images The color quantization result, Q R ,Q G ,Q B Represents the quantized values of the R, G, and B color channels, respectively, where the R color channel is quantized to [0, Q R -1], the G color channel is quantized to [0,Q G-1], the B color channel is quantized to [0,Q B -1], Ω represents the color space quantization result set {0,1,2,...,Q G Q R Q B -1};
[0193] Represent surface defect images Medium Pixels Color values in R, G, B color channels;
[0194] X and Y represent the surface defect images respectively. The total number of row pixels and column pixels;
[0195] S32: Extracting surface defect images using texture feature extraction network Texture features Texture feature extraction network for surface defect images Grayscale processing is performed, and the grayscale image after grayscale processing is divided into several grayscale image areas of the same size. The central pixel of each grayscale image area is selected, and the pixels in the grayscale image area with grayscale values greater than the central pixel are set to 1, and the remaining pixels are set to 0, and the central pixel is set to empty to obtain the binary code representation of each grayscale image area; the binary code representation is converted into a decimal code, and the decimal codes of all grayscale image areas are sorted according to the position of the grayscale image area to obtain the texture feature
[0196] S33: Extracting surface defect images using detail feature extraction network Detailed features The detail feature extraction algorithm is SIFT feature extraction algorithm;
[0197] S34: Splice and fuse the extracted features of different types to obtain a surface defect image The defect feature vector
[0198]
[0199] The defect feature vector set of different machines under machine type k is:
[0200]
[0201] in:
[0202] B represents the total number of surface defect images of different types of machinery.
[0203] S4: Using the feature extraction network to extract the defect detection feature vector of the surface defect image of the machine to be inspected, and calculating the similarity between the defect detection feature vector and the defect feature vector of the same type of machine to obtain the defect similarity matrix of the machine to be inspected.
[0204] In the step S4, the feature extraction network is used to extract features from the surface defect image of the machine to be inspected, a defect detection feature vector is obtained, and the similarity between the defect detection feature vector and the defect feature vector of the same type of machine is calculated, including:
[0205] The feature extraction network is used to extract features of the mechanical surface defect images to be detected in the mechanical surface defect image set to be detected, and a defect detection feature vector is obtained, wherein the defect detection feature vector set corresponding to the mechanical surface defect image set to be detected is:
[0206] {f(h j )|j∈[1,m]}
[0207] in:
[0208] f(h j ) represents the defect detection feature vector corresponding to the surface defect image of the machine to be detected;
[0209] The machine type to be inspected is k′, and the defect feature vector set of different machines under machine type k′ is Calculate the similarity between the defect feature vector set of different machines under machine type k′ and any two feature vectors in the defect detection feature vector set, where the surface defect image h of the machine to be detected is j The corresponding defect detection feature vector f(h j )and Corresponding defect feature vector The similarity is The similarity calculation method is the cosine similarity calculation formula.
[0210] In the step S4, based on the similarity between the defect detection feature vector and the defect feature vector of the same type of machinery, a defect similarity matrix of the machinery to be inspected is formed, including:
[0211] Based on the similarity between the defect detection feature vector and the defect feature vector of the same type of machinery, the defect similarity matrix D of the machinery to be inspected is constructed:
[0212]
[0213] in:
[0214] k′ represents the machine type of the machine to be tested, represents the bth surface defect image of k′ type machinery, b∈[1,B], k′∈[1,K];
[0215] Represents the image h of the mechanical surface defect to be detected m The corresponding defect detection feature vector and The similarity of the corresponding defect feature vector, h m Represents the jth surface defect image of the machine to be inspected.
[0216] S5: Diffusion of the defect similarity matrix is performed to obtain a defect similarity diffusion matrix, and the defect similarity diffusion matrix is traversed to calculate the maximum value of each row in the defect similarity diffusion matrix. If there is a maximum value greater than a preset threshold, the surface defect image of the machine to be detected corresponding to the row is marked as a defect extraction result.
[0217] In the step S5, the defect similarity matrix is diffused to obtain a defect similarity diffusion matrix, including:
[0218] The defect similarity matrix D is diffused to obtain the defect similarity diffusion matrix, where the diffusion process of the defect similarity matrix D is:
[0219] S51: Normalize the defect similarity matrix D to obtain a normalized defect similarity matrix D′:
[0220] D′=exp[(-D×D / σ 2 )]
[0221]
[0222] in:
[0223] It represents the δth maximum value of the jth row in the defect similarity matrix D, where δ is a random number of 1 or 2;
[0224] The normalized defect similarity matrix D′ is a matrix with m rows and B columns;
[0225] S52: Initialize the transfer matrix U, where the transfer matrix U is a matrix with m rows and B columns:
[0226]
[0227] in:
[0228] U(j,b) represents the matrix element value of the jth row and bth column in the transfer matrix U, and D′(j,b) represents the defect similarity matrix D ′
[0229] The matrix element value at the jth row and bth column in ;
[0230] D′ j (max,δ′) is the maximum value of the δ′th row in the defect similarity matrix D′, and δ′ is set to 4;
[0231] S53: Initialize diffusion matrix ω0=U;
[0232] S54: setting the current iteration number of the diffusion matrix to t, and the initial value of t to 0;
[0233] S55: Iterate the diffusion matrix:
[0234] ω t+1 =Uω t U T
[0235] in:
[0236] ω t represents the diffusion matrix after the tth iteration;
[0237] S56: Compare ω before and after iteration t and ω t+1 The order of the matrix elements in each row is calculated, and the number of elements whose order changes in each row is recorded to obtain the average number of element order changes. where num j Indicates the number of elements whose order changes in row j;
[0238] S57: If the current average element sequence change number is less than the preset threshold, then ω t+1 As the defect similarity diffusion matrix, where ω t+1 is a matrix with m rows and B columns, and the jth row in the matrix represents the surface defect image h of the machine to be detected. m The similarity with the image of different surface defects of the same machine type, otherwise set t=t+1 and return to step S55.
[0239] In the step S5, the defect similarity diffusion matrix is traversed, and the maximum value of each row in the defect similarity diffusion matrix is calculated. If there is a maximum value greater than a preset threshold, the surface defect image of the machine to be detected corresponding to the row is marked as a defect extraction result, including:
[0240] The defect similarity diffusion matrix obtained by diffusion is traversed row by row, and the maximum value of each row in the defect similarity diffusion matrix is calculated. If there is a maximum value greater than a preset threshold, the surface defect image of the machine to be detected corresponding to the row is marked as a defect extraction result.
[0241] Embodiment 2:
[0242] like Figure 2, is a schematic diagram of the structure of an electronic device for implementing a mechanical surface defect segmentation and extraction algorithm based on a deep neural network provided by an embodiment of the present invention.
[0243] The electronic device 1 may include a processor 10 , a memory 11 , a communication interface 13 and a bus, and may also include a computer program stored in the memory 11 and executable on the processor 10 , such as a program 12 .
[0244] The memory 11 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a mobile hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a magnetic memory, a disk, an optical disk, etc. The memory 11 may be an internal storage unit of the electronic device 1 in some embodiments, such as a mobile hard disk of the electronic device 1. The memory 11 may also be an external storage device of the electronic device 1 in other embodiments, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 1. Further, the memory 11 may also include both an internal storage unit of the electronic device 1 and an external storage device. The memory 11 may be used not only to store application software and various types of data installed in the electronic device 1, such as the code of the program 12, etc., but also to temporarily store data that has been output or is to be output.
[0245] The processor 10 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips, etc. The processor 10 is the control core (Control Unit) of the electronic device, and uses various interfaces and lines to connect various components of the entire electronic device, and executes or executes programs or modules stored in the memory 11 (such as the program 12 for realizing the segmentation and extraction of mechanical surface defects), and calls the data stored in the memory 11 to execute various functions of the electronic device 1 and process data.
[0246] The communication interface 13 may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device 1 and other electronic devices, and to achieve connection and communication between internal components of the electronic device.
[0247] The bus may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is configured to realize connection and communication between the memory 11 and at least one processor 10, etc.
[0248] Figure 2 Only an electronic device with components is shown, and those skilled in the art will understand that Figure 2 The structure shown does not constitute a limitation on the electronic device 1, and may include fewer or more components than shown in the figure, or combine certain components, or arrange the components differently.
[0249] For example, although not shown, the electronic device 1 may also include a power source (such as a battery) for supplying power to each component. Preferably, the power source may be logically connected to the at least one processor 10 through a power management device, so that the power management device can realize functions such as charging management, discharging management, and power consumption management. The power source may also include any components such as one or more DC or AC power sources, recharging devices, power failure detection circuits, power converters or inverters, power status indicators, etc. The electronic device 1 may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.
[0250] Optionally, the electronic device 1 may further include a user interface, which may be a display, an input unit (such as a keyboard), or a standard wired interface or a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode) touch device. The display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device 1 and to display a visual user interface.
[0251] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited to this structure.
[0252] The program 12 stored in the memory 11 in the electronic device 1 is a combination of multiple instructions. When running in the processor 10, it can achieve:
[0253] Collecting surface area images of different areas of the machine to be inspected, and preprocessing the collected surface area images to obtain preprocessed surface area images;
[0254] A mechanical surface defect recognition model is constructed, the preprocessed surface area image is input into the mechanical surface defect recognition model, and the original surface area image with the defect recognized is marked as a mechanical surface defect image to be detected, so as to obtain a set of mechanical surface defect images to be detected;
[0255] Construct a surface defect image set of different types of machinery, and use a feature extraction network to extract features from the surface defect images in the surface defect image set to obtain a defect feature vector set of different types of machinery;
[0256] The defect detection feature vector of the surface defect image of the machine to be inspected is extracted by using a feature extraction network, and the similarity between the defect detection feature vector and the defect feature vector of the same type of machine is calculated to obtain the defect similarity matrix of the machine to be inspected;
[0257] The defect similarity matrix is diffused to obtain the defect similarity diffusion matrix, and the defect similarity diffusion matrix is traversed to calculate the maximum value of each row in the defect similarity diffusion matrix. If there is a maximum value greater than a preset threshold, the surface defect image of the machine to be detected corresponding to the row is marked as the defect extraction result.
[0258] Specifically, the specific implementation algorithm of the processor 10 for the above instructions can refer to Figure 1 to Figure 2 The description of the relevant steps in the corresponding embodiments will not be repeated here.
[0259] It should be noted that the serial numbers of the above-mentioned embodiments of the present invention are only for description and do not represent the advantages and disadvantages of the embodiments. And the terms "including", "comprising" or any other variants thereof in this article are intended to cover non-exclusive inclusion, so that a process, device, article or algorithm including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, device, article or algorithm. In the absence of further restrictions, an element defined by the sentence "including one..." does not exclude the existence of other identical elements in the process, device, article or algorithm including the element.
[0260] Through the description of the above implementation methods, those skilled in the art can clearly understand that the algorithm of the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the algorithm described in each embodiment of the present invention.
[0261] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A mechanical surface defect segmentation and extraction method based on deep neural network, characterized in that: The method comprises: S1: collecting surface area images of different areas of the machine to be inspected, and preprocessing the collected surface area images to obtain preprocessed surface area images; S2: construct a mechanical surface defect recognition model, input the preprocessed surface area image into the mechanical surface defect recognition model, and mark the original surface area image with defects identified as the mechanical surface defect image to be detected, so as to obtain a set of mechanical surface defect images to be detected; S3: construct a set of surface defect images of different types of machinery, and use a feature extraction network to extract features from the surface defect images in the set of surface defect images to obtain a set of defect feature vectors of different types of machinery; S4: extracting a defect detection feature vector of the surface defect image of the machine to be inspected by using a feature extraction network, and calculating the similarity between the defect detection feature vector and the defect feature vector of the same type of machine to obtain a defect similarity matrix of the machine to be inspected; S5: diffuse the defect similarity matrix to obtain the defect similarity diffusion matrix, traverse the defect similarity diffusion matrix, calculate the maximum value of each row in the defect similarity diffusion matrix, and if there is a maximum value greater than a preset threshold, mark the surface defect image of the machine to be detected corresponding to the row as a defect extraction result; The defect similarity matrix D is diffused to obtain the defect similarity diffusion matrix, where the diffusion process of the defect similarity matrix D is: S51: Normalize the defect similarity matrix D to obtain a normalized defect similarity matrix : ; ; in: represents the jth row in the defect similarity matrix D. The maximum value, A random number of 1 or 2; The normalized defect similarity matrix is a matrix with m rows and B columns; S52: Initialize the transfer matrix , where the transfer matrix U is a matrix with m rows and B columns: ; in: represents the matrix element value of the jth row and bth column in the transfer matrix U, Defect similarity matrix The matrix element value at the jth row and bth column in ; Defect Similarity Matrix The jth row in The maximum value will Set to 4; S53: Initialize the diffusion matrix ; S54: setting the current iteration number of the diffusion matrix to t, and the initial value of t to 0; S55: Iterate the diffusion matrix: ; in: represents the diffusion matrix after the tth iteration; S56: Compare before and after iterations and The order of the matrix elements in each row is calculated, and the number of elements whose order changes in each row is recorded to obtain the average number of element order changes. ,in Indicates the number of elements whose order changes in row j; S57: If the current average element sequence change number is less than the preset threshold, As the defect similarity diffusion matrix, It is a matrix with m rows and B columns. The jth row in the matrix represents the image of the mechanical surface defect to be detected. The similarity with the images of different surface defects of the same machine type, otherwise , return to step S55.
2. A mechanical surface defect segmentation and extraction method based on deep neural network as claimed in claim 1, characterized in that: In the step S1, surface area images of different areas of the machine to be inspected are collected, and the collected surface area images are preprocessed, including: The surface area images of different areas of the machine to be inspected are collected by using a camera. The adjacent surface area images have an image overlap of less than 10%. The collected surface area images are: ; in: represents the i-th surface area image collected, and n represents the total number of surface area images collected; The collected surface area image is preprocessed to obtain a preprocessed surface area image, wherein the surface area image The preprocessing process is: S11: Surface area image Grayscale processing is performed, where the grayscale processing formula is: ; in: Respectively, images Medium Pixels The color value of the R, G, B color channels, pixels Representing images The pixel at row x and column y in Represents pixels Gray value of S12: Set the filter window, where the initial specification of the filter window is The maximum size of the matrix is matrix; S13: moving the filter window in the grayscale processed surface area image, with each movement range being 3 pixels; S14: sorting all the pixels in the filter window according to the grayscale value, and recording the maximum grayscale value, the median grayscale value, and the minimum grayscale value of the pixels in the filter window; S15: If the maximum grayscale value> the median grayscale value> the minimum grayscale value, then update the grayscale value of the central pixel in the filter window to the median grayscale value of the pixel in the filter window, and move the filter window; otherwise, determine whether the current filter window specification reaches the maximum specification. If it reaches the maximum specification, do not update the grayscale value of the central pixel in the filter window, and directly move the filter window. If it does not reach the maximum specification, add 2 to the rows and columns of the filter window, expand the filter window specification, and return to step S14; S16: repeating steps S13-S15 until filtering is completed on the grayscale processed surface area image; S17: traverse the surface area image after filtering, and take the average of the maximum grayscale value and the minimum grayscale value of the pixels in the surface area image as a binarization threshold; S18: Segmenting the surface area image into foreground and background based on a binary threshold, and calculating average grayscale values of the foreground and background parts respectively, wherein pixels greater than the binary threshold are background pixels, pixels less than or equal to the binary threshold are foreground pixels, the foreground pixels constitute the foreground, and the background pixels constitute the background; S19: If the average gray value of the foreground and background parts is equal to the binarization threshold, the iteration is terminated, and the surface area image after filtering is segmented into the foreground and the background using the binarization threshold to obtain the preprocessed surface area image , otherwise the average grayscale value of the foreground and background parts is used as the binarization threshold after iteration, and the process returns to step S18.
3. The method for segmenting and extracting mechanical surface defects based on a deep neural network according to claim 1, characterized in that: The mechanical surface defect recognition model is constructed in step S2, including: Construct a mechanical surface defect recognition model, wherein the constructed mechanical surface defect recognition model includes an input layer, a recognition layer and an output layer. The input layer is used to receive the preprocessed surface area image. The recognition layer structure is a plurality of residual units, which are used to perform residual convolution processing on the preprocessed surface area image to obtain the corresponding feature map. The output layer structure is a fully connected layer, which is used to receive the feature map and output the defect recognition result of the feature map. , where 0 means that there is no defect in the preprocessed surface area image, and 1 means that there is a defect in the preprocessed surface area image.
4. The method for segmenting and extracting mechanical surface defects based on a deep neural network according to claim 3, characterized in that: In the step S2, the preprocessed surface area image is input into the mechanical surface defect recognition model, and the corresponding original surface area image with the recognized defect is marked as the mechanical surface defect image to be detected, including: The preprocessed surface area image is input into the mechanical surface defect recognition model. The mechanical surface defect recognition model outputs the defect recognition result of the image, and marks the corresponding original surface area image with the recognized defect as the mechanical surface defect image to be detected, wherein the original surface area image represents the surface area image that has not been preprocessed. If it is recognized that the preprocessed surface area image has defects, the original surface area image corresponding to the preprocessed surface area image is marked as the mechanical surface defect image to be detected, and a set of mechanical surface defect images to be detected is obtained: ; in: represents the jth image of the surface defect of the machine to be inspected, and m represents the total number of the surface defect images of the machine to be inspected; Based on the mechanical surface defect recognition model, the pre-processed surface area image The process of defect identification is as follows: S21: Input layer receives the preprocessed surface area image , and the preprocessed surface area image Input to the recognition layer; S22: The recognition layer is based on L cascaded residual units to preprocess the surface area image Perform residual convolution processing to obtain the corresponding feature map, where the zth residual unit outputs the result The calculation formula is: ; in: represents the output result of the z-1th residual unit, Represents the surface area image after preprocessing ; Indicates the use of The pixel-sized convolution kernel performs convolution on the input value. Indicates the use of The pixel-sized convolution kernel convolves the input value; represents the activation function; The output of the Lth residual unit is used as the feature map , and input the feature map into the output layer; S23: The output layer uses the fully connected matrix to process the feature map to obtain the preprocessed surface area image Probability of defects : ; in: W represents the fully connected matrix, and T represents the transpose; If the probability is greater than the preset threshold, it means that the surface area image after preprocessing There are defects, otherwise it means the surface area image after preprocessing There are no defects.
5. The method for segmenting and extracting mechanical surface defects based on a deep neural network according to claim 1, characterized in that: In the step S3, a surface defect image set of different types of machinery is constructed, and a feature extraction network is used to extract defect feature vectors from the surface defect images in the surface defect image set, including: Construct a collection of surface defect images of different types of machinery: ; in: k represents the mechanical type, represents a set of surface defect images of k types of machinery, represents the bth surface defect image of the k-type machinery, and B represents the total number of surface defect images of different types of machinery; The feature extraction network is used to extract defect feature vectors from the surface defect images in the surface defect images, wherein the feature extraction network includes a color feature extraction network, a texture feature extraction network and a detail feature extraction network. The surface defect images in the k-type mechanical corresponding surface defect image set are The defect feature vector extraction process is as follows: S31: Extracting surface defect images using color feature extraction network Color characteristics : ; ; ; in: Representing surface defect images The color quantization result is Represent the quantized values of the R, G, and B color channels respectively, where the R color channel is quantized as , the G color channel is quantized to , the B color channel is quantized to , Represents the color space quantization result set ; Represent surface defect images Medium Pixels Color values in R, G, B color channels; X and Y represent the surface defect images respectively. The total number of row pixels and column pixels; S32: Extracting surface defect images using texture feature extraction network Texture features , texture feature extraction network for surface defect images Grayscale processing is performed, and the grayscale image after grayscale processing is divided into several grayscale image areas of the same size. The central pixel of each grayscale image area is selected, and the pixels in the grayscale image area with grayscale values greater than the central pixel are set to 1, and the remaining pixels are set to 0, and the central pixel is set to empty to obtain the binary code representation of each grayscale image area; the binary code representation is converted into a decimal code, and the decimal codes of all grayscale image areas are sorted according to the position of the grayscale image area to obtain the texture feature ; S33: Extracting surface defect images using detail feature extraction network Detailed features , where the detail feature extraction algorithm is the SIFT feature extraction algorithm; S34: Combine and fuse the extracted features of different types to obtain a surface defect image The defect feature vector : ; The defect feature vector set of different machines under machine type k is: ; in: B represents the total number of surface defect images of different types of machinery.
6. The method for segmenting and extracting mechanical surface defects based on a deep neural network according to claim 5, characterized in that: In the step S4, the feature extraction network is used to extract features from the surface defect image of the machine to be inspected, a defect detection feature vector is obtained, and the similarity between the defect detection feature vector and the defect feature vector of the same type of machine is calculated, including: The feature extraction network is used to extract features of the mechanical surface defect images to be detected in the mechanical surface defect image set to be detected, and a defect detection feature vector is obtained, wherein the defect detection feature vector set corresponding to the mechanical surface defect image set to be detected is: ; in: A defect detection feature vector corresponding to the image of the mechanical surface defect to be detected; The machine type to be tested is , corresponding to the mechanical type The defect feature vector set of different machines is , computing machine type The similarity between the defect feature vector set of different machines and any two feature vectors in the defect detection feature vector set, where the surface defect image of the machine to be detected Corresponding defect detection feature vector and Corresponding defect feature vector The similarity is , the similarity calculation method is the cosine similarity calculation formula.
7. The method for segmenting and extracting mechanical surface defects based on a deep neural network according to claim 6, characterized in that: In the step S4, based on the similarity between the defect detection feature vector and the defect feature vector of the same type of machinery, a defect similarity matrix of the machinery to be inspected is formed, including: Based on the similarity between the defect detection feature vector and the defect feature vector of the same type of machinery, a defect similarity matrix of the machinery to be inspected is constructed. : ; in: Indicates the machine type to be tested. express The bth surface defect image of type machinery, , ; Represents the image of mechanical surface defects to be detected The corresponding defect detection feature vector and The similarity of the corresponding defect feature vector, Represents the mth surface defect image of the machine to be inspected.
8. The method for segmenting and extracting mechanical surface defects based on a deep neural network according to claim 1, characterized in that: In the step S5, the defect similarity diffusion matrix is traversed, and the maximum value of each row in the defect similarity diffusion matrix is calculated. If there is a maximum value greater than a preset threshold, the surface defect image of the machine to be detected corresponding to the row is marked as a defect extraction result, including: The defect similarity diffusion matrix obtained by diffusion is traversed row by row, and the maximum value of each row in the defect similarity diffusion matrix is calculated. If there is a maximum value greater than a preset threshold, the surface defect image of the machine to be detected corresponding to the row is marked as a defect extraction result.
Citation Information
Patent Citations
Mobile phone casing defect detecting method based on depth learning
CN106875381A
surface defect detection algorithm for an LCD light guide plate
CN109801286A
