Bladder irrigation liquid volume automatic regulation method and system based on drainage and color monitoring

CN122605019APending Publication Date: 2026-08-21BEIJING CHAOYANG HOSPITAL CAPITAL MEDICAL UNIVERSITY +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610766877.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-05-29
Publication Date
2026-08-21

AI Technical Summary

Technical Problem

真实的冲洗图像中包含大量与流体无关的背景冗余信息,传统图像处理多采用全局均匀的图块切分与固定密度采样,无法根据流体特征及模型不确定性进行差异化采样,导致计算资源严重浪费且极易受到背景光影干扰;现有方法在构建网络输入的图像Token时,往往采用粗放的线性映射,不具备对图块局部聚集特征、簇内分布离散度的考量,也无法充分利用前后帧图像的时序演变信息对突变特征进行突出性加权,导致模型对微小出血或状态转移的感知迟钝;现有的液量控制端多采用固定增益系数的常规PID控制器,无法感知并融合前端视觉网络预测状态时的模型不确定性风险,在复杂非线性的临床冲洗环境下极易出现流量超调或响应迟缓,无法保障冲洗系统的稳定性与高精度

Benefits of technology

[0019]本发明通过颜色梯度流与连通域精准区分流体与背景区域,并结合前一帧的模型不确定性差异化调节采样密度,在减少背景冗余数据计算的同时提升了流体关键特征的检测精度;利用密度聚类将初始token聚合为图块簇,结合质心与离散度向量生成簇token,降低了数据维度并保留了图像空间分布的稳定特征;计算帧间距离获取突出性分值并对簇token进行差异化加权,引导模型重点关注变化突出的关键区域,提升了Transformer网络状态预测的准确度与抗干扰能力;根据状态预测差值及模型不确定性调节PID控制器增益系数,实现了对膀胱冲洗液量的精准、平稳调控。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122605019A_ABST
    Figure CN122605019A_ABST
Patent Text Reader

Abstract

The present application relates to the field of control, especially a bladder irrigation liquid volume automatic regulation method and system based on drainage and color monitoring, the method comprises the following steps: collecting an irrigation image, distinguishing fluid and background area through color gradient flow and connected domain, setting sampling density combined with historical frame model uncertainty differentiation, generating two types of region tile set respectively, linearly embedding the tile set to obtain initial token, dividing tile cluster through density clustering, determining clustering neighborhood radius by referring to the discrete degree parameter of the previous frame, constructing cluster token through vector operation, determining the region prominence relying on the distance between inter-frame cluster tokens and completing weight assignment, inputting the weighted cluster token into the Transformer network, outputting the irrigation state prediction value and model uncertainty, adjusting the PID controller gain by using the model uncertainty combined with the deviation between the predicted state and the target state, generating the irrigation pump control signal, and realizing intelligent and accurate automatic regulation of bladder irrigation liquid flow.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of automatic control, and in particular relates to an automatic control method and system for bladder irrigation fluid volume based on drainage and color monitoring. Background Technology

[0002] In current clinical practice, the volume and flow rate of bladder irrigation fluid are controlled by regular manual rounds by medical staff. They visually observe the color and turbidity of the irrigation fluid in the drainage bag or tube and manually adjust the drip rate based on experience. This traditional manual intervention is inherently delayed and subjective, and medical staff cannot achieve continuous, real-time monitoring around the clock. If a patient experiences sudden active bleeding and the irrigation fluid volume cannot be increased promptly, it can easily lead to the formation of large blood clots in the bladder, causing severe bladder spasms or urinary retention. Clinically, there is an urgent need for an intelligent solution that can monitor the irrigation fluid status in real time and achieve fully automated, precise control of the irrigation fluid volume to reduce the burden of clinical care and improve postoperative patient safety.

[0003] By acquiring flushing images from the drainage tubing, extracting image features using neural network models such as the Visual Transformer to assess fluid color and state, and combining this with an automatic control algorithm to drive the infusion pump, this has become a crucial technological integration point for controlling bladder flushing fluid volume. Real flushing images contain a large amount of redundant background information unrelated to the fluid. Traditional image processing often employs globally uniform patch segmentation and fixed-density sampling, failing to differentiate sampling based on fluid characteristics and model uncertainties. This results in significant waste of computational resources and susceptibility to background lighting interference. Existing methods often use coarse linear mapping when constructing image tokens for network input, lacking consideration of local patch clustering features and intra-cluster distribution dispersion. They also fail to fully utilize temporal evolution information from consecutive frames to prominently weight abrupt changes, leading to sluggish model perception of minor bleeding or state transitions. Furthermore, existing fluid control terminals often use conventional PID controllers with fixed gain coefficients, unable to perceive and integrate model uncertainties in the front-end visual network's state predictions. In complex, nonlinear clinical flushing environments, this easily leads to flow overshoot or slow response, compromising the stability and high precision of the flushing system. Summary of the Invention

[0004] To improve the accuracy, timeliness, and safety of bladder irrigation diagnosis and treatment, this invention provides a method and system for automatic control of bladder irrigation fluid volume based on drainage and color monitoring.

[0005] According to one aspect of the present invention, an automatic regulation method for bladder irrigation fluid volume based on drainage and color monitoring is provided, comprising the following steps: Acquire rinsing images and identify fluid and background regions based on color gradient flow and connected components; if the fluid region contains the previous frame, adjust the first sampling density positively according to the model uncertainty of the previous frame; otherwise, use the initial sampling density to generate a first set of patches in the fluid region; generate a second set of patches for the background region with a second sampling density. Linear embedding is performed on the first and second tile sets to obtain initial tokens, and density clustering is performed to obtain tile clusters. If a previous frame exists, the neighborhood radius is set according to the mean and variance of the cluster scatter vector of the previous frame; otherwise, a preset radius is used. The centroid vector of the initial token in the tile cluster and the scatter vector composed of the diagonal elements of the covariance are calculated. The Hadamard product of the centroid vector and the negative exponent of the scatter vector is used to obtain the cluster token. When a previous frame exists, the distance between each cluster token and the nearest cluster token in the previous frame is calculated to obtain a salience score. If the salience score exceeds a preset threshold, a first weight is assigned; otherwise, a second weight is assigned. When there is no previous frame, an initial weight is assigned. The cluster tokens are then weighted to obtain a weighted cluster token. The weighted cluster tokens are then input into the Transformer network to output state prediction and model uncertainty. Based on the difference between the predicted state and the preset target state, the gain coefficient of the PID controller is adjusted using the model uncertainty, and a pump control signal is generated based on the adjusted gain coefficient of the PID controller.

[0006] Optionally, the identification of fluid and background regions based on color gradient flow and connected components includes: The washed image is converted to the HSV color space, the gradient magnitude matrix of the V channel image is extracted, and the gradient flow features are calculated. Binarization thresholding is performed on the S-channel image, and morphological opening and closing operations are combined with gradient flow features for denoising. Calculate the pixel area of ​​the binary connected region, retain the connected regions with an area greater than a preset area threshold as fluid regions, and mark the remaining regions as background regions.

[0007] Optionally, the step of positively adjusting the first sampling density based on the model uncertainty of the previous frame when the fluid region exists, and otherwise using the initial sampling density to generate a first tile set within the fluid region, includes: Extract the model uncertainty scalar value output by the Transformer network in the previous frame; Construct a negative correlation exponential mapping function between uncertainty scalar values ​​and grid sampling step size; When the model uncertainty increases, the grid sampling step size in the fluid region is reduced by the mapping function to increase the first sampling density, and the first tile set is generated by two-dimensional grid clipping in the fluid region according to the sampling step size.

[0008] Optionally, the step of setting the neighborhood radius based on the mean and variance of the cluster scatter vector of the previous frame when a previous frame exists includes: Extract the discrete vector of all tile clusters in the previous frame; Calculate the mean vector and variance vector of all discrete vector sets respectively; The baseline radius is obtained by weighted summing of the square roots of the L2 norm of the mean vector and the L1 norm of the variance vector. The radius reference value is multiplied by a preset scaling factor to obtain the neighborhood radius for the density clustering algorithm of the current image frame.

[0009] Optionally, the calculation of the centroid vector of the initial token within the tile cluster and the discreteness vector composed of the diagonal elements of the covariance includes: For each tile cluster, the arithmetic mean of the feature vectors of all initial tokens within the cluster is calculated to obtain the centroid vector of the cluster. Calculate the covariance matrix formed by the eigenvectors of all initial tokens within the cluster; Extract the main diagonal elements of the covariance matrix to form a one-dimensional variance feature vector, and use the variance feature vector as the discreteness vector of the tile cluster.

[0010] Optionally, the step of obtaining the cluster token by calculating the Hadamard product of the centroid vector and the negative exponent of the discreteness vector includes: Verify whether the feature dimension lengths of the centroid vector and the discreteness vector are consistent. When the dimensions are consistent, the weight vector is obtained by taking the negative exponent of each element of the discrete vector, and the product vector is obtained by multiplying the corresponding elements of the centroid vector and the weight vector point by point. The product vector is concatenated with the original centroid vector, and after dimensionality reduction and fusion by a fully connected layer, the output is used as the cluster token of the tile cluster.

[0011] Optionally, the step of adjusting the PID controller gain coefficient using model uncertainty and generating a pump control signal based on the adjusted PID controller gain coefficient includes: Obtain the initial proportional gain and initial integral gain of the PID controller; The attenuation factor is calculated by substituting the model uncertainty into a preset inverse proportional attenuation function, so that the greater the model uncertainty, the smaller the attenuation factor. The attenuation factor is multiplied by the initial proportional gain and the initial integral gain respectively to obtain the updated current control gain, so as to suppress control overshoot under high uncertainty conditions, and the pump control signal is output based on the current control gain.

[0012] According to another aspect of the present invention, an automatic bladder irrigation fluid volume control system based on drainage and color monitoring is provided, comprising the following modules: The first generation module is used to acquire the rinsing image, identify the fluid and background regions based on color gradient flow and connected components; when the fluid region contains the previous frame, the first sampling density is positively adjusted according to the model uncertainty of the previous frame; otherwise, the initial sampling density is used to generate a first set of patches in the fluid region; and a second set of patches is generated for the background region with a second sampling density. The calculation module is used to linearly embed the first and second tile sets to obtain the initial token and perform density clustering to obtain the tile cluster. If there is a previous frame, the neighborhood radius is set according to the mean and variance of the cluster scatter vector of the previous frame; otherwise, the preset radius is used. The centroid vector of the initial token in the tile cluster and the scatter vector composed of the diagonal elements of the covariance are calculated, and the Hadamard product of the centroid vector and the negative exponent of the scatter vector is obtained to obtain the cluster token. The output module is used to calculate the salience score by measuring the distance between each cluster token and the nearest cluster token in the previous frame when a previous frame exists. If the salience score exceeds a preset threshold, a first weight is assigned; otherwise, a second weight is assigned. If there is no previous frame, an initial weight is assigned. The cluster tokens are then weighted to obtain a weighted cluster token. The weighted cluster tokens are then input into the Transformer network to output state prediction and model uncertainty. The second generation module is used to adjust the PID controller gain coefficient based on the difference between the state prediction and the preset target state, taking advantage of model uncertainty, and to generate a pump control signal based on the adjusted PID controller gain coefficient.

[0013] Furthermore, the method of identifying fluid and background regions based on color gradient flow and connected components includes: The washed image is converted to the HSV color space, the gradient magnitude matrix of the V channel image is extracted, and the gradient flow features are calculated. Binarization thresholding is performed on the S-channel image, and morphological opening and closing operations are combined with gradient flow features for denoising. Calculate the pixel area of ​​the binary connected region, retain the connected regions with an area greater than a preset area threshold as fluid regions, and mark the remaining regions as background regions.

[0014] Further, the step of positively adjusting the first sampling density based on the model uncertainty of the previous frame when the fluid region exists, and otherwise using the initial sampling density to generate a first tile set within the fluid region, includes: Extract the model uncertainty scalar value output by the Transformer network in the previous frame; Construct a negative correlation exponential mapping function between uncertainty scalar values ​​and grid sampling step size; When the model uncertainty increases, the grid sampling step size in the fluid region is reduced by the mapping function to increase the first sampling density, and the first tile set is generated by two-dimensional grid clipping in the fluid region according to the sampling step size.

[0015] Further, the step of setting the neighborhood radius based on the mean and variance of the cluster scatter vector of the previous frame when a previous frame exists includes: Extract the discrete vector of all tile clusters in the previous frame; Calculate the mean vector and variance vector of all discrete vector sets respectively; The baseline radius is obtained by weighted summing of the square roots of the L2 norm of the mean vector and the L1 norm of the variance vector. The radius reference value is multiplied by a preset scaling factor to obtain the neighborhood radius for the density clustering algorithm of the current image frame.

[0016] Further, the computation of the centroid vector of the initial token within the tile cluster and the discreteness vector composed of the diagonal elements of the covariance include: For each tile cluster, the arithmetic mean of the feature vectors of all initial tokens within the cluster is calculated to obtain the centroid vector of the cluster. Calculate the covariance matrix formed by the eigenvectors of all initial tokens within the cluster; Extract the main diagonal elements of the covariance matrix to form a one-dimensional variance feature vector, and use the variance feature vector as the discreteness vector of the tile cluster.

[0017] Furthermore, the step of obtaining the cluster token by calculating the Hadamard product of the centroid vector and the negative exponent of the discreteness vector includes: Verify whether the feature dimension lengths of the centroid vector and the discreteness vector are consistent. When the dimensions are consistent, the weight vector is obtained by taking the negative exponent of each element of the discrete vector, and the product vector is obtained by multiplying the corresponding elements of the centroid vector and the weight vector point by point. The product vector is concatenated with the original centroid vector, and after dimensionality reduction and fusion by a fully connected layer, the output is used as the cluster token of the tile cluster.

[0018] Furthermore, the step of adjusting the PID controller gain coefficient using model uncertainty and generating a pump control signal based on the adjusted PID controller gain coefficient includes: Obtain the initial proportional gain and initial integral gain of the PID controller; The attenuation factor is calculated by substituting the model uncertainty into a preset inverse proportional attenuation function, so that the greater the model uncertainty, the smaller the attenuation factor. The attenuation factor is multiplied by the initial proportional gain and the initial integral gain respectively to obtain the updated current control gain, so as to suppress control overshoot under high uncertainty conditions, and the pump control signal is output based on the current control gain.

[0019] This invention accurately distinguishes fluid and background regions through color gradient flow and connected components, and adjusts the sampling density differentially based on the model uncertainty of the previous frame. This reduces redundant background data computation while improving the detection accuracy of key fluid features. Density clustering is used to aggregate initial tokens into tile clusters, and cluster tokens are generated by combining centroids and discreteness vectors, reducing data dimensionality and preserving stable features of image spatial distribution. The inter-frame distance is calculated to obtain salience scores, and cluster tokens are differentially weighted to guide the model to focus on key areas with prominent changes, improving the accuracy and anti-interference ability of Transformer network state prediction. The gain coefficient of the PID controller is adjusted based on the state prediction difference and model uncertainty, achieving precise and stable control of bladder irrigation fluid volume. Attached Figure Description

[0020] Figure 1 A flowchart of the first embodiment; Figure 2 A schematic diagram of the area of ​​the connected components used for fluid region filtration; Figure 3 This is a schematic diagram showing the distribution of the discreteness vector across each feature channel. Figure 4 This is a schematic diagram of crossover ratio for fluid identification. Detailed Implementation

[0021] The features and exemplary embodiments of various aspects of this application will be described in detail below. To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain this application and not to limit it. For those skilled in the art, this application can be implemented without some of these specific details. The following description of the embodiments is merely to provide a better understanding of this application by illustrating examples.

[0022] In the first embodiment, the present invention proposes an automatic control method for bladder irrigation fluid volume based on drainage and color monitoring, such as... Figure 1 As shown, it includes the following steps: S1, acquire the rinsing image, identify the fluid and background regions based on color gradient flow and connected components; when the fluid region contains the previous frame, adjust the first sampling density positively according to the model uncertainty of the previous frame, otherwise use the initial sampling density to generate the first tile set in the fluid region; generate the second tile set for the background region with the second sampling density.

[0023] The process involves acquiring rinsing images, extracting single-frame image data from the real-time video stream detected by the medical endoscope camera system, converting the rinsing images from the RGB color space to the HSV color space, and using the Sobel operator to calculate the square root of the sum of the squares of the spatial derivatives of the hue and saturation channels to obtain the color gradient magnitude image, i.e., the color gradient stream. The threshold function is used to perform threshold binarization on the color gradient stream to highlight high-gradient pixels. The findContours function is called to find connected components, and the area of ​​each connected component is calculated using the contourArea function to remove noisy connected components with areas smaller than an empirical threshold. The retained connected components are set as fluid regions, and the remaining pixels are classified as background regions. The initial sampling density is set to a sliding window step size of 16 pixels. If the previous frame data exists in memory, the model uncertainty value output by the Transformer network in the previous frame is read, and the model uncertainty value is multiplied by a preset positive scaling factor to obtain the density adjustment amount. The initial sampling density is adjusted by subtracting the density adjustment amount from the sliding window step size corresponding to the initial sampling density to reduce the sliding window step size, thereby capturing more tiles per unit area and positively adjusting the first sampling density. When there is no previous frame, the step size corresponding to the initial sampling density is used. The NumPy array slicing method is used to extract 16×16 pixel 2D tiles within the fluid region according to the adjusted step size, generating the first tile set. For the background region, a second sampling density sliding window step size of 32 pixels is set to ensure that this step size is larger than the fluid region step size. The same NumPy array slicing method is used to extract 2D tiles of the same size within the background region to generate the second tile set. Preferably, the second sampling density is smaller than the first sampling density.

[0024] In some embodiments, the identification of fluid and background regions based on color gradient flow and connected components includes: The washed image is converted to the HSV color space, the gradient magnitude matrix of the V channel image is extracted, and the gradient flow features are calculated. Binarization thresholding is performed on the S-channel image, and morphological opening and closing operations are combined with gradient flow features for denoising. Calculate the pixel area of ​​the binary connected region, retain the connected regions with an area greater than a preset area threshold as fluid regions, and mark the remaining regions as background regions.

[0025] The acquired RGB processing image (e.g., 1920×1080 resolution) is converted to the HSV color space using a color space conversion algorithm, and the two-dimensional pixel matrix of the luminance V channel is extracted. The Sobel operator is used to calculate the first derivatives in the horizontal and vertical directions, thereby obtaining the gradient magnitude matrix and direction matrix for each pixel. Pixels with gradient magnitudes exceeding a set threshold (e.g., greater than 50) are filtered out to form the gradient flow feature distribution of the fluid boundary. The saturation S channel of the image is extracted, and the Otsu method is applied or a fixed threshold is set (e.g.,...). Set to 60, perform binarization thresholding on the S channel to generate a fluid binary mask.

[0026] Since background reflections and tissue debris can cause noise in the mask, elliptical structural elements of size 5×5 or 7×7 are used, combined with previously extracted gradient flow features, to sequentially perform morphological opening operations on the binary mask to remove isolated noise, followed by closing operations to fill voids within the fluid, thus smoothing the fluid boundaries. A connected component labeling algorithm is applied to calculate the pixel area of ​​all binary connected components in the mask. If the total number of pixels in a connected component exceeds a preset area threshold, for example, 25,000 pixels, the connected component is determined to be a fluid region, and the mask value is retained. For connected components that do not meet the condition, the mask value is set to zero, and these components, along with regions that did not pass binarization, are marked as background region masks. Figure 2 As shown, the dashed line represents the area threshold of 25,000 pixels. Connected components with an area exceeding the threshold are identified as fluid regions, demonstrating the effectiveness of distinguishing between background noise and the target fluid region.

[0027] In some embodiments, the step of positively adjusting the first sampling density based on the model uncertainty of the previous frame when the fluid region exists, and otherwise using the initial sampling density, to generate a first tile set within the fluid region includes: Extract the model uncertainty scalar value output by the Transformer network in the previous frame; Construct a negative correlation exponential mapping function between uncertainty scalar values ​​and grid sampling step size; When the model uncertainty increases, the grid sampling step size in the fluid region is reduced by the mapping function to increase the first sampling density, and the first tile set is generated by two-dimensional grid clipping in the fluid region according to the sampling step size.

[0028] When processing video stream sequences, the model uncertainty scalar value predicted by the Transformer network at time t-1 is read from the buffer memory from the previous frame image. The Transformer network comprises a location embedding layer, a multi-head attention encoder layer, and a multi-task perception output head. The input to the Transformer network is a serialized cluster tensor containing local texture feature information, with a tensor dimension of N×d, where N is the sequence length and d is the feature dimension. The location embedding layer adds the learnable location encoding vector element-wise to the input sequence and inputs it to the multi-head attention encoder layer. The multi-head attention encoder layer consists of alternating cascaded layer normalization modules, multi-head self-attention mechanism modules, and feedforward neural network modules. After extracting deep semantic association features, the multi-head attention encoder layer outputs these features to the multi-task perception output head. The multi-task perception output head contains an uncertainty evaluation multilayer perceptron, which outputs a continuous model uncertainty scalar value through a Bayesian inference algorithm. This uncertainty scalar value represents the model's confidence level in extracting features such as bloodiness and turbidity from the current flushing fluid condition, and its value is normalized to the [0,1] interval. To achieve high-resolution image sampling, a model uncertainty scalar value U and a grid sampling step size were constructed. The negative correlation index mapping function between them is calculated using the following formula: .

[0029] In the above function, The maximum grid sampling step size is set to, for example, 32 pixels. The hyperparameter range for adjusting the sampling step size attenuation sensitivity is [1.5, 3.0]. An example value can be set to 2.0. When the model uncertainty U increases from 0.1 to 0.8 in the previous frame, the grid sampling step size... Driven by an exponential function, the size is reduced from approximately 26 pixels to approximately 6 pixels. Using the calculated sampling step size as the spatial span of the sliding window, a two-dimensional mesh is clipped within the identified fluid region boundary using a fixed-size window, such as 16×16 pixels. This uncertainty-driven clipping operation improves the feature resolution of local fluid textures under complex conditions and combines and maps all the clipped local patches to generate a first patch set containing multi-scale information.

[0030] S2, perform linear embedding on the first and second tile sets to obtain the initial token and perform density clustering to obtain the tile cluster; if there is a previous frame, set the neighborhood radius according to the mean and variance of the cluster scatter vector of the previous frame, otherwise use the preset radius; calculate the centroid vector of the initial token in the tile cluster and the scatter vector composed of the diagonal elements of the covariance, and calculate the Hadamard product of the centroid vector and the negative exponent of the scatter vector to obtain the cluster token.

[0031] Each 2D tile in the first and second tile sets is flattened into a 1D tensor. The 1D tensor is then mapped to a multi-dimensional feature space using the Linear function in the PyTorch deep learning framework to form a 1D feature vector. This feature vector is then added to the corresponding absolute position encoding vector to obtain the initial token. For density clustering, the DBSCAN algorithm from the Scikit-Learn machine learning library is used to perform cluster analysis on all initial tokens. When configuring the DBSCAN algorithm parameters, if a previous frame exists, the mean and variance of the discrete vector elements of all clusters in the previous frame are calculated. The mean plus the variance, multiplied by a preset constant coefficient, is used as the neighborhood radius (Epsilon parameter) for the current frame's DBSCAN algorithm. If the first frame is processed without data from the previous frame, the Epsilon parameter is set to a preset radius constant, such as 0.5. After execution, the initial tokens with sufficient density are divided into multiple tile clusters. The mean vector of all initial tokens within the same tile cluster across each feature dimension is calculated and used as the centroid vector of that cluster. The `cov` function is called to calculate the covariance matrix of the feature matrices of the initial tokens within the same tile cluster, and the diagonal elements are extracted to form a one-dimensional discreteness vector. The `exp` function of the NumPy library is used to calculate the negative exponent of each element of the discreteness vector to obtain a negative exponent vector. The `multiply` function is then used to perform a Hadamard product operation, multiplying the centroid vector and the negative exponent vector element-wise, thereby reducing the unstable feature dimensions according to the discreteness of the feature distribution to obtain the denoised cluster tokens.

[0032] In some embodiments, setting the neighborhood radius based on the mean and variance of the cluster scatter vector of the previous frame when a previous frame exists includes: Extract the discrete vector of all tile clusters in the previous frame; Calculate the mean vector and variance vector of all discrete vector sets respectively; The baseline radius is obtained by weighted summing of the square roots of the L2 norm of the mean vector and the L1 norm of the variance vector. The radius reference value is multiplied by a preset scaling factor to obtain the neighborhood radius for the density clustering algorithm of the current image frame.

[0033] The discrete vector set of all K tile clusters generated by clustering the previous image is extracted from the feature buffer. Each tile cluster's discrete vector is a fixed-dimensional d-dimensional feature sequence, such as d=64 or 128 dimensions. After obtaining the features, element-wise statistics are performed on the K discrete vectors at the feature dimension level to calculate the d-dimensional mean vector representing the overall expectation of divergence within the cluster. , and the d-dimensional variance vector representing the intensity of inter-cluster characteristic fluctuations. To integrate multi-dimensional statistics into a distance metric, a mean vector is calculated. The L2 norm is the square root of the sum of the squares of the elements of a vector. It is used to calculate the variance vector. The L1 norm is the sum of the absolute values ​​of the elements plus the square root.

[0034] Input a pair of normalized weight hyperparameters and satisfy Example value =0.7 and =0.3, and then perform a linear weighted sum of the mean and variance characteristics after the above processing to obtain a one-dimensional radius benchmark value. Input the preset scaling factor to control the cluster relaxation. The value range is between [0.8, 1.5]. An example value of 1.2 is used as the baseline value. and The result of the multiplication amplification is used as the Epsilon neighborhood search radius parameter when performing the DBSCAN equal-density clustering algorithm on the current image frame. This adjustment mechanism expands the clustering perception field of the current frame to encompass fluid patches when the previous image exhibits high discreteness and feature variation.

[0035] In some embodiments, the computation of the centroid vector of the initial token within the tile cluster and the discreteness vector composed of the diagonal elements of the covariance includes: For each tile cluster, the arithmetic mean of the feature vectors of all initial tokens within the cluster is calculated to obtain the centroid vector of the cluster. Calculate the covariance matrix formed by the eigenvectors of all initial tokens within the cluster; Extract the main diagonal elements of the covariance matrix to form a one-dimensional variance feature vector, and use the variance feature vector as the discreteness vector of the tile cluster.

[0036] For the k-th tile cluster partitioned by the density clustering algorithm, traverse the N initial tokens contained in the cluster. Each token is a d-dimensional feature vector generated after mapping through a linear embedding layer, for example, fixed at 256 dimensions. On the same coordinate dimension of the multidimensional feature space, perform element-wise arithmetic summation on the N 256-dimensional feature vectors, and divide the sum of each dimension by the total number N, thus outputting a smooth 256-dimensional arithmetic mean feature vector. This vector represents the central tendency feature of the tile cluster in Euclidean space, serving as the centroid vector of the cluster.

[0037] After obtaining the centroid vector, it is used as the mean benchmark of the multivariate normal distribution. The dispersion of the N initial tokens within the cluster relative to the centroid in multidimensional space is calculated. A covariance matrix of size d×d (256×256) is constructed through matrix multiplication. This matrix not only represents the divergence of single-dimensional features but also encompasses the correlation between cross-dimensions. To extract channel divergence indices and reduce the number of parameters in the subsequent neural network, the covariance matrix is ​​dimensionality-reduced by slicing, extracting 256 independent variance values ​​on the main diagonal. These values ​​are then rearranged according to the original feature channel order to construct a 256-dimensional one-dimensional variance feature vector. This vector is used as the dispersion vector representing the information richness and fluctuation amplitude of the tile cluster in each high-dimensional channel, such as... Figure 3 As shown, the variance value decreases exponentially with the increase of the feature channel index. The early channels carry most of the feature fluctuation information within the cluster, while the variance of the later channels approaches zero, which represents the distribution characteristics of information within the cluster in the high-dimensional feature space.

[0038] In some embodiments, obtaining the cluster token by calculating the Hadamard product of the centroid vector and the negative exponent of the discreteness vector includes: Verify whether the feature dimension lengths of the centroid vector and the discreteness vector are consistent. When the dimensions are consistent, the weight vector is obtained by taking the negative exponent of each element of the discrete vector, and the product vector is obtained by multiplying the corresponding elements of the centroid vector and the weight vector point by point. The product vector is concatenated with the original centroid vector, and after dimensionality reduction and fusion by a fully connected layer, the output is used as the cluster token of the tile cluster.

[0039] After extracting the tile cluster features, verify that the extracted d-dimensional centroid vector and the d-dimensional discrete vector (e.g., both are 256-dimensional) are consistent in dimensionality. If the dimensions are consistent, then for each floating-point element in the discrete vector... Using the base e of the natural logarithm to perform negative exponentiation function ,in The preset uncertainty penalty sensitivity coefficient is set to 1.0. This operation converts the discrete value into a d-dimensional weight vector distributed in the interval (0,1], achieving the adjustment effect that the larger the feature variance, the smaller the information weight assigned.

[0040] The generated d-dimensional weight vector is combined with the original d-dimensional centroid vector using the Hadamard Product operation, which multiplies the corresponding channel elements of the two vectors element by element to obtain a d-dimensional product vector adjusted for dispersion. To prevent the loss of feature magnitude due to negative exponential penalties, at the Channel level, the d-dimensional product vector is concatenated with the undecayed original d-dimensional centroid vector to generate a 2d-dimensional (e.g., 512-dimensional) combined feature tensor, doubling its length. This combined feature is then input to a single fully connected LinearLayer for dimensionality reduction and fusion, compressing the dimension back to the input dimension of 256. After processing with a non-linear activation function, it serves as a cluster token representing the semantics of the tile cluster, which is then fed into the Transformer attention layer.

[0041] S3. When there is a previous frame, calculate the distance between each cluster token and the nearest cluster token in the previous frame to obtain the salience score. If the salience score exceeds the preset threshold, assign the first weight; otherwise, assign the second weight. When there is no previous frame, assign the initial weight. Use this to weight the cluster tokens to obtain the weighted cluster tokens. Input the weighted cluster tokens into the Transformer network to output the state prediction and model uncertainty.

[0042] When a previous frame exists, the Euclidean distance matrix between each cluster token vector in the current frame and all cluster token vectors in the previous frame is calculated using the `cdist` function in the SciPy scientific computing library. The minimum value of each row in the matrix is ​​extracted as the distance between the corresponding cluster token in the current frame and the nearest cluster token in the previous frame, and this distance value is set as the salience score. A preset threshold, such as 0.8, is set. Python's built-in conditional statements are used to compare the salience score with the preset threshold. If the salience score is greater than the preset threshold, it indicates that the cluster token contains salience change information, and the cluster token is assigned a first weight of 1.5. If the salience score is less than or equal to the preset threshold, the cluster token is assigned a second weight of 0.5. When there is no previous frame, all cluster tokens are uniformly assigned an initial weight of 1.0. Preferably, the second weight is less than the first weight.

[0043] Each cluster token vector is weighted by multiplying its feature elements by their corresponding weights to obtain a weighted cluster token. These serialized weighted cluster tokens are then combined into a batch tensor and fed into a Transformer network built using PyTorch. The Transformer network includes a multi-head self-attention mechanism module and a feedforward neural network module to extract global spatiotemporal correlation features. At the network's end, a multilayer perceptron regression head is connected to output the state prediction value for the current degree of redness in the bladder irrigation fluid. An uncertainty estimation head constructed using a Monte Carlo Dropout mechanism is set at the network's end, and ten random forward propagations are performed during the inference phase to calculate the standard deviation of multiple state prediction results, thus outputting the model uncertainty representing the confidence level.

[0044] S4. Based on the difference between the predicted state and the preset target state, the gain coefficient of the PID controller is adjusted using the model uncertainty, and a pump control signal is generated based on the adjusted gain coefficient of the PID controller.

[0045] In the main control program, a preset target state representing the ideal flushing fluid clarity standard is set. The difference between the state prediction output by the Transformer network and the preset target state is calculated, which is the current deviation. The integral term of the accumulated deviation and the differential term of the adjacent deviation difference are updated using accumulation and backward difference operations. The proportional gain coefficient, integral gain coefficient and differential gain coefficient of the standard positional PID controller are initialized. The model uncertainty is mapped to a decay factor between 0 and 1 using the natural exponential function, so that the decay factor decreases accordingly when the model uncertainty increases. The decay factor is multiplied by the initial proportional gain coefficient, integral gain coefficient and differential gain coefficient respectively to complete the adjustment of the PID controller gain coefficient. Based on the adjusted PID controller gain coefficient and the previously calculated integral and differential terms of the deviation, the weighted summation is performed in the positional PID control equation to obtain the target flushing pump operating frequency value. The system obtains the real-time drainage flow feedback value of the drainage tube. When the input flow rate calculated from the target flushing pump operating frequency is significantly greater than the drainage flow feedback value, it performs amplitude limiting compensation to prevent bladder overfilling. Then, using a preset mapping function, such as the first coefficient × operating frequency + second coefficient, the target flushing pump operating frequency value is converted into a pulse width modulation (PWM) duty cycle format pump control signal and sent to the peristaltic flushing pump drive circuit to achieve real-time closed-loop regulation of fluid injection volume and drainage flow.

[0046] In some embodiments, adjusting the PID controller gain coefficient using model uncertainty and generating a pump control signal based on the adjusted PID controller gain coefficient includes: Obtain the initial proportional gain and initial integral gain of the PID controller; The attenuation factor is calculated by substituting the model uncertainty into a preset inverse proportional attenuation function, so that the greater the model uncertainty, the smaller the attenuation factor. The attenuation factor is multiplied by the initial proportional gain and the initial integral gain respectively to obtain the updated current control gain, so as to suppress control overshoot under high uncertainty conditions, and the pump control signal is output based on the current control gain.

[0047] The reference PID control parameters, pre-calibrated according to bladder hydrodynamics, are read from the flushing pump control module, i.e., the initial proportional gain is extracted. Example 2.5 and initial integral gain The example value is 0.08, and this set of baseline parameters corresponds to control when the image field of view is clear and the state confidence is high. During closed-loop control operation, the model uncertainty scalar U, which takes values ​​in the range [0,1], is received in real time from the Transformer branch evaluation output for each control cycle. The uncertainty scalar U is then substituted into the inverse proportional decay function. The conversion is performed in the middle, where The parameter for adjusting the shape of the attenuation curve is set to, for example, 3.0.

[0048] When the model uncertainty U increases to 0.9 due to bubble obstruction in the field of view, the attenuation factor calculated by substituting it into the function decreases to approximately 0.29. This attenuation factor of 0.29 is then multiplied by the extracted initial proportional gain of 2.5 and the initial integral gain of 0.08. The updated proportional gain decreases to 0.725, and the integral gain decreases to 0.0232. This parameter suppression process causes the controller's action amplitude to converge. Substituting this updated control gain into the incremental PID formula, and combining it with the deviation between the predicted and target states, the adjustment duty cycle command for the flushing fluid flow rate is calculated. The controller converts this duty cycle into a PWM waveform and sends it as a pump control signal to the motor driver, thereby preventing flushing oscillations or overshoot caused by model uncertainty.

[0049] To verify the reliability of the system's various mechanisms, a test set containing 500 cystoscopic irrigation videos was constructed. This dataset covers conditions such as air bubble obstruction and high turbidity. The average crossover ratio of fluid identification, model state prediction accuracy, control overshoot, and system settling time were used as evaluation metrics. Five sets of comparisons were set up for the ablation experiments: a baseline model with fixed parameters and conventional control; Variant 1 with uncertainty-removed grid sampling; Variant 2 with discrete clustering and cluster features removed; Variant 3 with controller gain attenuation removed; and the complete scheme employing all the mechanisms of the embodiments.

[0050] Under uniform operating conditions, the baseline model achieved an average cross-union ratio (CUP) of 74.2%, a prediction accuracy of 79.5%, a control overshoot of 18.6%, and a settling time of 12.4 seconds. Compared to the complete scheme, Variant 1 showed a CUP of 78.1%, a prediction accuracy of 84.3%, and a settling time of 9.8 seconds. Variant 2 showed a CUP of 81.5%, a prediction accuracy of 82.8%, and a settling time of 10.5 seconds. Variant 3 achieved a prediction accuracy of 91.2%, but the control overshoot rebounded to 16.2%, and the settling time increased to 11.1 seconds. The complete scheme achieved the best results across all experiments, with an average CUP of 86.7%, a prediction accuracy of 92.4%, a control overshoot of 4.3%, and a settling time of 6.2 seconds. Figure 4 As shown, the average crossover ratio (CRO) of fluid identification was compared between the baseline model, three variant schemes, and the complete method. With the gradual input of mechanisms such as sampling, discrete clustering, and uncertainty control, the accuracy of fluid identification improved stepwise. At the same time, the addition of the uncertainty decay control mechanism effectively reduced the system overshoot. The complete method achieved the highest CRO and the fastest control convergence, verifying the synergistic optimization effect of each module.

[0051] In a second embodiment, the present invention also provides an automatic bladder irrigation fluid volume control system based on drainage and color monitoring, comprising the following modules: The first generation module is used to acquire the rinsing image, identify the fluid and background regions based on color gradient flow and connected components; when the fluid region contains the previous frame, the first sampling density is positively adjusted according to the model uncertainty of the previous frame; otherwise, the initial sampling density is used to generate a first set of patches in the fluid region; and a second set of patches is generated for the background region with a second sampling density. The calculation module is used to linearly embed the first and second tile sets to obtain the initial token and perform density clustering to obtain the tile cluster. If there is a previous frame, the neighborhood radius is set according to the mean and variance of the cluster scatter vector of the previous frame; otherwise, the preset radius is used. The centroid vector of the initial token in the tile cluster and the scatter vector composed of the diagonal elements of the covariance are calculated, and the Hadamard product of the centroid vector and the negative exponent of the scatter vector is obtained to obtain the cluster token. The output module is used to calculate the salience score by measuring the distance between each cluster token and the nearest cluster token in the previous frame when a previous frame exists. If the salience score exceeds a preset threshold, a first weight is assigned; otherwise, a second weight is assigned. If there is no previous frame, an initial weight is assigned. The cluster tokens are then weighted to obtain a weighted cluster token. The weighted cluster tokens are then input into the Transformer network to output state prediction and model uncertainty. The second generation module is used to adjust the PID controller gain coefficient based on the difference between the state prediction and the preset target state, taking advantage of model uncertainty, and to generate a pump control signal based on the adjusted PID controller gain coefficient.

[0052] It should be clarified that this application is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of this application is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of this application.

[0053] The above description is merely a specific implementation of this application. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, modules, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. It should be understood that the protection scope of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and these modifications or substitutions should all be covered within the protection scope of this application.

Claims

1. A method for automatically controlling the volume of bladder irrigation fluid based on drainage and color monitoring, characterized in that, Includes the following steps: Acquire rinsing images and identify fluid and background regions based on color gradient flow and connected components; if the fluid region contains the previous frame, adjust the first sampling density positively according to the model uncertainty of the previous frame; otherwise, use the initial sampling density to generate a first set of patches in the fluid region; generate a second set of patches for the background region with a second sampling density. Linear embedding is performed on the first and second tile sets to obtain initial tokens, and density clustering is performed to obtain tile clusters. If a previous frame exists, the neighborhood radius is set according to the mean and variance of the cluster scatter vector of the previous frame; otherwise, a preset radius is used. The centroid vector of the initial token in the tile cluster and the scatter vector composed of the diagonal elements of the covariance are calculated. The Hadamard product of the centroid vector and the negative exponent of the scatter vector is used to obtain the cluster token. When a previous frame exists, the distance between each cluster token and the nearest cluster token in the previous frame is calculated to obtain a salience score. If the salience score exceeds a preset threshold, a first weight is assigned; otherwise, a second weight is assigned. When there is no previous frame, an initial weight is assigned. The cluster tokens are then weighted to obtain a weighted cluster token. The weighted cluster tokens are then input into the Transformer network to output state prediction and model uncertainty. Based on the difference between the predicted state and the preset target state, the gain coefficient of the PID controller is adjusted using the model uncertainty, and a pump control signal is generated based on the adjusted gain coefficient of the PID controller.

2. The method according to claim 1, characterized in that, The method for identifying fluid and background regions based on color gradient flow and connected components includes: The washed image is converted to the HSV color space, the gradient magnitude matrix of the V channel image is extracted, and the gradient flow features are calculated. Binarization thresholding is performed on the S-channel image, and morphological opening and closing operations are combined with gradient flow features for denoising. Calculate the pixel area of ​​the binary connected region, retain the connected regions with an area greater than a preset area threshold as fluid regions, and mark the remaining regions as background regions.

3. The method according to claim 1, characterized in that, The process of adjusting the first sampling density positively based on the model uncertainty of the previous frame when the fluid region contains data from the previous frame, and otherwise using the initial sampling density to generate a first tile set within the fluid region, includes: Extract the model uncertainty scalar value output by the Transformer network in the previous frame; Construct a negative correlation exponential mapping function between uncertainty scalar values ​​and grid sampling step size; When the model uncertainty increases, the grid sampling step size in the fluid region is reduced by the mapping function to increase the first sampling density, and the first tile set is generated by two-dimensional grid clipping in the fluid region according to the sampling step size.

4. The method according to claim 1, characterized in that, The step of setting the neighborhood radius based on the mean and variance of the cluster scatter vector of the previous frame when a previous frame exists includes: Extract the discrete vector of all tile clusters in the previous frame; Calculate the mean vector and variance vector of all discrete vector sets respectively; The baseline radius is obtained by weighted summing of the square roots of the L2 norm of the mean vector and the L1 norm of the variance vector. The radius reference value is multiplied by a preset scaling factor to obtain the neighborhood radius for the density clustering algorithm of the current image frame.

5. The method according to claim 1, characterized in that, The computational graph includes the centroid vector of the initial token within the tile cluster and the discreteness vector composed of the diagonal elements of the covariance, comprising: For each tile cluster, the arithmetic mean of the feature vectors of all initial tokens within the cluster is calculated to obtain the centroid vector of the cluster. Calculate the covariance matrix formed by the eigenvectors of all initial tokens within the cluster; Extract the main diagonal elements of the covariance matrix to form a one-dimensional variance feature vector, and use the variance feature vector as the discreteness vector of the tile cluster.

6. The method according to claim 1, characterized in that, The process of obtaining the cluster token by calculating the Hadamard product of the centroid vector and the negative exponent of the discreteness vector includes: Verify whether the feature dimension lengths of the centroid vector and the discreteness vector are consistent. When the dimensions are consistent, the weight vector is obtained by taking the negative exponent of each element of the discrete vector, and the product vector is obtained by multiplying the corresponding elements of the centroid vector and the weight vector point by point. The product vector is concatenated with the original centroid vector, and after dimensionality reduction and fusion by a fully connected layer, the output is used as the cluster token of the tile cluster.

7. The method according to claim 1, characterized in that, The method of adjusting the PID controller gain coefficient using model uncertainty and generating a pump control signal based on the adjusted PID controller gain coefficient includes: Obtain the initial proportional gain and initial integral gain of the PID controller; The attenuation factor is calculated by substituting the model uncertainty into a preset inverse proportional attenuation function, so that the greater the model uncertainty, the smaller the attenuation factor. The attenuation factor is multiplied by the initial proportional gain and the initial integral gain respectively to obtain the updated current control gain, so as to suppress control overshoot under high uncertainty conditions, and the pump control signal is output based on the current control gain.

8. An automatic bladder irrigation fluid volume control system based on drainage and color monitoring, characterized in that, Includes the following modules: The first generation module is used to acquire the rinsing image, identify the fluid and background regions based on color gradient flow and connected components; when the fluid region contains the previous frame, the first sampling density is positively adjusted according to the model uncertainty of the previous frame; otherwise, the initial sampling density is used to generate a first set of patches in the fluid region; and a second set of patches is generated for the background region with a second sampling density. The calculation module is used to linearly embed the first and second tile sets to obtain the initial token and perform density clustering to obtain the tile cluster. If there is a previous frame, the neighborhood radius is set according to the mean and variance of the cluster scatter vector of the previous frame; otherwise, the preset radius is used. The centroid vector of the initial token in the tile cluster and the scatter vector composed of the diagonal elements of the covariance are calculated, and the Hadamard product of the centroid vector and the negative exponent of the scatter vector is obtained to obtain the cluster token. The output module is used to calculate the salience score by measuring the distance between each cluster token and the nearest cluster token in the previous frame when a previous frame exists. If the salience score exceeds a preset threshold, a first weight is assigned; otherwise, a second weight is assigned. If there is no previous frame, an initial weight is assigned. The cluster tokens are then weighted to obtain a weighted cluster token. The weighted cluster tokens are then input into the Transformer network to output state prediction and model uncertainty. The second generation module is used to adjust the PID controller gain coefficient based on the difference between the state prediction and the preset target state, taking advantage of model uncertainty, and to generate a pump control signal based on the adjusted PID controller gain coefficient.

9. The system according to claim 8, characterized in that, The method for identifying fluid and background regions based on color gradient flow and connected components includes: The washed image is converted to the HSV color space, the gradient magnitude matrix of the V channel image is extracted, and the gradient flow features are calculated. Binarization thresholding is performed on the S-channel image, and morphological opening and closing operations are combined with gradient flow features for denoising. Calculate the pixel area of ​​the binary connected region, retain the connected regions with an area greater than a preset area threshold as fluid regions, and mark the remaining regions as background regions.

10. The system according to claim 8, characterized in that, The process of adjusting the first sampling density positively based on the model uncertainty of the previous frame when the fluid region contains data from the previous frame, and otherwise using the initial sampling density to generate a first tile set within the fluid region, includes: Extract the model uncertainty scalar value output by the Transformer network in the previous frame; Construct a negative correlation exponential mapping function between uncertainty scalar values ​​and grid sampling step size; When the model uncertainty increases, the grid sampling step size in the fluid region is reduced by the mapping function to increase the first sampling density, and the first tile set is generated by two-dimensional grid clipping in the fluid region according to the sampling step size.