Method for analyzing morphological parameters of activated sludge components based on improved sam model
Patent Information
- Application Number
- CN202611185776.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-06
- Publication Date
- 2026-10-20
AI Technical Summary
[0006]本发明为了解决活性污泥显微图像智能分析时缺少专用模型,导致活性污泥形态学参数提取与分析结果不准确的问题,进而提出了一种基于改进SAM模型的活性污泥组分形态学参数分析方法
[0016]本发明将SAM模型迁移到活性污泥显微图像领域,基于SAM模型在活性污泥显微图像领域的不足,创建了专用的污泥组分分割模型Sludge-SAM,污泥组分分割模型Sludge-SAM在传统SAM模型的基础上加入了局部纹理编码器和动态特征融合模块,并通过Adapter模块仅更新图像编码器的少量参数,在保留SAM模型通用视觉知识的同时,提升了Sludge-SAM模型对污泥显微图像特征分布的适应能力,降低了全量微调带来的计算成本和灾难性遗忘风险。局部纹理编码器和动态特征融合模块形成局部纹理特征与全局语义特征的协同表达,能够增强Sludge-SAM模型对污泥组分边缘、孔洞、不规则轮廓和小目标的识别能力,提高了分割结果的整体完整性和边界精细度。
Smart Images

Figure FT_1 
Figure FT_2 
Figure FT_3
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent monitoring of wastewater treatment, and specifically to a method for analyzing the morphological parameters of activated sludge components based on an improved SAM model. Background Technology
[0002] The activated sludge process is a widely used secondary biological treatment process in municipal wastewater treatment plants. Activated sludge consists of various components, including flocs, inorganic particles, microorganisms, microbial communities, and incompletely degraded organic matter. Its microscopic morphological changes are closely related to sludge settling performance, pollutant removal efficiency, and process operation risks. Timely and accurate acquisition of the microscopic morphological information of activated sludge components is of great significance for monitoring the operational status and analyzing abnormal conditions of wastewater treatment plants.
[0003] Traditional activated sludge detection mainly relies on manual microscopic examination and macroscopic operating parameters such as settling ratio, sludge volume index, and pollutant removal rate. However, manual microscopic examination suffers from high subjectivity, low efficiency, and difficulty in continuous batch processing. While macroscopic operating parameters can reflect the overall process status, they typically have a certain lag and are difficult to explain the impact of microscopic morphological changes in sludge components on the operating status. With the development of online microscopic imaging systems and computer vision technology, extracting sludge morphological parameters using microscopic image segmentation algorithms has become an important direction for intelligent activated sludge analysis. The accuracy of the segmentation results directly affects the reliability of subsequent morphological parameter calculations. Therefore, how to achieve accurate segmentation of different components in activated sludge microscopic images is a key foundation for conducting intelligent sludge analysis.
[0004] Existing deep learning image segmentation methods have achieved good results in fields such as natural images and medical images, but they still have significant shortcomings when directly transferred to activated sludge microscopic images. On the one hand, activated sludge microscopic images are characterized by blurred boundaries, irregular component morphology, low foreground-background contrast, a small number of small targets, and class imbalance. Therefore, directly transferring image segmentation models pre-trained on natural images can easily lead to undersegmentation, missed segmentation, and boundary discontinuities. On the other hand, although convolutional neural networks have strong local texture extraction capabilities, their global context modeling capabilities are limited. While the Transformer structure can capture long-distance dependencies, it is insufficient in depicting local high-frequency textures and edge details. To further improve the generalization ability of image segmentation models in complex microscopic images, general segmentation models such as SAM have been introduced into relevant image analysis tasks. However, although the SAM model has strong general segmentation capabilities, its original structure mainly relies on manually provided points, boxes, or masks, and the output does not directly carry specific category labels. In the scenario of batch analysis of activated sludge microscopic images, manually providing prompts for each image is not only inefficient but also easily affected by subjective differences. Meanwhile, segmenting only a single sludge component makes it difficult to fully reflect the multi-component structure in activated sludge microscopic images, and subsequent morphological parameter extraction and parameter screening also lack stable pixel-level input, resulting in inaccurate morphological parameter results.
[0005] Furthermore, activated sludge microscopic videos typically contain a large number of consecutive similar frames. Without effective filtering, this can easily lead to data redundancy and wasted computational resources, and also affect the processing efficiency of subsequent model training, image segmentation, and parameter analysis. Therefore, there is an urgent need for a method that can adapt to the activated sludge microscopic image domain, take into account both global semantics and local texture, support automatic identification of multiple sludge components, and further output morphological parameters and parameter filtering results. Summary of the Invention
[0006] To address the problem of inaccurate morphological parameter extraction and analysis results in activated sludge due to the lack of a dedicated model in intelligent analysis of activated sludge microscopic images, this invention proposes a method for analyzing the morphological parameters of activated sludge components based on an improved SAM model.
[0007] The technical solution adopted in this invention is:
[0008] It includes the following steps:
[0009] S1. Collect microscopic videos of activated sludge, extract keyframes from the microscopic videos of activated sludge, and obtain a set of keyframes.
[0010] S2. Construct a classification suggestion generator, which consists of a backbone network, a feature fusion network, and a detection head.
[0011] S3. Construct a sludge component segmentation model. The sludge component segmentation model includes an image encoder, a local texture encoder, a dynamic feature fusion module, a cue encoder, and a mask decoder. The image encoder and the local texture encoder are set up in parallel and are both connected to the dynamic feature fusion module. The dynamic feature fusion module and the cue encoder are set up in parallel and are both connected to the mask decoder.
[0012] S4. Input the keyframe set into the classification prompt generator. The classification prompt generator outputs the bounding box of each keyframe with sludge component category labels. Input the bounding box as a bounding box prompt into the prompt encoder of the sludge component segmentation model. The prompt encoder outputs the prompt feature embedding of each keyframe.
[0013] Simultaneously, the keyframe set is input into the image encoder and local texture encoder of the sludge component segmentation model to obtain the global semantic features and local texture features of each keyframe. The global semantic features and local texture features of each keyframe are input into the dynamic feature fusion module to obtain the fused features of each keyframe. The fused features of each keyframe and the prompt features are embedded into the input mask decoder. The mask decoder outputs the segmentation mask of different sludge components on each keyframe.
[0014] S5. Based on the segmentation mask of different sludge components on each keyframe, extract the morphological parameters of each sludge component, and filter and analyze the morphological parameters according to the sludge working conditions to obtain the specific morphological parameters of the sludge working conditions.
[0015] The beneficial effects of this invention are as follows:
[0016] This invention transfers the SAM model to the field of activated sludge microscopic images. Addressing the shortcomings of the SAM model in activated sludge microscopic image processing, a dedicated sludge component segmentation model, Sludge-SAM, is created. Sludge-SAM adds a local texture encoder and a dynamic feature fusion module to the traditional SAM model, and updates only a small number of parameters of the image encoder through an adapter module. While retaining the general visual knowledge of the SAM model, it improves the adaptability of the Sludge-SAM model to the feature distribution of sludge microscopic images, reducing the computational cost and catastrophic forgetting risk associated with full-scale fine-tuning. The local texture encoder and dynamic feature fusion module form a collaborative expression of local texture features and global semantic features, enhancing the Sludge-SAM model's ability to recognize sludge component edges, pores, irregular contours, and small targets, thus improving the overall integrity and boundary fineness of the segmentation results.
[0017] This invention trains the Sludge-SAM model using an adaptive prompting mechanism, solving the prompt generation problem during the Sludge-SAM model training phase. Furthermore, by using a classification prompt generator in conjunction with the Sludge-SAM model during the inference phase, it addresses the issue of automatic prompting during reasoning. This reduces the Sludge-SAM model's reliance on manual prompts and obtains category labels for flocculents, inorganic particles, and micro-animals while generating the segmentation mask.
[0018] This invention combines multi-category segmentation results with morphological parameter extraction, statistical screening, and operating condition analysis, enabling the acquisition of structured morphological parameters from activated sludge microscopic images, providing data support for parameter analysis under operating conditions such as sludge poisoning and sludge bulking. Attached Figure Description
[0019] Figure 1 This is a flowchart of the present invention;
[0020] Figure 2 This is a structural diagram of the Sludge-SAM sludge component segmentation model;
[0021] Figure 3 This is a diagram illustrating the differentiated deployment of the Adapter module;
[0022] Figure 4 This is a structural diagram of the dynamic feature fusion module;
[0023] Figure 5 This is a diagram illustrating the generation of dot hints and bounding box hints;
[0024] Figure 6 This is a diagram of the category suggestion generator structure;
[0025] Figure 7 This is a schematic diagram illustrating the results of multi-category segmentation of activated sludge components according to the present invention; Detailed Implementation
[0026] Specific implementation method one: Combining Figures 1-7 This embodiment describes a method for analyzing the morphological parameters of activated sludge components based on an improved SAM model, which includes the following steps:
[0027] S1. Acquire activated sludge microscopic videos. Since the field of view changes little between adjacent frames in the activated sludge microscopic videos, and there is a large amount of repetitive sludge component morphology information in consecutive frames, it is necessary to extract keyframes from the activated sludge microscopic videos to obtain a set of keyframes with reduced redundancy and containing effective sludge component morphology information. The specific process is as follows:
[0028] Microscopic videos of activated sludge are acquired using an online microscopic imaging system (such as the ROMIDAS system). Since the field of view of the activated sludge microscopic video moves at an approximately horizontal and uniform speed, it is assumed that the motion between adjacent video frames in the activated sludge microscopic video is a horizontal translation. Therefore, the normalized cross-power spectrum between adjacent video frames is calculated using the phase correlation method. ,for:
[0029] (1)
[0030] in, For the first One video frame, For the first One video frame, Indicates Fourier transform, Represents complex conjugation. Normalized cross-power spectrum between adjacent video frames. Perform an inverse Fourier transform and take the peak position to obtain the displacement between adjacent video frames. :
[0031] (2)
[0032] in, This represents the inverse Fourier transform.
[0033] Furthermore, the horizontal displacement of adjacent video frames in the activated sludge microscopic video was analyzed. Accumulate the data to obtain the cumulative horizontal displacement. :
[0034] (3)
[0035] in, This is the current video frame.
[0036] when At that time, the current video frame is used as the keyframe, and the accumulated horizontal displacement is reset. If the value is 0, continue calculation for the next keyframe; otherwise, continue calculating the cumulative horizontal displacement. until satisfied Or the activated sludge microscopic video may end here. The preset displacement threshold can be expressed as:
[0037] (4)
[0038] in, For a custom scaling factor, The width of the video frame.
[0039] By traversing the activated sludge microscopic video using formulas (1) to (4), a set of keyframes can be obtained. This step solves the problems of high redundancy in continuous frames of activated sludge microscopic video and large computational load in direct frame-by-frame processing.
[0040] S2. Using the Labelme open-source annotation tool, sludge components within each keyframe of the keyframe set are categorized and labeled. The labeled objects include at least flocs, inorganic particles, and microorganisms, resulting in a label file for each keyframe. This label file is a JSON annotation file, including the keyframe resolution, keyframe path, category label, and contour coordinates of each sludge component within the keyframe. Based on the label file, a binarized mask image, original image, and category label file are generated for each keyframe. The mask is a set of pixels in the foreground region of each sludge component. All binarized masks corresponding to the keyframe set are combined to obtain a set of binarized mask images; similarly, the set of original images can be obtained.
[0041] S3. To address the issue of insufficient adaptability when directly transferring image segmentation models pre-trained on natural images to activated sludge microscopic images, this invention constructs a sludge component segmentation model, Sludge-SAM, based on the SAM model, as follows: Figure 2 As shown, the sludge component segmentation model Sludge-SAM includes an image encoder, a local texture encoder, a dynamic feature fusion module, a cue encoder, and a mask decoder. The image encoder and local texture encoder are arranged in parallel and both connected to the dynamic feature fusion module. The dynamic feature fusion module and the cue encoder are arranged in parallel and both connected to the mask decoder. This invention also employs an efficient parameter fine-tuning method to achieve domain adaptation of the Sludge-SAM model.
[0042] This invention introduces an Adapter module into the traditional image encoder ViT within the SAM model. The Adapter module includes an input adapter, an attention adapter, and a feedforward network adapter. The input adapter is used for domain adaptation of shallow input features. The attention adapter is used to adjust the feature representation after attention calculation. The feedforward network adapter is used to inject domain knowledge of activated sludge microscopic images into deep features. This invention, through the coordinated fine-tuning of the input adapter, attention adapter, and feedforward network adapter, achieves domain transfer from the natural image domain to the sludge microscopic image domain by updating only a very small number of learnable parameters while freezing the main parameters of the image encoder. Figure 3As shown, the improved image encoder ViT includes an image patch embedding layer, an input adapter, a location embedding layer, and four Transformer Blocks. The image patch embedding layer, input adapter, and four Transformer Blocks are connected sequentially. The image patch embedding layer and the location embedding layer are arranged side-by-side, and the outputs of the input adapter and the location embedding layer are residually connected. The location embedding layer is used to generate location encoding information corresponding to the features of the image patch embedding layer. Each Transformer Block includes a first normalization layer, a window partitioning layer, a multi-head attention layer, an attention adapter, a window restoration layer, a feedforward network adapter, a second normalization layer, and a feedforward network layer. The first normalization layer, window partitioning layer, multi-head attention layer, attention adapter, window restoration layer, second normalization layer, and feedforward network layer are connected sequentially. The feedforward network adapter is connected to the window restoration layer. The input of the first normalization layer and the output of the window restoration layer are fused and then input into the feedforward network adapter and the second normalization layer, respectively. The outputs of the feedforward network adapter, the second normalization layer, and the feedforward network layer are fused to obtain the final output of each Transformer Block. Thus, during training, the main parameters of the SAM model are frozen, and only the newly added Adapter parameters are updated. This fine-tuning method preserves the general visual representation capabilities of the SAM model while enabling the transfer of the pre-trained image segmentation model from natural images to the domain of activated sludge microscopic images, reducing the computational cost and catastrophic forgetting risk associated with full-scale fine-tuning.
[0043] The local texture encoder addresses the problem of pixel-level texture detail loss caused by insufficient local perception capability of the image encoder, providing rich high-frequency texture information for feature fusion. The local texture encoder sequentially comprises a convolutional block, three downsampling blocks, and a dimension rearrangement layer. Each convolutional block includes a 3×3 convolutional layer, a third normalization layer, and a GELU activation layer. Each downsampling block includes a 2×2 max-pooling layer, a 3×3 convolutional layer, a fourth normalization layer, and a GELU activation layer. The local texture encoder progressively encodes the input activated sludge microscopic image into local texture features that match the global semantic features output by the image encoder in terms of spatial resolution and channel dimension.
[0044] like Figure 4 As shown, the dynamic feature fusion module is used to solve the problem of local information being suppressed.
[0045] The sludge component segmentation model Sludge-SAM is trained using a set of keyframes and a set of binary mask images. The input is the set of keyframes and the set of binary mask images, and the output is the predicted segmentation mask for different sludge components on each keyframe. This process continues until the number of iterations or the loss remains essentially constant, resulting in the trained sludge component segmentation model Sludge-SAM. The specific process is as follows:
[0046] (1) Input the keyframe set into the image encoder, and the image encoder outputs the global semantic features of each keyframe.
[0047] (2) The keyframe set is input into the local texture encoder, and then processed by a convolutional block, three downsampling blocks and a dimension rearrangement layer to output the local texture features of each keyframe. The local texture features are used to supplement the edge, pore, fine particle and irregular contour information of sludge components.
[0048] (3) Input the global semantic features and local texture features of each keyframe into the dynamic feature fusion module, such as... Figure 4 As shown, the dynamic feature fusion module uses the global semantic features as a query vector. The local texture features are used as key vectors. Sum value vector , respectively , and Perform linear projection and dimensional rearrangement. Utilize the dimensional rearrangement... and Calculate the scaled dot product to obtain the attention score matrix. Normalize the attention score matrix to obtain the attention weight matrix. Then, reorder the dimensions of the attention weight matrix. Matrix multiplication is performed to obtain an attention-weighted output. This output is then restored to its original spatial dimension and concatenated with local texture features to obtain concatenated features. Linear projection of these concatenated features yields fused image features. Residual concatenation of these fused image features with the global semantic features output by the image encoder further completes the fused features. This method achieves dynamic fusion of global semantic features and local texture features, improving the sludge component segmentation model's ability to segment sludge component boundaries and detailed structures.
[0049] (4) such as Figure 5 As shown, the left side is a diagram of point cues, and the right side is a diagram of bounding box cues. Based on each binary mask image in the set of binary mask images, the sludge component segmentation model Sludge-SAM automatically generates corresponding point cues and bounding box cues through an adaptive cueing mechanism. These point cues and bounding box cues are then input into the cue encoder, which outputs the cue feature embedding for each keyframe. The specific process is as follows:
[0050] Based on each binarized mask in the set of binarized masks, a distance transform algorithm is used to find the farthest skeleton point in the foreground mask of each sludge component. This point is located near the geometric center of the sludge component and is used as a positive guiding point cue. When the point cue deviates from the foreground region, the distance transform algorithm finds the nearest foreground pixel within a preset search radius as a replacement point cue. Simultaneously, random Gaussian dithering is used to expand the sludge component annotation contour outward by 5%-10% and confine it to the image space of the binarized mask. The expanded annotation contour is used as a bounding box cue to improve the tolerance of the sludge component segmentation model Sludge-SAM to cue deviation and annotation noise. This yields the point cue and bounding box cue for each binarized mask. These cue and bounding box cue are input into the cue encoder, which outputs the cue feature embedding for each binarized mask, thus obtaining the cue feature embedding for each keyframe.
[0051] (5) Embed the fusion features and cue features of each keyframe into the input mask decoder. The mask decoder outputs pixel-level predicted segmentation masks for different sludge components on each keyframe, including multi-class segmentation masks for at least flocs, inorganic particles, and microorganisms, and makes the pixel-level predicted segmentation masks inherit the corresponding class labels. Calculate the loss based on the predicted segmentation masks and the true segmentation masks.
[0052] (6) Repeat (1)-(5) to train the sludge component segmentation model Sludge-SAM until the number of iterations or loss remains basically unchanged, and obtain the trained sludge component segmentation model Sludge-SAM.
[0053] S4. Construct a category suggestion generator, such as Figure 6As shown, the classification prompt generator is based on the YOLOv11 object detection model, which includes a backbone network, a feature fusion network, and a detection head. The backbone network includes convolutional layer 3, convolutional layer 4, C3K2 module 1, convolutional layer 5, C3K2 module 2, convolutional layer 6, C3K2 module 3, convolutional layer 7, and C3K2 module 4. The feature fusion network includes the SPFF module, C2PSA module, upsampling layer 1, feature splicing layer 1, C3K2 module 5, upsampling layer 2, feature splicing layer 2, C3K2 module 6, convolutional layer 8, feature splicing layer 3, C3K2 module 7, convolutional layer 9, feature splicing layer 4, and C3K2 module 8. Among them, the SPFF module, C2PSA module, upsampling layer 1, feature splicing layer 1, C3K2 module 5, upsampling layer 2, feature splicing layer 2, and C3K2 module 6 are connected in sequence, and the convolutional layer 8, feature splicing layer 3, C3K2 module 7, convolutional layer 9, feature splicing layer 4, and C3K2 module 8 are connected in sequence. Among them, convolutional layer seven is also connected to the SPFF module, C3K2 module three is also connected to feature splicing layer one, C3K2 module one is also connected to feature splicing layer two, C2PSA module is also connected to feature splicing layer four, C3K2 module five is also connected to feature splicing layer three, and C3K2 modules six, seven, and eight are all connected to the detection head. The classification cue generator is used to output bounding boxes with sludge component category labels and confidence scores, and uses the bounding boxes with sludge component category labels as input cue encoders.
[0054] Since the original image in S2 contains sludge component labels and sludge component bounding boxes, this invention uses the set of original images to train the classification prompt generator. The original image set is input, and the bounding boxes and confidence scores with sludge component category labels corresponding to each original image are output according to the forward propagation, thus obtaining the trained classification prompt generator.
[0055] S5. In the sludge component inference stage, firstly, microscopic videos of activated sludge are acquired, and the corresponding key frame set is obtained through S1. The key frame set is input into the trained classification prompt generator. The classification prompt generator outputs the bounding box and confidence score corresponding to each key frame with sludge component category labels. The bounding box is used as a bounding box prompt and input into the prompt encoder of the trained sludge component segmentation model Sludge-SAM. The prompt encoder outputs the prompt feature embedding of each key frame.
[0056] Simultaneously, the keyframe set described in the previous paragraph is input into the trained sludge component segmentation model Sludge-SAM to obtain the fused features of each keyframe. These fused features and cue features are then embedded into the input mask decoder. The mask decoder outputs segmentation masks for different sludge components on each keyframe. While generating each entity mask, the mask decoder automatically inherits the corresponding category label, thus endowing the Sludge-SAM sludge component segmentation model with the ability to discriminate sludge component categories.
[0057] Based on the segmentation mask of different sludge components in each keyframe, morphological parameters of each sludge component are extracted. These morphological parameters are then filtered and analyzed according to the sludge operating conditions to obtain specific morphological parameters for each sludge operating condition. The specific process is as follows:
[0058] Based on the segmentation mask of each sludge component in each keyframe, morphological parameters of each sludge component are extracted. These morphological parameters are then categorized according to the size, pore density, shape, stability, and statistical characteristics of the sludge components, resulting in a morphological parameter table for each sludge component, as shown in Table 1. This table characterizes the microscopic morphological features of activated sludge in terms of size, outline, pore structure, morphological stability, and component quantity distribution.
[0059] Table 1
[0060]
[0061] Subsequently, to facilitate subsequent statistical analysis of morphological parameters, the sludge was categorized into sludge poisoning and sludge bulking conditions based on its component states. Each condition was assigned four sludge component state levels: Level A (healthy), Level B (slightly abnormal), Level C (abnormal), and Level D (system failure). A morphological parameter sample set corresponding to each level was constructed based on the morphological parameter table for each sludge component. The sludge poisoning classification table is shown in Table 2, and the sludge bulking classification table is shown in Table 3.
[0062] Table 2
[0063]
[0064] Table 3
[0065]
[0066] Next, the Kruskal-Wallis H statistic, Epsilon-squared effect size, and Spearman rank correlation coefficient were calculated for each morphological parameter sample in the morphological parameter sample set for each level. The differences and trends of the same morphological parameter between different state levels were analyzed from the perspectives of significance, intensity of difference, and trend. When the Kruskal-Wallis H statistic, Epsilon-squared effect size, and Spearman rank correlation coefficient of a morphological parameter all met the corresponding threshold requirements, this morphological parameter was retained and considered to have state characterization ability. This process allowed for the selection of specific morphological parameters with state characterization ability for each operating condition. Through this screening process, parameters that did not respond significantly to changes in operating conditions or had weak distinguishing ability were eliminated, while morphological indicators with a high degree of correlation with changes in sludge state were retained. The specific morphological parameters include at least one of the following: area, equivalent diameter, maximum Feret diameter, length, width, perimeter, convex hull perimeter, number of pores, void ratio, aspect ratio, solidity, bounding box aspect ratio, eccentricity, shape factor, roundness, density, solidity, simplified radius of gyration, convexity, number of inorganic particles, percentage of inorganic particle area, and number of microorganisms. It should be noted that the operating condition analysis in this invention is based on statistical screening and analysis using morphological parameters, and is not limited to an automatic classification method that directly outputs the state category after inputting a single image. This screening process can eliminate parameters that do not respond significantly to changes in operating conditions or have weak distinguishing ability, retaining morphological indicators that are highly correlated with changes in sludge state.
[0067] In one embodiment, the screening results of morphological parameters under sludge poisoning conditions are shown in Table 4, and the screening results of morphological parameters under sludge expansion conditions are shown in Table 5.
[0068] Table 4
[0069]
[0070] Table 5
[0071]
[0072] in, Threshold for the Kruskal-Wallis H statistic. The Epsilon-squared effect size threshold. The threshold value is the Spearman rank correlation coefficient. Tables 4 and 5 show that the specific morphological parameters obtained under different abnormal operating conditions are not entirely the same. Specifically, the parameters obtained under the sludge poisoning condition mainly reflect changes such as floc breakage, loose internal structure, and exposure of inorganic particles; the parameters obtained under the sludge bulking condition mainly reflect characteristics such as floc elongation, decreased roundness, and changes in the number of microorganisms. Through this method, the multi-category segmentation results can be transformed into structured morphological parameters, providing data support for the analysis of operating conditions such as sludge poisoning and sludge bulking.
[0073] To verify the effectiveness of this invention, the following description is based on experimental results. First, to verify the role of the Adapter module in the migration of activated sludge in microscopic images, ablation experiments were conducted on the Adapter module and the LoRA module, and the experimental results are shown in Table 6.
[0074] Table 6
[0075]
[0076] As shown in Table 6, compared with the ViT-B basic model without the Adapter module, the IoU and DSC of the model are significantly improved after the Adapter module is introduced. This indicates that the Adapter module can effectively improve the cross-domain adaptation ability of the natural image pre-trained model on activated sludge microscopic images.
[0077] Furthermore, to verify the role of the local texture encoder and dynamic feature fusion module in sludge microscopic image segmentation, a module ablation experiment was conducted on the sludge component segmentation model Sludge-SAM, and the experimental results are shown in Table 7.
[0078] Table 7
[0079]
[0080] As shown in Table 7, the model segmentation performance continued to improve after adding a local texture encoder and a dynamic feature fusion module to the Adapter module, indicating that the fusion of local texture and global semantics can enhance the ability to depict boundaries and details.
[0081] Based on this, in order to verify the contribution of the adaptive prompting mechanism and the classification prompting generator to the multi-class segmentation task, an ablation experiment was conducted on the sludge component segmentation model Sludge-SAM and the classification prompting generator. The results are shown in Table 8.
[0082] Table 8
[0083]
[0084] As shown in Table 8, the model segmentation performance is further improved after the introduction of the adaptive prompting mechanism. After the introduction of the classification prompt generator, the model can not only generate pixel-level segmentation masks, but also output the corresponding category information, and finally achieve multi-category fine segmentation of flocs, inorganic particles and micro animals.
[0085] To further illustrate the performance advantages of the method of the present invention compared with existing segmentation models, the method of the present invention is compared with models such as DeepLabV3+, UNet++ and SegFormer. The performance comparison results are shown in Table 9.
[0086] Table 9
[0087]
[0088] As shown in Table 9, the sludge component segmentation model Sludge-SAM described in this invention achieves superior results in evaluation indicators such as mIoU, mDSC, and mAP, indicating that the method of this invention can more effectively adapt to segmentation scenarios with blurred boundaries, irregular shapes, and coexistence of multiple component categories in activated sludge microscopic images. Figure 7 As shown, the sludge component segmentation model Sludge-SAM can perform pixel-level multi-class segmentation of flocs, inorganic particles and microorganisms in activated sludge microscopic images, and the obtained segmentation results can be used as input for subsequent morphological parameter extraction.
[0089] In summary, the experimental results show that the present invention, through the combined design of the Adapter module, local texture encoding, dynamic feature fusion module, adaptive prompting mechanism, and classification prompt generator, improves the domain adaptation ability, multi-class segmentation ability, and subsequent morphological parameter analysis ability of the sludge component segmentation model Sludge-SAM in activated sludge microscopic images.
[0090] This invention may have other embodiments. Without departing from the spirit and essence of this invention, those skilled in the art can make various corresponding changes and modifications according to this invention, but these corresponding changes and modifications should all fall within the protection scope of the appended claims.
Claims
1. A method for analyzing the morphological parameters of activated sludge components based on an improved SAM model, characterized in that: It includes the following steps: S1. Collect microscopic videos of activated sludge, extract keyframes from the microscopic videos of activated sludge, and obtain a set of keyframes. S2. Construct a classification suggestion generator, which consists of a backbone network, a feature fusion network, and a detection head. S3. Construct a sludge component segmentation model. The sludge component segmentation model includes an image encoder, a local texture encoder, a dynamic feature fusion module, a cue encoder, and a mask decoder. The image encoder and the local texture encoder are set up in parallel and are both connected to the dynamic feature fusion module. The dynamic feature fusion module and the cue encoder are set up in parallel and are both connected to the mask decoder. S4. Input the keyframe set into the classification prompt generator. The classification prompt generator outputs the bounding box of each keyframe with sludge component category labels. Input the bounding box as a bounding box prompt into the prompt encoder of the sludge component segmentation model. The prompt encoder outputs the prompt feature embedding of each keyframe. Simultaneously, the keyframe set is input into the image encoder and local texture encoder of the sludge component segmentation model to obtain the global semantic features and local texture features of each keyframe. The global semantic features and local texture features of each keyframe are input into the dynamic feature fusion module to obtain the fused features of each keyframe. The fused features of each keyframe and the prompt features are embedded into the input mask decoder. The mask decoder outputs the segmentation mask of different sludge components on each keyframe. S5. Based on the segmentation mask of different sludge components on each keyframe, extract the morphological parameters of each sludge component, and filter and analyze the morphological parameters according to the sludge working conditions to obtain the specific morphological parameters of the sludge working conditions.
2. The method for analyzing the morphological parameters of activated sludge components based on the improved SAM model according to claim 1, characterized in that: The specific process of S1 is as follows: Microscopic videos of activated sludge were acquired using an online microscopic imaging system. Assuming horizontal translation occurs between adjacent video frames, the normalized cross-power spectrum between adjacent video frames was calculated using the phase correlation method. : (1) in, For the first One video frame, For the first One video frame, Indicates Fourier transform, Indicates complex conjugation; Normalized cross-power spectrum Perform an inverse Fourier transform and take the peak position to obtain the displacement between adjacent video frames. : (2) in, Indicates the inverse Fourier transform; Horizontal displacement of adjacent video frames Accumulate the data to obtain the cumulative horizontal displacement. : (3) in, The current video frame; when When the current video frame is selected as the keyframe, the accumulated horizontal displacement is reset to 0, and the calculation of the next keyframe continues; when Continue calculating the cumulative horizontal displacement. ;in, Preset displacement threshold: (4) in, For a custom scaling factor, The width of the video frame; The keyframe set is obtained by iterating through the activated sludge microscopic video according to formulas (1) to (4).
3. The method for analyzing the morphological parameters of activated sludge components based on the improved SAM model according to claim 1, characterized in that: The backbone network in S2 includes, in sequence, convolutional layer 3, convolutional layer 4, C3K2 module 1, convolutional layer 5, C3K2 module 2, convolutional layer 6, C3K2 module 3, convolutional layer 7, and C3K2 module 4; The feature fusion network includes an SPFF module, a C2PSA module, an upsampling layer 1, a feature splicing layer 1, a C3K2 module 5, an upsampling layer 2, a feature splicing layer 2, a C3K2 module 6, a convolutional layer 8, a feature splicing layer 3, a C3K2 module 7, a convolutional layer 9, a feature splicing layer 4, and a C3K2 module 8. The SPFF module, C2PSA module, upsampling layer 1, feature splicing layer 1, C3K2 module 5, upsampling layer 2, feature splicing layer 2, and C3K2 module 6 are connected sequentially. Convolutional layer 8, feature splicing layer 3, C3K2 module 7, convolutional layer 9, feature splicing layer 4, and C3K2 module 8 are also connected sequentially. The C2PSA module is also connected to feature splicing layer 4, and C3K2 module 5 is also connected to feature splicing layer 3. Meanwhile, C3K2 module one is also connected to feature splicing layer two, C3K2 module three is also connected to feature splicing layer one, convolutional layer seven is also connected to the SPFF module, and C3K2 module six, C3K2 module seven and C3K2 module eight are all connected to the detection head.
4. The method for analyzing the morphological parameters of activated sludge components based on the improved SAM model according to claim 1, characterized in that: The image encoder in S3 includes an image block embedding layer, an input adapter, a position embedding layer, and four Transformer Blocks. The image block embedding layer, the input adapter, and the four Transformer Blocks are connected in sequence. The image block embedding layer and the position embedding layer are arranged in parallel, and the output of the input adapter and the output of the position embedding layer are residually connected. Each Transformer Block includes a first normalization layer, a window partitioning layer, a multi-head attention layer, an attention adapter, a window restoration layer, a feedforward network adapter, a second normalization layer, and a feedforward network layer. The first normalization layer, window partitioning layer, multi-head attention layer, attention adapter, window restoration layer, second normalization layer, and feedforward network layer are connected sequentially. The feedforward network adapter is connected to the window restoration layer, and the input of the first normalization layer and the output of the window restoration layer are fused and then input into the feedforward network adapter and the second normalization layer, respectively. The output of the feedforward network adapter, the output of the second normalization layer, and the output of the feedforward network layer are fused to form the output of each Transformer Block.
5. The method for analyzing the morphological parameters of activated sludge components based on the improved SAM model according to claim 1, characterized in that: The local texture encoder in S3 sequentially includes a convolutional block, three downsampling blocks, and a dimension rearrangement layer. The convolutional block sequentially includes a first convolutional layer, a third normalization layer, and a first GELU activation layer. Each downsampling block sequentially includes a second max pooling layer, a second convolutional layer, a fourth normalization layer, and a second GELU activation layer.
6. The method for analyzing the morphological parameters of activated sludge components based on the improved SAM model according to claim 1, characterized in that: During training, the sludge component segmentation model in S3 automatically generates corresponding point cues and bounding box cues based on the training images using an adaptive cueing mechanism. These point cues and bounding box cues are then input into the cueing encoder, which outputs the corresponding cue feature embedding. The specific process is as follows: Based on the binarized mask image of the training image, the distance transform algorithm is used to find the farthest skeleton point in the foreground mask of each sludge component, and the farthest skeleton point is used as a positive guiding point prompt. At the same time, random Gaussian jitter is used to expand the sludge component annotation outline outward by 5%-10% and limit it to the image space of the binary mask image, and the expanded annotation outline is used as a bounding box prompt. The point cue and bounding box cue are input into the cue encoder, and the cue encoder outputs the corresponding cue feature embedding.
7. The method for analyzing the morphological parameters of activated sludge components based on the improved SAM model according to claim 1, characterized in that: In step S4, the global semantic features and local texture features of each keyframe are input into the dynamic feature fusion module to obtain the fused features of each keyframe. The specific process is as follows: The global semantic features and local texture features of each keyframe are input into the dynamic feature fusion module, which uses the global semantic features as a query vector. The local texture features are used as key vectors. Sum value vector , respectively , and Perform linear projection and dimensional rearrangement, and utilize the rearranged dimensions. and Calculate the scaled dot product to obtain the attention score matrix. Normalize the attention score matrix to obtain the attention weight matrix. Then, reorder the dimensions of the attention weight matrix. Perform matrix multiplication to obtain attention-weighted output, restore the attention-weighted output to the original spatial dimension, and concatenate it with the local texture features to obtain concatenated features. Perform linear projection on the concatenated features to obtain fused image features. Perform residual connection between the fused image features and the global semantic features to obtain fused features.
8. The method for analyzing the morphological parameters of activated sludge components based on the improved SAM model according to claim 1, characterized in that: The process of S5 is as follows: Based on the segmentation mask of different sludge components on each keyframe, the morphological parameters of each sludge component are extracted. The morphological parameters are then classified according to the size characteristics, pore density characteristics, shape characteristics, stability characteristics and component statistical characteristics of the sludge components to obtain a morphological parameter table for each sludge component. Based on the state of sludge components, the conditions are divided into sludge poisoning and sludge bulking, and each condition corresponds to four sludge component state levels: Grade A, which represents health; Grade B, which represents slight abnormality; Grade C, which represents abnormality; and Grade D, which represents system paralysis. Based on the morphological parameter table for each sludge component, a morphological parameter sample set corresponding to each level under each working condition is constructed. The Kruskal-Wallis H statistic, Epsilon-squared effect size, and Spearman rank correlation coefficient of each morphological parameter in the morphological parameter sample set are calculated. When the Kruskal-Wallis H statistic, Epsilon-squared effect size, and Spearman rank correlation coefficient of the morphological parameter all meet the corresponding thresholds, the specific morphological parameters for each working condition are obtained.