Segmentation threshold self-generation alumen ustum detection method and system based on convolutional neural network
By using a segmentation threshold self-generation method based on convolutional neural networks, the problems of lag and subjectivity in alum floc detection are solved, and automatic separation of alum floc from the background and parameter calculation are realized, meeting the real-time and accuracy requirements of sewage treatment scenarios.
Patent Information
- Application Number
- CN202511117842.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-11
- Publication Date
- 2025-11-21
AI Technical Summary
Existing technologies for detecting alum floc have drawbacks such as detection lag, subjectivity, high computational complexity, poor real-time performance, and the risk of overfitting, making it difficult to meet the accuracy and reliability requirements of wastewater treatment scenarios.
A segmentation threshold self-generation method based on convolutional neural networks is adopted. Through a three-level convolution-pooling feature extraction network, combined with custom weighted grayscale and global average pooling, the optimal segmentation threshold is generated to achieve automatic separation of alum flowers from the background. The outline of alum flowers and the calculation parameters are identified by the 8-neighborhood rule.
It achieves adaptive threshold generation for alum flower detection, has strong anti-interference capabilities, lightweight computation, meets real-time monitoring requirements, eliminates the bias of manual detection, and provides fully automated alum flower status analysis.
Smart Images

Figure CN120997180A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of floc detection technology in water treatment plants, and in particular to a floc detection method and system based on the self-generation of segmentation thresholds using a convolutional neural network. Background Technology
[0002] Floc detection is a crucial step in water treatment. By monitoring the morphology, size, and distribution density of flocs in real time, the effectiveness of coagulant dosing can be accurately assessed. Currently, floc detection primarily employs three technical solutions: traditional manual detection, traditional digital image processing algorithms, and general-purpose deep learning models. Research has revealed significant technical shortcomings in all of these existing technologies:
[0003] Traditional manual inspection methods suffer from technical problems such as detection lag and subjectivity. They rely entirely on the experience and judgment of operators, resulting in inconsistent evaluation standards, easy human error, and difficulty in guaranteeing inspection quality under harsh working conditions. Traditional image segmentation algorithms suffer from the following technical bottlenecks: Global thresholding methods based on grayscale statistics (such as Otsu and P-Tile algorithms) are limited by the assumption of a single-peak or bi-peak grayscale distribution in the image. When encountering uneven lighting or interference from water impurities that cause non-uniform grayscale distribution, the segmentation threshold is prone to shift, leading to misjudgment of alum flocs and background. Local thresholding techniques (such as Niblack and Sauvola algorithms) can adapt to changes in local statistical quantities, but when processing alum floc images with complex and dynamically changing backgrounds, they are easily affected by noise interference from water bubbles and flocculent impurities, resulting in threshold fluctuations. At the same time, block processing can also cause statistical deviations in boundary pixels, leading to inconsistencies in inter-block segmentation and stitching artifacts. Edge detection segmentation techniques (such as Canny and Sobel algorithms) are difficult to determine ideal starting detection points due to the irregular shape and blurred edges of alum flocs. Not only is edge extraction incomplete, but gradient calculation is also sensitive to noise, easily producing false edges. Internal holes often appear after segmentation, requiring additional morphological operations or region filling and other post-processing methods, which significantly increases computational complexity and processing time.
[0004] While general segmentation models based on deep learning (such as U-Net and ResNet) possess high-order feature extraction capabilities, they suffer from technical drawbacks such as high computational resource consumption, difficulty in meeting the real-time requirements of wastewater treatment scenarios, and a significant risk of overfitting. These technical issues severely restrict the accuracy and reliability of floc detection, impacting the optimization and control of water treatment processes. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a method and system for detecting flocs based on the self-generated segmentation threshold of a convolutional neural network, which provides accurate binary images for the analysis of floc state in the sewage treatment process and meets the needs of image recognition and processing in sewage treatment scenarios.
[0006] To achieve the above objectives, the present invention adopts the following technical solution: a method for detecting flocs based on the self-generated segmentation threshold of a convolutional neural network, comprising the following steps:
[0007] S1: Acquire image data from multiple angles of the sewage treatment pond;
[0008] S2: Image data preprocessing: The central 2 / 3 region of the image is cropped as the confidence interval data to eliminate the influence of camera angle distortion; the confidence interval image is enhanced; custom weighted grayscale is used to suppress background noise and enhance image separability;
[0009] S3: Image binarization: An adaptive threshold segmentation method is used to generate the optimal binarization threshold, which is suitable for separating the alum flowers from the background; the preprocessed image is binarized based on the above binarization threshold to obtain binarized image data with white alum flowers and black background;
[0010] S4: Alum floc screening: Identify the outer contour in the binarized image based on the 8-neighborhood rule to obtain the alum floc contour point set; calculate the pixel area of each contour; screen the effective alum floc area according to the preset area threshold range, and remove noise points and abnormal agglomerates;
[0011] S5: Calculation and output of alum flower parameters: Calculate the circumscribed circle diameter of the effective alum flower contour and take the average value to obtain the average diameter of the alum flower in the frame image; sum up the total pixels of the effective alum flower area and divide by the total pixels of the preprocessed image to obtain the alum flower density; output the average diameter and density of the alum flower.
[0012] In a preferred embodiment, S1 is specifically as follows:
[0013] At least three industrial-grade high-speed cameras are arranged in a ring around the perimeter of the wastewater treatment tank at equal intervals. The cameras are installed 1.5-2.0 meters above the liquid surface, and the angle between the lens optical axis and the vertical line of the liquid surface is 30°-60° to ensure comprehensive monitoring of the central reaction area and the edge flocculation area of the tank without blind spots.
[0014] In a preferred embodiment, the custom weighted grayscale in S2 is as follows:
[0015] Constructing a grayscale model:
[0016] Gray value = 0.7 × B + 0.1 × G + 0.02 × R
[0017] Where B, G, and R represent image channels, respectively.
[0018] In a preferred embodiment, the adaptive threshold segmentation method in S3 is as follows:
[0019] S31: The input image is sequentially processed through a three-level convolution-activation-pooling feature extraction unit via a multi-level feature extraction module.
[0020] Convolutional layer: After filling the image with a circle, a 3×3 convolutional kernel is used to slide the image region by region with a stride of 1 to extract local features of the image and generate an initial feature map;
[0021] Extract the calculation formula:
[0022]
[0023] O is the output feature map, I is the input feature map, K is the convolution kernel, and C is the input feature map. in is the number of input channels, k is the kernel size, i and j are the coordinates of the output feature map, c is the output channel index, d is the input channel index, m represents the row index of the kernel, with a value range of [0, k-1], and n represents the column index of the kernel, with a value range of [0, k-1].
[0024] Activation layer: The ReLU activation function is used to perform a non-linear transformation on the output of the convolutional layer. The calculation formula is as follows:
[0025] ReLU(x) = max(0,x)
[0026] Where x is the input and y is the output, when x>0, y=x; when x≤0, y=0;
[0027] Pooling layer: A 2×2 max pooling operation with a stride of 2 is used to downsample the feature map. Local aggregation of the feature map is performed, and the calculation formula is as follows:
[0028] For the input feature map X∈R H×W and pooling window K∈Z + The window size is K x K, the stride is S, and the output feature map is...
[0029] Y∈R H'×W' The calculation formula is:
[0030]
[0031] Where [i, j] are the coordinates of the output feature map, [m, n] are the relative coordinates within the pooling window, and the size of the pooled image is calculated using the following formula:
[0032]
[0033] The above convolution-activation-pooling operation is repeated three times;
[0034] S32: Feature Dimensionality Reduction and Format Conversion
[0035] Average pooling layer: Global average pooling is performed on the output after the three-level feature extraction, compressing the size of each feature map to 1×1. The calculation formula is as follows:
[0036]
[0037] Where: Y is the output feature, X is the input feature map, c is the channel index, H is the height of the input feature map, and W is the width of the input feature map;
[0038] Flattening layer: Converts multidimensional feature tensors into one-dimensional vectors, which serve as inputs to subsequent fully connected layers;
[0039]
[0040] Where: A is the flattened one-dimensional vector, Z is the input two-dimensional tensor, k is the index of the flattened vector, and N is the number of columns in the input tensor. It is the integer part of k divided by N, and k%N is the remainder when k is divided by N;
[0041] S33: Threshold Prediction and Binarization:
[0042] Fully connected layer: The one-dimensional feature vector is mapped to four values through a fully connected neural network. The optimal segmentation threshold for the current image is then calculated using linear regression. The calculation formula is as follows:
[0043] For input vector X∈R B×64 The output vector Y∈R B×4 Calculated as:
[0044] Y = XW + b
[0045] Where W is the weight and b is the bias term;
[0046] Binarization: The predicted threshold is applied to the original image to perform a binarization operation, resulting in a binarized image where the alum flower area is white and the background area is black. The calculation formula is as follows:
[0047]
[0048] Where I(x,y) is the pixel value of the preprocessed image, and B(x,y) is the pixel value of the binarized image.
[0049] In a preferred embodiment, the specific parameter configuration and hierarchical mapping relationship in the adaptive threshold segmentation method in S3 are as follows:
[0050] (1) Input layer definition:
[0051] The input image has dimensions (w, h, x).
[0052] Where: w is the image width in pixels, h is the image height in pixels, and x is the number of data channels;
[0053] (2) Three-level convolution-pooling feature extraction unit
[0054] First-level feature extraction unit:
[0055] Convolutional layer: The number of input channels is x, the number of output channels is 16, a 3×3 convolutional kernel is used, the sliding stride is 1, and the number of boundary padding layers is 1. Through this parameter configuration, the feature map spatial dimension is maintained as (w,h) after the convolution operation, and the output dimension is (w,h,16), realizing the preliminary extraction of the basic texture of the alum flower image.
[0056] Activation layer: The ReLU activation function is used for nonlinear transformation to enhance the network's ability to learn nonlinear features;
[0057] Pooling layer: A 2×2 max pooling kernel with a sliding step of 2 is used to downsample the feature map, and the output dimension is (w / 2, h / 2, 16). While preserving key features, the amount of data is compressed to 1 / 4, reducing computational complexity.
[0058] Second-level feature extraction unit:
[0059] Convolutional layer: 16 input channels, 32 output channels, 3×3 convolutional kernel, stride 1, padding = 1; feature map space dimension is maintained at (w / 2, h / 2), output dimension is (w / 2, h / 2, 32), doubling the number of channels improves the ability to extract mid-level features of alum flower morphology;
[0060] Activation layer: Same as the first level, but enhances feature discrimination through nonlinear transformation;
[0061] Pooling layer: 2×2 max pooling with a stride of 2, output dimension is (w / 4, h / 4, 32), further compressing the spatial dimension to focus on core features.
[0062] Third-level feature extraction unit:
[0063] Convolutional layer: 32 input channels, 64 output channels, 3×3 convolutional kernel, stride 1, padding = 1; feature map spatial dimension is maintained at (w / 4, h / 4), output dimension is (w / 4, h / 4, 64), abstract difference features between alum flowers and background are extracted through higher-dimensional channels;
[0064] Activation layer: Same as the previous two levels, enhances the network's ability to fit complex patterns;
[0065] Pooling layer: 2×2 max pooling with a stride of 2, output dimension (w / 8, h / 8, 64), which compresses and aggregates high-dimensional features.
[0066] (3) Global feature aggregation and output unit
[0067] Average pooling layer: Global average pooling is performed on the (w / 8,h / 8,64) feature map output by the third pooling layer, compressing the spatial dimension to 1×1, and the output dimension is (1,1,64), realizing the global integration of the full image features and weakening the interference of local noise.
[0068] Flattening layer: Converts the three-dimensional feature tensor (1,1,64) into a one-dimensional vector (1,64), providing an adapted input format for the fully connected layer;
[0069] Fully connected layer: Through a linear mapping from 64 to 4, it outputs a vector with dimensions (1,4), which corresponds to 4 adaptive threshold parameters for subsequent binarization segmentation.
[0070] In a preferred embodiment, S4 specifically includes the following:
[0071] First, seed growth initialization is performed to obtain seed growth points; an adaptive grayscale threshold generation method based on gridded sparse sampling is adopted; the image frame resolution is W×H, and a uniform sampling grid is constructed with an interval width D=5 to generate a spatially balanced sample set.
[0072] {(x i ,y i )|x i =D·m,y i =D·n}
[0073]
[0074] A dynamic threshold T is constructed using the mean. init ,I(x i ,y i ) represents (x i ,y i The grayscale value at the point:
[0075]
[0076] Based on the characteristics of the alum flower image, a horizontal gradient detection method is simultaneously used to identify the boundary; specifically, a preset grayscale gradient threshold is used. And for pixel (x) i ,y i grayscale gradient Defined as:
[0077]
[0078] When pixel (x) i ,y i )satisfy:
[0079]
[0080] That is, determine the pixel point (x) i ,y i ) are candidate seed points;
[0081] After the seed point is triggered, a direction vector array is constructed based on the single sidewall method to represent the motion trajectory, and a direction priority strategy is embedded in the eight-neighbor detection.
[0082] Left boundary tracing: First, construct the cyclic direction vector array dir_left[4][2]:
[0083]
[0084] Each element dir_left[i] defines the forward direction. Let the current direction index be i and the current coordinate be (x, y).
[0085] Dynamic decision-making is implemented by analyzing the eight-neighbor features of the pixels in front and to the left in real time: when the area in front is detected as a passable area and the area to the left is an area outside the boundary, the current direction vector dir_left[i] is maintained and the movement continues; if both the area in front and to the left are determined to be outside the boundary, a right turn mechanism is triggered, and the direction index is updated to i = i + 1; when the area to the left is detected as a passable area, a left turn correction is initiated, and the index is updated to i = i - 1.
[11] The coordinate iteration formula in matrix form is:
[0086]
[0087] In a preferred embodiment, the method for calculating the diameter of the alum flower in S5 is as follows:
[0088] First, iterate through all the alum flowers. Then, iterate through the position of each pixel in the outline of a single alum flower. Using the least squares method, iteratively calculate the optimal center and radius to minimize the maximum distance from all outline points to the center. The calculation formula is as follows:
[0089] To obtain the diameter of the alum flower, iterate through all alum flowers and take the average diameter of all flowers. The specific formula is as follows:
[0090]
[0091] Complete the detection of alum flower diameter.
[0092] distance = 2 * radius.
[0093] In a preferred embodiment, the method for calculating the density of alum floc in S5 is as follows:
[0094] For the binarized image, a pixel traversal method is used to scan all pixels row by row and column by column. The total number of pixels in the alum flower region is counted by determining whether the pixel value is 255; the calculation formula is as follows:
[0095]
[0096] Where i and j represent the row and column coordinates, I ij X represents the pixel value corresponding to the original image. ij This is an intermediate variable; it is 1 when the corresponding pixel coordinate is 255 and 0 when the corresponding pixel coordinate is 0.
[0097] Then, the calculated value of all pixels is divided by the pixel size of the entire image. This result is output as a quantitative indicator representing the density of the *Hemiberlesia lataniae* distribution in the image, and its formula is as follows:
[0098]
[0099] Where w and h represent the length and width of the image, and d is the density quantization index.
[0100] The present invention also provides a floc detection system based on a self-generated segmentation threshold using a convolutional neural network, comprising a processor, a memory, and a computer program stored in the memory. When the processor executes the computer program, it specifically performs the floc detection method based on a self-generated segmentation threshold using a convolutional neural network as described above.
[0101] Compared with the prior art, the present invention has the following beneficial effects:
[0102] 1. Adaptive threshold generation capability: By constructing a three-level convolution-pooling feature extraction network, it achieves in-depth mining of the features of alum flower images, and can automatically learn and generate the optimal segmentation threshold. This effectively overcomes the technical limitations of traditional threshold segmentation algorithms (such as Otsu, Niblack, etc.) that rely on manual presets or statistical assumptions, and significantly improves the accuracy and adaptability of threshold selection.
[0103] 2. Strong anti-interference capability: Employing multi-scale Retinex enhancement and custom weighted grayscale preprocessing techniques (blue channel weight 0.7, green 0.1, red 0.02), the algorithm effectively suppresses noise interference from water bubbles, suspended impurities, and other sources, enhancing the contrast between flocs and the background. Combined with the feature aggregation capability of the global average pooling layer, the impact of local noise on threshold generation is further mitigated, ensuring the algorithm's robustness in complex water quality environments.
[0104] 3. High real-time performance: Through a lightweight network design of "increasing channel number + decreasing spatial dimension" (channel number of three-level convolutional layers 16→32→64), the computational load is compressed while retaining key features. Experiments show that the processing time for a single frame image can be controlled within 50ms, meeting the stringent requirements for real-time monitoring in wastewater treatment scenarios.
[0105] 4. Fully automated analysis: The entire process from image acquisition and preprocessing to threshold generation and parameter calculation is automated, eliminating the subjective bias and lag of manual detection (traditional methods lag by 2-4 hours), supporting 24 / 7 continuous monitoring, and providing real-time data support for flocculation process optimization. Attached Figure Description
[0106] Figure 1 This is a flowchart of a preferred embodiment of the present invention;
[0107] Figure 2 This is a structural block diagram of a preferred embodiment of the present invention. Detailed Implementation
[0108] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0109] It should be noted that the following detailed descriptions are illustrative and intended to provide further explanation of this application. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains.
[0110] It should be noted that the terminology used herein is for the purpose of describing particular implementations only and is not intended to limit the exemplary implementations according to this application; as used herein, the singular form is intended to include the plural form as well, unless the context clearly indicates otherwise; furthermore, it should be understood that when the terms “comprising” and / or “including” are used in this specification, they indicate the presence of features, steps, operations, devices, components and / or combinations thereof.
[0111] refer to Figure 1 and Figure 2In this embodiment, a segmentation threshold self-generation algorithm for alum floc detection based on convolutional neural networks is provided. First, high-speed cameras are deployed at multiple angles in the wastewater treatment tank to acquire images and transmit them to a host computer. Then, the images undergo preprocessing such as cropping the central region, enhancement processing, and custom weighted grayscale conversion. Next, an optimal binarization threshold is generated through a specific convolutional neural network and binarized. Subsequently, contours are identified based on the 8-neighborhood rule, and valid alum flocs are filtered according to area thresholds. Finally, the average diameter and density of the alum flocs are calculated and output, as detailed below:
[0112] S1: Based on the structural characteristics and monitoring requirements of the wastewater treatment pond, the positions and angles of the industrial-grade high-speed cameras should be rationally arranged. The cameras should be positioned to cover the central reaction zone and the edge flocculation area of the pond. Taking a certain wastewater treatment pond as an example, no fewer than three industrial-grade high-speed cameras (resolution = 1920×1080) should be arranged in a ring at equal intervals around the pond. The cameras should be installed at a height of 1.5-2.0 meters above the liquid surface, and the angle between the lens optical axis and the vertical line to the liquid surface should be 30°-60° to ensure comprehensive monitoring of the central reaction zone and the edge flocculation area. The host computer in the wastewater treatment control room should be used to ensure that all industrial-grade high-speed cameras are on the same data transmission link and can communicate and transmit data.
[0113] S2: Image data preprocessing steps: First, to address the image distortion problem caused by the camera's angle, a region cropping algorithm is used to extract the central 2 / 3 region of the image as the confidence interval data to eliminate edge distortion interference; then, multi-scale Retinex enhancement and adaptive histogram equalization are performed on the confidence interval image to improve the clarity of floc boundaries; finally, a custom weighted grayscale method (blue channel weight 0.7, green 0.1, red 0.02) is used to construct a grayscale model;
[0114] Preferably, in this embodiment, the preprocessing is as follows:
[0115] Region of Interest Extraction: To address the image distortion problem caused by the camera's angle, a region cropping algorithm is used to automatically identify and extract the central two-thirds of the image as the confidence interval image data, thereby eliminating the interference of edge distortion on subsequent analysis.
[0116] Image enhancement processing: Multi-scale Retinex enhancement is performed on the image data within the confidence interval. Adaptive histogram equalization is used to improve the contrast between flocs and the background, with a focus on enhancing the gradient features of floc boundaries to provide clear image input for subsequent feature extraction.
[0117] Custom Weighted Grayscale Conversion: Considering the color characteristics of alum floc images in wastewater treatment scenarios, an improved color channel weighted grayscale conversion method is proposed. Optimal weight parameters (blue channel 0.7, green channel 0.1, red channel 0.02) are determined through experimental analysis, and a grayscale conversion model is constructed.
[0118] Gray value = 0.7 × B + 0.1 × G + 0.02 × R
[0119] Compared to standard OpenCV grayscale algorithms (such as the YUV model), this method can effectively suppress yellowish-brown background noise, enhance the contrast between alum floc particles and water, and improve the separability of the image.
[0120] S3: Image binarization steps: ① Generate the optimal binarization threshold using an adaptive threshold segmentation algorithm. This threshold is suitable for separating the alum flowers from the background. ② Binarize the preprocessed image based on the above threshold to obtain binarized image data where the alum flowers are white and the background is black.
[0121] Preferably, in this embodiment, the specific steps of the image binarization algorithm are as follows:
[0122] (1) Multi-level feature extraction module, which sequentially passes the input image through three levels of convolution-activation-pooling feature extraction units:
[0123] Convolutional layer: After filling the image with a circle, a 3×3 convolutional kernel is used to slide the image region by region with a stride of 1 to extract local features of the image and generate an initial feature map;
[0124] Extract the calculation formula:
[0125]
[0126] O is the output feature map, I is the input feature map, K is the convolution kernel, and C is the input feature map. in Here, k is the number of input channels, k is the kernel size, i and j are the coordinates of the output feature map, c is the output channel index, and d is the input channel index.
[0127] Activation Layer: The ReLU activation function is used to perform a non-linear transformation on the output of the convolutional layer, avoiding the gradient vanishing problem. This enables the neural network to learn complex features and patterns, while controlling the output range to stabilize training and helping the network extract abstract features layer by layer.
[0128] The calculation formula is as follows:
[0129] ReLU(x) = max(0,x)
[0130] Where x is the input and y is the output, y = x when x > 0 and y = 0 when x ≤ 0.
[0131] Pooling layer: A 2×2 max pooling operation with a stride of 2 is used to downsample the feature map. By performing local aggregation on the feature map, the data dimensionality is reduced while retaining key features, thus reducing computation and enhancing the model's robustness to small changes in the input.
[0132] Its calculation formula:
[0133] For the input feature map X∈R H×W and pooling window K∈Z + (Window size is K x K), stride is S, output feature map
[0134] Y∈R H'×W' The calculation formula is:
[0135]
[0136] in:
[0137] [i, j] are the coordinates of the output feature map, [m, n] are the relative coordinates within the pooling window, and the size of the pooled image is calculated using the following formula:
[0138]
[0139] The above convolution-activation-pooling operation is repeated three times to achieve a gradual and in-depth abstract extraction of image features.
[0140] (2) Feature reduction and format conversion:
[0141] Average pooling layer: Performs global average pooling on the output after the three-level feature extraction, compressing the size of each feature map to 1×1, and realizing the aggregation of global features;
[0142] The calculation formula is as follows:
[0143]
[0144] Where: Y is the output feature, X is the input feature map, c is the channel index, H is the height of the input feature map, and W is the width of the input feature map;
[0145] Flattening layer: Converts multidimensional feature tensors into one-dimensional vectors, which serve as inputs to subsequent fully connected layers.
[0146]
[0147] Where: A is the flattened one-dimensional vector, Z is the input two-dimensional tensor, k is the index of the flattened vector, and N is the number of columns in the input tensor. It is the integer part of k divided by N (row index), and k%N is the remainder of k divided by N (column index);
[0148] (3) Threshold prediction and binarization:
[0149] Fully connected layer: The one-dimensional feature vector is mapped to four values through a fully connected neural network. The optimal segmentation threshold for the current image is then calculated using linear regression. The calculation formula is as follows:
[0150] For input vector X∈R B×64 The output vector Y∈R B×4 Calculated as:
[0151] Y = XW + b
[0152] Where W is the weight and b is the bias term;
[0153] Binarization: The predicted threshold is applied to the original image to perform a binarization operation, resulting in a binarized image where the alum flower area is white and the background area is black. The calculation formula is as follows:
[0154]
[0155] Where I(x,y) is the pixel value of the preprocessed image, and B(x,y) is the pixel value of the binarized image.
[0156] The specific parameter configurations and hierarchical mapping relationships of the network framework are as follows:
[0157] (1) Input layer definition:
[0158] The input image has dimensions (w, h, x).
[0159] in:
[0160] w is the image width in pixels.
[0161] h is the image height in pixels.
[0162] x is the number of data channels (for a three-channel color flocculent image, x = 3);
[0163] This dimension setting can be customized to fit the raw images captured by cameras in wastewater treatment scenarios.
[0164] The format provides the raw data foundation for subsequent feature extraction.
[0165] (2) Three-level convolution-pooling feature extraction unit
[0166] First-level feature extraction unit:
[0167] Convolutional layer: The number of input channels is x, the number of output channels is 16, a 3×3 convolutional kernel is used, the sliding stride is 1, and the number of boundary padding layers is 1 (i.e., padding=1). Through this parameter configuration, the feature map spatial dimension is maintained as (w,h) after the convolution operation, and the output dimension is (w,h,16), realizing the preliminary extraction of the basic texture of the alum flower image.
[0168] Activation layer: The ReLU activation function is used for nonlinear transformation to enhance the network's ability to learn nonlinear features;
[0169] Pooling layer: A 2×2 max pooling kernel with a sliding step of 2 is used to downsample the feature map, and the output dimension is (w / 2, h / 2, 16). While preserving key features, the amount of data is compressed to 1 / 4, reducing computational complexity.
[0170] Second-level feature extraction unit:
[0171] Convolutional layer: 16 input channels, 32 output channels, 3×3 convolutional kernel, stride 1, padding = 1; feature map space dimension is maintained at (w / 2, h / 2), output dimension is (w / 2, h / 2, 32), doubling the number of channels improves the ability to extract mid-level features of alum flower morphology;
[0172] Activation layer: Same as the first level, but enhances feature discrimination through nonlinear transformation;
[0173] Pooling layer: 2×2 max pooling with a stride of 2, output dimension is (w / 4, h / 4, 32), further compressing the spatial dimension to focus on core features.
[0174] Third-level feature extraction unit:
[0175] Convolutional layer: 32 input channels, 64 output channels, 3×3 convolutional kernel, stride 1, padding = 1; feature map spatial dimension is maintained at (w / 4, h / 4), output dimension is (w / 4, h / 4, 64), abstract difference features between alum flowers and background are extracted through higher-dimensional channels;
[0176] Activation layer: Same as the previous two levels, enhances the network's ability to fit complex patterns;
[0177] Pooling layer: 2×2 max pooling with a stride of 2, output dimension (w / 8, h / 8, 64), which compresses and aggregates high-dimensional features.
[0178] (3) Global feature aggregation and output unit
[0179] Average pooling layer: Global average pooling is performed on the (w / 8,h / 8,64) feature map output by the third pooling layer, compressing the spatial dimension to 1×1, and the output dimension is (1,1,64), realizing the global integration of the full image features and weakening the interference of local noise.
[0180] Flattening layer: Converts the three-dimensional feature tensor (1,1,64) into a one-dimensional vector (1,64), providing an adapted input format for the fully connected layer;
[0181] Fully connected layer: Through a linear mapping from 64 to 4, it outputs a vector with dimensions (1,4), which corresponds to 4 adaptive threshold parameters for subsequent binarization segmentation.
[0182] S4: Alum floc screening steps: ① Identify the outer contour in the binarized image based on the 8-neighborhood rule to obtain the alum floc contour point set; ② Calculate the pixel area of each contour; ③ Filter the effective alum floc area according to the preset area threshold range and remove noise points and abnormal agglomerates.
[0183] Preferably, in this embodiment, the connected component analysis is as follows:
[0184] First, seed growth initialization is performed to obtain seed growth points. An adaptive grayscale threshold generation method based on gridded sparse sampling is employed. With an image frame resolution of W×H, a uniform sampling grid is constructed with an interval width D=5 to generate a spatially balanced sample set.
[0185] {(x i ,y i )|x i =D·m,y i =D·n}
[0186]
[0187] A dynamic threshold T is constructed using the mean. init (I(x i ,y i ) represents (x i ,y i (Gray value at the point):
[0188]
[0189] To identify the boundaries of the alum flower image, a horizontal gradient detection method is simultaneously employed. Specifically, a preset grayscale gradient threshold is used. (T is usually taken) init 10%-20%), and for pixel (x) i ,y i grayscale gradient Defined as:
[0190]
[0191] When pixel (x) i ,y i )satisfy:
[0192]
[0193] That is, the pixel (x) can be determined i ,y i ) are candidate seed points.
[0194] After the seed point is triggered, a direction vector array is constructed based on the single sidewall method to represent the motion trajectory, and a direction priority strategy is embedded in the eight-neighbor detection to optimize the computational flow of boundary detection.
[0195] Taking left boundary tracking as an example, first construct the cyclic direction vector array dir_left[4][2]:
[0196]
[0197] Each element dir_left[i] defines the forward direction. Let the current direction index be i and the current coordinates be (x, y).
[0198] Dynamic decision-making is implemented by analyzing the eight-neighbor features of the pixels in front and to the left in real time: when the area in front is detected as a passable area (binarized white) and the area to the left is an outside-boundary area (binarized black), the current direction vector dir_left[i] is maintained and the movement continues; if both the area in front and to the left are determined to be outside-boundary areas, a right turn mechanism is triggered, and the direction index is updated to i = i + 1; when the area to the left is detected as a passable area, a left turn correction is initiated, and the index is updated to i = i - 1.
[11] The coordinate iteration formula in matrix form is:
[0199]
[0200] S5: Steps for calculating and outputting alum flower parameters: ① Calculate the diameter of the circumscribed circle of the effective alum flower contour and take the average value to obtain the average diameter of the alum flower in the frame image; ② Accumulate the total pixels of the effective alum flower area and divide it by the total pixels of the preprocessed image to obtain the alum flower density; ③ Output the average diameter and density of the alum flower.
[0201] Preferably, in this embodiment, the method for obtaining alum flower data is as follows:
[0202] First, iterate through all the alum flowers. Then, iterate through the position of each pixel in the outline of a single alum flower. Using the least squares algorithm, iteratively calculate the optimal center and radius to minimize the maximum distance from all outline points to the center. The calculation formula is as follows:
[0203] To obtain the diameter of the alum flower, iterate through all alum flowers and take the average diameter of all flowers. The specific formula is as follows:
[0204]
[0205] Complete the detection of alum flower diameter.
[0206] distance = 2 * radius
[0207] For the binarized image (where the pixel value of the alum flower region is 255 and the pixel value of the background region is 0), a pixel traversal algorithm is used to scan all pixels in the image row by row and column by column. The total number of pixels in the alum flower region is counted by determining whether the pixel value is 255; the calculation formula is as follows:
[0208]
[0209] Where i and j represent the row and column coordinates, I ij X represents the pixel value corresponding to the original image. ij It is an intermediate variable, which is 1 when the corresponding pixel coordinate is 255 and 0 when the corresponding pixel coordinate is 0.
[0210] Then, the calculated value of all pixels is divided by the pixel size of the entire image. This result is output as a quantitative indicator representing the density of the *Hemiberlesia lataniae* distribution in the image, and its formula is as follows:
[0211]
[0212] Where w and h represent the length and width of the image, and d is the density quantization index.
[0213] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0214] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0215] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0216] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0217] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention in any other way. Any person skilled in the art may make changes or modifications to the above-disclosed technical content to create equivalent embodiments. However, any simple modifications, equivalent changes, and modifications made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the protection scope of the present invention.
Claims
1. A method for detecting flocs based on self-generated segmentation thresholds using a convolutional neural network, characterized in that, Includes the following steps: S1: Acquire image data from multiple angles of the sewage treatment pond; S2: Image data preprocessing: Crop the central 2 / 3 region of the image as the confidence interval data to eliminate the influence of camera angle distortion; enhance the image of the confidence interval; Custom weighted grayscale is used to suppress background noise and enhance image separability; S3: Image binarization: An adaptive thresholding method is used to generate the optimal binarization threshold, which is suitable for separating the alum flowers from the background; Based on the above binarization threshold, the preprocessed image is binarized to obtain binarized image data with white alum flowers and black background. S4: Alum flower screening: Identify the outer contour in the binarized image based on the 8-neighborhood rule, obtain the alum flower contour point set; calculate the pixel area of each contour; Valid alum floc areas are selected based on preset area threshold ranges, and noise points and abnormal agglomerates are removed. S5: Calculation and output of alum flower parameters: Calculate the circumscribed circle diameter of the effective alum flower contour and take the average value to obtain the average diameter of the alum flower in the frame image; sum up the total pixels of the effective alum flower area and divide by the total pixels of the preprocessed image to obtain the alum flower density; output the average diameter and density of the alum flower.
2. The method for detecting flocs based on self-generated segmentation thresholds using a convolutional neural network according to claim 1, characterized in that, S1 is specifically as follows: At least three industrial-grade high-speed cameras are arranged in a ring around the perimeter of the wastewater treatment tank at equal intervals. The cameras are installed 1.5-2.0 meters above the liquid surface, and the angle between the lens optical axis and the vertical line of the liquid surface is 30°-60° to ensure comprehensive monitoring of the central reaction area and the edge flocculation area of the tank without blind spots.
3. The method for detecting flocs based on self-generated segmentation thresholds using a convolutional neural network according to claim 1, characterized in that, The specific steps for custom weighted grayscale in S2 are as follows: Constructing a grayscale model: Gray value = 0.7 × B + 0.1 × G + 0.02 × R Where B, G, and R represent image channels, respectively.
4. The method for detecting flocs based on self-generated segmentation thresholds using a convolutional neural network according to claim 1, characterized in that, The adaptive threshold segmentation method in S3 is as follows: S31: The input image is sequentially processed through a three-level convolution-activation-pooling feature extraction unit via a multi-level feature extraction module. Convolutional layer: After filling the image with a circle, a 3×3 convolutional kernel is used to slide the image region by region with a stride of 1 to extract local features of the image and generate an initial feature map; Extract the calculation formula: O is the output feature map, I is the input feature map, K is the convolution kernel, and C is the input feature map. in is the number of input channels, k is the kernel size, i and j are the coordinates of the output feature map, c is the output channel index, d is the input channel index, m represents the row index of the kernel, with a value range of [0, k-1], and n represents the column index of the kernel, with a value range of [0, k-1]. Activation layer: The ReLU activation function is used to perform a non-linear transformation on the output of the convolutional layer. The calculation formula is as follows: ReLU(x) = max(0,x) Where x is the input and y is the output, when x>0, y=x; when x≤0, y=0; Pooling layer: A 2×2 max pooling operation with a stride of 2 is used to downsample the feature map. Local aggregation of the feature map is performed, and the calculation formula is as follows: For the input feature map X∈R H×W and pooling window K∈Z + The window size is K x K, the stride is S, and the output feature map is... Y∈R H'×W' The calculation formula is: Where [i, j] are the coordinates of the output feature map, [m, n] are the relative coordinates within the pooling window, and the size of the pooled image is calculated using the following formula: The above convolution-activation-pooling operation is repeated three times; S32: Feature Dimensionality Reduction and Format Conversion Average pooling layer: Global average pooling is performed on the output after the three-level feature extraction, compressing the size of each feature map to 1×1. The calculation formula is as follows: Where: Y is the output feature, X is the input feature map, c is the channel index, H is the height of the input feature map, and W is the width of the input feature map; Flattening layer: Converts multidimensional feature tensors into one-dimensional vectors, which serve as inputs to subsequent fully connected layers; Where: A is the flattened one-dimensional vector, Z is the input two-dimensional tensor, k is the index of the flattened vector, and N is the number of columns in the input tensor. It is the integer part of k divided by N, and k%N is the remainder when k is divided by N; S33: Threshold Prediction and Binarization: Fully connected layer: The one-dimensional feature vector is mapped to four values through a fully connected neural network. The optimal segmentation threshold for the current image is then calculated using linear regression. The calculation formula is as follows: For input vector X∈R B×64 The output vector Y∈R B×4 Calculated as: Y = XW + b Where W is the weight and b is the bias term; Binarization: The predicted threshold is applied to the original image to perform a binarization operation, resulting in a binarized image where the alum flower area is white and the background area is black. The calculation formula is as follows: Where I(x,y) is the pixel value of the preprocessed image, and B(x,y) is the pixel value of the binarized image.
5. The method for detecting flocs based on self-generated segmentation thresholds using a convolutional neural network according to claim 4, characterized in that, The specific parameter configurations and hierarchical mapping relationships in the adaptive threshold segmentation method of S3 are as follows: (1) Input layer definition: The input image has dimensions (w, h, x). Where: w is the image width in pixels, h is the image height in pixels, and x is the number of data channels; (2) Three-level convolution-pooling feature extraction unit First-level feature extraction unit: Convolutional layer: The number of input channels is x, the number of output channels is 16, a 3×3 convolutional kernel is used, the sliding stride is 1, and the number of boundary padding layers is 1. Through this parameter configuration, the feature map spatial dimension is maintained as (w,h) after the convolution operation, and the output dimension is (w,h,16), realizing the preliminary extraction of the basic texture of the alum flower image. Activation layer: The ReLU activation function is used for nonlinear transformation to enhance the network's ability to learn nonlinear features; Pooling layer: A 2×2 max pooling kernel with a sliding step of 2 is used to downsample the feature map, and the output dimension is (w / 2, h / 2, 16). While preserving key features, the amount of data is compressed to 1 / 4, reducing computational complexity. Second-level feature extraction unit: Convolutional layer: 16 input channels, 32 output channels, 3×3 convolutional kernel, stride 1, padding = 1; feature map space dimension is maintained at (w / 2, h / 2), output dimension is (w / 2, h / 2, 32), doubling the number of channels improves the ability to extract mid-level features of alum flower morphology; Activation layer: Same as the first level, but enhances feature discrimination through nonlinear transformation; Pooling layer: 2×2 max pooling with a stride of 2, output dimension is (w / 4, h / 4, 32), further compressing the spatial dimension to focus on core features. Third-level feature extraction unit: Convolutional layer: 32 input channels, 64 output channels, 3×3 convolutional kernel, stride 1, padding = 1; feature map spatial dimension is maintained at (w / 4, h / 4), output dimension is (w / 4, h / 4, 64), abstract difference features between alum flowers and background are extracted through higher-dimensional channels; Activation layer: Same as the previous two levels, enhances the network's ability to fit complex patterns; Pooling layer: 2×2 max pooling with a stride of 2, output dimension (w / 8, h / 8, 64), which compresses and aggregates high-dimensional features. (3) Global feature aggregation and output unit Average pooling layer: Global average pooling is performed on the (w / 8,h / 8,64) feature map output by the third pooling layer, compressing the spatial dimension to 1×1, and the output dimension is (1,1,64), realizing the global integration of the full image features and weakening the interference of local noise. Flattening layer: Converts the three-dimensional feature tensor (1,1,64) into a one-dimensional vector (1,64), providing an adapted input format for the fully connected layer; Fully connected layer: Through a linear mapping from 64 to 4, it outputs a vector with dimensions (1,4), which corresponds to 4 adaptive threshold parameters for subsequent binarization segmentation.
6. The method for detecting flocs based on self-generated segmentation thresholds using a convolutional neural network according to claim 1, characterized in that, The specific details in S4 are as follows: First, seed growth initialization is performed to obtain seed growth points; an adaptive grayscale threshold generation method based on gridded sparse sampling is adopted; the image frame resolution is W×H, and a uniform sampling grid is constructed with an interval width D=5 to generate a spatially balanced sample set. {(x i ,y i )|x i =D·m,y i =D·n} A dynamic threshold T is constructed using the mean. init ,I(x i ,y i ) represents (x i ,y i The grayscale value at the point: Based on the characteristics of the alum flower image, a horizontal gradient detection method is simultaneously used to identify the boundary; specifically, a preset grayscale gradient threshold is used. And for pixel (x) i ,y i grayscale gradient Defined as: When pixel (x) i ,y i )satisfy: That is, determine the pixel point (x) i ,y i ) are candidate seed points; After the seed point is triggered, a direction vector array is constructed based on the single sidewall method to represent the motion trajectory, and a direction priority strategy is embedded in the eight-neighbor detection. Left boundary tracing: First, construct the cyclic direction vector array dir_left[4][2]: Each element dir_left[i] defines the forward direction. Let the current direction index be i and the current coordinate be (x, y). Dynamic decision-making is implemented by analyzing the eight-neighbor features of the pixels in front and to the left in real time: when the area in front is detected as a passable area and the area to the left is an area outside the boundary, the current direction vector dir_left[i] is maintained and the movement continues; if both the area in front and to the left are determined to be outside the boundary, a right turn mechanism is triggered, and the direction index is updated to i = i + 1; when the area to the left is detected as a passable area, a left turn correction is initiated, and the index is updated to i = i - 1. [11] The coordinate iteration formula in matrix form is:
7. The method for detecting flocs based on self-generated segmentation thresholds using a convolutional neural network according to claim 1, characterized in that, The specific method for calculating the diameter of hemlock flowers in S5 is as follows: First, iterate through all the alum flowers. Then, iterate through the position of each pixel in the outline of a single alum flower. Using the least squares method, iteratively calculate the optimal center and radius to minimize the maximum distance from all outline points to the center. The calculation formula is as follows: To obtain the diameter of the alum flower, iterate through all alum flowers and take the average diameter of all flowers. The specific formula is as follows: Complete the detection of alum flower diameter. distance = 2 * radius.
8. The method for detecting flocs based on self-generated segmentation thresholds using a convolutional neural network according to claim 1, characterized in that, The specific method for calculating the density of hemlock in S5 is as follows: For the binarized image, a pixel traversal method is used to scan all pixels row by row and column by column. The total number of pixels in the alum flower region is counted by determining whether the pixel value is 255; the calculation formula is as follows: Where i and j represent the row and column coordinates, I ij X represents the pixel value corresponding to the original image. ij This is an intermediate variable; it is 1 when the corresponding pixel coordinate is 255 and 0 when the corresponding pixel coordinate is 0. Then, the calculated value of all pixels is divided by the pixel size of the entire image. This result is output as a quantitative indicator representing the density of the *Hemiberlesia lataniae* distribution in the image, and its formula is as follows: Where w and h represent the length and width of the image, and d is the density quantization index.
9. A floc detection system based on self-generated segmentation thresholds using a convolutional neural network, characterized in that, The device includes a processor, a memory, and a computer program stored in the memory. When the processor executes the computer program, it specifically performs a method for detecting flocs based on the self-generated segmentation threshold of a convolutional neural network as described in any one of claims 1-8.
Citation Information
Cited By
Oxidation flocculation treatment system for sulfur-containing wastewater in mancozeb production
CN122010265A