An image processing algorithm based on texture fusion analysis

By combining multi-resolution frequency domain decomposition and nonlocal texture similarity calculation with a dynamic weight allocation network, the problem of insufficient differentiation between defect areas and background textures in industrial visual inspection is solved, and high-precision defect recognition of complex texture surfaces is achieved.

CN122134812APending Publication Date: 2026-06-02STORAGEX TECH INC

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
STORAGEX TECH INC
Filing Date
2026-05-06
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

Existing industrial vision inspection methods struggle to distinguish between defect areas and background textures when dealing with defects on complex textured surfaces. Furthermore, the weighting of the defect response map is not dynamically adjusted, resulting in limited defect localization accuracy and an inability to effectively identify minute defects obscured by the background texture.

Method used

An image processing algorithm based on texture fusion analysis is adopted. Sub-band image groups are generated by multi-resolution frequency domain decomposition. By combining non-local texture similarity calculation and dynamic weight allocation network, texture structure consistency metric and fusion weight matrix are generated. Cross-scale feature association and regional stability evaluation are performed, and the fusion weight is adaptively adjusted to improve the accuracy of defect recognition.

Benefits of technology

Breaking through the limitations of single-scale texture analysis, it can more accurately identify tiny defects obscured by complex backgrounds, improve the clarity of the boundary between defective and normal areas, effectively separate defect signals from background textures, and improve defect location accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122134812A_ABST
    Figure CN122134812A_ABST
Patent Text Reader

Abstract

This invention relates to the field of image processing technology in industrial visual inspection, specifically an image processing algorithm based on texture fusion analysis. The algorithm includes: performing multi-resolution frequency domain decomposition on a surface grayscale image to generate a sub-band image group; generating background suppression frequency domain mask data for a process background reference image; inputting the sub-band image group into a non-local texture similarity calculation engine to output a texture structure consistency metric value, and performing point-by-point logical operations with the background suppression frequency domain mask data to generate a preliminary defect response map; calling a dynamic weight allocation network to perform regional stability evaluation on the preliminary defect response map, and generating a texture fusion weight matrix based on the local gradient distribution characteristics of the surface grayscale image; and performing weighted fusion and threshold segmentation on the preliminary defect response map based on the weight matrix to output the defect region localization result. This invention combines a dynamic weight allocation network to optimize defect response fusion, improving the accuracy of defect localization in industrial visual inspection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial visual inspection image processing technology, and in particular to an image processing algorithm based on texture fusion analysis. Background Technology

[0002] In industrial visual inspection, traditional defect recognition methods often rely on single-scale grayscale thresholding or edge detection, which struggles to extract defects from complex textured surfaces. Existing frequency-domain filtering-based techniques typically employ noise suppression within a fixed frequency band, failing to consider the frequency distribution differences of texture features under varying process backgrounds, leading to confusion between valid defect signals and background textures. Some schemes incorporating texture analysis utilize local window statistical features (such as gray-level co-occurrence matrices), but these can only extract texture information at a single resolution, failing to capture cross-scale structural correlations and prone to false detections in the presence of periodic background texture interference.

[0003] In processing industrial scenarios with non-uniform lighting or varying surface roughness, existing technologies often rely on static empirical values ​​for weight allocation in defect response maps, failing to dynamically adjust based on local texture stability. This results in insufficient differentiation between defect and normal texture regions. For sub-band images after multi-resolution frequency domain decomposition, conventional methods process each frequency band feature independently and then simply overlay them, lacking quantitative correlation of cross-scale texture structure consistency. This leads to minute defects being masked against a high-noise background. Furthermore, background suppression processing often relies on global statistical characteristics to generate masks, making it difficult to adapt to the spectral overlap between local process defects and background textures, resulting in excessive suppression of defect signals or background residue.

[0004] In industrial visual inspection, the texture features of surface defects are often distributed across multiple spatial frequency scales, and there are structural similarity differences between normal process textures and defect textures in non-local regions. Traditional methods do not logically fuse non-local texture similarity metrics with frequency domain masks point by point, making it impossible to accurately locate defect regions enveloped by background textures. Furthermore, existing dynamic weight adjustment mechanisms mostly rely on manually set rules and do not adaptively generate fusion weights by combining the regional stability and local gradient distribution characteristics of the defect response map, resulting in limited defect localization accuracy on complex textured surfaces. Summary of the Invention

[0005] The purpose of this invention is to address the shortcomings of existing technologies by proposing an image processing algorithm based on texture fusion analysis.

[0006] To achieve the above objectives, the present invention adopts the following technical solution: an image processing algorithm based on texture fusion analysis, comprising: Acquire a set of raw industrial visual inspection images to be processed, wherein the set of raw industrial visual inspection images includes at least one grayscale image of the surface of the object to be tested and a corresponding process background reference image. Multi-resolution frequency domain decomposition processing is performed on the surface grayscale image to generate sub-band image groups covering different spatial frequencies. At the same time, adaptive spectral mask generation processing is performed on the process background reference image to obtain background suppression frequency domain mask data. The sub-band image group is input into a pre-built non-local texture similarity calculation engine for cross-scale feature association processing, outputting a texture structure consistency metric value for each pixel location, and performing point-by-point logical operations on the texture structure consistency metric value and the background suppression frequency domain mask data to generate a preliminary defect response map. The dynamic weight allocation network is invoked to perform regional stability assessment on the preliminary defect response map, and a texture fusion weight matrix is ​​generated by combining the local gradient distribution features of the surface grayscale image. Based on the texture fusion weight matrix, the preliminary defect response map is subjected to weighted fusion and threshold segmentation processing to output the final defect region localization result data.

[0007] As a further aspect of the present invention, the step of performing multi-resolution frequency band decomposition processing on the surface grayscale image to generate sub-band image groups covering different spatial frequencies includes: The surface grayscale image is subjected to two-dimensional discrete wavelet transform decomposition to obtain low-frequency approximate components and high-frequency detail components in multiple directions. The low-frequency approximation component is recursively subjected to wavelet packet decomposition until the preset number of decomposition layers is reached, generating a multi-level set of frequency domain sub-band coefficients. For each set of frequency domain subband coefficients, inverse wavelet transform reconstruction is performed to restore a subband image with the same size as the original image. Each subband image corresponds to a specific frequency range and spatial direction. The sub-band images from all levels are aggregated to construct the sub-band image group.

[0008] As a further aspect of the present invention, the step of performing adaptive spectral mask generation processing on the process background reference image to obtain background suppression frequency domain mask data includes: Fourier spectrum analysis was performed on the process background reference image to calculate its power spectral density distribution. Identify the dominant frequency peak point corresponding to the process texture on the power spectral density distribution map, and record the radial and angular coordinates of the dominant frequency peak point; An elliptical attenuation bandstop filter is constructed with each dominant frequency peak point as the center, and the major axis of the elliptical attenuation bandstop filter is aligned with the direction of the process texture. All the elliptical attenuation bandstop filters are superimposed to generate a frequency domain mask function, and the frequency domain mask function is converted into a spatial domain convolution kernel to obtain the background suppression frequency domain mask data.

[0009] As a further aspect of the present invention, the step of inputting the sub-band image group into a pre-constructed non-local texture similarity calculation engine for cross-scale feature association processing, and outputting a texture structure consistency metric value for each pixel location, includes: Select at least three sub-band images of different scales from the sub-band image group as a reference scale image group; For each target pixel in the reference scale image group, a set of pixels with similar grayscale patterns is searched in its neighborhood to construct a non-local similar pixel index table. Calculate the structural tensor difference value between the target pixel and each pixel in the non-local similar pixel index table; An exponentially weighted sum of all the structural tensor differences is performed to generate a texture structure consistency metric for the target pixel. By traversing all pixels in the reference scale image group, a texture structure consistency metric map with the same size as the surface grayscale image is generated.

[0010] As a further aspect of the present invention, the step of performing point-by-point logical operations on the texture structure consistency metric and the background suppression frequency domain mask data to generate a preliminary defect response map includes: Read the value of each pixel in the texture structure consistency measurement map and map it to a probability range of zero to one; Read the mask gain coefficient at the corresponding pixel position in the background suppression frequency domain mask data; Multiply the value within the probability interval by the mask gain coefficient to obtain the weighted intermediate response value; Determine whether the intermediate response value exceeds the preset initial activation threshold. If it does, mark the pixel as a potential defect point; otherwise, mark it as a background point. The labeling results of all pixels are combined to generate the preliminary defect response map.

[0011] As a further aspect of the present invention, the step of calling a dynamic weight allocation network to perform regional stability evaluation processing on the preliminary defect response map, and generating a texture fusion weight matrix by combining the local gradient distribution features of the surface grayscale image, includes: The preliminary defect response map is divided into multiple non-overlapping evaluation windows; Within each evaluation window, the number and spatial distribution of potential defect points are statistically analyzed, and the defect clustering index of that window is calculated. Simultaneously, the local gradient magnitude histogram of the corresponding window region in the surface grayscale image is extracted, and its skewness and kurtosis characteristics are calculated to generate a gradient distribution feature vector. The defect clustering index is concatenated with the gradient distribution feature vector to form the network input feature vector; The network input feature vector is input into the dynamic weight allocation network for forward inference, and the texture fusion weight value corresponding to each evaluation window is output. Based on the texture fusion weight values ​​of all evaluation windows, the resolution is restored to pixel level using bilinear interpolation to generate the texture fusion weight matrix.

[0012] As a further aspect of the present invention, the step of statistically analyzing the number and spatial distribution of potential defect points within each evaluation window and calculating the defect clustering index of that window includes: The total number of pixels marked as potential defect points within the evaluation window is counted to obtain the defect point count. Calculate the centroid coordinates of all the potential defect points within the evaluation window; Measure the Euclidean distance from each potential defect point to the centroid coordinates, and calculate the average distance value; Dividing the number of defect points by the average distance value yields the initial clustering degree, which reflects the tightness of the clustering. The initial clustering degree is subjected to a logarithmic transformation to generate the defect clustering degree index.

[0013] As a further aspect of the present invention, the step of extracting the local gradient magnitude histogram of the corresponding window region in the surface grayscale image, and calculating its skewness and kurtosis features to generate a gradient distribution feature vector includes: The Sobel operator is used to perform convolution operations on the corresponding window regions in the surface grayscale image to obtain the horizontal gradient component map and the vertical gradient component map. Calculate the combined gradient magnitude of each pixel in the horizontal gradient component map and the vertical gradient component map; The synthesized gradient magnitude is divided into a preset number of gray level intervals, the pixel frequency in each interval is counted, and a gradient magnitude histogram is constructed. The skewness and kurtosis coefficients of the gradient magnitude histogram are calculated using statistical formulas. The skewness coefficient, the kurtosis coefficient, and the energy value of the gradient magnitude histogram are combined to form the gradient distribution feature vector.

[0014] As a further aspect of the present invention, the step of performing weighted fusion and threshold segmentation processing on the preliminary defect response map based on the texture fusion weight matrix to output the final defect region localization result data includes: Read the weight coefficients for each pixel position in the texture fusion weight matrix; The weighting coefficient is multiplied by the response value of the corresponding pixel in the preliminary defect response map to obtain the weighted response value; Gaussian smoothing filtering is applied to the weighted response values ​​to eliminate interference from isolated noise points; Calculate the global mean and standard deviation of the weighted response values ​​of the entire image after smoothing; The final segmentation threshold is set to the global mean plus twice the standard deviation, and pixels larger than this threshold are classified as defect areas; Record the contour coordinates and area attributes of all the defective regions to generate the final defective region location result data.

[0015] As a further aspect of the present invention, the step of inputting the network input feature vector into the dynamic weight allocation network for forward inference and outputting the texture fusion weight value corresponding to each evaluation window includes: Receive the network input feature vector formed by concatenating the defect clustering index and the gradient distribution feature vector, and input the network input feature vector into the input layer of the dynamic weight allocation network; The input feature vector of the network is normalized by the input layer of the dynamic weight allocation network to eliminate the difference in the units of different features and obtain a normalized feature vector. The normalized feature vector is transmitted to the multi-level cascaded fully connected layer structure in the dynamic weight allocation network. The multi-level cascaded fully connected layer structure contains at least three hidden layers, wherein the first hidden layer performs linear transformation and nonlinear activation operations to generate a primary abstract feature representation. The primary abstract feature representation is passed to the second hidden layer, which introduces a gating unit based on an attention mechanism. The gating unit adaptively adjusts the weight distribution ratio of each dimension in the primary abstract feature representation according to the magnitude of the defect clustering index, and outputs the intermediate feature representation after gating modulation. The intermediate feature representation is passed to the third hidden layer, which performs feature compression and dimensionality reduction operations, and generates a high-level nonlinear feature representation by modifying the linear unit activation function. The high-level nonlinear feature representation is transmitted to the output layer of the dynamic weight allocation network. The output layer contains a single-neuron regression prediction head. The regression prediction head performs a weighted summation operation on the high-level nonlinear feature representation and applies a saturation limiting process ranging from 0 to 1 to obtain the original texture fusion weight prediction value corresponding to each evaluation window. A post-processing operation based on neighborhood smoothing constraints is performed on the original texture fusion weight prediction value. The post-processing operation calculates the average weight of the evaluation window within a preset neighborhood range and outputs the average weight as the final texture fusion weight value.

[0016] Compared with the prior art, the advantages and positive effects of the present invention are as follows: Multi-resolution frequency domain decomposition generates sub-band image groups covering different spatial frequencies. A non-local texture similarity calculation engine is then used for cross-scale feature association, outputting a texture structure consistency metric for each pixel location. This technique overcomes the limitations of single-scale texture analysis by quantifying the similarity of texture structures across different frequency bands through cross-scale feature matching of non-local neighborhoods. It effectively separates defect signals with multi-scale distribution characteristics from periodic background textures, and compared to traditional single-scale texture analysis methods, it can more accurately identify minute defect structures obscured by complex backgrounds.

[0017] After generating a preliminary defect response map by performing point-by-point logical operations on the texture structure consistency metric and background suppression frequency domain mask data, a dynamic weight allocation network is invoked to evaluate the regional stability of this map. A texture fusion weight matrix is ​​then generated by combining the local gradient distribution characteristics of the surface grayscale image. This technique dynamically analyzes the stability differences and local gradient changes in the defect response regions, adaptively adjusting the fusion weights for different regions. This avoids the weakening of defect signals or amplification of background noise caused by static weight allocation. Compared to fixed-weight fusion methods, it can suppress non-uniform background interference while preserving defect details, improving the boundary clarity between defect and normal regions. Attached Figure Description

[0018] Figure 1 This is a schematic diagram illustrating the working principle of an image processing algorithm based on texture fusion analysis as described in this invention. Figure 2 A flowchart for generating sub-band image groups covering different spatial frequencies. Detailed Implementation

[0019] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.

[0020] In the description of this invention, it should be understood that the terms "length," "width," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," and "outer," etc., indicating orientation or positional relationships, are based on the orientation or positional relationships shown in the accompanying drawings and are only for the convenience of describing the invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of the invention. Furthermore, in the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.

[0021] This invention provides an image processing algorithm based on texture fusion analysis. The specific implementation process of the algorithm is as follows: A set of raw industrial visual inspection images to be processed is acquired. This set includes a grayscale image of the surface of at least one object under test and a corresponding process background reference image. Multi-resolution frequency domain decomposition is performed on the surface grayscale image to generate sub-band image groups covering different spatial frequencies. Simultaneously, adaptive spectral mask generation is performed on the process background reference image to obtain background suppression frequency domain mask data. The sub-band image groups are input into a pre-constructed non-local texture similarity calculation engine for cross-scale feature association processing, outputting a texture structure consistency metric for each pixel location. This texture structure consistency metric is then processed with the background suppression frequency domain mask data through point-by-point logical operations to generate a preliminary defect response map. A dynamic weight allocation network is invoked to perform regional stability evaluation on the preliminary defect response map, and a texture fusion weight matrix is ​​generated by combining the local gradient distribution features of the surface grayscale image. Based on this texture fusion weight matrix, weighted fusion and threshold segmentation are performed on the preliminary defect response map to output the final defect region localization result data.

[0022] Example 1: Multi-resolution frequency domain decomposition is performed on the surface grayscale image to generate sub-band image sets covering different spatial frequencies. This includes performing two-dimensional discrete wavelet transform decomposition on the surface grayscale image to obtain low-frequency approximate components and high-frequency detail components in multiple directions. The low-frequency approximate components are then recursively subjected to wavelet packet decomposition until a preset number of decomposition levels is reached, generating multi-level frequency domain sub-band coefficient sets. Inverse wavelet transform reconstruction is performed on each frequency domain sub-band coefficient set to restore a sub-band image with the same size as the original image, where each sub-band image corresponds to a specific frequency range and spatial direction. All levels of sub-band images are then aggregated to construct a sub-band image set. Adaptive spectral mask generation is performed on the process background reference image to obtain background suppression frequency domain mask data. This includes performing Fourier spectrum analysis on the process background reference image to calculate its power spectral density distribution map. The dominant frequency peak points corresponding to the process texture are identified on the power spectral density distribution map, and the radial and angular coordinates of the dominant frequency peak points are recorded. Elliptical attenuation bandstop filters are constructed centered on each dominant frequency peak, with the major axis of the elliptical attenuation bandstop filters aligned with the fabrication texture. All elliptical attenuation bandstop filters are superimposed to generate a frequency domain mask function, which is then converted into a spatial domain convolution kernel to obtain the background suppression frequency domain mask data.

[0023] In practical implementation, the raw image dataset for industrial visual inspection includes a grayscale image of the surface of a metal stamping part and a corresponding process background reference image. The resolution of the surface grayscale image is 1024×1024 pixels, and the pixel grayscale value ranges from 0 to 255. The process background reference image is an image of a defect-free metal stamping part of the same model acquired under the same lighting conditions. When performing multi-resolution frequency domain decomposition processing on the surface grayscale image, a two-dimensional discrete wavelet transform decomposition process is adopted, with the db4 wavelet as the basis function and a decomposition level of 2 layers, resulting in a low-frequency approximation component LL2, a horizontal high-frequency detail component LH2, a vertical high-frequency detail component HL2, and a diagonal high-frequency detail component HH2. The size of the low-frequency approximation component LL2 is 512×512 pixels, and the size of each high-frequency detail component is also 512×512 pixels.

[0024] In the specific implementation, the low-frequency approximation component LL2 is recursively subjected to wavelet packet decomposition, with the number of decomposition layers set to 1, generating a set of frequency domain sub-band coefficients, specifically including low-frequency sub-band coefficients LL2_LL1, horizontal sub-band coefficients LL2_LH1, vertical sub-band coefficients LL2_HL1, and diagonal sub-band coefficients LL2_HH1, with each set of frequency domain sub-band coefficients having a size of 256×256 pixels. For each set of frequency domain subband coefficients, inverse wavelet transform reconstruction is performed, using the same wavelet basis function db4 as the forward transform, to restore the subband image with the same size as the original surface grayscale image. Specifically, the low-frequency subband coefficient LL2_LL1 is reconstructed to obtain the subband image corresponding to the low-frequency range, the horizontal subband coefficient LL2_LH1 is reconstructed to obtain the subband image corresponding to the high-frequency range in the horizontal direction, the vertical subband coefficient LL2_HL1 is reconstructed to obtain the subband image corresponding to the high-frequency range in the vertical direction, and the diagonal subband coefficient LL2_HH1 is reconstructed to obtain the subband image corresponding to the high-frequency range in the diagonal direction. The size of all subband images is 1024×1024 pixels.

[0025] In some embodiments, subband image groups are constructed by summing the subband images of all levels. The subband image group includes the low-frequency approximation component LL2, the horizontal high-frequency detail component LH2, the vertical high-frequency detail component HL2, and the diagonal high-frequency detail component HH2 obtained from the first-level decomposition, as well as the low-frequency subband image, the horizontal subband image, the vertical subband image, and the diagonal subband image obtained from the second-level wavelet packet decomposition and reconstruction, for a total of 8 subband images. Each subband image corresponds to a specific frequency range and spatial direction. For example, the horizontal high-frequency detail component LH2 corresponds to the edge texture frequency range in the horizontal direction, and the diagonal subband image corresponds to the detail texture frequency range in the diagonal direction.

[0026] In the specific implementation, when performing adaptive spectral mask generation on the process background reference image, the process background reference image is first subjected to Fourier spectrum analysis to calculate its power spectral density distribution map. The size of the power spectral density distribution map is 1024×1024 pixels, and each pixel value represents the power intensity at that frequency point. The dominant frequency peak points corresponding to the process texture are identified on the power spectral density distribution map. The peak detection algorithm is used to find pixels whose power spectral density value is more than 3 times the average power spectral density value of the surrounding 8 neighborhoods. The radial coordinates (r) and angular coordinates (θ) of these dominant frequency peak points are recorded, where the radial coordinate r represents the distance from the center of the spectrum map to the point, and the angular coordinate θ represents the angle between the line connecting the point to the center and the horizontal direction. A total of 3 dominant frequency peak points are identified, with radial coordinates of 128, 192, and 256, and angular coordinates of 30°, 60°, and 90°, respectively.

[0027] In some embodiments, an elliptical attenuation bandstop filter is constructed centered on each dominant frequency peak. The major axis of the elliptical attenuation bandstop filter is aligned with the direction of the process texture, which is determined by the angular coordinates of the dominant frequency peak in the power spectral density distribution map. For example, if the dominant frequency peak with an angular coordinate of 30° corresponds to a process texture direction of 30°, then the major axis of the elliptical attenuation bandstop filter is set to 30°, the minor axis is set to 0.5 times the length of the major axis, and the attenuation bandwidth is set to 10% of the radial coordinate, i.e., 12.8 pixels. All elliptical attenuation bandstop filters are superimposed to generate a frequency domain mask function. The frequency domain mask function takes a value of 0 in the frequency region corresponding to the dominant frequency peak and a value of 1 in other regions. Then, the frequency domain mask function is converted into a spatial domain convolution kernel through inverse Fourier transform. The size of the spatial domain convolution kernel is 65×65 pixels, resulting in background suppression frequency domain mask data.

[0028] Optionally, the mathematical expression for two-dimensional discrete wavelet transform decomposition is: in, The scale is represented as Location is wavelet coefficients, Represents the surface grayscale image in coordinates grayscale value at that location The scale is represented as Location is Discrete wavelet basis functions, and These represent the row and column coordinates of the image, respectively, with values ​​ranging from 0 to 1023.

[0029] Optionally, when constructing an elliptic attenuation bandstop filter, the filter transfer function... The calculation method is as follows: for the radial coordinate of each dominant frequency peak point and angular coordinates In frequency domain coordinates At this point, calculate the radial distance from the dominant frequency peak point. ,in The coordinates of the dominant frequency peak point in the frequency domain, when exist Within the range and the angle difference is When within range, ,otherwise , To attenuate bandwidth, For angular bandwidth.

[0030] It is understandable that by performing multi-resolution frequency domain decomposition on the surface grayscale image, texture information of different frequencies and directions can be separated. The construction of sub-band image groups provides a multi-scale data foundation for subsequent cross-scale feature association. The background suppression frequency domain mask data obtained by processing the process background reference image can effectively suppress the interference of the process texture itself and highlight potential defect signals.

[0031] It is understandable that wavelet packet decomposition can provide a more refined frequency division compared to ordinary wavelet decomposition, and is especially suitable for scenarios where there are multiple different frequency texture features in surface grayscale images. By recursively decomposing the low-frequency approximation components, detailed information in the low-frequency band can be further separated, avoiding the omission of high-frequency features corresponding to minor defects.

[0032] Example 2: The sub-band image set is input into a pre-built non-local texture similarity calculation engine for cross-scale feature association processing, outputting a texture structure consistency metric for each pixel location. This includes selecting at least three sub-band images of different scales from the sub-band image set as a reference scale image set. For each target pixel in the reference scale image set, a set of pixels with similar grayscale patterns is searched within its neighborhood to construct a non-local similar pixel index table. The structural tensor difference value between the target pixel and each pixel in the non-local similar pixel index table is calculated. All structural tensor difference values ​​are exponentially weighted and summed to generate the texture structure consistency metric for the target pixel. All pixels in the reference scale image set are traversed to generate a texture structure consistency metric map with the same size as the surface grayscale image. The texture structure consistency metric is processed point-by-point logically with the background suppression frequency domain mask data to generate a preliminary defect response map, including reading the value of each pixel in the texture structure consistency metric map and mapping it to a probability interval of zero to one. The mask gain coefficient at the corresponding pixel location in the background suppression frequency domain mask data is read. Multiply the values ​​within the probability interval by the mask gain coefficient to obtain the weighted intermediate response value. Determine whether the intermediate response value exceeds a preset initial activation threshold. If it does, mark the pixel as a potential defect point; otherwise, mark it as a background point. Combine the marking results of all pixels to generate a preliminary defect response map.

[0033] In specific implementation, the raw image dataset for industrial visual inspection includes a grayscale image of the fabric surface and a corresponding process background reference image. The grayscale image of the fabric surface has a resolution of 800×800 pixels, and the pixel grayscale value ranges from 0 to 255. The sub-band image group is generated by Example 1 and contains 8 sub-band images, each with a size of 800×800 pixels. Three sub-band images of different scales are selected from the sub-band image group as a reference scale image group. The selection criterion is that the frequency range corresponding to the sub-band image covers the low, medium, and high frequency bands. Specifically, it includes the low-frequency approximate component LL2 (corresponding to the low-frequency range) obtained by the first layer decomposition in Example 1, the horizontal high-frequency detail component LH2 (corresponding to the mid-frequency horizontal direction), and the diagonal sub-band image (corresponding to the high-frequency diagonal direction) obtained by the second layer wavelet packet decomposition and reconstruction.

[0034] In practice, for each target pixel in the reference scale image group, a set of pixels with similar grayscale patterns is searched in its neighborhood to construct a non-local similar pixel index table. The neighborhood size of the target pixel is set to 21×21 pixels. The condition for determining similar grayscale patterns is that the absolute value of the difference between the grayscale value of the target pixel and the grayscale value of the target pixel is less than or equal to 15. For each target pixel, all pixels in its neighborhood are traversed, and pixels that meet the condition are selected. The coordinates of these pixels are recorded in the non-local similar pixel index table corresponding to the target pixel. Each non-local similar pixel index table stores at least 5 pixel coordinates and at most 50 pixel coordinates.

[0035] In some embodiments, the structure tensor difference value between the target pixel and each pixel in the non-local similar pixel index table is calculated. The structure tensor is constructed using the gradient information of the target pixel and the pixels in the non-local similar pixel index table. The structure tensor elements of the target pixel... It is the sum of the squared gradients of the target pixel in the x-direction and the squared gradients in the y-direction. It is twice the product of the gradients of the target pixel in the x and y directions. The sum of the squared gradients of the target pixel in the y-direction and the x-direction is used. The calculation method for the structure tensor elements of pixels in the non-locally similar pixel index table is the same. The structure tensor difference value is obtained by calculating the Frobenius norm difference between the two structure tensors, as shown in the formula: ,in The structure tensor representing the target pixel. The structure tensor representing the pixels in the non-local similar pixel index table. This represents the Frobenius norm.

[0036] In practice, all structural tensor difference values ​​are summed exponentially to generate a texture structure consistency metric for the target pixel. The exponential weighting function uses... ,in This represents the difference value of the structure tensor. This is a weighting coefficient with a value of 0.1. For each target pixel, it is used to calculate the weights of all pixels corresponding to it in the non-local similarity pixel index table. The values ​​are added together, and the sum is the texture structure consistency metric value of the target pixel. The texture structure consistency metric value ranges from 0 to 50. All pixels in the reference scale image group are traversed to generate a texture structure consistency metric map with the same size as the surface grayscale image. The texture structure consistency metric map is 800×800 pixels in size, and each pixel value corresponds to the texture structure consistency metric value of the target pixel.

[0037] In some embodiments, the texture structure consistency metric and the background suppression frequency domain mask data are processed point-by-point logically to generate a preliminary defect response map. This includes reading the value of each pixel in the texture structure consistency metric map and mapping it to a probability range of zero to one. The mapping method is to divide the texture structure consistency metric by the maximum texture structure consistency metric of 50 to obtain the probability value. , The range is 0 to 1. The mask gain coefficient of the corresponding pixel position in the background suppression frequency domain mask data is read. The background suppression frequency domain mask data is a 65×65 pixel spatial domain convolution kernel generated in Example 1. The convolution kernel is expanded to 800×800 pixels by bilinear interpolation to obtain a mask gain coefficient map with the same size as the texture structure consistency metric map. The mask gain coefficient of each pixel is 0.2 or 1.0, where the mask gain coefficient of the corresponding process texture frequency region is 0.2 and the other regions are 1.0.

[0038] Optionally, the values ​​within the probability interval are multiplied by the mask gain coefficient to obtain the weighted intermediate response values. ,in This represents the weighted intermediate response value. This represents the probability value after mapping. This represents the mask gain coefficient. It determines the intermediate response value. Does it exceed the preset initial activation threshold? The initial activation threshold is set to 0.3. If a pixel is marked as a potential defect point with a value of 1, it is marked as a background point with a value of 0. The marking results of all pixels are combined to generate a preliminary defect response map. The preliminary defect response map is an 800×800 pixel binary image. The area with a pixel value of 1 represents a potential defect point, and the area with a pixel value of 0 represents a background point.

[0039] Alternatively, another way to calculate the structure tensor difference value is... The denominator is used for normalization to avoid deviations in the difference values ​​caused by excessively large structural tensor magnitudes. This calculation method is suitable for grayscale images of fabric surfaces with complex textures and can enhance the distinguishability of subtle structural differences.

[0040] It is understandable that selecting multiple sub-band images at different scales as a reference scale image group can integrate texture information from different frequency ranges, avoiding missed defects due to a single scale. The construction of a non-local similar pixel index table breaks through the limitations of local neighborhoods, enabling the capture of pixels that are far apart but have similar textures in the image, thus improving the accuracy of texture structure consistency metrics.

[0041] It is understandable that aggregating the structural tensor difference values ​​through exponential weighted summation can assign greater weight to pixels with high similarity, effectively highlighting the continuity of the real texture structure while suppressing noise interference. Combining the texture structure consistency metric with the background suppression frequency domain mask data for point-by-point logical operations, and using the mask gain coefficient to further suppress the influence of the process texture background, makes the preliminary defect response map more focused on the real defect area.

[0042] Example 3: A dynamic weight allocation network is invoked to perform regional stability assessment on the preliminary defect response map. A texture fusion weight matrix is ​​generated by combining the local gradient distribution features of the surface grayscale image. This includes dividing the preliminary defect response map into multiple non-overlapping evaluation windows. Within each evaluation window, the number and spatial distribution of potential defect points are statistically analyzed, and the defect clustering index for that window is calculated. Simultaneously, the local gradient magnitude histogram of the corresponding window region in the surface grayscale image is extracted, and its skewness and kurtosis features are calculated to generate a gradient distribution feature vector. The defect clustering index and the gradient distribution feature vector are concatenated to form the network input feature vector. The network input feature vector is input into the dynamic weight allocation network for forward inference, outputting the texture fusion weight value corresponding to each evaluation window. Based on the texture fusion weight values ​​of all evaluation windows, the resolution is restored to pixel level using bilinear interpolation, generating the texture fusion weight matrix. The network input feature vector is input into the dynamic weight allocation network for forward inference, outputting the texture fusion weight value corresponding to each evaluation window. This includes receiving the network input feature vector formed by concatenating the defect clustering index and the gradient distribution feature vector, and inputting the network input feature vector into the input layer of the dynamic weight allocation network. The input feature vector of the dynamic weight allocation network is normalized by performing standardization on the input layer to eliminate the dimensional differences between features of different dimensions, resulting in a normalized feature vector. This normalized feature vector is then passed to a multi-level cascaded fully connected layer structure within the dynamic weight allocation network. This structure contains at least three hidden layers. The first hidden layer performs linear transformations and nonlinear activation operations to generate a primary abstract feature representation. This primary abstract feature representation is then passed to the second hidden layer, which introduces an attention-based gating unit. This unit adaptively adjusts the weight distribution ratio of each dimension in the primary abstract feature representation based on the magnitude of the defect clustering index, outputting a gated intermediate feature representation. This intermediate feature representation is then passed to the third hidden layer, which performs feature compression and dimensionality reduction operations and generates a high-level nonlinear feature representation by modifying the linear unit activation function. This high-level nonlinear feature representation is then passed to the output layer of the dynamic weight allocation network. The output layer contains a single-neuron regression prediction head. This regression prediction head performs a weighted summation operation on the high-level nonlinear feature representation and applies a saturation limiting operation ranging from 0 to 1, obtaining the original texture fusion weight prediction value corresponding to each evaluation window. A post-processing operation based on neighborhood smoothing constraints is performed on the original texture fusion weight prediction values. The post-processing operation calculates the average weight of the evaluation window within a preset neighborhood range and outputs the average weight as the final texture fusion weight value.

[0043] In specific implementation, the raw image dataset for industrial visual inspection includes a grayscale image of the glass cover surface and a corresponding process background reference image. The grayscale image of the glass cover surface has a resolution of 1200×1200 pixels. The preliminary defect response map is generated by Example 2 and is a 1200×1200 pixel binary image. The surface grayscale image is the original acquired grayscale image of the glass cover surface, with pixel grayscale values ​​ranging from 0 to 255. The preliminary defect response map is divided into multiple non-overlapping evaluation windows, with the evaluation window size set to 40×40 pixels. The 1200×1200 pixel preliminary defect response map can be divided into 30×30=900 evaluation windows. Each evaluation window corresponds to a 40×40 pixel region in the preliminary defect response map and a 40×40 pixel region in the same spatial location in the surface grayscale image.

[0044] In practice, the number and spatial distribution of potential defect points are statistically analyzed within each evaluation window. The defect clustering index for that window is calculated, including the total number of pixels marked as potential defect points within the evaluation window, resulting in a defect point count. The defect point count ranges from 0 to 1600. The centroid coordinates of all potential defect points within the evaluation window are also calculated. Through formula , Calculation, where To count the number of defects, For the first The relative coordinates of each potential defect point within the evaluation window are calculated. The origin of the relative coordinates is the top-left corner of the evaluation window, with the positive x-axis pointing to the right and the positive y-axis pointing downwards. The values ​​range from 0 to 39. The Euclidean distance from each potential defect point to the centroid coordinates is measured. And calculate the average distance value. The average distance value is in pixels. Dividing the defect point count by the average distance value yields the initial clustering degree, which reflects the tightness of the cluster. The initial clustering degree is logarithmically transformed to generate a defect clustering degree index. The defect clustering index ranges from 0 to 11.

[0045] In some embodiments, the local gradient magnitude histogram of the corresponding window region in the surface grayscale image is extracted simultaneously, and its skewness and kurtosis features are calculated to generate a gradient distribution feature vector. This includes performing a convolution operation on the corresponding window region in the surface grayscale image using the Sobel operator, wherein the horizontal convolution kernel of the Sobel operator is... The vertical convolution kernel is After convolution, horizontal and vertical gradient component maps are obtained, each with a size of 40×40 pixels, and the pixel value is the gradient component magnitude. The combined gradient magnitude of each pixel in the horizontal and vertical gradient component maps is then calculated. ,in These are the horizontal gradient component values. These are the vertical gradient component values, and the range of the synthesized gradient magnitude is 0 to... .

[0046] In practice, the synthesized gradient magnitude is divided into a preset number of grayscale level intervals, with the preset number set at 16 grayscale level intervals, and the width of each interval being [missing information]. The ranges are [0, 22.54), [22.54, 45.08), ..., [338.06, 360.6]. The pixel frequency within each range is counted, and a gradient magnitude histogram is constructed. The gradient magnitude histogram is a 16-dimensional vector, where each dimension represents the number of pixels within that range, with a total value of 1600. The skewness coefficient of the gradient magnitude histogram is calculated using statistical formulas. With kurtosis coefficient The formula for calculating the skewness coefficient is: The formula for calculating the kurtosis coefficient is: ,in The central moment is the third order. It is the fourth-order central moment. The standard deviation is used. The skewness coefficient, kurtosis coefficient, and energy values ​​from the gradient magnitude histogram are combined to form a gradient distribution feature vector. The energy values ​​are expressed using the formula... Calculation, where The gradient magnitude histogram of the first... The pixel frequency of each interval has a gradient distribution feature vector that is a 3-dimensional vector containing skewness coefficient, kurtosis coefficient and energy value.

[0047] In some embodiments, the defect clustering index is concatenated with the gradient distribution feature vector to form the network input feature vector. The network input feature vector is a 4-dimensional vector, with the first dimension being the defect clustering index, the second dimension being the skewness coefficient, the third dimension being the kurtosis coefficient, and the fourth dimension being the energy value. The network input feature vector is then fed into a dynamic weight allocation network for forward inference, outputting the texture fusion weight value corresponding to each evaluation window. The input layer of the dynamic weight allocation network receives the network input feature vector and performs standardization and normalization processing on it. The standardization formula is... ,in The original values ​​of the feature vector are input to the network. The mean of the corresponding dimension of the training set. The standard deviation of the corresponding dimension of the training set is used to obtain the normalized feature vector.

[0048] Optionally, the multi-level cascaded fully connected layer structure in the dynamic weight allocation network contains three hidden layers. The first hidden layer contains 64 neurons and performs a linear transformation. ,in The weight matrix is ​​64×4. It is a 64-dimensional bias vector, then activated by the ReLU function. A primary abstract feature representation is generated, which is a 64-dimensional vector. This primary abstract feature representation is then passed to a second hidden layer containing 32 neurons. An attention-based gating unit is introduced, which adaptively adjusts the weight distribution of each dimension in the primary abstract feature representation based on the magnitude of the defect clustering index. ,in For the gating weight parameters, This is an indicator of defect clustering. For gated bias, the intermediate feature after gated modulation is represented as follows: A 32-dimensional vector.

[0049] Optionally, the intermediate feature representation is passed to a third hidden layer containing 16 neurons to perform feature compression and dimensionality reduction operations through linear transformation. A modified linear unit activation function is used to generate a high-level nonlinear feature representation, which is a 16-dimensional vector. This high-level nonlinear feature representation is then passed to the output layer of a dynamically weighted network. The output layer contains a single-neuron regression prediction head, which performs a weighted summation operation on the high-level nonlinear feature representation. And apply a saturation limiting process ranging from 0 to 1. This process yields the original texture fusion weight prediction value for each evaluation window. A post-processing operation based on neighborhood smoothing constraints is then performed on the original texture fusion weight prediction values. This post-processing operation calculates the average weight of the evaluation window within a preset neighborhood range. The preset neighborhood range is set to 3×3 evaluation windows, i.e., the eight surrounding evaluation windows. The average weight is then output as the final texture fusion weight value.

[0050] It is understandable that dividing the preliminary defect response map into non-overlapping evaluation windows allows for the statistical analysis of defect point clustering characteristics within local areas. The defect clustering index, calculated by combining the defect point count with the average distance and a logarithmic transformation, effectively quantifies the density of defects. The gradient distribution feature vector, through skewness, kurtosis, and energy values, describes the gradient distribution pattern of the surface grayscale image within the evaluation window, reflecting the uniformity of the texture and the gradient changes caused by defects.

[0051] It is understandable that the dynamic weight allocation network, through multi-level cascaded fully connected layers and attention mechanism gating units, can adaptively fuse defect clustering index and gradient distribution characteristics, and output texture fusion weight values ​​related to local region stability. The post-processing operation of neighborhood smoothing constraint can reduce the abrupt change of weight values, making the generated texture fusion weight matrix more continuous in space, which is convenient for subsequent weighted fusion processing.

[0052] Example 4: Within each evaluation window, the number and spatial distribution of potential defect points are statistically analyzed, and the defect clustering index for that window is calculated. This includes counting the total number of pixels marked as potential defect points within the evaluation window to obtain the defect point count. The centroid coordinates of all potential defect points within the evaluation window are calculated. The Euclidean distance from each potential defect point to its centroid coordinates is measured, and the average distance value is calculated. The defect point count is divided by the average distance value to obtain the initial clustering degree, reflecting the degree of clustering. The initial clustering degree is logarithmically transformed to generate the defect clustering index. The local gradient magnitude histogram of the corresponding window region in the surface grayscale image is extracted, and its skewness and kurtosis features are calculated to generate a gradient distribution feature vector. This includes performing a convolution operation on the corresponding window region in the surface grayscale image using the Sobel operator to obtain the horizontal gradient component map and the vertical gradient component map. The composite gradient magnitude of each pixel in the horizontal and vertical gradient component maps is calculated. The composite gradient magnitude is divided into a preset number of grayscale level intervals, and the pixel frequency in each interval is statistically analyzed to construct a gradient magnitude histogram. The skewness and kurtosis coefficients of the gradient magnitude histogram are calculated using statistical formulas. The skewness, kurtosis, and energy values ​​of the gradient magnitude histogram are then combined to form the gradient distribution feature vector.

[0053] In specific implementation, the industrial vision inspection raw image data set includes a grayscale image of the metal bearing surface and a corresponding process background reference image. The resolution of the grayscale image of the metal bearing surface is 1000×1000 pixels. The preliminary defect response map is generated by Example 2 and is a 1000×1000 pixel binary image. The evaluation window is divided by Example 3 and has a size of 40×40 pixels. The corresponding window area in the grayscale image of the metal bearing surface is a 40×40 pixel area in the same spatial position as the evaluation window of the preliminary defect response map, and the pixel grayscale value ranges from 0 to 255.

[0054] In practice, the total number of pixels marked as potential defect points within the evaluation window is counted to obtain the defect point count. Potential defect points are marked as 1, and background points are marked as 0. The defect point count ranges from 0 to 1600. When there are no potential defect points within the evaluation window, the defect point count is 0; when the evaluation window contains only potential defect points, the defect point count is 1600. The centroid coordinates of all potential defect points within the evaluation window are calculated. Through formula , Calculation, where To count the number of defects, For the first The relative coordinates of each potential defect point within the evaluation window are given. The relative coordinates are taken from the top left corner of the evaluation window as the origin, with the positive x-axis pointing to the right and the positive y-axis pointing downwards. The values ​​range from 0 to 39. When the defect point count is 0, the centroid coordinates are set to the center coordinates of the evaluation window (19.5, 19.5).

[0055] In some embodiments, the Euclidean distance from each potential defect point to the centroid coordinates is measured. And calculate the average distance value. The unit of the average distance value is pixels. When the defect count is 1, the average distance value is 0; when the defect count is greater than 1, the average distance value is greater than 0. The average distance value ranges from 0 to... Dividing the defect count by the average distance value yields the initial clustering degree, which reflects the tightness of the cluster. The initial aggregation degree is when the defect count is 0. Set to 0, the initial aggregation degree when the defect count is 1. Assuming an infinity value, the initial clustering degree is used in practice when the defect point count is 1. Set the initial clustering degree to 1600. The value ranges from 0 to 1600. A logarithmic transformation is performed on the initial clustering degree to generate a defect clustering degree index. Defect clustering index The value range is 0 to .

[0056] In specific implementation, the local gradient magnitude histogram of the corresponding window region in the surface grayscale image is extracted, and its skewness and kurtosis features are calculated to generate a gradient distribution feature vector. This includes performing a convolution operation on the corresponding window region in the surface grayscale image using the Sobel operator. The horizontal convolution kernel of the Sobel operator is... The vertical convolution kernel is After convolution, horizontal and vertical gradient component maps are obtained. Each component map is 40×40 pixels in size, and the pixel value is the gradient component magnitude. The range of both horizontal and vertical gradient component values ​​is -1020 to 1020. The composite gradient magnitude of each pixel in the horizontal and vertical gradient component maps is calculated. ,in These are the horizontal gradient component values. The vertical gradient component values ​​are used to synthesize the gradient magnitude. The range is 0 to .

[0057] In some embodiments, the synthesized gradient magnitude is divided into a preset number of grayscale level intervals, where the preset number is set to 16 grayscale level intervals, and the width of each interval is [missing information]. The ranges are [0, 90.16), [90.16, 180.32), ..., [1352.34, 1442.5]. The pixel frequency within each range is counted, and a gradient magnitude histogram is constructed. The gradient magnitude histogram is a 16-dimensional vector, where each dimension represents the number of pixels within that range, with a total value of 1600. The skewness coefficient of the gradient magnitude histogram is calculated using statistical formulas. With kurtosis coefficient The formula for calculating the skewness coefficient is: The formula for calculating the kurtosis coefficient is: ,in The central moment is the third order. It is the fourth-order central moment. Standard deviation, skewness coefficient The value range is -3 to 3, and the kurtosis coefficient is... The value range is -2 to 10. The skewness coefficient, kurtosis coefficient, and energy values ​​from the gradient magnitude histogram are combined to form a gradient distribution feature vector. The energy value is obtained through the formula... Calculation, where The gradient magnitude histogram of the first... The pixel frequency of each interval has a gradient distribution feature vector that is a 3-dimensional vector containing skewness coefficient, kurtosis coefficient and energy value.

[0058] Optionally, when the defect count within the evaluation window is 0, the defect clustering index... Setting it to 0, the gradient distribution feature vector is still calculated according to the normal process, but the dynamic weight allocation network will reduce the weight influence of this evaluation window during processing. The initial aggregation degree is determined when the defect point count within the evaluation window equals the total number of pixels in the evaluation window, which is 1600. Set to 1600, the defect clustering index after logarithmic transformation The value is approximately 10.64, indicating that this region is a high-defect-aggregation area.

[0059] Optional, the energy value of the gradient magnitude histogram. The value range is 0 to A larger energy value indicates a more concentrated gradient distribution within the evaluation window, while a smaller energy value indicates a more dispersed gradient distribution. Combining the skewness coefficient and kurtosis coefficient can comprehensively describe the morphological characteristics of the gradient distribution.

[0060] It is understandable that calculating the initial clustering degree by the ratio of defect point count to the average distance value can quantify the tightness of defect point clustering within the evaluation window. Logarithmic transformation can compress the dynamic range of the initial clustering degree, making it more suitable as an input feature for dynamic weight allocation networks. The calculation of centroid coordinates provides a reference point for measuring the spatial distribution of potential defect points, while the average distance value reflects the degree of dispersion of defect points relative to the centroid.

[0061] It can be understood that the gradient distribution feature vector describes the symmetry of the gradient magnitude histogram through the skewness coefficient, the steepness of the gradient magnitude histogram through the kurtosis coefficient, and the concentration of the gradient magnitude through the energy value. The combination of the three can effectively characterize the texture gradient characteristics of the surface grayscale image within the evaluation window, providing a quantitative basis for the texture stability of the dynamic weight allocation network.

[0062] Example 5: Based on the texture fusion weight matrix, weighted fusion and threshold segmentation are performed on the preliminary defect response map to output the final defect region localization result data. This includes reading the weight coefficient of each pixel position in the texture fusion weight matrix. The weight coefficient is multiplied by the response value of the corresponding pixel in the preliminary defect response map to obtain the weighted response value. Gaussian smoothing filtering is performed on the weighted response value to eliminate interference from isolated noise points. The global mean and standard deviation of the weighted response values ​​of the entire image after smoothing are calculated. The final segmentation threshold is set to the global mean plus twice the standard deviation, and pixels greater than this threshold are classified as defect regions. The contour coordinates and area attributes of all defect regions are recorded to generate the final defect region localization result data.

[0063] In specific implementation, the raw image dataset for industrial visual inspection includes a grayscale image of the ceramic substrate surface and a corresponding process background reference image. The grayscale image of the ceramic substrate surface has a resolution of 900×900 pixels. The texture fusion weight matrix, generated by Example 3, is a 900×900 pixel floating-point matrix with pixel values ​​ranging from 0 to 1. The preliminary defect response map, generated by Example 2, is a 900×900 pixel binary image, where a pixel value of 1 represents a potential defect point and a pixel value of 0 represents a background point. The weight coefficients for each pixel position in the texture fusion weight matrix are read and stored at the corresponding coordinate positions in the texture fusion weight matrix. For example, the weight coefficient at coordinates (100, 200) is 0.85, and the weight coefficient at coordinates (300, 400) is 0.32.

[0064] In practice, the weighting coefficient is multiplied by the response value of the corresponding pixel in the preliminary defect response map to obtain the weighted response value. In the preliminary defect response map, a pixel value of 1 results in a response value of 1, and a pixel value of 0 results in a response value of 0. The formula for calculating the weighted response value is as follows: ,in Indicates the weighted response value. This represents the weight coefficient of the corresponding pixel in the texture blending weight matrix. This represents the response value of the corresponding pixel in the preliminary defect response map. The weighted response value ranges from 0 to 1. hour ,when hour Gaussian smoothing filtering was applied to the weighted response values ​​to eliminate interference from isolated noise points. The convolution kernel size for Gaussian smoothing was 5×5 pixels, and the standard deviation was set to 1.0. The weighted response values ​​after Gaussian smoothing were denoted as follows: The weighted response value after Gaussian smoothing filtering still ranges from 0 to 1, but the numerical distribution is more continuous.

[0065] In some embodiments, the global mean and standard deviation of the weighted response values ​​of the entire image after smoothing are calculated. The global mean is the average of the weighted response values ​​of all 900×900=810000 pixels after Gaussian smoothing, denoted as . The standard deviation is the square root of the variance of the weighted response values ​​after Gaussian smoothing, denoted as . For example, calculating the global mean Standard deviation The final segmentation threshold is set to the global mean plus twice the standard deviation, i.e. Substituting the above values, we obtain the final segmentation threshold. And will be greater than the final segmentation threshold. Pixels are classified as defect areas, and pixel values ​​less than or equal to the final segmentation threshold. The pixels are classified as background area.

[0066] In practice, the contour coordinates and area attributes of all defective regions are recorded to generate the final defective region location data. Defective region identification is achieved through connected component analysis, using the 8-neighborhood connectivity rule, and ensuring that the weighted response value after Gaussian smoothing filtering is greater than the final segmentation threshold. Pixels are grouped into the same connected component, and each connected component is considered a candidate defect region. For each candidate defect region, its contour coordinates are calculated. The contour coordinates are obtained through a boundary tracking algorithm. The coordinates of all pixels on the outer boundary of the defect region are recorded and arranged in order. At the same time, the area attribute of the defect region is calculated. The area attribute is the total number of pixels in the defect region, in pixels. For example, the area of ​​one defect region is 150 pixels, and the area of ​​another defect region is 320 pixels.

[0067] In some embodiments, the final defect area location result data is stored in JSON format, containing a unique identifier for each defect area, an array of contour coordinates, and an area attribute, such as {"defect_id":1,"contour":[(120,150),(121,150),...,(135,165)],"area":150}, {"defect_id":2,"contour":[(300,400),(301,400),...,(320,420)],"area":320}. The final defect area location result data may also include the center coordinates of the defect area, which are calculated by averaging the contour coordinates.

[0068] Optionally, the convolution kernel size for Gaussian smoothing filtering can be set to 3×3 pixels, with a standard deviation of 0.5. In this case, Gaussian smoothing filtering provides a lower smoothness to the weighted response values, preserving more detail information, and is suitable for detecting minute defects. When the weight coefficients in the texture fusion weight matrix are generally high, the final segmentation threshold can be appropriately reduced, for example, by setting the final segmentation threshold to the global mean plus 1.5 times the standard deviation, to accommodate defect responses in high-weight regions.

[0069] Optionally, the connected component analysis can also use the 4-neighborhood connectivity rule. In this case, the defect region is divided more compactly, but some irregularly shaped defect regions may be split into multiple small regions. It is necessary to combine the area attribute for merging. The merging condition is that the center distance between two connected components is less than a preset threshold and the sum of their areas is less than another preset threshold.

[0070] It is understandable that by weighting the initial defect response map using a texture fusion weight matrix, the intensity of the defect response can be dynamically adjusted according to the texture stability of different regions. The weighted response value combines the defect probability and regional weight information. Gaussian smoothing filtering can effectively suppress the influence of isolated noise points, avoid misclassifying a single noise point as a defect region, and improve the accuracy of defect localization.

[0071] It is understandable that setting the final segmentation threshold based on the global mean and twice the standard deviation is an adaptive thresholding method that can determine a reasonable segmentation boundary based on the overall image response without manual intervention. Recording the contour coordinates and area attributes of the defect region can provide direct data support for subsequent defect classification and size assessment. The complete defect region localization results can be easily integrated with other modules of the industrial vision inspection system.

[0072] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention in any other way. Any person skilled in the art may make changes or modifications to the above-disclosed technical content to create equivalent embodiments that can be applied to other fields. However, any simple modifications, equivalent changes, and modifications made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the protection scope of the present invention.

Claims

1. An image processing algorithm based on texture fusion analysis, characterized in that, The algorithm includes: Acquire a set of raw industrial visual inspection images to be processed, wherein the set of raw industrial visual inspection images includes at least one grayscale image of the surface of the object to be tested and a corresponding process background reference image. Multi-resolution frequency domain decomposition processing is performed on the surface grayscale image to generate sub-band image groups covering different spatial frequencies. At the same time, adaptive spectral mask generation processing is performed on the process background reference image to obtain background suppression frequency domain mask data. The sub-band image group is input into a pre-built non-local texture similarity calculation engine for cross-scale feature association processing, outputting a texture structure consistency metric value for each pixel location, and performing point-by-point logical operations on the texture structure consistency metric value and the background suppression frequency domain mask data to generate a preliminary defect response map. The dynamic weight allocation network is invoked to perform regional stability assessment on the preliminary defect response map, and a texture fusion weight matrix is ​​generated by combining the local gradient distribution features of the surface grayscale image. Based on the texture fusion weight matrix, the preliminary defect response map is subjected to weighted fusion and threshold segmentation processing to output the final defect region localization result data.

2. The image processing algorithm based on texture fusion analysis according to claim 1, characterized in that, The step of performing multi-resolution frequency band decomposition processing on the surface grayscale image to generate sub-band image groups covering different spatial frequencies includes: The surface grayscale image is subjected to two-dimensional discrete wavelet transform decomposition to obtain low-frequency approximate components and high-frequency detail components in multiple directions. The low-frequency approximation component is recursively subjected to wavelet packet decomposition until the preset number of decomposition layers is reached, generating a multi-level set of frequency domain sub-band coefficients. For each set of frequency domain subband coefficients, inverse wavelet transform reconstruction is performed to restore a subband image with the same size as the original image. Each subband image corresponds to a specific frequency range and spatial direction. The sub-band images from all levels are aggregated to construct the sub-band image group.

3. The image processing algorithm based on texture fusion analysis according to claim 1, characterized in that, The adaptive spectral mask generation process performed on the process background reference image to obtain background suppression frequency domain mask data includes: Fourier spectrum analysis was performed on the process background reference image to calculate its power spectral density distribution. Identify the dominant frequency peak point corresponding to the process texture on the power spectral density distribution map, and record the radial and angular coordinates of the dominant frequency peak point; An elliptical attenuation bandstop filter is constructed with each dominant frequency peak point as the center, and the major axis of the elliptical attenuation bandstop filter is aligned with the direction of the process texture. All the elliptical attenuation bandstop filters are superimposed to generate a frequency domain mask function, and the frequency domain mask function is converted into a spatial domain convolution kernel to obtain the background suppression frequency domain mask data.

4. The image processing algorithm based on texture fusion analysis according to claim 1, characterized in that, The step of inputting the sub-band image group into a pre-constructed non-local texture similarity calculation engine for cross-scale feature association processing, and outputting a texture structure consistency metric value for each pixel location, includes: Select at least three sub-band images of different scales from the sub-band image group as a reference scale image group; For each target pixel in the reference scale image group, a set of pixels with similar grayscale patterns is searched in its neighborhood to construct a non-local similar pixel index table. Calculate the structural tensor difference value between the target pixel and each pixel in the non-local similar pixel index table; An exponentially weighted sum of all the structural tensor differences is performed to generate a texture structure consistency metric for the target pixel. By traversing all pixels in the reference scale image group, a texture structure consistency metric map with the same size as the surface grayscale image is generated.

5. The image processing algorithm based on texture fusion analysis according to claim 1, characterized in that, The step of performing point-by-point logical operations on the texture structure consistency metric and the background suppression frequency domain mask data to generate a preliminary defect response map includes: Read the value of each pixel in the texture structure consistency measurement map and map it to a probability range of zero to one; Read the mask gain coefficient at the corresponding pixel position in the background suppression frequency domain mask data; Multiply the value within the probability interval by the mask gain coefficient to obtain the weighted intermediate response value; Determine whether the intermediate response value exceeds the preset initial activation threshold. If it does, mark the pixel as a potential defect point; otherwise, mark it as a background point. The labeling results of all pixels are combined to generate the preliminary defect response map.

6. The image processing algorithm based on texture fusion analysis according to claim 1, characterized in that, The process of calling a dynamic weight allocation network to perform regional stability assessment on the preliminary defect response map, and generating a texture fusion weight matrix by combining the local gradient distribution features of the surface grayscale image, includes: The preliminary defect response map is divided into multiple non-overlapping evaluation windows; Within each evaluation window, the number and spatial distribution of potential defect points are statistically analyzed, and the defect clustering index of that window is calculated. Simultaneously, the local gradient magnitude histogram of the corresponding window region in the surface grayscale image is extracted, and its skewness and kurtosis characteristics are calculated to generate a gradient distribution feature vector. The defect clustering index is concatenated with the gradient distribution feature vector to form the network input feature vector; The network input feature vector is input into the dynamic weight allocation network for forward inference, and the texture fusion weight value corresponding to each evaluation window is output. Based on the texture fusion weight values ​​of all evaluation windows, the resolution is restored to pixel level using bilinear interpolation to generate the texture fusion weight matrix.

7. The image processing algorithm based on texture fusion analysis according to claim 6, characterized in that, The step of statistically analyzing the number and spatial distribution of potential defect points within each evaluation window, and calculating the defect clustering index for that window, includes: The total number of pixels marked as potential defect points within the evaluation window is counted to obtain the defect point count. Calculate the centroid coordinates of all the potential defect points within the evaluation window; Measure the Euclidean distance from each potential defect point to the centroid coordinates, and calculate the average distance value; Dividing the number of defect points by the average distance value yields the initial clustering degree, which reflects the tightness of the clustering. The initial clustering degree is subjected to a logarithmic transformation to generate the defect clustering degree index.

8. The image processing algorithm based on texture fusion analysis according to claim 6, characterized in that, The step of extracting the local gradient magnitude histogram of the corresponding window region in the surface grayscale image, calculating its skewness and kurtosis features, and generating a gradient distribution feature vector includes: The Sobel operator is used to perform convolution operations on the corresponding window regions in the surface grayscale image to obtain the horizontal gradient component map and the vertical gradient component map. Calculate the combined gradient magnitude of each pixel in the horizontal gradient component map and the vertical gradient component map; The synthesized gradient magnitude is divided into a preset number of gray level intervals, the pixel frequency in each interval is counted, and a gradient magnitude histogram is constructed. The skewness and kurtosis coefficients of the gradient magnitude histogram are calculated using statistical formulas. The skewness coefficient, the kurtosis coefficient, and the energy value of the gradient magnitude histogram are combined to form the gradient distribution feature vector.

9. The image processing algorithm based on texture fusion analysis according to claim 1, characterized in that, The process of performing weighted fusion and threshold segmentation on the preliminary defect response map based on the texture fusion weight matrix, and outputting the final defect region localization result data, includes: Read the weight coefficients for each pixel position in the texture fusion weight matrix; The weighting coefficient is multiplied by the response value of the corresponding pixel in the preliminary defect response map to obtain the weighted response value; Gaussian smoothing filtering is applied to the weighted response values ​​to eliminate interference from isolated noise points; Calculate the global mean and standard deviation of the weighted response values ​​of the entire image after smoothing; The final segmentation threshold is set to the global mean plus twice the standard deviation, and pixels larger than this threshold are classified as defect areas; Record the contour coordinates and area attributes of all the defective regions to generate the final defective region location result data.

10. The image processing algorithm based on texture fusion analysis according to claim 6, characterized in that, The step of inputting the network input feature vector into the dynamic weight allocation network for forward inference and outputting the texture fusion weight value corresponding to each evaluation window includes: Receive the network input feature vector formed by concatenating the defect clustering index and the gradient distribution feature vector, and input the network input feature vector into the input layer of the dynamic weight allocation network; The input feature vector of the network is normalized by the input layer of the dynamic weight allocation network to eliminate the difference in the units of different features and obtain a normalized feature vector. The normalized feature vector is transmitted to the multi-level cascaded fully connected layer structure in the dynamic weight allocation network. The multi-level cascaded fully connected layer structure contains at least three hidden layers, wherein the first hidden layer performs linear transformation and nonlinear activation operations to generate a primary abstract feature representation. The primary abstract feature representation is passed to the second hidden layer, which introduces a gating unit based on an attention mechanism. The gating unit adaptively adjusts the weight distribution ratio of each dimension in the primary abstract feature representation according to the magnitude of the defect clustering index, and outputs the intermediate feature representation after gating modulation. The intermediate feature representation is passed to the third hidden layer, which performs feature compression and dimensionality reduction operations, and generates a high-level nonlinear feature representation by modifying the linear unit activation function. The high-level nonlinear feature representation is transmitted to the output layer of the dynamic weight allocation network. The output layer contains a single-neuron regression prediction head. The regression prediction head performs a weighted summation operation on the high-level nonlinear feature representation and applies a saturation limiting process ranging from 0 to 1 to obtain the original texture fusion weight prediction value corresponding to each evaluation window. A post-processing operation based on neighborhood smoothing constraints is performed on the original texture fusion weight prediction value. The post-processing operation calculates the average weight of the evaluation window within a preset neighborhood range and outputs the average weight as the final texture fusion weight value.