Water surface target detection method based on improved flood filling algorithm
By improving the flood filling algorithm and combining multi-fuzzy scale background modeling and adaptive threshold interval calculation, the problems of illumination changes and dynamic target interference in water surface target detection are solved, and high-precision and efficient water surface target detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-16
- Publication Date
- 2026-03-13
AI Technical Summary
Existing methods based on fixed threshold segmentation are poorly adaptable to changes in illumination, and traditional background modeling methods cannot effectively separate the background due to the continuous presence of dynamic targets, resulting in insufficient accuracy in water surface target detection.
An improved flood filling algorithm is adopted, which combines multi-fuzzy scale background modeling, edge enhancement processing and dynamic adaptive threshold interval calculation to generate high-quality static background images of empty scenes, and water surface target detection is performed by local adaptive thresholding and multi-feature false alarm filtering.
It improves the accuracy and adaptability of surface target detection, reduces background interference, enhances the versatility and reliability of the method, reduces the false alarm rate, and avoids tedious manual labeling work.
Smart Images

Figure CN121661316A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of target detection technology, and in particular to a method for detecting water surface targets based on an improved flood filling algorithm. Background Technology
[0002] Surface target detection is a key technology in applications such as maritime safety monitoring, waterway management, and bridge collision warning. Its core lies in accurately separating the water surface area to avoid the impact of background interference such as riverbanks and docks on the detection accuracy.
[0003] Currently, there are two main methods for water surface region segmentation. The first is a fixed threshold-based segmentation method. This method is computationally efficient and can quickly binarize images. However, due to the large variations in water surface lighting and complex reflections, it is difficult to standardize the threshold, which can easily lead to missegmentation of the background or missed targets. The second method is the traditional background modeling method. This method models the static parts of the video sequence to extract a pure background without targets, and then uses a foreground detection algorithm to identify water surface targets. Traditional background modeling methods mainly rely on inter-frame variation statistics. However, in water surface target detection, because ships are always in motion, it is difficult to obtain a pure background model, affecting the accuracy of target segmentation.
[0004] Fixed threshold segmentation methods are poorly adaptable to changes in illumination, and traditional background modeling methods cannot effectively separate the background due to the continuous presence of dynamic targets, resulting in insufficient accuracy in water surface target detection. Summary of the Invention
[0005] Based on the above analysis, the present invention aims to provide a water surface target detection method based on an improved flood filling algorithm, in order to solve the technical problems of poor adaptability of existing fixed threshold segmentation methods to changes in illumination and the inability of traditional background modeling methods to effectively separate the background due to the continuous presence of dynamic targets, resulting in insufficient accuracy of water surface target detection.
[0006] This invention is mainly achieved through the following technical solutions: This invention provides a method for detecting water surface targets based on an improved flood filling algorithm, comprising the following steps: Video stream data of the water surface area covering different time periods and lighting conditions was collected and preprocessed to generate a static background image of an empty scene. ; The improved flood filling algorithm was used to process the static background image of the empty scene. Perform water surface area segmentation processing to generate a water surface area mask; Water surface target detection is performed based on real-time acquired video stream data and the water surface area mask to obtain water surface target detection results.
[0007] Furthermore, the video stream data of the water surface area is preprocessed to generate a static background image of an empty scene. ,include: Sparse frame extraction is performed on the video stream data of the water surface area to extract multiple frames of images, which are used as background modeling images. Based on preset A set of fuzzy scales is used to model each frame of the background image, respectively. Blurring was performed at different scales to obtain blurred images of each frame's background modeling image at each blur scale; among them... ; Pixel-level averaging is performed on all blurred images at each blur scale to obtain the background image corresponding to each blur scale. The weights of the background images corresponding to each fuzziness scale are calculated using a residual minimization strategy. These weighted images are then fused to obtain a static background image of an empty scene. .
[0008] Furthermore, a preset set of contents includes A set of fuzzy scales with different standard deviations , Small standard deviation corresponds to low fuzziness scale, and large standard deviation corresponds to high fuzziness scale; Each frame of the background modeling image , Each fuzzy scale is convolved with the corresponding two-dimensional Gaussian kernel; In the Individual scale Below, background modeling image With the corresponding Gaussian kernel Convolution is performed to obtain the corresponding blurred image. As shown below: ; in, Model the pixel coordinates in the background image; For the first Frame background modeling image in the first Pixel values after Gaussian blurring at each blur scale; For the first Frame background modeling image; The standard deviation is The two-dimensional Gaussian kernel function; The symbol for convolution; The size of a Gaussian half-window; These are the relative coordinates of the Gaussian kernel in the horizontal and vertical directions, respectively. The range of values is .
[0009] Furthermore, an improved flood-fill algorithm is used to process the static background image of the empty scene. Water surface area segmentation processing includes: For the static background image of the empty scene Perform edge enhancement processing and define an edge response map to generate a boundary enhancement image. ; The boundary enhancement image Multiple pixels located scattered within the water surface area are selected as seed points. The values of these seed points in the static background image of the empty scene are then calculated. The gray values in the data are used to obtain multiple gray values to form a gray set. ; Calculate the gray set The mean and standard deviation are used to dynamically calculate the adaptive threshold interval for region growth; A queue structure is used to perform region growth traversal starting from the seed point set. For the neighboring pixels of the current pixel, if both conditions 1 and 2 are satisfied, they are included in the water surface region: Condition 1: Neighboring pixels are in an empty scene with a static background image. The grayscale values are within the adaptive threshold range; Condition 2: The value of the neighboring pixel on the edge response map is lower than the preset boundary threshold. ; Static background image of empty scene After all pixels have been traversed, the pixels included in the water surface area form the water surface area mask. .
[0010] Furthermore, the edge enhancement method using structure tensor is employed to enhance the static background image of the empty scene. Perform edge enhancement processing and define the edge response map. Generate boundary enhancement image ,include: The Sobel operator is used to calculate the static background image with empty background. The gradient vector of each pixel (x, y); Within the neighborhood of pixel (x, y), a Gaussian weighted average of the outer product of the gradient vectors is applied to obtain the positive semidefinite structure tensor. ; Extract the semidefinite structure tensor eigenvalues , ; based on Define edge response graph ,as follows: ; Where c is a small positive constant; Based on the edge response map The boundary enhancement image is generated by weighted fusion of a static background image with an empty background. ,as follows: ; in, This is the enhancement coefficient.
[0011] Further, the grayscale set is calculated. The mean and standard deviation are used to dynamically calculate the adaptive threshold interval for region growth, including: Calculate the gray set mean and Standard deviation; Define the adaptive threshold interval As shown below: ; in, As a scale factor, This is the absolute offset.
[0012] Furthermore, based on the real-time acquired video stream data and the water surface region mask, water surface target detection is performed to obtain water surface target detection results, including: Obtain the current frame image based on real-time acquisition of video stream data. ; Based on the water surface area mask For the current frame image Foreground extraction is performed to obtain the foreground image. ; The foreground image is based on a local adaptive threshold. Binarization is performed to obtain the binarized foreground image. ; The binarized foreground image By performing closing operations and connected component analysis sequentially, a set of candidate regions is obtained. ; For each candidate region Perform multi-feature false alarm filtering to obtain feature vectors. ,Will The targets on the water surface are classified to obtain the detection results.
[0013] Furthermore, the foreground image is based on a local adaptive threshold. Binarization includes: Foreground image any pixel in The result after binarization Determined by the following formula: ; in, The local adaptive threshold is as follows: ; in, pixels A surrounding area of size The mean and standard deviation of pixels within the window; This represents the maximum value of the dynamic range of the standard deviation. This is an adjustable parameter.
[0014] Furthermore, the binarized foreground image Performing a dilation-erosion closing operation yields a morphologically processed binary image, as shown below: ; in, As a structural element, , These represent morphological expansion and erosion operations, respectively. An 8-connectivity algorithm is used to perform connected component analysis on the morphologically processed binary image, grouping all interconnected foreground pixels into the same set and assigning a unique label to each set, thus obtaining a set of candidate regions. .
[0015] Furthermore, for each candidate region Perform multi-feature false alarm filtering to obtain feature vectors. ,Will Classification includes: For each candidate region ,from The corresponding current frame image Extract texture features, shape features, and gradient features to construct a feature vector. ; Principal Component Analysis (PCA) was used to analyze the eigenvectors. Dimensionality reduction and decorrelation are performed to obtain feature vectors. ; eigenvectors The pre-trained support vector machine (SVM) is input for classification to obtain the water surface target detection results; The surface target detection results include real ship targets and false alarms.
[0016] Compared with the prior art, the present invention can achieve at least one of the following beneficial effects: 1. This invention, through an improved flood filling algorithm, combined with edge enhancement processing and dynamic adaptive threshold interval calculation, can more accurately segment water surface areas, reduce background interference, improve the accuracy of water surface target detection, and enhance the detection precision of water surface targets; the improved flood filling algorithm can flexibly adapt to various bridge monitoring scenarios without retraining the model or adjusting the threshold for each new monitoring angle, thus enhancing the versatility and generalizability of the method. 2. This invention utilizes multi-fuzzy scale background modeling and residual minimization strategies to generate high-quality static background images of empty scenes, effectively addressing changes in different lighting conditions and time periods, and improving the algorithm's adaptability to complex environments; 3. This invention utilizes multi-feature false alarm filtering, combining texture, shape and gradient features, and effectively distinguishes between real targets and false alarms through PCA dimensionality reduction and SVM classification, thereby improving the reliability of detection results and reducing the false alarm rate of water surface targets; 4. This invention constructs a dynamic background model using multiple frames of images, effectively eliminating moving targets such as ships without the need for precise labeling of river areas, retaining only stable water surface areas, avoiding the tedious manual labeling work in traditional methods, and improving deployment efficiency; 5. This invention adopts a seed point selection strategy that combines image sharpening with user-interactive point selection, which enhances the robustness of water surface area extraction, effectively copes with image differences under different lighting conditions, water surface reflection and different monitoring angles, and significantly improves the segmentation accuracy of flood filling.
[0017] In this invention, the above-described technical solutions can be combined with each other to achieve more preferred combinations. Other features and advantages of this invention will be set forth in the following description, and some advantages may become apparent from the description or be learned by practicing the invention. The objects and other advantages of this invention can be realized and obtained from what is particularly pointed out in the description and drawings. Attached Figure Description
[0018] The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. Throughout the drawings, the same reference numerals denote the same parts. Figure 1 This is a flowchart of the water surface target detection method based on the improved flood filling algorithm in an embodiment of the present invention; Figure 2(a) is a schematic diagram of a monitoring screen of a bridge at a certain moment in an embodiment of the present invention; Figure 2(b) is a schematic diagram of the monitoring screen of a bridge at another moment in an embodiment of the present invention; Figure 3 The static background image of an empty scene generated in the embodiments of the present invention. Schematic diagram; Figure 4 This is a schematic diagram of a sharpened image in an embodiment of the present invention; Figure 5 This is a schematic diagram of the seed point selection interface in an embodiment of the present invention; Figure 6 This is a schematic diagram of the water surface segmentation result in an embodiment of the present invention. Detailed Implementation
[0019] Preferred embodiments of the present invention will now be described in detail with reference to the accompanying drawings, which form part of this application and are used together with the embodiments of the present invention to illustrate the principles of the present invention, but are not intended to limit the scope of the present invention.
[0020] To address the aforementioned technical problems, this invention studies a robust and efficient background modeling method, which is of great significance for improving the reliability of water surface target detection and reducing human intervention.
[0021] The water surface target detection method disclosed in this invention based on an improved flood filling algorithm first obtains the background by background modeling of multiple frames of images in a video sequence, then accurately segments the water surface area using the improved flood filling algorithm, and finally performs target detection within the extracted water surface area, thereby improving detection accuracy and reducing background interference.
[0022] A specific embodiment of the present invention discloses a method for detecting water surface targets based on an improved flood filling algorithm, such as... Figure 1 As shown, it includes the following steps: Step S1: Collect video stream data of the water surface area covering different time periods and different lighting conditions, and preprocess it to generate a static background image of an empty scene. ; Step S2: Apply the improved flood fill algorithm to the static background image of the empty scene. Perform water surface area segmentation processing to generate a water surface area mask; Step S3: Detect water surface targets based on the real-time acquired video stream data and the water surface area mask to obtain water surface target detection results.
[0023] Step S1 includes steps S11-S12.
[0024] Step S11: Collect video stream data covering water surface areas under different time periods and lighting conditions.
[0025] Video stream data is obtained by using cameras installed on the bridge.
[0026] This method aims to solve the problem of bridge collision avoidance and early warning. It primarily involves monitoring footage from cameras deployed on the bridge to detect and analyze the movement of vessels crossing the water. To ensure the accuracy and stability of the detection, a fixed-view surveillance camera must first be selected to ensure the consistency of the monitoring footage throughout the entire detection process.
[0027] This invention selected surveillance video stream data from a bridge as experimental data, covering bridge monitoring footage from June to September 2024. To ensure the generalization ability and robustness of the background model, this invention chose video stream data sources covering different lighting conditions and time periods. This video stream data was used for subsequent background modeling and target detection experiments to verify the applicability and effectiveness of the proposed method in a real water surface environment.
[0028] As shown in Figures 2(a) and 2(b), these are monitoring images of a bridge at two different times on two different days. It can be clearly seen that due to different lighting conditions, the brightness and uniformity of the water surface are quite different. Using monitoring videos from different time periods (with sufficient lighting) for background modeling can have higher robustness.
[0029] For example, the video stream data sequence is in MP4 format.
[0030] Step S12: Preprocess the video stream data of the water surface area to generate a static background image of an empty scene. .
[0031] The video stream data of the water surface area is preprocessed to generate a static background image of an empty scene. ,include: Sparse frame extraction is performed on the video stream data of the water surface area to extract multiple frames of images, which are used as background modeling images. Based on preset A set of fuzzy scales is used to model each frame of the background image, respectively. Blurring was performed at different scales to obtain blurred images of each frame's background modeling image at each blur scale; among them... ; Pixel-level averaging is performed on all blurred images at each blur scale to obtain the background image corresponding to each blur scale. The weights of the background images corresponding to each fuzziness scale are calculated using a residual minimization strategy. These weighted images are then fused to obtain a static background image of an empty scene. .
[0032] From dynamic video surveillance sequences, a high-quality, static background image of the empty scene that realistically reflects fixed scene elements is constructed. Constructing this static background image aims to eliminate interference from dynamic or semi-dynamic targets such as ships and water ripples, providing a stable and clean input for subsequent water surface region segmentation.
[0033] The multi-scale fusion background modeling method proposed in this step, by combining temporal averaging and spatial multi-scale analysis, effectively balances background detail preservation and dynamic target suppression, generating robust static background images of empty scenes. It effectively eliminates the influence of moving objects such as ships, achieving preliminary separation between the static background and the water surface area.
[0034] To avoid "ghosting" effects on the background model caused by the brief pauses or slow movements of moving objects (such as ships) in the video, the video sequence is first subjected to temporal sparse frame sampling, also known as non-correlated frame sampling. This process aims to extract a set of temporally independent image frames that represent the statistical characteristics of the background. The sparse frame sampling formula is as follows: Formula (1) in, This represents the t-th frame extracted from the video stream data, where V represents the input MP4 format video stream data, and r is the frame extraction interval (unit: frames), meaning one frame is extracted every r frames to avoid extracting continuously stationary moving targets. This indicates a frame extraction operation, which selects frames from the video stream V at intervals r. D(.) represents a frame decoding function that converts compressed video frames (such as MP4) into raw pixel data; C(.) represents a color space conversion function (such as converting from BGR or YUV to RGB). Video stream data is typically stored in the YUV compressed color space and then converted to RGB for subsequent image processing.
[0035] Image frames are uniformly and sparsely extracted from MP4 format video stream data V. This can effectively reduce the interference of short-lived moving targets on background modeling. For example, at least 800 frames are selected from a video stream data sequence.
[0036] The monitoring video in this example is 25 frames per second. Based on the speed of the ships, each ship stays in the image for about 5 minutes. Therefore, the frame extraction interval r is selected as 250 frames, and one frame is extracted every 10 seconds. Five video clips from different days or different monitoring periods are selected to generate a total of 900 images as background modeling images, with 180 images for each period.
[0037] If the ship remains in the frame for about 5 minutes (300 seconds), one frame is extracted every 10 seconds, resulting in a total of 30 frames of images involving the ship.
[0038] Addressing the "moving boats on still water" characteristic of bridge collision avoidance videos, this invention does not employ simple pixel averaging but instead proposes a multi-scale fusion background modeling method. By processing images at multiple different spatial blur scales, it can more precisely separate and suppress dynamic targets of varying sizes while better preserving details of the static background. This involves sparsely extracting n frames of images... In this example, n=900, the background modeling image is used as the background modeling image. The background modeling image is processed at multiple blur scales, with pixel averaging performed at each scale to obtain multi-scale background images. The results from each scale are then fused using a weighted method to form the final static background image of the empty scene. .
[0039] Specifically as follows: The first step is to perform multi-scale Gaussian blur processing on each frame of the background modeling image to obtain the background image corresponding to each blur scale.
[0040] A preset set includes A set of fuzzy scales with different standard deviations , Small standard deviation corresponds to low fuzziness scale, and large standard deviation corresponds to high fuzziness scale; Each frame of the background modeling image , Each fuzzy scale is convolved with the corresponding two-dimensional Gaussian kernel; In the Individual scale Below, background modeling image With the corresponding Gaussian kernel Convolution is performed to obtain the corresponding blurred image. As shown below: Formula (2) in, Model the pixel coordinates in the background image; For the first Frame background modeling image in the first Pixel values after Gaussian blurring at each blur scale; For the first Frame background modeling image; The standard deviation is The two-dimensional Gaussian kernel function; The symbol for convolution; The size of a Gaussian half-window; These are the relative coordinates of the Gaussian kernel in the horizontal and vertical directions, respectively. The range of values is .
[0041] Define a set containing A set of fuzzy scales with different standard deviations For the input set Each frame of background modeling image (j=1, ..., N), respectively in Gaussian blurring is performed at different scales. At the s-th scale... Below, image Blurry version By using the corresponding two-dimensional Gaussian kernel The result is obtained by convolution, as shown in formula (2).
[0042] The standard deviation is The two-dimensional Gaussian kernel function is shown below: Formula (3) When the size is small, the blur level is low, and it can preserve high-frequency details in the background (such as water ripples and dock textures) well, but it is more sensitive to small dynamic targets or noise. When the target size is large, the blur level is high, which can strongly suppress and "smear" away large dynamic targets (such as the main body of a ship), but it will also blur some background details.
[0043] The second step is to perform pixel-level averaging on all blurred images at each blur scale to obtain the background image corresponding to each blur scale.
[0044] At each blur scale, the pixel-level average of all frames is calculated to obtain the background image at that scale, as shown below: Formula (4) in, Let i be the background image at the s-th blur scale, i be the blurred image of the i-th frame, and n be the total number of images, such as 900 frames in this invention. The physical meaning of this step is: at the same blur scale, dynamic objects (such as ships) are weakened in pixel-level averaging due to their displacement over time, while static backgrounds are preserved; as the position of a ship changes in different frames, its blurred pixel values tend to approach the background values after time averaging, while the pixel values of static backgrounds remain stable.
[0045] The third step involves calculating the weights of the background images corresponding to each fuzziness scale using a residual minimization strategy, and then performing weighted fusion of the background images corresponding to each fuzziness scale to obtain a static background image of an empty scene. .
[0046] Background images of all scales are fused in a weighted manner to obtain the final static background image of the empty scene. As shown below: Formula (5) in, The final multi-scale background image after fusion, i.e., the static background image of the empty scene. .
[0047] The weights of the background image corresponding to each blur scale are calculated using a residual minimization strategy. The core of this strategy is to find a set of optimal weights through an optimization algorithm (such as constrained least squares). This makes the merged background B blend with the idealized static and pure background. Minimize the difference (residual) between them. The objective function is as follows: Formula (6) in, Let Frobenius norm represent the matrix. By solving this optimization problem, the system can adaptively adjust the contribution of the background at various scales, resulting in a fused static background image of the empty scene. It can eliminate the interference of dynamic targets to the greatest extent and approximate the static state of the real scene to the greatest extent, thereby forming the high-quality "empty scene" background described in this invention, providing a reliable basis for the accurate separation of the water surface area from the surrounding static objects in subsequent steps.
[0048] Static background image of the merged empty scene The empty scene background constructed for this invention is used to separate ships on the water from surrounding static objects, such as... Figure 3 As shown.
[0049] Step S1 involves collecting water surface video stream data under different time periods and lighting conditions, and then performing sparse frame extraction and multi-scale fusion processing to generate high-quality static background images of empty scenes. This provides a stable, clean, and robust background model for subsequent water surface target detection.
[0050] Step S2, specifically.
[0051] The improved flood filling algorithm was used to process the static background image of the empty scene. Water surface area segmentation processing includes: For the static background image of the empty scene Perform edge enhancement processing and define an edge response map to generate a boundary enhancement image. ; The boundary enhancement image Multiple pixels located scattered within the water surface area are selected as seed points. The values of these seed points in the static background image of the empty scene are then calculated. The gray values in the data are used to obtain multiple gray values to form a gray set. ; Calculate the gray set The mean and standard deviation are used to dynamically calculate the adaptive threshold interval for region growth; A queue structure is used to perform region growth traversal starting from the seed point set. For the neighboring pixels of the current pixel, if both conditions 1 and 2 are satisfied, they are included in the water surface region: Condition 1: Neighboring pixels are in an empty scene with a static background image. The grayscale values are within the adaptive threshold range; Condition 2: The value of the neighboring pixel on the edge response map is lower than the preset boundary threshold. ; Static background image of empty scene After all pixels have been traversed, the pixels included in the water surface area form the water surface area mask. .
[0052] Obtaining high-quality static background images of empty scenes The core task of this step is to accurately segment the water surface area. Traditional flood filling algorithms often fail to segment water surfaces with uneven lighting and specular reflection due to limitations of fixed thresholds and single seed points. To overcome this problem, this invention proposes an improved flood filling algorithm that combines boundary reinforcement constraints with multi-point adaptive threshold generation.
[0053] Step 1: Static background image of the empty scene Perform edge enhancement processing and define the edge response map. Generate boundary enhancement image .
[0054] The edge enhancement method using structure tensor is applied to the static background image of the empty scene. Perform edge enhancement processing and define the edge response map. Generate boundary enhancement image ,include: The Sobel operator is used to calculate the static background image with empty background. The gradient vector of each pixel (x, y); Within the neighborhood of pixel (x, y), a Gaussian weighted average of the outer product of the gradient vectors is applied to obtain the positive semidefinite structure tensor. ; Extract the semidefinite structure tensor eigenvalues , ; based on Define edge response graph ,as follows: Formula (7) Where c is a small positive constant; Based on the edge response map The boundary enhancement image is generated by weighted fusion of a static background image with an empty background. ,as follows: Formula (8) in, This is the enhancement coefficient.
[0055] To effectively prevent the segmented area from "leaking" into non-water areas such as the shore and docks during the flood filling process, it is first necessary to create a static background image of the empty scene. Boundary enhancement is performed to strengthen the gradient at the water-land interface, providing a clear "physical barrier" for subsequent regional growth.
[0056] Compared to the simple Laplacian operator (which is sensitive to noise and lacks directionality), this invention employs an edge enhancement method based on structure tensors. Structure tensors not only measure edge strength but also provide directional information, thus enabling more robust identification of continuous boundaries.
[0057] For static background images in an empty scene Its pixel The gradient vector at is ,in, and The images are respectively in and The partial derivatives in the direction are calculated using gradient operators such as Sobel.
[0058] Structure Tensor It is a 2x2 positive semi-definite matrix, expressed in pixels. neighborhood The inner product of the gradient and the outer product is obtained by Gaussian weighted averaging, as shown in the following Soth: Formula (9) in, It is an integral-scale Gaussian kernel used to smooth gradient information to suppress noise.
[0059] Structure Tensor Two eigenvalues and This describes the gradient distribution within the local neighborhood: like This indicates that the area is a corner point or a high-frequency texture area.
[0060] like This indicates that the area is flat.
[0061] Based on this, the present invention defines an edge response function. Used for quantizing pixels Possibility of belonging to the boundary: Formula (10) in, It is a small positive constant used to suppress the response in corner regions. This function... It can effectively highlight continuous edges (such as shorelines) and suppress the response of flat areas and isolated noise points.
[0062] Finally, a boundary enhancement image is generated. As shown below: Formula (11) in, This is an enhancement coefficient used to control the enhancement strength of the edge gradient.
[0063] For example, Choose a value between 0.1 and 2.0. In scenes with uniform lighting and clear water features, a smaller value can be selected. (e.g., 0.5); however, when strong specular reflection causes local blurring of the waterfront boundary, the value needs to be increased. (e.g. 1.5) to strengthen the edges and provide stronger constraints for subsequent steps.
[0064] like Figure 4 As shown in the sharpened image, this processing significantly increases the boundary gradient between water and non-water areas in visual space, enhancing contrast and providing reliable spatial constraint information for the flood filling algorithm.
[0065] Step 2: Enhance the image at the boundaries. Multiple pixels located scattered within the water surface area are selected as seed points. The values of these seed points in the static background image of the empty scene are then calculated. The gray values in the data are used to obtain multiple gray values to form a gray set. .
[0066] To accommodate potential brightness and color inhomogeneities within the water surface, this algorithm employs a multi-point seeding strategy. This is used in boundary enhancement images. Select at least 3 pixels above. These pixels must be located within the water surface area and represent the typical texture and brightness characteristics of the water surface. The selected pixels serve as the starting seed set for the flood filling. For example... Figure 5 The diagram shown illustrates the seed point selection interface; the crosshair intersection represents a selected seed point.
[0067] The selection of seed points should follow the principle of representativeness: Location dispersion: Seed points should be dispersed as much as possible in different locations of the water surface area to be segmented, covering possible bright areas, dark areas and intermediate areas.
[0068] Internality of the region: All seed points must be explicitly located within the water surface region and far from the waterfront boundary.
[0069] After selecting the seed points, record the coordinates of all seed points and their corresponding static background images in the empty scene. (rather than boundary enhancement image) The pixel values on the screen form a grayscale sample set, as shown below: Formula (12) in, Represents seed point Static background image in an empty scene grayscale values; , The total number of seed points selected.
[0070] The third step is adaptive region growth combined with boundary constraints.
[0071] This is the core of the improved flood filling algorithm in this invention. It upgrades the traditional growth criterion based on a fixed threshold to an adaptive criterion based on the statistical characteristics of seed points, and incorporates boundary enhancement information as a hard spatial constraint.
[0072] (1) Dynamically calculate the adaptive threshold range for region growth.
[0073] Calculate the gray set The mean and standard deviation are used to dynamically calculate the adaptive threshold interval for region growth, including: Calculate the gray set mean and standard deviation ; Define the adaptive threshold interval [ ] As shown below: Formula (13) in, As a scale factor, This is the absolute offset.
[0074] It is a scaling factor (for example, This determines the width of the growth interval relative to the dispersion of the sample data. The larger the value, the wider the range of grayscale variations it can tolerate.
[0075] It is a small absolute offset (for example, ), used to provide basic growth tolerance and prevent [damage / losses]. Too small a size results in an excessively narrow growth range.
[0076] This invention no longer uses a globally fixed threshold T, but instead uses a seed point grayscale sample set. Dynamically calculate an adaptive threshold range .
[0077] Calculate the sample set mean and standard deviation As shown below: Formula (14) (2) Judgment of regional growth and constraints: Starting from the seed point set, a queue data structure is used for region growing. Let the currently processed pixel be p, and its unvisited neighbor pixel be q. Pixel q is included in the water surface region. Both of the following conditions must be met simultaneously: Condition 1: Gray-scale similarity criterion (adaptive threshold) Pixel q in an empty scene static background image The grayscale value v(q) must fall within the dynamically calculated growth range, as shown below: Formula (15) Only pixels that have statistically similar grayscale characteristics to the water surface area represented by the seed point are considered part of the water surface.
[0078] Condition 2: Boundary Constraint Criteria The pixel value E(q) of pixel q on the edge response map E must be lower than a preset boundary threshold. As shown below: Formula (16) The growth process is prohibited from crossing pixels identified as strong boundaries. This effectively utilizes the edge information extracted in Section 2.1 to form a "firewall" that prevents the filled area from "overflowing" onto the shore, even if the grayscale of a certain spot on the shore is similar to that of the water surface.
[0079] For example, It can be taken as an edge response map The 80th-95th percentile of all pixel values.
[0080] Static background image of empty scene After all pixels have been traversed, the pixels included in the water surface area form the water surface area mask. .
[0081] like Figure 6 As shown, the black area represents the background region, i.e., the non-water surface area, where ship detection and tracking are not performed; the light-colored area represents the region mask. .
[0082] Step S2 is to process the static background image of the empty scene using an improved flood filling algorithm. Through edge enhancement, multiple sub-point selection and adaptive threshold region growing, the water surface region is accurately segmented and a water surface region mask is generated, providing a foundation for subsequent water surface target detection.
[0083] Step S3 includes steps S31-S34.
[0084] Water surface target detection is performed based on real-time acquired video stream data and the water surface region mask to obtain water surface target detection results, including: Obtain the current frame image based on real-time acquisition of video stream data. ; Based on the water surface area mask For the current frame image Foreground extraction is performed to obtain the foreground image. ; The foreground image is based on a local adaptive threshold. Binarization is performed to obtain the binarized foreground image. ; The binarized foreground image By performing closing operations and connected component analysis sequentially, a set of candidate regions is obtained. ; For each candidate region Perform multi-feature false alarm filtering to obtain feature vectors. ,Will The targets on the water surface are classified to obtain the detection results.
[0085] In step S2, the water surface region is precisely segmented (from the region mask image). After indicating that, this step aims to efficiently and accurately detect moving targets (such as ships) on the water surface in each frame of the real-time acquired video stream data, and effectively filter out false alarms such as water surface ripples and reflections.
[0086] Step S31: Foreground extraction based on water surface mask, using a water surface region mask. For the current frame image Foreground extraction is performed to obtain the foreground image. .
[0087] set up This is the current frame image of the real-time video stream at time t. (Water surface mask) The current frame is processed to mask interference from all non-water surface areas. The processed foreground image. Only pixel information within the water surface area is retained, as shown below: Formula (17) in, Indicates the water surface. This operation restricts all subsequent calculations to the region of interest (ROI), greatly reducing computational complexity and fundamentally eliminating interference from the background, such as the shoreline and buildings.
[0088] Step S32: Apply a local adaptive threshold to the foreground image. Binarization is performed to obtain the binarized foreground image. .
[0089] Due to uneven illumination on the water surface, segmentation using a single global threshold often yields poor results. Therefore, this method employs a local adaptive thresholding approach, such as the Sauvola or Niblack algorithm, to segment the water foreground image. Binarization is performed. Taking the Sauvola algorithm as an example, its core idea is to dynamically calculate the threshold based on the local mean and standard deviation of each pixel's neighborhood.
[0090] The foreground image is based on a local adaptive threshold. Binarization includes: Foreground image any pixel in The result after binarization Determined by the following formula: Formula (18) in, The local adaptive threshold is as follows: Formula (19) in, and pixels A surrounding area of size The mean and standard deviation of pixels within the window; This represents the maximum value of the dynamic range of the standard deviation. This is an adjustable parameter.
[0091] For example, Typically, 128 is used for 8-bit grayscale images; The value is typically between 0.2 and 0.5, and is used to control the sensitivity of the threshold to the standard deviation.
[0092] This method can adaptively adjust the segmentation threshold according to the brightness changes of local areas of the water surface, thereby effectively extracting the target contour with relatively high contrast from the water surface background with different brightness levels.
[0093] Step S33: The binarized foreground image... By performing closing operations and connected component analysis sequentially, a set of candidate regions is obtained. .
[0094] The binarized foreground image Performing a dilation-erosion closing operation yields a morphologically processed binary image, as shown below: Formula (20) in, As a structural element, , These represent morphological expansion and erosion operations, respectively. An 8-connectivity algorithm is used to perform connected component analysis on the morphologically processed binary image, grouping all interconnected foreground pixels into the same set and assigning a unique label to each set, thus obtaining a set of candidate regions. .
[0095] Foreground image Closing operations are applied to fill small holes inside the target and connect adjacent fractured parts. The closing operation is defined as dilation followed by erosion.
[0096] For example, For one or A rectangular or circular core.
[0097] Binarized foreground image There may be isolated noise points caused by ripples or reflections, or voids inside the target. Morphological post-processing is required to obtain a complete and clear target outline.
[0098] Connected component analysis is as follows: Connectivity analysis is performed on the morphologically processed binary image to identify and label all independent candidate target regions. Algorithms (such as the 8-connectivity algorithm) traverse the image, grouping all interconnected foreground pixels into the same set and assigning a unique label to each set. This yields a set of candidate regions. .
[0099] For each connected component Calculate its basic geometric properties, such as area. ,perimeter And the minimum bounding box. By setting an area threshold The aspect ratio threshold can initially filter out false targets that are too small (which may be noise) or have an extreme shape (which may be strip-shaped reflections).
[0100] Step S34: False alarm filtering based on PCA-SVM; for each candidate region Perform multi-feature false alarm filtering to obtain feature vectors. ,Will The targets on the water surface are classified to obtain the detection results.
[0101] For each candidate region Perform multi-feature false alarm filtering to obtain feature vectors. ,Will Classification includes: For each candidate region ,from The corresponding current frame image Extract texture features, shape features, and gradient features to construct a feature vector. ; Principal Component Analysis (PCA) was used to analyze the eigenvectors. Dimensionality reduction and decorrelation are performed to obtain feature vectors. ; eigenvectors The pre-trained support vector machine (SVM) is input for classification to obtain the water surface target detection results; The surface target detection results include real ship targets and false alarms.
[0102] Even after initial screening, candidate targets may still include false alarms caused by complex water surface ripples. To achieve accurate differentiation between targets and false alarms, this invention employs a method based on multi-feature fusion and machine learning classification.
[0103] Feature extraction: For each candidate region that passes the initial screening From its corresponding current frame image Extract a set of descriptive features from the original grayscale image patch to form a feature vector. These features include: Texture features: For example, contrast, energy, correlation, etc. calculated from the Local Binary Pattern (LBP) histogram and the Gray-Level Co-occurrence Matrix (GLCM); Shape characteristics: For example, the compactness of the region Rectangularity, Hu invariant moments, etc.; Gradient features: For example, histogram of gradient directions (HOG).
[0104] Feature vector , means as follows: Formula (21) in, This is a local binary pattern histogram feature; Features of the gray-level co-occurrence matrix; This is a gradient orientation histogram feature.
[0105] Feature vector It is a feature vector that can be dynamically expanded according to specific needs.
[0106] For eigenvectors Perform principal component analysis (PCA) for dimensionality reduction: Since the extracted features may have high dimensionality and redundancy, Principal Component Analysis (PCA) is first used to reduce the dimensionality and decorrelate the feature vectors. Let PCA find a projection matrix W to transform the high-dimensional feature vectors... This is mapped to a lower-dimensional, more discriminative feature space, as shown below: Formula (22) in, It is the mean of all eigenvectors.
[0107] Dimensionally reduced feature vectors It retains most of the variance information from the original data.
[0108] eigenvectors The pre-trained support vector machine (SVM) is input for classification to obtain the water surface target detection results.
[0109] The dimensionality-reduced feature vector The input is fed into a pre-trained Support Vector Machine (SVM) classifier. The SVM distinguishes between "real targets" (such as ships) and "false alarms" (such as ripples) by finding an optimal hyperplane.
[0110] This SVM classifier is trained offline using a training set containing a large number of labeled positive samples (ships) and negative samples (ripples, reflections, etc.). For a given candidate region, the SVM's decision function... The output category labels are as follows: Formula (23) in, Category labels for candidate regions; Let be the decision function; For the summation index, For support vectors, b are SVM model parameters. For the sample labels of the support vectors, For kernel functions (such as radial basis function (RBF) kernels); For the total number of support vectors, .
[0111] Positive samples, such as ships; Negative samples, such as ripples and reflections, are false alarms.
[0112] for If the result calculated within the parentheses is greater than or equal to 0, output +1; if the result calculated within the parentheses is less than 0, output -1.
[0113] for The corresponding real category label has a value of +1 or -1.
[0114] b represents the Lagrange multiplier; b represents the bias term. The bounding boxes (BBoxi) of candidate regions identified as true targets (Label=1) by the SVM classifier are confirmed as the final detected true ship targets. In this way, the method can effectively distinguish false alarms with complex shapes and textures, thus achieving high-precision surface target detection.
[0115] Step S3 aims to accurately detect and identify moving targets (such as ships) on the water surface based on real-time video stream data and the generated water surface area mask, through foreground extraction, binarization processing, morphological analysis, and multi-feature classification, while effectively filtering out false alarm interference.
[0116] In summary, the water surface target detection method based on the improved flood filling algorithm of this invention has the following beneficial effects: 1. This invention, through an improved flood filling algorithm, combined with edge enhancement processing and dynamic adaptive threshold interval calculation, can more accurately segment water surface areas, reduce background interference, improve the accuracy of water surface target detection, and enhance the detection precision of water surface targets; the improved flood filling algorithm can flexibly adapt to various bridge monitoring scenarios without retraining the model or adjusting the threshold for each new monitoring angle, thus enhancing the versatility and generalizability of the method. 2. This invention utilizes multi-fuzzy scale background modeling and residual minimization strategies to generate high-quality static background images of empty scenes, effectively addressing changes in different lighting conditions and time periods, and improving the algorithm's adaptability to complex environments; 3. This invention utilizes multi-feature false alarm filtering, combining texture, shape and gradient features, and effectively distinguishes between real targets and false alarms through PCA dimensionality reduction and SVM classification, thereby improving the reliability of detection results and reducing the false alarm rate of water surface targets; 4. This invention constructs a dynamic background model using multiple frames of images, effectively eliminating moving targets such as ships without the need for precise labeling of river areas, retaining only stable water surface areas, avoiding the tedious manual labeling work in traditional methods, and improving deployment efficiency; 5. This invention adopts a seed point selection strategy that combines image sharpening with user-interactive point selection, which enhances the robustness of water surface area extraction, effectively copes with image differences under different lighting conditions, water surface reflection and different monitoring angles, and significantly improves the segmentation accuracy of flood filling.
[0117] Those skilled in the art will understand that all or part of the processes of the methods described in the above embodiments can be implemented by a computer program instructing related hardware, and the program can be stored in a computer-readable storage medium. The computer-readable storage medium may be a disk, optical disk, read-only memory, or random access memory, etc.
[0118] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for detecting water surface targets based on an improved flood filling algorithm, characterized in that, include: Video stream data of the water surface area covering different time periods and lighting conditions was collected and preprocessed to generate a static background image of an empty scene. ; The improved flood filling algorithm was used to process the static background image of the empty scene. Perform water surface area segmentation processing to generate a water surface area mask; Water surface target detection is performed based on real-time acquired video stream data and the water surface area mask to obtain water surface target detection results.
2. The water surface target detection method based on the improved flood filling algorithm according to claim 1, characterized in that, The video stream data of the water surface area is preprocessed to generate a static background image of an empty scene. ,include: Sparse frame extraction is performed on the video stream data of the water surface area to extract multiple frames of images, which are used as background modeling images. Based on preset A set of fuzzy scales is used to model each frame of the background image, respectively. Blurring was performed at different scales to obtain blurred images of each frame's background modeling image at each blur scale; among them... ; Pixel-level averaging is performed on all blurred images at each blur scale to obtain the background image corresponding to each blur scale. The weights of the background images corresponding to each fuzziness scale are calculated using a residual minimization strategy. These weighted images are then fused to obtain a static background image of an empty scene. .
3. The water surface target detection method based on the improved flood filling algorithm according to claim 2, characterized in that, A preset set includes A set of fuzzy scales with different standard deviations , Small standard deviation corresponds to low fuzziness scale, and large standard deviation corresponds to high fuzziness scale; Each frame of the background modeling image , Each fuzzy scale is convolved with the corresponding two-dimensional Gaussian kernel; In the Individual scale Below, background modeling image With the corresponding Gaussian kernel Convolution is performed to obtain the corresponding blurred image. As shown below: ; in, Model the pixel coordinates in the background image; For the first Frame background modeling image in the first Pixel values after Gaussian blurring at each blur scale; For the first Frame background modeling image; The standard deviation is The two-dimensional Gaussian kernel function; The symbol for convolution; The size of a Gaussian half-window; These are the relative coordinates of the Gaussian kernel in the horizontal and vertical directions, respectively. The range of values is .
4. The water surface target detection method based on the improved flood filling algorithm according to claim 1, characterized in that, The improved flood filling algorithm was used to process the static background image of the empty scene. Water surface area segmentation processing includes: For the static background image of the empty scene Perform edge enhancement processing and define an edge response map to generate a boundary enhancement image. ; The boundary enhancement image Multiple pixels located scattered within the water surface area are selected as seed points. The values of these seed points in the static background image of the empty scene are then calculated. The gray values in the data are used to obtain multiple gray values to form a gray set. ; Calculate the gray set The mean and standard deviation are used to dynamically calculate the adaptive threshold interval for region growth; A queue structure is used to perform region growth traversal starting from the seed point set. For the neighboring pixels of the current pixel, if both conditions 1 and 2 are satisfied, they are included in the water surface region: Condition 1: Neighboring pixels are in an empty scene with a static background image. The grayscale values are within the adaptive threshold range; Condition 2: The value of the neighboring pixel on the edge response map is lower than the preset boundary threshold. ; Static background image of empty scene After all pixels have been traversed, the pixels included in the water surface area form the water surface area mask. .
5. The water surface target detection method based on the improved flood filling algorithm according to claim 4, characterized in that, The edge enhancement method using structure tensor is applied to the static background image of the empty scene. Perform edge enhancement processing and define the edge response map. Generate boundary enhancement image ,include: The Sobel operator is used to calculate the static background image with empty background. The gradient vector of each pixel (x, y); Within the neighborhood of pixel (x, y), a Gaussian weighted average of the outer product of the gradient vectors is applied to obtain the positive semidefinite structure tensor. ; Extract the semidefinite structure tensor eigenvalues and , ; based on and Define edge response graph ,as follows: ; Where c is a small positive constant; Based on the edge response map The boundary enhancement image is generated by weighted fusion of a static background image with an empty background. ,as follows: ; in, This is the enhancement coefficient.
6. The water surface target detection method based on the improved flood filling algorithm according to claim 4, characterized in that, Calculate the gray set The mean and standard deviation are used to dynamically calculate the adaptive threshold interval for region growth, including: Calculate the grayscale set mean and standard deviation ; Define the adaptive threshold interval As shown below: ; in, As a scale factor, This is the absolute offset.
7. The water surface target detection method based on the improved flood filling algorithm according to claim 1, characterized in that, Water surface target detection is performed based on real-time acquired video stream data and the water surface region mask to obtain water surface target detection results, including: Obtain the current frame image based on real-time acquisition of video stream data. ; Based on the water surface area mask For the current frame image Foreground extraction is performed to obtain the foreground image. ; The foreground image is based on a local adaptive threshold. Binarization is performed to obtain the binarized foreground image. ; The binarized foreground image By performing closing operations and connected component analysis sequentially, a set of candidate regions is obtained. ; For each candidate region Perform multi-feature false alarm filtering to obtain feature vectors. ,Will The targets on the water surface are classified to obtain the detection results.
8. The water surface target detection method based on the improved flood filling algorithm according to claim 7, characterized in that, The foreground image is based on a local adaptive threshold. Binarization includes: Foreground image any pixel in The result after binarization Determined by the following formula: ; in, The local adaptive threshold is as follows: ; in, pixels A surrounding area of size The mean and standard deviation of pixels within the window; This represents the maximum value of the dynamic range of the standard deviation. This is an adjustable parameter.
9. The water surface target detection method based on the improved flood filling algorithm according to claim 8, characterized in that, The binarized foreground image Performing a dilation-erosion closing operation yields a morphologically processed binary image, as shown below: ; in, As a structural element, , These represent morphological expansion and erosion operations, respectively. An 8-connectivity algorithm is used to perform connected component analysis on the morphologically processed binary image, grouping all interconnected foreground pixels into the same set and assigning a unique label to each set, thus obtaining a set of candidate regions. .
10. The water surface target detection method based on the improved flood filling algorithm according to claim 9, characterized in that, For each candidate region Perform multi-feature false alarm filtering to obtain feature vectors. ,Will Classification includes: For each candidate region ,from The corresponding current frame image Extract texture features, shape features, and gradient features to construct a feature vector. ; Principal Component Analysis (PCA) was used to analyze the eigenvectors. Dimensionality reduction and decorrelation are performed to obtain feature vectors. ; eigenvectors The pre-trained support vector machine (SVM) is input for classification to obtain the water surface target detection results; The surface target detection results include real ship targets and false alarms.