Industrial component contour segmentation method based on diffusion enhancement and guided filtering
By employing a two-stage segmentation architecture that progresses from coarse to fine and low-rank adaptive fine-tuning, combined with lightweight segmentation networks, diffusion models, and guided filtering techniques, the challenge of achieving high precision and high efficiency in industrial component contour segmentation is solved. This enables sub-pixel-level edge localization and second-level inference, adapting to the diverse and rapid iteration needs of industrial scenarios.
Patent Information
- Application Number
- CN202610191295.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-02-10
- Publication Date
- 2026-03-20
AI Technical Summary
Existing technologies struggle to balance high precision and high efficiency in industrial component contour segmentation, especially in high-speed operation scenarios. Existing methods suffer from severe edge jaggedness, significant loss of detail, and a lack of temporal correlation and rapid domain adaptation capabilities.
A two-stage segmentation architecture, from coarse to fine, is adopted, which combines a lightweight segmentation network, a diffusion model, and guided filtering technology. A coarse mask is generated through temporal correlation, and fine correction is performed by iterative optimization of diffusion edges and guided filtering. Adaptive fine-tuning of low-rank neighborhood is also adopted to achieve sub-pixel-level edge localization and second-level inference speed.
It achieves a balance between sub-pixel-level edge localization accuracy and second-level inference speed, reduces edge jaggedness by more than 35%, reduces false detection rate by more than 28%, shortens training time by more than 90%, and requires only about 5% of labeled data to adapt to new scenarios.
Smart Images

Figure CN121708592A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer vision and image processing technology, specifically relating to a method for contour segmentation of industrial components based on diffusion enhancement and guided filtering. Background Technology
[0002] With the rapid development of China's railway infrastructure and the transformation and upgrading of the intelligent manufacturing industry, industrial production lines have placed higher demands on the accuracy and efficiency of component quality inspection. Industrial components, such as railway track pads, are core load-bearing components of passenger dedicated lines, and their dimensional accuracy directly affects the safety and comfort of train operation. Traditional manual sampling inspection methods using vernier calipers suffer from low measurement efficiency and insufficient full inspection coverage. Given the continuously increasing train speeds, errors in manual inspection can lead to serious risks of quality control failure.
[0003] Image segmentation technology, as a key component in the automated inspection of industrial parts, can accurately extract the contour boundaries of target components from complex backgrounds, providing fundamental data for subsequent dimensional measurement and defect detection. However, the high-speed operation of industrial production lines presents a severe challenge to segmentation algorithms, making it difficult to balance accuracy and speed. On the one hand, industrial components typically have complex geometries and precise dimensional tolerances, requiring sub-pixel level edge localization accuracy; on the other hand, the high-frequency operation of production lines demands that the inspection time for a single component be controlled within the range of seconds, imposing stringent limitations on the computational efficiency of the algorithms.
[0004] Existing image segmentation methods are mainly divided into two categories. The first category is end-to-end segmentation methods based on deep learning, which directly output pixel-level classification results through convolutional neural networks. These methods have achieved good results in general scenarios, but in high-precision industrial scenarios, they often suffer from severe edge jaggedness and significant loss of detail, making it difficult to meet sub-pixel accuracy requirements. The second category is segmentation methods that combine post-processing optimization, such as conditional random fields or guided filtering, to refine the edges of the initial segmentation results. In the prior art, patent application CN113269786A discloses an assembly image segmentation method based on deep learning and guided filtering. This method constructs a semantic segmentation model through a feature extraction module, a feature fusion module, and a filtering module, and uses a guided filter to optimize the segmentation edges. However, this method uses a single filtering approach for edge refinement, which has limited optimization capabilities for complex edge regions and lacks a temporal correlation mechanism for continuous frame scenarios in industrial production lines. Its real-time performance and robustness in high-speed operation scenarios need to be improved.
[0005] In recent years, diffusion probability models have demonstrated powerful distribution modeling capabilities in image generation and reconstruction, gradually approximating the target distribution through multi-step iterative denoising. Research shows that introducing diffusion models into image segmentation tasks can effectively improve edge localization accuracy. Methods such as ERSegDiff have applied diffusion models to edge reshaping in medical image segmentation, while SegRefiner proposed a model-independent segmentation refinement method based on discrete diffusion processes, achieving iterative mask optimization by predicting pixel-level state transition probabilities. However, existing diffusion segmentation methods are primarily geared towards static image scenarios, failing to fully consider the real-time constraints of industrial production lines and the temporal correlation characteristics of consecutive frames, and lacking the ability to quickly adapt to new scenarios.
[0006] Furthermore, when transferring deep learning models to new industrial scenarios, it is often necessary to collect a large amount of labeled data and retrain the entire model. This is not only time-consuming and labor-intensive, but also difficult to adapt to the diverse and rapidly iterative needs of industrial scenarios. Low-rank adaptation (LoRA) technology provides a new approach to solving this problem by injecting a small number of trainable parameters into the pre-trained model to achieve rapid fine-tuning. However, how to effectively integrate it with the diffusion segmentation framework remains a technical challenge that needs to be addressed.
[0007] In summary, there is an urgent need for an industrial component contour segmentation method that can balance segmentation accuracy, inference speed, and domain adaptability to meet the intelligent inspection needs of high-speed industrial production lines. Summary of the Invention
[0008] To address the technical problem of balancing accuracy and speed in industrial component contour segmentation in existing technologies, this invention provides an industrial component contour segmentation method based on diffusion enhancement and guided filtering. Through a two-stage segmentation architecture from coarse to fine, combined with edge iteration optimization of the diffusion model and high-frequency information transmission of the guided filter, an effective balance is achieved between sub-pixel-level edge positioning accuracy and second-level inference speed.
[0009] The technical solution of the present invention is as follows:
[0010] The industrial component contour segmentation method based on diffusion enhancement and guided filtering includes the following steps:
[0011] Step S1, rapid generation of coarse mask: Input the image of industrial component into a lightweight segmentation network to obtain an initial segmentation feature map, use a tracker to perform temporal association matching on the target component in consecutive frames, perform region focusing processing on the initial segmentation feature map according to the temporal association results, and use a decoder to upsample and classify the focused feature map at the pixel level to generate a coarse segmentation mask.
[0012] Step S2, Diffusion Edge Iterative Optimization: The coarse segmentation mask is input as the initial state of the diffusion process to the edge diffusion optimization module. The discrete diffusion process is used to predict the state transition probability of the mask edge region pixel by pixel. The classification results of the edge pixels are gradually corrected through multi-step conditional denoising iteration. After a preset number of iterations, the edge-optimized mask is output.
[0013] Step S3, Guided Filtering High-Frequency Transmission: Using the industrial component image as the guide image and the edge optimization mask as the filter input image, the high-frequency edge information in the industrial component image is transmitted to the mask boundary region through the guide filter. The filter coefficients are calculated according to the local linear model of the guide image and the edge optimization mask is filtered to output a fine segmentation mask.
[0014] Step S4, Low-rank domain adaptive fine-tuning: For new industrial component types or production scenarios, freeze the backbone network weights of the lightweight segmentation network and edge diffusion optimization module, inject the low-rank decomposition matrix into the self-attention layer and feedforward layer of the backbone network, perform parameter update training only on the low-rank decomposition matrix, and superimpose the trained low-rank incremental parameters with the original backbone weights to form the adapted model parameters.
[0015] The beneficial effects of this invention are as follows:
[0016] First, the present invention adopts a two-stage segmentation architecture from coarse to fine. In the first stage, a coarse mask is quickly generated by a lightweight segmentation network in conjunction with a tracker mechanism. In the second stage, the edges are finely optimized by a diffusion module and a guided filter, which effectively decouples the speed requirements and accuracy requirements, and achieves sub-pixel level edge positioning accuracy while keeping the single-frame inference time no more than 0.6 seconds.
[0017] Second, this invention introduces an edge iteration optimization mechanism based on the discrete diffusion process, which gradually corrects the classification results of edge pixels through multi-step conditional denoising. Compared with the single-pass filtering method disclosed in CN113269786A, it can handle more complex edge morphologies, reduce the edge jaggedness by more than 35%, and reduce the edge false detection rate by more than 28%.
[0018] Third, the present invention adopts a filtering strategy that is directly guided by industrial component images, which retains more high-frequency texture details and avoids the information loss that may be introduced in the preprocessing stage of the guide image in the prior art, thereby further improving the precision of edge localization.
[0019] Fourth, this invention proposes a fast domain adaptation strategy for low-rank matrix fine-tuning. By freezing the backbone network and training only the injected low-rank parameters, compared with the full parameter fine-tuning method, the training time for new scenario adaptation is shortened by more than 90% and only about 5% of the labeled data is required, effectively meeting the actual needs of diversified and rapid iteration in industrial scenarios. Attached Figure Description
[0020] Figure 1 This is an overall flowchart of the method of the present invention.
[0021] Figure 2 This is a detailed flowchart of the rapid generation of the coarse mask in step S1.
[0022] Figure 3 This is a detailed flowchart of step S2, diffusion edge iterative optimization.
[0023] Figure 4 This is a detailed flowchart of step S3 guiding the high-frequency transmission of the filter.
[0024] Figure 5 This is a detailed flowchart of step S4, low-rank neighborhood adaptive fine-tuning. Detailed Implementation
[0025] Please refer to the attached document. Figures 1-5 The present invention will now be described in further detail with reference to the accompanying drawings and specific embodiments.
[0026] This invention provides an industrial component contour segmentation method based on diffusion enhancement and guided filtering. Addressing the challenge of balancing accuracy and speed in high-speed industrial production line scenarios, this method constructs a two-stage segmentation architecture, progressing from coarse to fine. The core design idea is as follows: In the first stage, a lightweight network and tracker mechanism are used to quickly locate the target region and generate a coarse mask. In the second stage, multi-step iterative optimization of the diffusion model and high-frequency information transmission through guided filtering refine the edges. A deeply coupled closed-loop collaborative relationship is formed between the two stages. The output of the first stage serves as the key input to the second stage, and the refinement results of the second stage can be used to adjust the parameter configuration of the first stage through quality evaluation feedback, achieving continuous optimization of overall performance.
[0027] Step S1: Rapid generation of coarse mask.
[0028] Reference Figure 2 The goal of step S1 is to quickly generate a preliminary segmentation mask while ensuring real-time performance. The input to this step is a sequence of industrial component images, and the output is a coarse segmentation mask and its corresponding target tracking information.
[0029] First, the input industrial component images are fed into a lightweight segmentation network for feature extraction. The industrial component images are original high-resolution images. In this embodiment, the lightweight segmentation network uses depthwise separable convolution as the basic feature extraction unit. Depthwise separable convolution decomposes standard convolution into two steps: depthwise convolution and pointwise convolution. Depthwise convolution performs spatial convolution independently on each input channel, while pointwise convolution uses a one-to-one convolution kernel to fuse information between channels. Compared to standard convolution, depthwise separable convolution significantly reduces the number of parameters and computational cost, thus significantly improving inference speed while maintaining feature extraction capabilities.
[0030] The lightweight segmentation network employs an encoder-decoder structure. The encoder consists of multiple cascaded depthwise separable convolutional modules, each followed by a batch normalization layer and an activation function layer. The encoder extracts multi-scale feature maps at different spatial resolutions, forming a feature pyramid structure. In this embodiment, the feature pyramid contains four scale levels, corresponding to half, one-quarter, one-eighth, and one-sixteenth of the resolution of the industrial component image, respectively. The fusion of multi-scale feature maps adopts a top-down path aggregation method. High-level semantic features are upsampled through bilinear interpolation and then concatenated with low-level detail features through channel concatenation. After adjusting the number of channels through a one-to-one convolution, the fused features are output.
[0031] Secondly, a tracker is used to perform temporal correlation matching of target components in consecutive frames. In the scenario of continuous operation of an industrial production line, there is a strong temporal correlation between the target positions of adjacent frames. Fully utilizing this correlation can reduce redundant calculations and improve segmentation stability. In this embodiment, the tracker maintains a historical frame cache queue with a queue length of five frames. The tracker extracts the center point coordinates and feature description vectors of the target candidate region from the feature map of the current frame and matches them with the corresponding information of the confirmed targets in the historical frames.
[0032] The temporal correlation matching algorithm uses the Hungarian algorithm to find the optimal match. Let the number of target candidates in the current frame be... The number of confirmed targets in historical frames is , build Cost matrix Each element of the cost matrix represents the matching cost between the current frame candidate and the historical frame target, calculated as follows:
[0033] ,
[0034] in, For the current frame number Candidates and historical frames The cost of matching between targets The normalized Euclidean distance between the centers of the two points. The cosine similarity between the feature description vectors of the two is used. This is the distance weighting coefficient with a value of 0.4. The feature weight coefficient is 0.6. The Hungarian algorithm solves for the minimum total cost matching scheme on the cost matrix. Pairs with matching costs below the threshold of 0.6 are identified as temporal associations of the same target.
[0035] Based on the temporal association results, the tracker performs region focusing processing on the feature map of the current frame. For targets with established temporal associations, its bounding box information in historical frames is extracted, and the bounding boxes are expanded by a factor of 1.2. The corresponding region of interest is then cropped on the feature map of the current frame. Region focusing processing concentrates subsequent computations within the regions where the target may appear, avoiding invalid processing of background regions, thereby improving overall inference efficiency. For newly appearing unassociated targets, processing is still performed across the entire map.
[0036] Finally, the decoder upsamples and performs pixel-level classification on the focused feature map. The decoder employs a progressive upsampling strategy, gradually restoring the feature map resolution to the size of the industrial component image through transposed convolution or bilinear interpolation. At each upsampling level, the decoder features are fused with the skip connection features of the corresponding level from the encoder, preserving more spatial detail. The final output layer uses a 1:1 convolution to map the number of channels to the number of classes, and after passing through a softmax function, outputs the probability distribution of each pixel belonging to each class. The class with the highest probability is taken as the classification result for that pixel, forming a coarse segmentation mask.
[0037] Step S2: Iterative optimization of the diffusion edge.
[0038] Reference Figure 3 The goal of step S2 is to refine the edge regions of the coarse segmentation mask. The input to this step is the coarse segmentation mask output from step S1 and the image of the industrial component; the output is an edge-optimized mask. This step is the core innovative module of this invention. By introducing a discrete diffusion process to perform multi-step iterative optimization of edge pixels, the edge refinement task is modeled as a conditional denoising process.
[0039] The design of the edge diffusion optimization module is based on the following core idea: treat the coarse mask as a noisy target segmentation result, where the noise is mainly concentrated in the edge region; gradually correct the classification error of edge pixels through multi-step iterative denoising, each step only needs to correct the most obvious error, thereby reducing the difficulty of single-step optimization, and finally converging to an accurate segmentation result.
[0040] First, the coarse segmentation mask and the industrial component image are jointly encoded. The state encoder employs a dual-branch structure: the mask branch extracts features from the binarized coarse mask, and the image branch extracts features from the original grayscale or color image. Both branches use convolutional neural network structures, outputting feature maps with the same spatial resolution and number of channels. The feature maps from the two branches are fused element-wise to form a joint feature representation. The purpose of joint encoding is to provide sufficient conditional information for the conditional denoising network, enabling it to guide the correction direction of the mask edges based on the edge texture features of the industrial component image.
[0041] Secondly, a discrete diffusion process is defined. Unlike continuous diffusion models that process continuous numerical images, the segmentation mask in this invention is a discrete binary label map; therefore, a discrete diffusion process is used for modeling. Let the label value of the mask pixels be zero or one, representing the background and foreground, respectively. During the diffusion process, pixels undergo state flipping with a certain probability, gradually transforming from true labels to a noisy label distribution. In the inverse denoising process, the model predicts the state transition probability of each pixel, gradually restoring the noisy mask to an accurate segmentation result.
[0042] The forward process of a discrete diffusion process is defined as follows. Let the first... The mask state of the step is The real label is The forward process is mediated by the state transition matrix. Will Convert to For each pixel, the state transition probability is:
[0043] ,
[0044] in, For the first Step time The label status of each pixel. For the first The probability of state reversal in a step, with a value ranging from 0.0001 to 0.02. A linear scheduling strategy is used to gradually increase the value from the initial value to the final value. After the first positive diffusion step, the mask state gradually approaches a uniformly distributed noise state.
[0045] The goal of the inverse denoising process is to progressively restore the true label from a noisy state. The conditional denoising network predicts the label for each pixel at the [missing information - likely a specific point or condition]. The state transition probability distribution of the step. Let the output of the conditional denoising network be... , indicating the first If a pixel has a probability of being transferred to the foreground label, then the reverse transfer rule is:
[0046] ,
[0047] in, Use images of industrial components as conditional input. Indicates the categorical distribution.
[0048] During the inference phase, a coarse segmentation mask is used as the initial state of non-pure noise in the diffusion process, and the semantic information already present in the mask guides the inverse denoising process. This design is based on the observation that although the coarse mask has edge errors, it is generally close to the target distribution, and using it as a starting point can significantly reduce the number of denoising steps required. In this embodiment, the number of iterations during inference is set to ten, which is far fewer than the hundreds of steps required to start from pure noise.
[0049] The conditional denoising network employs a U-shaped structure, including a downsampling encoding path, a bottleneck layer, and an upsampling decoding path. The encoding path extracts multi-scale features at each resolution level, the bottleneck layer uses a self-attention mechanism to model global context relationships, and the decoding path fuses encoded features through skip connections to progressively restore spatial resolution. At each denoising step, the network receives the mask state of the current step. Time step embedding and conditional features As input, the output is the state transition probability prediction for each pixel. .
[0050] To focus on optimizing edge regions, this invention introduces an edge-aware attention mechanism. First, edge regions of a coarse mask are extracted through morphological operations, specifically by dilating the mask and then subtracting the original mask. Then, spatial attention weights for the edge regions are calculated and applied to the feature map of the conditional denoising network, making the network more attentive to the state prediction of edge pixels. The formula for calculating the edge-aware attention weights is:
[0051] ,
[0052] in, For the first Edge attention weights per pixel, For the first The edge indicator value is 1 for edge pixels and 0 for non-edge pixels. The value is a temperature coefficient and is 1.0. The summation operation iterates through all pixels.
[0053] After a pre-set ten-step denoising process, an edge-optimized mask is output. Compared to coarse masks, edge-optimized masks provide more accurate pixel classification results in edge regions, and significantly improve edge jaggedness.
[0054] Step S3: Guide the high-frequency transmission of the filter.
[0055] Reference Figure 4 The goal of step S3 is to transfer the high-frequency edge information in the industrial component image to the segmentation mask, thereby further improving the edge localization accuracy. The input to this step is the edge optimization mask output from step S2 and the industrial component image, and the output is the fine segmentation mask.
[0056] Guided filtering is an edge-preserving filtering technique. Its core idea is to constrain the filtering process using the edge structure of a guide image, ensuring that the filtered output is smooth in flat areas while maintaining sharpness in edge areas. This invention uses an industrial component image as the guide image and an edge-optimized mask as the image to be filtered. Through guided filtering, clear edge texture information from the industrial component image is transferred to the mask boundary.
[0057] Guided filtering is based on the assumption of a local linear model: within each local window of the guide image, the filtered output is a linear transformation of the guide image. Let the guide image be... The input image is The output image is Then in pixels local window centered Within this model, the linear model is represented as:
[0058] ,
[0059] in, For the output image at the 1st The value of each pixel. To guide the image in the first The value of each pixel. and For window The linear coefficients within.
[0060] The linear coefficients are solved by minimizing the reconstruction error between the output and the input. The optimization objective function is:
[0061] ,
[0062] in, For the input image at the 1st The value of each pixel. The regularization parameter is used to prevent To ensure the stability of the filtering value, the value is not too large in this embodiment. The value is 0.001.
[0063] Taking the derivative of the above optimization problem and setting it to zero, we obtain a closed-form solution with linear coefficients:
[0064] ,
[0065] ,
[0066] in, The number of pixels within the window. To guide the mean of the image within the window, To guide the variance of the image within the window, This is the mean of the input image within the window.
[0067] Since each pixel is covered by multiple overlapping windows, the final output value is the average of the results calculated from all the overlapping windows:
[0068] ,
[0069] in, and For all pixels The window and The average value.
[0070] In this invention, the local window radius of the guided filter is set to eight pixels, corresponding to a window size of seventeen by seventeen pixels. This window size achieves a good balance between edge preservation and smoothing effect. During the transmission of high-frequency edge information, a gradient threshold is set to distinguish between effective edge information and noise interference. In this embodiment, the gradient threshold is set to 0.05, which is the midpoint between 0.01 and 0.1, effectively filtering out background noise while preserving the gradient information of real edges. For high-resolution images, a multi-scale guided filtering strategy is adopted: filtering is first performed at low resolution to obtain the overall optimization direction, and then fine filtering is performed at the original resolution.
[0071] This invention uses industrial component images directly as guide images, instead of the existing method of first performing edge detection on the industrial component images and then fusing them with the original image. This design preserves the complete high-frequency texture information in the industrial component images, avoiding information loss and false edges that may be introduced during edge detection. The edge-preserving properties of the guide filter ensure that in areas with sharp edges in the industrial component images, the filter coefficients... Approaching 1 Approaching 0, the output mask preserves the edge shape of the input; in flat areas of industrial component images, the filtering coefficients approach the averaging effect, and the output mask achieves smoothing.
[0072] After guided filtering, a fine segmentation mask is output. Compared with the edge optimization mask, the fine segmentation mask has a higher degree of agreement with the real edges of the industrial component image, and the edge positioning accuracy reaches the sub-pixel level.
[0073] Step S4: Adaptive fine-tuning of the low-rank neighborhood.
[0074] Reference Figure 5 The goal of step S4 is to enable the model to quickly adapt to the new scene. This step is the offline training phase, with a small number of labeled samples from the new scene as input and the adapted model parameters as output.
[0075] The types of industrial components and production scenarios are diverse. Different types of pads, different production line environments, and different lighting conditions can all affect the performance of segmentation models. Traditional transfer learning methods require fine-tuning the entire model, which is not only time-consuming and requires a large amount of labeled data, but also suffers from catastrophic forgetting problems. Low-rank adaptation techniques achieve efficient fine-tuning by injecting a small number of trainable parameters into the pre-trained model, gaining adaptability to new scenarios while maintaining the generalization ability of the original model.
[0076] The core idea of low-rank adaptation is that the weight changes of a model when adapting to a new task can be approximated by a low-rank matrix. Let the original pre-trained weight matrix be... The adapted weight matrix is ,in This represents the weight increment. Low-rank adaptation hypothesis. It can be decomposed into the product of two low-rank matrices:
[0077] ,
[0078] in, , , This is the rank parameter. In this embodiment, the rank parameter... Set to 16.
[0079] During forward propagation, the model's output calculation method is modified as follows:
[0080] ,
[0081] in, As input features, For output features, The output of the original model. This is the incremental output brought about by the low-rank adaptation module.
[0082] The initialization of low-rank decomposition matrices uses the following strategy: matrix Gaussian random initialization, matrix Initialize to a zero matrix. This initialization method ensures that training begins... The model's behavior is completely consistent with the original pre-trained model, avoiding the impact of initialization noise on model performance.
[0083] This invention injects low-rank decomposition matrices into key layers of the lightweight segmentation network and the edge diffusion optimization module. Specifically, low-rank modules are injected into the feature pyramid fusion layer and the upsampling layer of the decoder in the lightweight segmentation network; and into the self-attention layer and feedforward layer of the conditional denoising network in the edge diffusion optimization module. Since the guided filtering module does not contain learnable parameters, low-rank adaptation is unnecessary.
[0084] During fine-tuning training, the original pre-trained weights Keep frozen, only for low-rank decomposition matrices and Perform gradient updates. The training objective function is a weighted combination of segmentation loss and edge loss:
[0085] ,
[0086] in, The loss is pixel-level cross-entropy segmentation. The Dice loss for edge regions is used to enhance edge segmentation accuracy. The edge loss weight is 0.5.
[0087] Fine-tuning training uses the AdamW optimizer, with the learning rate set to... The weight decay coefficient is 0.01. The training rounds are set to fifty rounds, with each round iterating through all training samples once. Since only low-rank parameters are updated, the number of trainable parameters is only one to five percent of the original model's parameters, and the training time is reduced by more than ninety percent compared to full model fine-tuning.
[0088] After fine-tuning, the low-rank incremental parameters obtained during training are merged with the original backbone weights:
[0089] ,
[0090] Merged model parameters For inference in new scenarios, there is no need to calculate the low-rank increment separately during inference, and the inference speed remains consistent with the original model.
[0091] The four steps of this invention form a deeply coupled closed-loop collaborative process, with close data dependencies and parameter feedback relationships between each step.
[0092] The coupling relationship between steps S1 and S2 is reflected in the fact that the coarse mask output by step S1 is directly used as the initial state of the diffusion process in step S2, and the quality of the coarse mask determines the number of iterations required for diffusion optimization. When the edge error of the coarse mask is large, step S2 requires more iterations to converge to an accurate result; when the quality of the coarse mask is good, step S2 can use fewer iterations to improve the overall inference efficiency. In this embodiment, the number of iterations is adaptively adjusted according to the edge uncertainty of the coarse mask, and the edge uncertainty is quantified by the entropy value of the probability distribution output by Softmax.
[0093] The coupling relationship between steps S2 and S3 is reflected in the fact that the edge-optimized mask output from step S2 serves as the input image for the guided filtering in step S3. The effectiveness of diffusion optimization determines the refinement difficulty of the guided filtering. The diffusion module mainly corrects pixel classification errors in edge regions, while the guided filtering mainly transmits high-frequency texture details. The two functions are complementary and synergistic. The edges after diffusion optimization are close to the true boundaries, and the guided filtering further refines the edge positions on this basis, achieving sub-pixel-level positioning accuracy.
[0094] Step S4 forms a closed-loop feedback relationship with the previous three steps. The low-rank fine-tuning in step S4 not only updates the parameters of the lightweight segmentation network but also simultaneously updates the parameters of the edge diffusion optimization module, ensuring that the two modules adapt collaboratively to new scenarios. The loss function during fine-tuning comprehensively considers both coarse and fine mask quality, achieving joint optimization throughout the entire process through end-to-end training. Furthermore, when a decrease in segmentation quality is detected during the inference phase, the system can trigger online fine-tuning in step S4, forming a closed-loop mechanism for continuous learning.
[0095] The lightweight segmentation network employs an encoder-decoder architecture, with the encoder consisting of five cascaded depthwise separable convolutional modules. The first module has three input channels (corresponding to RGB images) or one (corresponding to grayscale images) and thirty-two output channels; subsequent modules double the number of channels, at sixty-four, one hundred and twenty-eight, two hundred and fifty-six, and five hundred and twelve respectively. Each depthwise separable convolutional module contains six sub-layers: a depthwise convolutional layer, a batch normalization layer, a ReLU activation layer, a pointwise convolutional layer, a batch normalization layer, and a ReLU activation layer.
[0096] Depthwise convolutions employ a 3x3 kernel with a stride of 2 for spatial downsampling and padding of 1 to maintain the regularity of the feature map size. Pointwise convolutions use a 1x1 kernel for inter-channel information fusion and channel number adjustment. The momentum coefficient of the batch normalization layer is set to 0.1 for statistical updates during training. The ReLU activation function introduces non-linear transformation capabilities, enhancing the network's feature representation ability.
[0097] The feature pyramid structure passes feature maps from different levels of the encoder to the decoder via skip connections. These skip connections employ feature concatenation, combining encoder features with upsampled decoder features along the channel dimension, followed by a one-to-one convolution to adjust the number of channels. The multi-scale nature of the feature pyramid allows the network to simultaneously capture both coarse-grained semantic information and fine-grained spatial details.
[0098] The decoder employs four upsampling modules, each containing a bilinear interpolation upsampling layer, a 3x3 convolutional layer, a batch normalization layer, and a ReLU activation layer. The upsampling factor is set to two, corresponding to the encoder's downsampling factor. The final output layer uses a 1x1 convolution to map the number of channels to two (corresponding to the background and foreground categories), and outputs a pixel-level probability distribution after passing through the Softmax function.
[0099] The tracker module maintains a target state database to store feature information of confirmed targets in historical frames. The target state database uses a first-in, first-out (FIFO) queue structure with a queue length of five, storing the target states of the five most recent frames. Each target state contains the following fields: target unique identifier, target center point coordinates, target bounding box coordinates, target feature description vector, and target survival frame count.
[0100] The target feature description vector is extracted from the feature map through region pooling. Specifically, the corresponding region is cropped from the feature map based on the target bounding box, and adaptive average pooling is performed on the cropped region to obtain a feature vector of fixed size. In this embodiment, the dimension of the pooled feature vector is 256. The feature description vector is used to calculate the similarity between targets in different frames and is an important basis for temporal correlation matching.
[0101] The specific process of the Hungarian algorithm for finding the optimal match is as follows: First, a bipartite graph is constructed based on the cost matrix, with the current frame candidate and the historical frame target serving as two vertex sets in the bipartite graph, respectively. Then, augmented matching is performed stepwise through alternating path search. Finally, the matching scheme with the minimum total cost is output. Pairs with matching costs below a threshold are confirmed as the same target, historical frame targets with costs above the threshold are marked as lost, and unmatched current frame candidates are initialized as new targets.
[0102] Region-of-interest (ROI) processing achieves centralized allocation of computational resources through region-of-interest extraction. The ROI extraction method involves predicting the target's possible position in the current frame based on its motion trajectory in historical frames, expanding the bounding box by a factor of 1.2 around the predicted position, and cropping the expanded region from the feature map as input for subsequent processing. The motion trajectory prediction uses a Kalman filter; the state vector contains the target's center point's position and velocity, while the observation vector represents the target's center point's position.
[0103] The mask branch of the state encoder employs a four-layer convolutional network structure. The first convolutional layer has one input channel (binary mask) and sixty-four output channels, with a 3x3 kernel size and a stride of 1. The second to fourth convolutional layers have 128, 256, and 512 channels respectively, while maintaining the 3x3 kernel size and using strides of 2, 2, and 1 respectively to achieve spatial downsampling. Each convolutional layer is followed by a batch normalization layer and a GELU activation layer.
[0104] The image branch of the state encoder uses the same network structure as the mask branch, but the number of input channels is set to three (RGB images) or one (grayscale images) depending on the image type. The output feature maps of both branches have the same spatial resolution and number of channels, and feature fusion is performed by element-wise addition. The fused feature map is then input to the conditional denoising network.
[0105] The conditional denoising network employs a U-shaped structure, comprising four downsampling levels and four upsampling levels. Each level of the downsampling path contains two residual blocks and one downsampling layer, with grouped normalization and the GELU activation function applied within the residual blocks. The bottleneck layer contains two residual blocks and a self-attention layer, which models global spatial relationships. Each level of the upsampling path contains one upsampling layer and two residual blocks, with upsampling implemented using bilinear interpolation. Skip connections pass the feature maps from the downsampling paths to the corresponding levels of the upsampling paths.
[0106] Temporal step embedding is implemented using sinusoidal positional encoding and a multilayer perceptron. Sinusoidal positional encoding transforms discrete temporal step indices into continuous high-dimensional vectors, while the multilayer perceptron further extracts temporal step features. Temporal step embedding is injected into the residual blocks via addition or multiplication, enabling the network to adjust its denoising strategy according to different temporal steps.
[0107] To improve the computational efficiency of guided filtering, this embodiment employs integral image acceleration technology. An integral image is a pre-computational data structure that can calculate the sum of pixel values within any rectangular region by traversing the image once. The mean and variance calculations involved in guided filtering can be completed in constant time using integral images, thereby reducing the filtering time complexity from quadratic to linear.
[0108] In the specific implementation, four integral images need to be constructed: the integral image of the guiding image, the integral image of the squared guiding image, the integral image of the input image, and the integral image of the product of the guiding image and the input image. Based on the recursive relationship of the integral images, each integral image can be constructed with only one image traversal. The calculation of the filter coefficients is achieved by looking up a table using the integral images, avoiding the need to traverse and sum for each window.
[0109] For high-resolution images, this embodiment employs a downsampling-filtering-upsampling strategy to further improve efficiency. First, the guiding image and input image are downsampled to a lower resolution, and the filtering coefficients are calculated at this lower resolution. Then, the filtering coefficients are upsampled to the original resolution, and the filtering operation is performed. Experiments show that the four-fold downsampling acceleration strategy reduces the computation time to one-quarter of the original while maintaining filtering quality.
[0110] The initialization of the low-rank decomposition matrix has a significant impact on the fine-tuning effect. Matrix A is initialized with a mean of zero and a standard deviation of... The model is randomly initialized using a Gaussian distribution, where r is the rank parameter. Matrix B is initialized as an all-zero matrix to ensure that the low-rank increments are zero at the start of training. This initialization strategy ensures that the model's behavior in the early stages of training is consistent with the pre-trained model, avoiding performance fluctuations caused by initialization noise.
[0111] Fine-tuning training employs a mixed-precision training strategy to improve training efficiency. Model parameters and gradients are stored using single-precision floating-point numbers, while forward and backward propagation calculations are performed using half-precision floating-point numbers. Mixed-precision training maintains numerical stability while reducing GPU memory usage to half its original value, resulting in a training speed increase of approximately 30%.
[0112] The learning rate is scheduled using a cosine annealing strategy. The initial learning rate is set to... During training, it decays according to the cosine function to Compared to a constant learning rate, cosine annealing allows for more precise parameter tuning in the later stages of training, helping the model converge to a better local minimum.
[0113] Data augmentation strategies include random horizontal flipping, random rotation (angle range from -15 degrees to +15 degrees), random brightness adjustment (adjustment range from -20% to +20% of the original brightness), and random contrast adjustment (adjustment range from -20% to +20% of the original contrast). Data augmentation can effectively expand the diversity of training samples and improve the model's generalization ability.
[0114] To verify the technical effectiveness of the method of this invention, an experiment was conducted on an industrial iron pad contour segmentation dataset. The experimental environment used an industrial computer equipped with an NVIDIA RTX 3080 graphics card, and the input image resolution was 1920 x 1080 pixels. The dataset contained 3,800 iron pad images, covering samples of different models, lighting conditions, and surface conditions, and was divided into training, validation, and test sets at a ratio of 70%, 15%, and 15%, respectively.
[0115] In terms of segmentation accuracy, the method of this invention achieves an average intersection-union ratio (IUR) of 96.3% and an edge localization accuracy of 0.08 mm (sub-pixel level), representing improvements of 4.2% and 35% respectively compared to single-stage segmentation methods. The average IUR is calculated by dividing the intersection area of the predicted mask and the ground mask by the union area, and the edge localization accuracy is calculated by the average distance between the predicted edge and the ground edge.
[0116] In terms of inference speed, the total processing time per frame is 0.52 seconds, with step S1 taking 0.18 seconds, step S2 taking 0.26 seconds, and step S3 taking 0.08 seconds, which meets the production line cycle time requirements. The inference speed test was conducted by averaging the results after processing one thousand consecutive frames, excluding the model warm-up time of the first frame.
[0117] In terms of domain adaptation, the adaptation training for the new model pad only requires 200 labeled samples and two hours of training time, which is 92% shorter than the fine-tuning of the full model. The adapted model achieves an average intersection-union ratio of 94.1% on the new model pad, which is comparable to the performance of the full model trained specifically for this model.
[0118] In terms of anti-interference, under complex working conditions such as metal reflection and oil stains, the edge false detection rate is controlled to within 8%, which is 28% lower than the benchmark method. The anti-interference test simulates complex working conditions by artificially adding noise, including Gaussian noise, salt-and-pepper noise, and partial occlusion.
[0119] To verify the contribution of each module to the overall performance, an ablation experiment was conducted in this embodiment. In the ablation experiment, the diffusion edge optimization module, the guided filtering module, and the low-rank adaptation module were removed respectively, and the segmentation performance under each configuration was compared. Experimental results show that: after removing the diffusion edge optimization module, the average intersection-over-union ratio (IoU) decreased by 3.8%, and the edge localization accuracy decreased by 42%, demonstrating the crucial role of the diffusion module in edge refinement; after removing the guided filtering module, the average IoU decreased by 1.5%, and the edge smoothness decreased by 28%, indicating the importance of guided filtering in the transmission of high-frequency details; after removing the low-rank adaptation module, the average IoU decreased by 8.3% during new scene adaptation, and the training time increased to twelve times the original, verifying the efficiency of the low-rank fine-tuning strategy. The ablation experiment results demonstrate that the modules of this invention work together to achieve an effective balance between accuracy and speed.
[0120] The embodiments of this invention also included comparative experiments with existing methods. The comparative methods included the deep learning and guided filtering method disclosed in CN113269786A, the SegRefiner diffusion refinement method, and the SAMRefiner mask refinement method. Experimental results show that the method of this invention achieves the best performance in terms of average intersection-union ratio, edge localization accuracy, and inference speed, demonstrating the effectiveness and advancement of the proposed method.
[0121] The embodiments of the present invention are not limited to the specific embodiments described above. Those skilled in the art can make various equivalent changes or substitutions based on the technical solutions of the present invention, and all such changes or substitutions should be included within the protection scope of the present invention.
Claims
1. A method for contour segmentation of industrial components based on diffusion enhancement and guided filtering, characterized in that, Includes the following steps: Step S1, rapid generation of coarse mask: Input the image of industrial component into the lightweight segmentation network to obtain the initial segmentation feature map, use the tracker to perform temporal association matching on the target component in consecutive frames, perform region focusing processing on the initial segmentation feature map according to the temporal association result, and use the decoder to upsample and classify the focused feature map to generate a coarse segmentation mask. Step S2, Diffusion Edge Iterative Optimization: The coarse segmentation mask is used as the initial state input to the edge diffusion optimization module. The discrete diffusion process is used to predict the state transition probability of the mask edge region pixel by pixel. The classification results of the edge pixels are gradually corrected through multi-step conditional denoising iteration. After a preset number of iterations, the edge optimized mask is output. Step S3, Guided Filtering High-Frequency Transmission: Using the industrial component image as the guide image and the edge optimization mask as the filter input image, the high-frequency edge information in the industrial component image is transmitted to the mask boundary region through the guide filter. The filter coefficients are calculated according to the local linear model of the guide image and the edge optimization mask is filtered to output a fine segmentation mask. Step S4, Low-rank domain adaptive fine-tuning: For new industrial component types or production scenarios, freeze the backbone network weights of the lightweight segmentation network and edge diffusion optimization module, inject the low-rank decomposition matrix into the self-attention layer and feedforward layer of the backbone network, perform parameter update training only on the low-rank decomposition matrix, and superimpose the trained low-rank incremental parameters with the original backbone weights to form the adapted model parameters.
2. The method according to claim 1, characterized in that, In step S1, the matching threshold range for the temporal correlation matching is 0.5 to 0.8, the number of historical frames buffered by the tracker is 3 to 10 frames, and the region of interest expansion ratio for the region focusing processing is 1.1 to 1.5 times.
3. The method according to claim 1, characterized in that, In step S2, the number of iterations in the discrete diffusion process ranges from 5 to 20, the temperature coefficient of the state transition probability ranges from 0.5 to 2.0, and the noise scheduling coefficient of the conditional denoising ranges from 0.0001 to 0.
02.
4. The method according to claim 1, characterized in that, In step S3, the local window radius of the guided filter ranges from 2 to 16 pixels, the regularization parameter of the guided filter ranges from 0.0001 to 0.1, and the gradient threshold for the high-frequency edge information transmission ranges from 0.01 to 0.
1.
5. The method according to claim 1, characterized in that, In step S1, the lightweight segmentation network uses depthwise separable convolution instead of standard convolution for feature extraction, and uses a multi-scale feature pyramid structure to fuse feature maps of different resolutions. The tracker uses the Hungarian algorithm to perform inter-frame target matching based on the distance between the target center point and feature similarity.
6. The method according to claim 1, characterized in that, In step S2, the edge diffusion optimization module includes a state encoder and a conditional denoising network. The state encoder encodes the coarse mask and the industrial component image into a joint feature representation. The conditional denoising network uses a U-shaped structure to predict the class correction amount and state transition probability of edge pixels in each denoising step.
7. The method according to claim 1, characterized in that, In step S3, the guided filter uses a local linear model to model the filtering process. The filter coefficients are solved by minimizing the reconstruction error between the output image and the input image and combining the gradient constraints of the guided image. The filter coefficients are adaptively calculated in each local window based on the mean and variance of the guided image.
8. The method according to claim 1, characterized in that, In step S4, the low-rank decomposition matrix is injected into the self-attention layer and feedforward layer of the backbone network. The low-rank decomposition matrix is composed of the product of two low-rank matrices, and the rank value of the low-rank matrix ranges from 4 to 32.
9. The method according to claim 1, characterized in that, Steps S1 to S3 constitute the serial processing flow of the inference stage. The total processing time of a single frame in the inference stage does not exceed 0.6 seconds. Step S4 is the offline training stage, and the number of adaptation training rounds in a single offline training stage does not exceed 50 rounds.
10. The method according to claim 1, characterized in that, The method further includes a quality assessment step: evaluating the edge smoothness and region integrity of the output fine segmentation mask, and triggering additional iterative optimization in step S2 or model readjustment in step S4 when the evaluation score is lower than a preset threshold.
Citation Information
Patent Citations
Assembly image segmentation method and device based on deep learning and guided filtering
CN113269786A