Cucumber leaf disease image segmentation method based on boundary perception guidance
By using a boundary-aware guided method, virtual boundary trajectories are generated and embedded with energy functionals. Combined with Bayesian information criteria and shape prior constraints, the problem of accurate segmentation of adhering lesions in cucumber leaf disease images is solved, achieving automated and accurate lesion separation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- QINGDAO AGRI UNIV
- Filing Date
- 2026-05-09
- Publication Date
- 2026-06-19
AI Technical Summary
In cucumber leaf disease images, existing technologies cannot accurately separate adhering lesions when multiple lesions merge into large, irregular areas, leading to inaccurate lesion counting. Existing methods also exhibit evolutionary stagnation or false concave boundaries in the merged areas, making accurate segmentation impossible.
By using a boundary-aware guided method, cucumber leaf images are acquired, an initial boundary response map is generated, continuous homology analysis is performed to extract topological loop features, candidate split points are identified, virtual boundary trajectories are generated and embedded with energy functionals, and iterative solutions are performed by combining Bayesian information criteria and shape prior constraints to output an independent segmentation mask.
It achieves accurate separation of adherent lesions, improves the automation level and repeatability of segmentation results, eliminates the need for manual annotation, and can adaptively determine the number of lesions and suppress false segmentation that deviates excessively from the elliptical shape.
Smart Images

Figure CN122244087A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and more specifically to a method for segmenting cucumber leaf disease images based on boundary awareness guidance. Background Technology
[0002] Automatic identification and segmentation of cucumber leaf diseases are fundamental to achieving quantitative disease assessment and precise pesticide application. Current deep learning-based image segmentation methods typically employ encoder-decoder structures (such as U-shaped networks) for pixel-level classification of lesion regions, or combine traditional edge detection with region growing to extract lesion contours.
[0003] In images of cucumber leaf diseases, when multiple lesions develop to the middle and late stages and merge to form irregular large areas, the true boundary at the fusion point of adjacent lesions disappears completely due to the complete infection of healthy tissue. This causes the energy functional based on the boundary response map to be unable to provide inward contraction force or outward expansion force, resulting in evolutionary stagnation, bottleneck effect, or false concave boundary in the fusion region of existing level set or graph cut iterative optimization frameworks. Consequently, it is impossible to achieve accurate separation of adherent lesions and counting of individual lesions. Summary of the Invention
[0004] The purpose of this invention is to provide a boundary-aware guided image segmentation method for cucumber leaf diseases to solve the problems mentioned above.
[0005] The objective of this invention can be achieved through the following technical solutions: A boundary-aware guided image segmentation method for cucumber leaf diseases includes the following steps: S1: Acquire cucumber leaf images, and after denoising, contrast enhancement and color space conversion, generate an initial boundary response map through edge detection; S2: Perform persistent homology analysis on the initial boundary response map to extract the topological ring features of the adherent lesion region, and automatically identify candidate split points based on the persistent interval of the topological ring and the local curvature extremum. S3: Based on candidate split points, virtual boundary trajectories are generated between adjacent split points through geodesic distance transformation and local curvature flow, and the virtual boundary trajectories are embedded into the energy functional as topological constraint terms. S4: Based on the number of topological rings and the statistics of regional colors, the number of lesion instances is dynamically estimated using the Bayesian information criterion, a multiphase competition framework is constructed, and elliptical fitting is performed on each phase region to apply shape prior constraints. S5: Iteratively solve the energy functional containing topological constraints and shape prior constraints. In each iteration, update the level set function of each phase and the virtual boundary trajectory in turn until convergence, and output the independent segmentation mask of each lesion.
[0006] As a further aspect of the present invention: S2 specifically includes: Using the pixel values of the boundary response map as weights, construct lower level set complexes under different thresholds, calculate the occurrence threshold and disappearance threshold of each connected component, and construct a zero-durability graph; Extract a topological ring in the durability graph whose persistence interval exceeds a preset threshold, and obtain the geometric center of each ring; Calculate the local curvature of the boundary response map within the neighborhood of the geometric center, and select the point with the minimum curvature as the candidate split point.
[0007] As a further aspect of the present invention: the construction of the zero-maintenance graph specifically includes: Sort all pixels in the boundary response map by response value from smallest to largest, activate each pixel in turn, and mark the connectivity of its neighboring activated pixels; When a newly activated pixel connects two independent connected components, the component with the smaller occurrence threshold is marked as disappearing. The disappearance threshold is taken as the response value of the current pixel. At the same time, the occurrence threshold of the merged component is taken as the smaller of the occurrence thresholds of the two components. After traversing all pixels, the occurrence threshold and disappearance threshold of each connected component are output to form a zero-durability graph.
[0008] As a further aspect of the present invention: S3 specifically includes: Using each candidate split point as the source point, calculate the geodesic distance from all pixels in the image to the corresponding source point to obtain the geodesic distance field; A saddle point in the geodesic distance field is selected between adjacent split points as a path guide point, and the split points and the saddle point are connected along the descent direction of the geodesic distance to form an initial trajectory; Apply local curvature flow to the initial trajectory for iterative updates. In each iteration, move each trajectory point along the negative curvature direction until the change in trajectory curvature is less than a preset threshold, and output the smoothed virtual boundary trajectory.
[0009] As a further aspect of the present invention: the calculation of the geodesic distance from all pixels in the image to the corresponding source point specifically includes: Calculate the local entropy value for each pixel, which is obtained based on the probability distribution of boundary response values within the pixel's neighborhood; The geodesic distance increment between adjacent pixels is defined as the product of the absolute value of the difference between the local entropy values of the two pixels and the Euclidean distance between the pixels; The geodesic distance of each pixel is repeatedly updated to the minimum value of the geodesic distance of all its neighboring pixels plus the corresponding geodesic distance increment, until the global update amount is lower than the preset threshold. The geodesic distance value of each pixel is then output to form a geodesic distance field.
[0010] As a further aspect of the present invention: S4 specifically includes: Using the number of topological rings as the baseline number, and adding or subtracting one from the baseline number, we obtain three candidate numbers; For each candidate number, iterative self-organizing clustering is used to divide the hue and saturation values of all pixels into the corresponding number of color clusters, and the average distance from the pixel in each color cluster to the cluster center is calculated as the negative log-likelihood. Add the negative logarithm of the likelihood of each candidate number to the penalty term, where the penalty term is the natural logarithm of the number of candidates multiplied by the total number of pixels. Select the candidate number with the smallest sum as the number of lesion instances.
[0011] As a further aspect of the present invention: the step of using iterative self-organizing clustering to divide the hue and saturation values of all pixels into a corresponding number of color clusters specifically includes: The hue and saturation values of each pixel are used as a two-dimensional vector, and the variance of the hue values in the neighborhood of each pixel is calculated. The reciprocal of the variance is taken as the local weight. A number of pixels are randomly selected as the initial cluster centers, and each cluster center carries the local weight of the corresponding pixel. In each iteration, the weighted Euclidean distance from each pixel to each cluster center is calculated. The pixel's own weight and the cluster center weight are multiplied by the sum of squared coordinate differences in the weighted Euclidean distance, and the pixel is assigned to the cluster with the smallest weighted distance. Update each cluster center to the weighted average position of all pixels under its jurisdiction, repeat the iteration until the sum of changes in cluster centers is less than a preset threshold, and output the color cluster affiliation of each pixel.
[0012] As a further aspect of the present invention: S5 specifically includes: By fixing the current virtual boundary trajectory, piecewise constant constraints are applied to the level set functions of each phase, and the updated field of each level set function is obtained by solving the Poisson equation with topological constraints. By fixing the updated phase level set functions, the update of the virtual boundary trajectory is transformed into a curve evolution problem of minimizing curvature energy, and an implicit difference scheme is used to iterate the position of each trajectory point. Substitute the updated virtual boundary trajectory into the topological constraint terms and recalculate the energy functional value; Compare the current energy value with the energy value of the previous round. When the absolute difference is less than the preset threshold, the iteration is terminated, and the positive domain of the level set function corresponding to each lesion is output as an independent segmentation mask.
[0013] As a further aspect of the present invention: the output process of the level set function is as follows: Each pixel is initially assigned a phase identifier based on its color cluster, and a directed distance field is constructed using the pixel region boundary of each phase identifier as the zero level set, such that pixels inside the zero level set take negative distance values and pixels outside the zero level set take positive distance values. A sign regularization constraint is applied to the directed distance field of each phase. The local distance is recalculated by flipping isolated pixels with different signs after comparing the consistency of the distance signs in the neighborhood pixel by pixel. After superimposing the directed distance fields of all phases, normalize them so that the sum of the distance values of each pixel in each phase is zero, and output the level set function of each phase.
[0014] The beneficial effects of this invention are: (1) This invention extracts the topological loop features of the adherent lesion region by performing persistent homology analysis on the initial boundary response map, and automatically identifies candidate split points based on persistent intervals and local curvature extrema. Then, virtual boundary trajectories are generated between adjacent split points and embedded as topological constraint terms into the energy functional. In regions where lesion fusion leads to the complete loss of the real boundary, this method can utilize virtual boundary trajectories to provide additional evolutionary driving force, achieving accurate separation of adherent lesions and improving the ability of the segmentation results to preserve the individual morphology of the lesions.
[0015] (2) Based on the number of topological rings and regional color statistics, this invention dynamically estimates the number of lesion instances using the Bayesian information criterion and constructs a multi-phase competition framework to simultaneously perform elliptical fitting on each phase region to apply shape prior constraints. This method eliminates the need for manual labeling of seed points or pre-setting the number of lesions, adaptively determines the number of lesions in the image, and suppresses false segmentation that deviates excessively from the elliptical shape through shape prior constraints. Thus, it obtains an independent segmentation mask for each lesion without interactive intervention, improving the automation level of the segmentation process and the repeatability of the results. Attached Figure Description
[0016] The invention will now be further described with reference to the accompanying drawings.
[0017] Figure 1 This is a flowchart of the method of the present invention. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] Please see Figure 1 As shown, this invention is a boundary-aware guided image segmentation method for cucumber leaf diseases, comprising the following steps: S1: Acquire cucumber leaf images, and after denoising, contrast enhancement and color space conversion, generate an initial boundary response map through edge detection; S2: Perform persistent homology analysis on the initial boundary response map to extract the topological ring features of the adherent lesion region, and automatically identify candidate split points based on the persistent interval of the topological ring and the local curvature extremum. S3: Based on candidate split points, virtual boundary trajectories are generated between adjacent split points through geodesic distance transformation and local curvature flow, and the virtual boundary trajectories are embedded into the energy functional as topological constraint terms. S4: Based on the number of topological rings and the statistics of regional colors, the number of lesion instances is dynamically estimated using the Bayesian information criterion, a multiphase competition framework is constructed, and elliptical fitting is performed on each phase region to apply shape prior constraints. S5: Iteratively solve the energy functional containing topological constraints and shape prior constraints. In each iteration, update the level set function of each phase and the virtual boundary trajectory in turn until convergence, and output the independent segmentation mask of each lesion.
[0020] In S1, cucumber leaf images are acquired, and after denoising, contrast enhancement, and color space conversion, an initial boundary response map is generated through edge detection, specifically including: An industrial camera mounted on a mobile acquisition platform was used to capture raw color images of cucumber leaves under natural light conditions, with each channel containing three channels (red, green, and blue) and an 8-bit bit depth. During acquisition, the camera was maintained at a distance of 30 cm from the leaf to ensure clear imaging of diseased areas.
[0021] The acquired red, green, and blue images were denoised. Median filtering was used with a 3-pixel by 3-pixel window. Each pixel in the image was iterated over, and the median value of all pixels within the window was used to replace the current pixel value, eliminating isolated noise points caused by dust on the leaf surface or uneven lighting. After denoising, histogram equalization was used to enhance image contrast: the pixel grayscale distribution of each color channel was statistically analyzed, and the cumulative distribution function was calculated to map the original grayscale to the full range of 0 to 255, making the grayscale difference between the edge of lesions and healthy leaf tissue more significant.
[0022] The contrast-enhanced red-green-blue image is converted to a hue-saturation-luminance color space. During the conversion, the red, green, and blue channel components are first normalized to the 0-1 range. Then, the hue, saturation, and luminance components of each pixel are calculated using a standard conversion formula. The hue and saturation components are retained for subsequent processing, while the luminance component is used to assist in edge detection.
[0023] An initial boundary response map is generated using an edge detection operator based on gradient magnitude. Specifically, the first derivative of each pixel in the horizontal and vertical directions is calculated for the luminance component to obtain the gradient magnitude; the gradient magnitudes are calculated for the hue and saturation components respectively, and the maximum value of the three is taken as the boundary response value of that pixel. After traversing the entire image, the boundary response values are normalized to the 0-1 range to obtain a single-channel grayscale image with the same size as the original image, i.e., the initial boundary response map.
[0024] In S2, persistent homology analysis is performed on the initial boundary response map to extract the topological ring features of the adherent lesion region. Candidate split points are automatically identified based on the persistent intervals and local curvature extrema of the topological rings, specifically including: To perform persistent homology analysis on the initial boundary response map, a series of lower level set complexes are first constructed. The response value of each pixel in the initial boundary response map is used as a weight, with the response value ranging from 0 to 1. A series of incremental thresholds, starting from 0 and ending at 1, are set with a step size of 0.01. At each threshold, all pixels with response values less than or equal to the current threshold are selected. These pixels and their adjacency relationships constitute a subgraph at that threshold, which is the lower level set complex. Adjacency relationships are defined as four-neighbor connections, meaning each pixel is connected only to pixels in its four directions: above, below, left, and right.
[0025] To calculate the occurrence and disappearance thresholds for each connected component, all pixels in the initial boundary response map are first sorted in ascending order of their response values, resulting in a pixel sequence. Initially, no pixels are activated. Each pixel is then activated sequentially according to the sorted order: the current pixel is marked as activated, and it is checked whether any other activated pixels exist within its four neighboring areas. This process gradually constructs the connected component structure under different thresholds.
[0026] When a newly activated pixel connects to two previously independent connected components, a merge and disappearance determination is performed. The specific rules are as follows: compare the occurrence thresholds of the two connected components; mark the component with the smaller occurrence threshold as disappearing, and set its disappearance threshold to the current pixel's response value. Simultaneously, the two components are merged into a new connected component, with the new component's occurrence threshold being the smaller of the two original component occurrence thresholds. If the newly activated pixel connects to only one existing connected component, the pixel is added to that component, and no disappearance event occurs. If the newly activated pixel does not connect to any activated pixels, a new connected component is created, and its occurrence threshold is set to the current pixel's response value.
[0027] After traversing all pixels, an occurrence threshold is recorded for each connected component. Except for the last largest connected component covering the entire image, a disappearance threshold is recorded for each of the remaining components. The occurrence and disappearance thresholds of all connected components are output in pairs. With the occurrence threshold as the x-axis and the disappearance threshold as the y-axis, each component corresponds to a coordinate point. The scatter plot formed by these points is the zero-persistence persistence plot. Points below the diagonal represent components with occurrence thresholds less than the disappearance threshold, and their vertical distance from the diagonal is the persistence interval of that component.
[0028] When extracting topological ring features from the adhesion lesion region, a persistence map is further analyzed. The matrix simplification method in the standard persistent cohomology algorithm is used to process the boundary matrix of the lower level set complex, obtaining one-dimensional cohomology generators. Each one-dimensional cohomology generator corresponds to a topological ring, and the occurrence threshold and disappearance threshold of this ring are recorded; the difference between the two is the persistence interval. The median of the persistence intervals of all topological rings is calculated, and a preset threshold is set to this median. Topological rings with persistence intervals greater than this median are selected as valid rings. For each valid ring, the coordinates of all pixels it contains are obtained, and the average of these pixel x-coordinates is calculated as the x-coordinate of the ring's geometric center, and the average of the y-coordinates is calculated as the y-coordinate of the ring's geometric center.
[0029] The local curvature of the initial boundary response map is calculated within the neighborhood of each geometric center. The neighborhood is defined as a circular region with a radius of 10 pixels centered at the geometric center. For each pixel within this region, a 3-pixel multiplied window is taken centered on that pixel. The second-order differences of the boundary response value in the horizontal and vertical directions within the window are calculated. The square root of the sum of the squares of the horizontal and vertical second-order differences is taken to obtain the curvature value of that pixel. After traversing all pixels within the region, pixels with curvature values less than the curvature values of all pixels in their eight neighborhoods are identified as curvature minima. These curvature minima are output as candidate split points; if no curvature minima exist within the region, the geometric center itself is output as a candidate split point.
[0030] In S3, based on candidate split points, virtual boundary trajectories are generated between adjacent split points through geodesic distance transformation and local curvature flow. These virtual boundary trajectories are then embedded as topological constraint terms into the energy functional, specifically including: Before calculating the geodesic distance using each candidate split point as the source point, it is first necessary to construct the local cost function required for the geodesic distance metric. For each pixel in the initial boundary response map, its local entropy value is defined. The specific calculation process is as follows: Take a square neighborhood window centered on the pixel with a side length of 7 pixels, and count the boundary response values of all pixels within the window. Divide the boundary response values from 0 to 1 into 16 equal intervals, each interval having a width of 0.0625. Count the frequency of pixels appearing in each interval, i.e., the number of pixels in that interval divided by the total number of pixels in the window (49), to obtain the probability distribution. The formula for calculating the local entropy value is: ; in, This represents the local entropy value of the pixel. Indicates the first The frequency of a pixel occurring within a response value interval. If the frequency in a certain interval is zero, then the contribution of that term is zero. The local entropy value reflects the degree of disorder in the boundary response values within the window; a larger entropy value indicates richer boundary variations within the window, and vice versa.
[0031] After obtaining the local entropy value of each pixel, the geodesic distance increment between adjacent pixels is defined. For any two adjacent pixels (four-neighbor connected, i.e., in the up, down, left, and right directions), let their local entropy values be respectively... and The Euclidean distance between two pixels on the image plane is 1 (the distance between adjacent pixels). Therefore, the geodesic distance increment... Defined as the product of the absolute value of the difference in local entropy between two pixels and the Euclidean distance, i.e.: ; Since the Euclidean distance is always 1, the geodesic distance increment simplifies to the absolute value of the difference between the local entropy values of two pixels. The larger this increment value, the more significant the difference in boundary response texture features between the two pixels, and the higher the cost of a path crossing that edge.
[0032] For each candidate split point, it is treated as an independent source point. The geodesic distance from all pixels in the entire image to this source point is calculated, thus obtaining the geodesic distance field for each source point. During initialization, the geodesic distance of each source point itself is set to 0, and the geodesic distance of all other pixels is set to a maximum value, which is 10 times the sum of the image width and height.
[0033] A multi-source iterative relaxation algorithm is used to simultaneously update the geodesic distance field of all source points. In each iteration, every pixel in the image is traversed. For the current pixel, its four neighboring pixels (top, bottom, left, and right) are examined. For each neighboring pixel, the current geodesic distance of that neighboring pixel is calculated plus the geodesic distance increment between the current pixel and that neighboring pixel to obtain a candidate distance value. The minimum value among all four candidate distance values is taken as the new geodesic distance of the current pixel. The global average update amount is obtained by summing the absolute values of the differences between the new geodesic distances of all pixels and the geodesic distances of the previous round, and dividing by the total number of pixels in the image. If the global average update amount is less than 0.001, the iteration stops; otherwise, the next iteration continues. After the iteration ends, the geodesic distance value from each pixel to the source point is output, forming the geodesic distance field of that source point.
[0034] For each pair of adjacent candidate split points (defined as two split points with a Euclidean distance of less than 50 pixels being adjacent), obtain two geodesic distance fields with these two split points as their source points. Add the values of the two geodesic distance fields at the same pixel location to obtain the sum distance field. Find saddle points in the sum distance field: a saddle point is a pixel whose sum distance value is less than the sum distance values of all four of its neighboring pixels, and simultaneously greater than the sum distance values of its two diagonally opposite pixels. Traverse all pixels and select the top 3 saddle points with the smallest sum distance values as candidate path guide points.
[0035] Starting from each split point, a path is traced along the descent direction of the geodesic distance to reach the saddle point. The specific tracing method is as follows: starting from a split point, find the pixel in its four neighboring areas whose geodesic distance value is smaller than the current point and has the largest difference, and use this as the next point. Repeat this process until the saddle point is reached. Similarly, starting from another adjacent split point, the path is traced to the same saddle point. The two tracing paths are merged to obtain a continuous pixel sequence from the split point through the saddle point to the adjacent split point, which serves as the initial virtual boundary trajectory.
[0036] The initial virtual boundary trajectory is represented as an ordered sequence of pixel coordinates. For each trajectory point (excluding endpoints), its local curvature is calculated. The local curvature is calculated as follows: take the point and its two immediate and next-to-last adjacent points (three points in total), calculate the cosine of the angle between the vector from the previous point to the current point and the vector from the current point to the next point, and subtract this cosine from 1 to obtain an approximate curvature value. Then, move the trajectory point along the negative curvature direction: the negative curvature direction points towards the concave side of the trajectory, and the movement step size is 0.2 times the curvature value. Simultaneously, a smoothing constraint is applied to bring each trajectory point closer to the average position of its left and right adjacent points, with a weighting coefficient of 0.5. After all points are updated synchronously, the pixelated representation of the trajectory is recalculated.
[0037] After each iteration, the sum of the squares of the movement distances of all trajectory points is calculated and divided by the total number of trajectory points to obtain the average movement distance. The iteration stops when the average movement distance is less than 0.1 pixels. The output pixel sequence at this point is the smoothed virtual boundary trajectory. This virtual boundary trajectory is then embedded as a topological constraint term into the energy functional. Specifically, a line integral term along the virtual boundary trajectory is added to the energy functional. The integral value is the negative of the boundary response value of each pixel on the trajectory. This reduces the energy at the virtual boundary trajectory position during the evolution of the level set, thereby guiding the segmentation curve towards this trajectory.
[0038] In S4, based on the number of topological rings and regional color statistics, the number of lesion instances is dynamically estimated using the Bayesian information criterion, and a multiphase competition framework is constructed. Simultaneously, ellipse fitting is performed on each phase region to apply shape prior constraints, specifically including: From the topological rings extracted in step S2 whose persistence interval exceeds a preset threshold, the total number of topological rings is counted, and this number is used as the baseline lesion instance count. Centered on the baseline count, the baseline count is decreased by one and increased by one, respectively, to obtain three candidate lesion instance counts. If the value after decreasing the baseline count by one is less than 1, it is fixed at 1; if the value after increasing the baseline count by one is greater than 20, it is fixed at 20.
[0039] For the cucumber leaf image that has been converted to the hue-saturation-luminance color space in step S1, extract the hue component value and saturation component value of each pixel. The hue component value ranges from 0 degrees to 360 degrees, and the saturation component value ranges from 0 to 1. Combine the hue value and saturation value of each pixel into a two-dimensional vector, which will be used as the feature for subsequent clustering.
[0040] For each pixel, a square neighborhood window with sides of 5 pixels is taken, centered on that pixel. The variance of the hue values of all pixels within the window is calculated: first, the arithmetic mean of the hue values within the window is calculated; then, the sum of the squares of the differences between each hue value and the mean is calculated, divided by the total number of pixels in the window (25) to obtain the variance. The reciprocal of this variance is then calculated; if the variance is 0, the reciprocal is taken as 1000. This reciprocal is the local weight of the pixel. The local weight reflects the uniformity of the hue in the pixel's neighborhood; the smaller the variance, the greater the weight, indicating that the pixel is in a hue-consistent region and is more likely to represent a typical color cluster center.
[0041] For each candidate lesion instance, an equal number of pixels are randomly selected from all pixels as initial cluster centers. Each cluster center carries the local weight of its corresponding pixel. In each iteration of clustering, the weighted Euclidean distance from each pixel to each cluster center is calculated: first, the square of the difference between the pixel's hue value and the cluster center's hue value is calculated, and then the square of the difference between the pixel's saturation value and the cluster center's saturation value is added to obtain the squared Euclidean distance; then, the pixel's own local weight is multiplied by the local weight of the cluster center, and then multiplied by the squared Euclidean distance value to obtain the weighted Euclidean distance. The current pixel is assigned to the cluster with the smallest weighted Euclidean distance.
[0042] After all pixels have been assigned, for each cluster, calculate the weighted arithmetic mean of the hue values of all pixels within it: multiply the hue value of each pixel by its local weight, sum the results, and then divide by the sum of the local weights of all its constituent pixels to obtain the new cluster center hue value. Similarly, calculate the new cluster center saturation value. After obtaining the new cluster centers, calculate the Euclidean distance between the new and old cluster centers: the square root of the sum of the squares of the hue difference and the squares of the saturation difference. Sum the distances of all cluster center changes to obtain the total change. Stop iterating when the total change is less than 0.01; otherwise, repeat the assignment and update process using the new cluster centers until the condition is met or the maximum number of iterations (100) is reached. After the iteration ends, output the color cluster assignment for each pixel.
[0043] For each candidate lesion instance number, after clustering, the Euclidean distance from all pixels within each color cluster to the cluster center is calculated, and the arithmetic mean of all pixel Euclidean distances is obtained as the average distance. This average distance is used as an estimate of the negative logarithm of the likelihood. Then, a penalty term is calculated: the penalty term equals the number of candidate instances multiplied by the natural logarithm of the total number of pixels. The total number of pixels is known, and the natural logarithm is calculated using a lookup table or series expansion method. The negative logarithm of the likelihood is added to the penalty term to obtain the Bayesian information criterion value for that candidate number. The Bayesian information criterion values for the three candidate numbers are calculated separately, and the candidate number corresponding to the minimum value is selected as the final number of lesion instances. Subsequently, a multiphase competition framework is constructed using this number of instances, and ellipse fitting is performed on the coordinates of all pixels within each phase region. The ratio of the major and minor axes of the fitted ellipse is used as a shape prior constraint, which is used in the subsequent energy functional to penalize segmentation results that deviate excessively from the elliptical shape.
[0044] In S5, the energy functional containing topological constraints and shape prior constraints is solved iteratively. In each iteration, the level set functions of each phase and the virtual boundary trajectory are updated sequentially until convergence. The independent segmentation mask for each lesion is output, specifically including: At the start of each iteration, the current virtual boundary trajectory is kept fixed. Piecewise constant constraints are applied to the level set functions of each phase, treating the level set function values within each phase region as constants. A Poisson equation with topological constraints is constructed: the left-hand side of the equation is the Laplace operator of the level set function, i.e., the sum of the second-order partial derivatives of the level set function in the horizontal and vertical directions; the right-hand side of the equation is the negative gradient of the topological constraint term, which is composed of the line integral on the virtual boundary trajectory generated in step S3. The Poisson equation is discretized using a five-point difference scheme, treating the level set function value of each pixel as an unknown, forming a system of linear equations. The system of equations is solved using a successive over-relaxation iteration method, with the number of iterations set to 500 and the relaxation factor set to 1.5. The iteration stops when the maximum change in the level set function values of all pixels between two adjacent iterations is less than 0.001, yielding the update field of the level set functions of each phase.
[0045] By fixing the updated level set functions of each phase, the update of the virtual boundary trajectory is transformed into a curve evolution problem that minimizes curvature energy. Each virtual boundary trajectory is represented as an ordered sequence of pixels. For each internal trajectory point (non-endpoint), vectors of its preceding and following points are constructed, and the curvature at that point is calculated. The curvature is approximated by the sine of the angle between adjacent vectors. An implicit difference scheme is used for position iteration: the update equation of the trajectory point is written as an implicit expression for the new position, i.e., the new position equals the old position plus the time step multiplied by the curvature force, where the curvature force is determined by the curvature of the new position. The time step is set to 0.1. The implicit equation is rewritten as a linear system, where the new position of each trajectory point is associated with the new positions of its neighbors. The tridiagonal linear system is solved using a chasing method, and the updated position of each trajectory point is obtained after 20 iterations.
[0046] Substitute the updated virtual boundary trajectory into the topological constraint term, and recalculate the total energy functional value, including the region term, boundary term, topological constraint term, and shape prior constraint term. The region term is calculated based on the color consistency of pixels within each phase level set function; the boundary term is calculated by accumulating the response values of the trajectory positions on the initial boundary response map; and the shape prior constraint term is calculated based on the degree to which the ratio of the major and minor axes of the fitted ellipse in each phase region deviates from 1. Subtract the current total energy value from the total energy value of the previous iteration and take the absolute value. If the absolute difference is less than 0.01, the iteration terminates; otherwise, the updated level set function and virtual boundary trajectory are used as the current values, and the next iteration continues.
[0047] After iterative convergence, the positive domain of the level set function corresponding to each lesion is output as an independent segmentation mask. The construction process of the level set function is as follows: First, from the color cluster affiliation of each pixel output in step S4, the color cluster identifier is directly used as the initial phase identifier of the pixel. For each phase identifier, all pixel regions covered by the phase identifier are extracted, and the boundary pixels of the region are taken as the zero level set. Then, a directed distance field is constructed: the shortest Euclidean distance from each pixel to the zero level set is calculated. If the pixel is located inside the zero level set (i.e., inside the phase region), the distance is negative; if it is located outside, the distance is positive; the distance of pixels on the boundary is zero. After traversing all pixels, the directed distance field of the phase is obtained.
[0048] Sign regularization is performed on the directed distance field of each phase. Specifically, each pixel is traversed, and the distance signs of all pixels within its four neighboring pixels (top, bottom, left, and right) are checked. If the distance sign of the current pixel is opposite to the distance signs of three or more of its four neighboring pixels, and the absolute value of the current pixel's distance is less than 0.5, then the pixel is determined to be an isolated out-of-sign pixel. The distance sign of this pixel is flipped (positive becomes negative or negative becomes positive), and then the shortest distance to the zero level set is recalculated within a 3-pixel multiplied window centered on this pixel, becoming the new distance value for the pixel. This process is repeated until no new isolated out-of-sign pixels are found after traversing all pixels.
[0049] The distance values of all directed distance fields at the same pixel location are summed to obtain the total distance for that pixel. Then, the distance value for each phase at that pixel is normalized: the current distance value of that phase is subtracted from the average distance values of all phases, where the average value equals the total distance divided by the number of lesion instances. After normalization, the sum of the distance values for each pixel across all phases is zero. The normalized distance values are used as the output values of the level set function for each phase. In the level set function of each phase, the pixel regions with negative values are the lesion segmentation masks for that phase. The segmentation masks of all phases together constitute the independent segmentation result for each lesion on the entire cucumber leaf image.
[0050] The working principle of this invention is as follows: Images of cucumber leaves are acquired and an initial boundary response map is generated. Persistent homology analysis is performed on the initial boundary response map to extract topological loop features of adherent lesion regions. Candidate split points are automatically identified based on persistent intervals and local curvature extrema. Based on these candidate split points, virtual boundary trajectories are generated between adjacent split points through geodesic distance transformation and local curvature flow, and these trajectories are embedded into the energy functional as topological constraint terms. Based on the number of topological loops and regional color statistics, the number of lesion instances is dynamically estimated using the Bayesian information criterion. A multiphase competition framework is constructed, and elliptical fitting is performed on each phase region to apply shape prior constraints. Finally, the energy functional containing topological and shape prior constraints is iteratively solved, sequentially updating the level set functions of each phase and the virtual boundary trajectory until convergence, outputting an independent segmentation mask for each lesion.
[0051] The foregoing has provided a detailed description of one embodiment of the present invention, but this description is merely a preferred embodiment and should not be construed as limiting the scope of the invention. All equivalent variations and modifications made within the scope of the claims of this invention should still fall within the patent coverage of this invention.
Claims
1. A cucumber leaf disease image segmentation method based on boundary perception guidance, characterized in that, Includes the following steps: S1: Acquire cucumber leaf images, and after denoising, contrast enhancement and color space conversion, generate an initial boundary response map through edge detection; S2: Perform persistent homology analysis on the initial boundary response map to extract the topological ring features of the adherent lesion region, and automatically identify candidate split points based on the persistent interval of the topological ring and the local curvature extremum. S3: Based on candidate split points, virtual boundary trajectories are generated between adjacent split points through geodesic distance transformation and local curvature flow, and the virtual boundary trajectories are embedded into the energy functional as topological constraint terms. S4: Based on the number of topological rings and the statistics of regional colors, the number of lesion instances is dynamically estimated using the Bayesian information criterion, a multiphase competition framework is constructed, and elliptical fitting is performed on each phase region to apply shape prior constraints. S5: Iteratively solve the energy functional containing topological constraints and shape prior constraints. In each iteration, update the level set function of each phase and the virtual boundary trajectory in turn until convergence, and output the independent segmentation mask of each lesion.
2. The cucumber leaf disease image segmentation method based on boundary perception guidance according to claim 1, characterized in that, S2 specifically includes: Using the pixel values of the boundary response map as weights, construct lower level set complexes under different thresholds, calculate the occurrence threshold and disappearance threshold of each connected component, and construct a zero-persistence graph; Extract a topological ring in the durability graph whose persistence interval exceeds a preset threshold, and obtain the geometric center of each ring; Calculate the local curvature of the boundary response map within the neighborhood of the geometric center, and select the point with the minimum curvature as the candidate split point.
3. The cucumber leaf disease image segmentation method based on boundary-aware guidance according to claim 2, characterized in that, The construction of the zero-maintenance graph specifically includes: Sort all pixels in the boundary response map by response value from smallest to largest, activate each pixel in turn, and mark the connectivity of its neighboring activated pixels; When a newly activated pixel connects two independent connected components, the component with the smaller occurrence threshold is marked as disappearing. The disappearance threshold is taken as the response value of the current pixel. At the same time, the occurrence threshold of the merged component is taken as the smaller of the occurrence thresholds of the two components. After traversing all pixels, the occurrence threshold and disappearance threshold of each connected component are output to form a zero-durability graph.
4. The cucumber leaf disease image segmentation method based on boundary perception guidance according to claim 1, characterized in that, S3 specifically includes: Using each candidate split point as the source point, calculate the geodesic distance from all pixels in the image to the corresponding source point to obtain the geodesic distance field; A saddle point in the geodesic distance field is selected between adjacent split points as a path guide point, and the split points and the saddle point are connected along the descent direction of the geodesic distance to form an initial trajectory; Apply local curvature flow to the initial trajectory for iterative updates. In each iteration, move each trajectory point along the negative curvature direction until the change in trajectory curvature is less than a preset threshold, and output the smoothed virtual boundary trajectory.
5. The method for segmenting cucumber leaf disease images based on boundary awareness guidance according to claim 4, characterized in that, The calculation of the geodesic distance from all pixels in the image to the corresponding source point specifically includes: Calculate the local entropy value for each pixel, which is obtained based on the probability distribution of boundary response values within the pixel's neighborhood; The geodesic distance increment between adjacent pixels is defined as the product of the absolute value of the difference between the local entropy values of the two pixels and the Euclidean distance between the pixels; The geodesic distance of each pixel is repeatedly updated to the minimum value of the geodesic distance of all its neighboring pixels plus the corresponding geodesic distance increment, until the global update amount is lower than the preset threshold. The geodesic distance value of each pixel is then output to form a geodesic distance field.
6. The method for segmenting cucumber leaf disease images based on boundary awareness guidance according to claim 1, characterized in that, S4 specifically includes: Using the number of topological rings as the baseline number, and adding or subtracting one from the baseline number, we obtain three candidate numbers; For each candidate number, iterative self-organizing clustering is used to divide the hue and saturation values of all pixels into the corresponding number of color clusters, and the average distance from the pixel in each color cluster to the cluster center is calculated as the negative log-likelihood. Add the negative logarithm of the likelihood of each candidate number to the penalty term, where the penalty term is the natural logarithm of the number of candidates multiplied by the total number of pixels. Select the candidate number with the smallest sum as the number of lesion instances.
7. The method for segmenting cucumber leaf disease images based on boundary awareness guidance according to claim 6, characterized in that, The step of using iterative self-organizing clustering to divide the hue and saturation values of all pixels into a corresponding number of color clusters specifically includes: The hue and saturation values of each pixel are used as a two-dimensional vector, and the variance of the hue values in the neighborhood of each pixel is calculated. The reciprocal of the variance is taken as the local weight. A number of pixels are randomly selected as the initial cluster centers, and each cluster center carries the local weight of the corresponding pixel. In each iteration, the weighted Euclidean distance from each pixel to each cluster center is calculated. The pixel's own weight and the cluster center weight are multiplied by the sum of squared coordinate differences in the weighted Euclidean distance, and the pixel is assigned to the cluster with the smallest weighted distance. Update each cluster center to the weighted average position of all pixels under its jurisdiction, repeat the iteration until the sum of changes in cluster centers is less than a preset threshold, and output the color cluster affiliation of each pixel.
8. The method for segmenting cucumber leaf disease images based on boundary awareness guidance according to claim 1, characterized in that, S5 specifically includes: By fixing the current virtual boundary trajectory, piecewise constant constraints are applied to the level set functions of each phase, and the updated field of each level set function is obtained by solving the Poisson equation with topological constraints. By fixing the updated phase level set functions, the update of the virtual boundary trajectory is transformed into a curve evolution problem of minimizing curvature energy, and an implicit difference scheme is used to iterate the position of each trajectory point. Substitute the updated virtual boundary trajectory into the topological constraint terms and recalculate the energy functional value; Compare the current energy value with the energy value of the previous round. When the absolute difference is less than the preset threshold, the iteration is terminated, and the positive domain of the level set function corresponding to each lesion is output as an independent segmentation mask.
9. The method for segmenting cucumber leaf disease images based on boundary awareness guidance according to claim 8, characterized in that, The output process of the level set function is as follows: Each pixel is initially assigned a phase identifier based on its color cluster, and a directed distance field is constructed using the pixel region boundary of each phase identifier as the zero level set, such that pixels inside the zero level set take negative distance values and pixels outside the zero level set take positive distance values. A sign regularization constraint is applied to the directed distance field of each phase. The local distance is recalculated by flipping isolated pixels with different signs after comparing the consistency of the distance signs in the neighborhood pixel by pixel. After superimposing the directed distance fields of all phases, normalize them so that the sum of the distance values of each pixel in each phase is zero, and output the level set function of each phase.