Industrial appearance defect detection method and equipment based on photometric stereo method and diffusion model
By combining multi-intensity photometric stereoscopic and condition-guided diffusion model methods, the accuracy of existing industrial appearance defect detection methods under view angle dependence and lighting environment complexity is solved, and a more efficient and robust defect detection effect is achieved.
Patent Information
- Application Number
- CN202410492510.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-23
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2044-04-23
AI Technical Summary
The existing industrial appearance defect detection methods rely on a single perspective and cannot fully detect object defects. They are low in accuracy in complex or uncontrollable lighting environments, high data marking costs, and diffusion models may introduce deviations when handling complex defects.
Combining the multi-intensity photometric stereo and conditional guided diffusion model, multi-angle lighting information is obtained through multiple light sources at different locations and directions, the Gaussian pyramid is used to smooth and downsample the image, and the brightness information of different lights is fused to build a defect-free normal sample data set, and a condition-guided diffusion model deep learning network is designed for training.
Improve the accuracy and robustness of defect detection, reduce the cost and complexity of data labeling, enhance the ability to identify complex defect patterns, and improve the generalization ability of the model when there is no defect type seen.
Smart Images

Figure CN118429284B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of machine vision technology, and in particular to an industrial appearance defect detection method and device combining multi-intensity photometric stereo and diffusion models. Background Art
[0002] Intelligent manufacturing is the main direction of manufacturing construction, and its development level is directly related to the quality level of my country's manufacturing industry. Industrial defect detection is important in intelligent manufacturing. It plays a vital role in improving product quality, enhancing production efficiency, and ensuring the sustainability of industrial manufacturing. Industrial defect detection can improve product quality and consistency and reduce manufacturing costs. And by timely detecting and handling defects, the waste of producing defective products is avoided.
[0003] Existing industrial appearance defect detection methods rely on viewing angles and can usually only observe images from a single perspective, which limits the global observation and analysis of the object surface. Some defects may only be visible at a certain viewing angle and not obvious at other viewing angles. It is impossible to fully detect and understand the defects of an object from a single viewing angle. Photometric stereo uses multiple light sources at different positions and directions to illuminate the surface of an object to obtain lighting information from multiple observation angles. This information includes reflection and scattering at different angles, which helps to understand the properties of the object surface more accurately. However, photometric stereo is highly dependent on uniform and known lighting conditions, which is often difficult to meet in practical applications, especially in complex or uncontrollable lighting environments. Photometric stereo is based on the assumption that the surface of an object has complete diffuse reflection, so the reconstruction effect is not ideal for those materials with specular reflection, transparency or complex textures. Occlusion and shadow problems are also a challenge because these factors will cause some areas to lack lighting information, thus affecting the final reconstruction quality. Finally, it is difficult to obtain the precise position and intensity of the light source in actual operation, which increases the complexity of the method. These limitations greatly reduce the scope of application and accuracy of traditional photometric stereo in practice.
[0004] Industrial production processes strictly control the defective rate, and defects are rare in products. Therefore, compared with normal samples that are easier to obtain, the number of defective samples is small, and the number of samples provided is limited. Compared with traditional defect detection deep learning models that can only use labeled defective samples for training, diffusion models can use a large number of normal samples without defects. It is an unsupervised learning method that does not require a large amount of manually labeled data or expert knowledge, which reduces the cost and complexity of data labeling in defect detection. Diffusion models have high efficiency and scalability when processing large-scale data sets because they do not require additional labeling or manual intervention. However, the lack of conditional guidance in the diffusion model when there are multiple possible reconstruction results may cause the model to introduce bias in the reconstruction process. Especially when faced with complex or unclearly defined defects, the model may choose a reconstruction path that does not match the actual situation. For some particularly complex or rare defect types, without proper conditional guidance, the model may be completely unable to recognize and handle these situations, resulting in the reconstruction results not only failing to repair the defects, but may even produce more inaccurate details. Summary of the invention
[0005] Based on the deficiencies of the prior art, the present invention proposes an industrial appearance defect detection method and device combining multi-intensity photometric stereo and conditional guided diffusion model, which improves the accuracy of defect detection, especially increases the accuracy of industrial appearance defect detection.
[0006] The industrial appearance defect detection method based on photometric stereo method and diffusion model designed by the present invention comprises the following steps:
[0007] Step S1, using multi-intensity fusion photometric stereo method to construct a defect-free normal sample data set, setting light sources in different positions and directions, first adjusting the light source intensity at the same angle and distance to obtain different illumination images, using Gaussian pyramid to smooth and downsample the images, fusing the brightness information of different illuminations, estimating the surface normal vector and albedo value of the object through the illumination model, integrating the albedo values of light sources at different positions to generate an albedo map as a defect-free normal sample;
[0008] Step S2, design and construct a conditionally guided diffusion model deep learning network, the deep learning network includes a denoising module, a denoising module and a conditional guided module; the denoising module is composed of an encoder and a decoder; wherein the input data of the denoising module are defect-free normal samples, random Gaussian noise and random mask images, and the input data of the denoising module are noisy samples, time control tensors and comprehensive features; the encoder and decoder contain a residual module and time embedding, the residual module is responsible for introducing time embedding information, and the attention mechanism of the residual module can make the network training faster;
[0009] The conditional guidance module includes multiple parallel dilated convolution layers, each dilated convolution layer has a different expansion rate, and the expansion rate defines the spatial distance between elements in the convolution kernel, allowing the network to cover receptive fields of different sizes, thereby capturing image features from fine-grained to coarse-grained. The conditional guidance module also includes a global average pooling layer, which is responsible for capturing the global context information of the image. The output of the pooling layer is upsampled to the same size as other dilated convolution layers, and then the outputs of all branches are fused in the depth direction. Finally, the fused feature map is processed by convolution to generate the comprehensive feature;
[0010] Step S3, using the image data set constructed in S1 to train the diffusion model deep learning network constructed in step S2, and continuously reducing the distance between the output noise and the real noise through training, thereby improving the accuracy of estimating normal samples;
[0011] Step S4, using the model trained in step S3 to perform defect detection and threshold segmentation on the input image.
[0012] Furthermore, the specific process of step 1 is as follows:
[0013] Step S1-1, use four light sources at different positions and directions to illuminate four positions on the sample surface respectively, obtain 4 images of the same scene at four viewing angles, change the light source intensity at the same angle and distance, repeat N times, and obtain N groups of images totaling N×4.
[0014] Step S1-2, the brightness intensity information extracted from the images under different light intensities is fused, and the image under each light intensity is convolved with a Gaussian kernel for smoothing using the Gaussian pyramid technology, and then down-sampled to obtain the next level of image, and this process is repeated until the required number of pyramid layers is reached, and the information of different light intensities is fused to obtain 4 complete and accurate intensity images;
[0015] Step S1-3, using the light intensity data collected in the above steps, the normal vector of the object surface at each position is estimated by modeling the light model, a total of 4 groups, by obtaining the light intensity and normal vector information, according to the albedo estimation method including Lambert's law, 4 groups of albedo values at each position of the sample are estimated;
[0016] Step S1-4: Integrate the estimated albedo values to obtain an albedo map of the sample surface. The albedo map is a grayscale image in which each pixel value represents the albedo of the object at that position. The albedo image is used as a normal sample without defects.
[0017] Furthermore, in step S1, the angles between the directions of the four light source beams and the central axis of the camera are 30°, 60°, 30°, and 60° respectively; the angles between the projection of the light source beam and the principal axis of the object to be measured, and the angles between the beam and the starting point are 0°, 90°, 180°, and 270°.
[0018] Furthermore, the specific process of step S2 is as follows:
[0019] S2-1, generate a random Gaussian noise image and a random mask image with the same resolution as the sample, input the defect-free normal sample, the generated random Gaussian noise image and the random mask image into the noise adding module, the noise adding module randomly generates a diffusion time control tensor, and outputs the noisy sample;
[0020] S2-2, input the defect-free normal sample into the guidance module, which extracts the features of the image. These features contain spatial information and context information, and fuse the features of different scales to obtain a comprehensive feature representation that comprehensively considers multi-scale spatial information;
[0021] S2-3, the noisy samples and time control tensor obtained in 2-1 are input into the denoising module. First, the time control tensor is embedded in time through the fully connected layer of the time tensor. Then N samples are input into the convolution layer to convolve the input image. The time embedding and the convolved image are input into the encoder. The encoder uses time embedding to control the residual module to extract features at different stages. Then, the downsampling module reduces the space and size of the features, and the features are recorded in the residual connection module.
[0022] S2-4, the features obtained in the previous step are passed through the feature extraction module for feature integration, the integrated features are input into the decoder with the features recorded in the residual connection module in the previous step and the comprehensive features obtained in S2-2 for upsampling and feature fusion, and the output is convolved through the convolution layer to obtain the predicted reconstructed sample image.
[0023] Furthermore, in step S2, the encoding network includes 13 residual blocks and 5 pooling layers; the decoding network includes 13 residual blocks, 5 upsampling layers and 4 concat connection layers.
[0024] Furthermore, the specific process of step S3 is as follows:
[0025] S3-1, in step S2-1, the diffusion time control tensor t of length N obeys the following distribution:
[0026] t~Uniform({1,...,T})
[0027] The defect-free normal sample is x0, and the random Gaussian noise image is ∈, which is taken from the normal distribution ∈~N(0,1). is the constant parameter obtained from the time control tensor, the random mask is M, and the noised sample x is obtained according to the following formula t .
[0028]
[0029] S3-2, in steps S2-2 and S2-3, the sample x after adding noise t , the time control tensor t, the noise of the neural network output is ∈ θ (x t ,t,c), the real noise∈~N(0,1),c represents the conditional mechanism, then the loss function is:
[0030]
[0031] According to the noise ∈ output by the neural network θ (x t ,t), the sample x after adding noise t , a constant parameter obtained from the time control tensor The estimated normal sample is obtained according to the following formula
[0032]
[0033] Furthermore, in step S3, the network structure in S2 is trained using a back propagation algorithm with noise loss as the target;
[0034] The conditioning mechanism is connected to the model via a cross-attention mechanism;
[0035] The denoising module of the diffusion model is trained unsupervised using self-supervised learning.
[0036] Furthermore, in step S4, the image is input into the network model to obtain a reconstructed sample The defect sample x0 and the reconstructed sample Bring in the anomaly score formula:
[0037]
[0038] Where n is the resolution of the image. The threshold is determined, and the exact location of the defect is obtained through threshold segmentation by combining the residual image and the anomaly score. The pixels with scores higher than the threshold are the defect locations.
[0039] Based on the same inventive concept, the present invention also designs an electronic device, including:
[0040] one or more processors;
[0041] A storage device for storing one or more programs;
[0042] When one or more programs are executed by the one or more processors, the one or more processors implement an industrial appearance defect detection method and device based on photometric stereo and diffusion model.
[0043] Based on the same inventive concept, the present solution also designs a computer-readable medium on which a computer program is stored. When the program is executed by a processor, an industrial appearance defect detection method and device based on photometric stereo and diffusion model are implemented.
[0044] The present invention is a little bit in that:
[0045] 1. This invention innovatively applies photometric stereo method combined with Gaussian pyramid multi-intensity fusion method to defect detection, which significantly improves the robustness of the algorithm to illumination changes. By using comprehensive information from multiple illumination intensities, the impact of illumination changes on detection accuracy is reduced. The diffusion model can automatically learn the characteristics and representation of data, and detect abnormal samples by "reconstructing" the defective part and using the distribution characteristics of the data itself, thereby greatly reducing the difficulty and cost of data collection and labeling, and improving the robustness and accuracy of defect detection.
[0046] 2. The present invention innovatively invented the multi-intensity fusion photometric stereo method. The method combines the powerful functions of photometric information and multi-scale image processing, and improves the ability to recognize surface details and textures of objects. By utilizing images under different lighting conditions, the method can more accurately estimate the surface normal and reflection characteristics of objects. The introduction of the Gaussian pyramid enables the method to analyze images at different scales, effectively extract texture information from coarse to fine, and enhance the adaptability and flexibility of the method for details of different scales. The multi-intensity fusion strategy also further enhances the dynamic range of the image, so that good detail capture capabilities can be maintained even under extreme lighting conditions such as shadows or highlights, greatly improving the sample quality of the data set.
[0047] 3. The present invention innovatively invented the conditional guided diffusion model. By introducing additional comprehensive features through the guidance module, it can more accurately reconstruct and repair damaged images, thereby improving detection accuracy. The conditional guidance module enables the model to optimize specific defect features and enhances the ability to recognize complex defect patterns. The conditional guided diffusion model can also improve the generalization ability of the model when facing unseen defect types by learning the data distribution under different conditions, bringing a qualitative improvement to defect detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 It is a flow chart of the multi-intensity photometry of the present invention.
[0049] Figure 2This is the overall architecture diagram of the diffusion model neural network of the embodiment of the present invention
[0050] Figure 3 This is a neural network architecture diagram of the guidance module of the present invention.
[0051] Figure 4 It is a neural network architecture diagram of the denoising module of the present invention.
[0052] Figure 5 It is a system flow chart of the present invention. DETAILED DESCRIPTION
[0053] In order to facilitate ordinary technicians in the field to understand and implement the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the implementation examples described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.
[0054] Embodiment 1
[0055] Existing industrial appearance defect detection methods can only observe images from a single perspective, but it is impossible to fully detect and understand the defects of objects from a single perspective. At the same time, due to the strict control of defective rates in the defective industrial production process, defects are rare in products. The present invention proposes an industrial appearance defect detection method that combines multi-intensity photometric stereo and diffusion models. The multi-intensity fusion photometric stereo method is combined with the conditional guided diffusion model, and a large number of defect-free samples in industrial production are used, combined with the training strategy of unsupervised learning, to improve the robustness and accuracy of defect detection.
[0056] The method provided by the present invention designs a conditional guided diffusion model deep learning network, and its overall structure is shown in Figure 1 . Figure 2 This is the neural network architecture diagram of the guidance module of the conditional guided diffusion model. Figure 3 is a neural network architecture diagram of the denoising module of the conditional guided diffusion model. The specific embodiment of this method includes the following steps:
[0057] Step S1, constructing a defect-free normal sample data set by multi-intensity fusion photometric stereo method. Each sample in the data set is an albedo image obtained under four viewing angles:
[0058] Step S1-1, use four light sources at different positions and directions to illuminate four positions on the sample surface, and obtain four images of the same scene at four viewing angles. At the same angle and distance, change the light intensity, repeat N times, and obtain N groups of pictures totaling N×4. For each pixel point (x, y), extract the pixel value I(x, y) of the grayscale image as the brightness intensity.
[0059] Step S1-2, the brightness intensity information extracted from the images under different light intensities is fused. Using the Gaussian pyramid technology, the image of each scale is convolved with a Gaussian kernel for smoothing, and then downsampled to obtain the image of the next level. Repeat this process until the required number of pyramid levels is reached. The intensity information is fused at different scales to obtain 4 more complete and accurate intensity images. The specific formula can be expressed as:
[0060]
[0061] Among them I i (x,y) represents the image of the i-th layer of the Gaussian pyramid, I kernel (x,y) is the Gaussian kernel and * indicates the convolution operation.
[0062] Step S1-3, using the illumination intensity data collected in the above steps and the surface normal constraint in the photometric stereo method, the normal vector N(x, y) of the object surface at each position is estimated by modeling the illumination model. The direction of the normal vector N(x, y) is opposite to the direction of the image brightness gradient. This can be expressed by the following formula:
[0063]
[0064] in is the gradient of brightness intensity. This step has obtained the normal vector information of the sample surface, a total of 4 groups. By obtaining the illumination intensity and normal vector information, according to the albedo estimation method Lambert's law equation:
[0065] I=ρL·N
[0066] Where I is the observed brightness, ρ is the reflectivity of the surface, L is the direction vector of the incident light, N is the surface normal vector, and L·N is the dot product of L and N, representing the cosine of the angle between the incident light and the surface normal. Given N, the albedo ρ can be obtained by dividing both sides of the above equation by the modulus of N, i.e., ||N||:
[0067]
[0068] Finally, four groups of albedo values at each position of the sample are obtained.
[0069] Step S1-4, the estimated albedo values are integrated to obtain an albedo map of the sample surface. The albedo map is a grayscale image, in which each pixel value represents the albedo of the object at that position. The albedo image is used as a normal sample without defects.
[0070] Furthermore, in step S1, the angles between the directions of the four light source beams and the central axis of the camera are 30°, 60°, 30°, and 60° respectively; the angles between the projection of the light source beam and the principal axis of the object to be measured, and the angles between the beam and the starting point are 0°, 90°, 180°, and 270°;
[0071] Step S2, construct a diffusion model deep learning network. The diffusion model includes a guiding module, a noise adding module and a denoising module. The denoising module is composed of an encoding network and a decoding network. The specific operation process of the conditional diffusion model is as follows:
[0072] S2-1, generate a random Gaussian noise image and a random mask image with the same resolution as the sample, input the defect-free normal sample, the generated random Gaussian noise image and the random mask image into the noise adding module, the noise adding module randomly generates a diffusion time control tensor, and outputs the noisy sample.
[0073] S2-2, input the defect-free normal sample into the guidance module, which extracts the features of the image. These features contain rich spatial information and context information. The features of different scales are fused to obtain a comprehensive feature representation that comprehensively considers multi-scale spatial information. This comprehensive feature representation contains both detailed information and global context information.
[0074] S2-3, input the noisy samples and time control tensor obtained in 2-1 into the denoising module. First, the time control tensor is embedded in time through the fully connected layer of the time tensor; then N samples are input into the convolution layer to convolve the input image. The time embedding and the convolved image are input into the encoder. The encoder uses time embedding to control the residual module to extract features at different stages, and then reduces the space and size of the features through the downsampling module, and records the features in the residual connection module.
[0075] S2-4, the features obtained in the previous step are passed through the feature extraction module for feature integration. The integrated features are input into the decoder with the features recorded in the residual connection module in the previous step and the comprehensive features obtained in S2-2 for upsampling and feature fusion, and the output is convolved through the convolution layer to obtain the predicted reconstructed sample image.
[0076] The temporal embedding in the denoising module in step S2 is introduced by the residual module;
[0077] The conditional guidance module in step S2 is implemented by using multiple dilated convolutional layers in parallel, each with a different dilation rate. These dilation rates define the spatial distance between elements in the convolution kernel, allowing the network to cover receptive fields of different sizes, thereby capturing image features from fine-grained to coarse-grained. Specifically, it includes four dilated convolution branches with different dilation rates, 1, 6, 12, and 18. This design is intended to aggregate contextual information at various scales and enhance the model's ability to understand different parts of the image. The conditional guidance module also includes a global average pooling layer, which is responsible for capturing the global contextual information of the image. The output of the pooling layer is upsampled to the same size as the other dilated convolutional layers, and then the outputs of all branches are fused in the depth direction. Finally, the fused feature map is processed by a 1x1 convolution to generate a comprehensive feature representation. This comprehensive feature representation contains both detail information and global context information.
[0078] Furthermore, in step S2, the encoding network includes 13 residual blocks and 5 pooling layers; the decoding network includes 13 residual blocks, 5 upsampling layers and 4 concat connection layers;
[0079] The residual block of the encoder and decoder in step S2 uses a convolution kernel of size 3*3.
[0080] Step S3, using the defect-free normal sample data set constructed in S1 to train the deep learning model constructed in step S2;
[0081] S3-1, in step S2-1, the diffusion time control tensor t of length N obeys the following distribution:
[0082] t~Uniform({1,...,T})
[0083] The defect-free normal sample is x0, and the random Gaussian noise image is ∈, which is taken from the normal distribution ∈~N(0,1). is a constant parameter obtained from the time control tensor, and the random mask is M. The noised sample x is obtained according to the following formula t .
[0084]
[0085] S3-2, in steps S2-2 and S2-3, the sample x after adding noise t , the time control tensor t, the noise of the neural network output is ∈ θ (x t ,t,c), the real noise∈~N(0,1),c represents the conditional mechanism. Then the loss function is:
[0086]
[0087] According to the noise ∈ output by the neural network θ (x t ,t), the sample x after adding noise t , a constant parameter obtained from the time control tensor The estimated normal sample is obtained according to the following formula
[0088]
[0089] Furthermore, the noise loss As the goal, the back propagation algorithm is used to train the network structure in S2;
[0090] Furthermore, the conditioning mechanism c is connected to the model via a cross-attention mechanism.
[0091] Furthermore, the normal sample It is obtained by calculating the noise after the defective image passes through the neural network, so the normal sample free from defects;
[0092] Furthermore, the denoising module of the diffusion model is trained unsupervisedly using self-supervised learning.
[0093] Step S4, using the deep learning model trained in step S3, sample x0 from the defective samples to be detected, and use the multi-intensity fusion photometric stereo method in S1 to obtain the processed image. Input the image into the network model to obtain the reconstructed sample The defect sample x0 and the reconstructed sample Bring in the anomaly score formula:
[0094]
[0095] Where n is the resolution of the image. The threshold is determined, and the exact location of the defect is obtained through threshold segmentation by combining the residual image and the anomaly score. The pixels with scores higher than the threshold are the defect locations.
[0096] Embodiment 2
[0097] Based on the same inventive concept, the present invention also provides an electronic device, including one or more processors; a storage device for storing one or more programs; when one or more programs are executed by the one or more processors, the one or more processors implement the method described in Example 1.
[0098] Since the device introduced in the second embodiment of the present invention is an electronic device used to implement the industrial appearance defect detection method based on the photometric stereo method and the diffusion model in the first embodiment of the present invention, the technical personnel in the field can understand the specific structure and deformation of the electronic device based on the method introduced in the first embodiment of the present invention, so it is not repeated here. All electronic devices used in a method in the embodiment of the present invention belong to the scope of protection of the present invention.
[0099] Embodiment 3
[0100] Based on the same inventive concept, the present invention further provides a computer-readable medium on which a computer program is stored, and when the program is executed by a processor, the method described in the first embodiment is implemented.
[0101] Since the device introduced in the third embodiment of the present invention is a computer-readable medium used to implement the industrial appearance defect detection method based on the photometric stereo method and the diffusion model in the first embodiment of the present invention, the technical personnel in the field can understand the specific structure and deformation of the electronic device based on the method introduced in the first embodiment of the present invention, so it is not repeated here. All electronic devices used in a method in the embodiment of the present invention belong to the scope of protection of the present invention.
[0102] The specific embodiments described herein are merely examples of the spirit of the present invention. Those skilled in the art may make various modifications or additions to the specific embodiments described or replace them in similar ways, but they will not deviate from the spirit of the present invention or exceed the scope defined by the appended claims.
Claims
1. An industrial appearance defect detection method based on photometric stereo and diffusion model, characterized by: Step S1, using multi-intensity fusion photometric stereo method to construct a defect-free normal sample data set, setting light sources in different positions and directions, first adjusting the light source intensity at the same angle and distance to obtain different illumination images, using Gaussian pyramid to smooth and downsample the images, fusing the brightness information of different illuminations, estimating the surface normal vector and albedo value of the object through the illumination model, integrating the albedo values of light sources at different positions to generate an albedo map as a defect-free normal sample; Step S2, designing and constructing a condition-guided diffusion model deep learning network, the deep learning network comprising a noise addition module, a noise removal module and a condition-guided module; The denoising module consists of an encoder and a decoder; the input data of the denoising module are defect-free normal samples, random Gaussian noise and random mask images, and the input data of the denoising module are noisy samples, time control tensors and comprehensive features; the encoder and decoder contain residual modules and time embedding. The residual module is responsible for introducing time embedding information. At the same time, the attention mechanism of the residual module can make the network training faster, where: the diffusion time control tensor t with a length of N obeys the following distribution: N is the number of input samples; The conditional guidance module includes a plurality of parallel dilated convolutional layers, each dilated convolutional layer has a different dilation rate, and the dilation rate defines the spatial distance between elements in the convolution kernel. The conditional guidance module also includes a global average pooling layer, which is responsible for capturing the global context information of the image. The output of the pooling layer is upsampled to the same size as other dilated convolutional layers, and then the outputs of all branches are fused in the depth direction. Finally, the fused feature map is processed by convolution to generate the comprehensive feature. Step S3, using the image data set constructed in S1 to train the diffusion model deep learning network constructed in step S2, and continuously reducing the distance between the output noise and the real noise through training, thereby improving the accuracy of estimating normal samples; Step S4, using the model trained in step S3 to perform defect detection and threshold segmentation on the input image.
2. The industrial appearance defect detection method based on photometric stereo and diffusion model according to claim 1, characterized in that: The specific process of step S1 is as follows: Step S1-1, using four light sources at different positions and directions, irradiating the light sources to four positions on the sample surface respectively, obtaining four images of the same scene at four viewing angles, changing the light source intensity at the same angle and distance, repeating N times, obtaining N groups of images totaling N×4 images; Step S1-2, the brightness intensity information extracted from the images under different light intensities is fused, and the image under each light intensity is convolved with a Gaussian kernel for smoothing using the Gaussian pyramid technology, and then down-sampled to obtain the next level of image, and this process is repeated until the required number of pyramid layers is reached, and the information of different light intensities is fused to obtain 4 complete and accurate intensity images; Step S1-3, using the light intensity data collected in the above steps, the normal vector of the object surface at each position is estimated by modeling the light model, a total of 4 groups, by obtaining the light intensity and normal vector information, according to the albedo estimation method including Lambert's law, 4 groups of albedo values at each position of the sample are estimated; Step S1-4, integrating the estimated albedo values to obtain an albedo map of the sample surface. The albedo map is a grayscale image in which each pixel value represents the albedo of the object at that position. The albedo image is used as a normal sample without defects.
3. The industrial appearance defect detection method based on photometric stereo and diffusion model according to claim 2, characterized in that: In step S1, the angles between the directions of the four light source beams and the central axis of the camera are 30°, 60°, 30°, and 60° respectively; the angles between the projection of the light source beam and the principal axis of the object to be measured, and the angles between the beam and the starting point are 0°, 90°, 180°, and 270°.
4. The industrial appearance defect detection method based on photometric stereo and diffusion model according to claim 1, characterized in that: The specific process of step S2 is as follows: S2-1, generate a random Gaussian noise image and a random mask image with the same resolution as the sample, input the defect-free normal sample, the generated random Gaussian noise image and the random mask image into the noise adding module, the noise adding module randomly generates a diffusion time control tensor, and outputs the noisy sample; S2-2, input the defect-free normal sample into the guidance module, which extracts the features of the image. These features contain spatial information and context information, and fuse the features of different scales to obtain a comprehensive feature representation that comprehensively considers multi-scale spatial information; S2-3, the noisy samples and time control tensor obtained in 2-1 are input into the denoising module. First, the time control tensor is embedded in time through the fully connected layer of the time tensor. Then N samples are input into the convolution layer to convolve the input image. The time embedding and the convolved image are input into the encoder. The encoder uses time embedding to control the residual module to extract features at different stages. Then, the downsampling module reduces the space and size of the features, and the features are recorded in the residual connection module. S2-4, the features obtained in the previous step are passed through the feature extraction module for feature integration, the integrated features are input into the decoder with the features recorded in the residual connection module in the previous step and the comprehensive features obtained in S2-2 for upsampling and feature fusion, and the output is convolved through the convolution layer to obtain the predicted reconstructed sample image.
5. The industrial appearance defect detection method based on photometric stereo and diffusion model according to claim 1, characterized in that: In step S2, the encoding network includes 13 residual blocks and 5 pooling layers; the decoding network includes 13 residual blocks, 5 upsampling layers and 4 concat connection layers.
6. The industrial appearance defect detection method based on photometric stereo and diffusion model according to claim 4, characterized in that: The specific process of step S3 is as follows: S3-1, the normal sample without defects is , the random Gaussian noise image is , taken from the normal distribution , is the constant parameter obtained according to the time control tensor, the random mask is M, and the noisy sample is obtained according to the following formula , S3-2, in steps S2-2 and S2-3, the sample after adding noise , the time control tensor t, the noise of the neural network output is , the real noise , c represents the conditional action mechanism, then the loss function is: According to the noise of the neural network output , the sample after adding noise , a constant parameter obtained from the time control tensor , according to the following formula, the estimated normal sample is obtained , 。 7. The industrial appearance defect detection method based on photometric stereo and diffusion model according to claim 1, characterized in that: In the step S3, the network structure in S2 is trained using a back propagation algorithm with the noise loss as the target; The conditioning mechanism is connected to the model via a cross-attention mechanism; The denoising module of the diffusion model is trained unsupervised using self-supervised learning.
8. The method for detecting industrial appearance defects based on photometric stereo and diffusion model according to claim 1, characterized in that: In step S4, the image is input into the network model to obtain a reconstructed sample. , the defective samples And the reconstructed sample Bring in the anomaly score formula: Where n is the resolution of the image. The threshold is determined, and the exact location of the defect is obtained through threshold segmentation by combining the residual image and the anomaly score. The pixels with scores higher than the threshold are the defect locations.
9. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs; When one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 8.
10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
System and method for simultaneous multi-layer multi-tasking imaging
CN115251885A
Small sample surface defect image generation method and system based on feedback reinforcement learning
CN117710349A