Method for generating leafminer tunnel image based on leaf constraint and multi-source probability fusion
Patent Information
- Application Number
- CN202611309476.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-27
- Publication Date
- 2026-09-25
AI Technical Summary
[0006]针对现有虫道图像生成技术拟真度不足的缺陷,解决轨迹形态失真、叶片结构约束缺失、虫道与叶脉空间关系不合理、轨迹自重叠、虫道宽窄突变、色彩与边缘过渡生硬等技术问题,提供基于叶片约束与多源概率融合的潜叶蝇虫道图像生成方法,该方法仅输入健康叶片图像与叶片、叶脉、主脉掩膜,自动生成形态、色彩、边缘均贴合真实虫害的仿真叶片图像,低成本扩充深度学习训练数据集
(1)本发明以叶片区域、叶脉、主脉掩膜为基础约束,将潜叶蝇取食惯性、叶脉牵引、已取食区域避让转化为三类可量化方向概率并加权融合,配合三级空间约束筛选轨迹候选点,有效避免传统生成方法虫道穿出叶片、横穿主脉、轨迹自重叠、曲线生硬等问题,生成轨迹完全贴合潜叶蝇真实生长路径规律;
Smart Images

Figure CN122820907A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer vision and agricultural engineering technology, specifically relating to a method for generating leafminer fly tunnel images based on leaf constraints and multi-source probability fusion. Background Technology
[0002] Leafminer flies form linear tunnels while feeding, and their trajectories are constrained by leaf boundaries, main veins, and the already fed areas, exhibiting clear continuity and spatial constraints. Constructing a deep learning-based detection model for leafminer fly pests requires a massive amount of leaf images carrying natural tunnels for training, thereby establishing semantic features specific to these tunnels.
[0003] The current collection of real pest samples has significant shortcomings: the pest outbreak cycle is short, the field samples of leaves with pests are scarce, and the cost of manually annotating the outline and boundary of the insect tunnels on each leaf is extremely high. This results in insufficient total number of samples in the dataset and poor diversity of insect tunnel morphology, which seriously limits the accuracy of model recognition.
[0004] However, existing technologies have the following shortcomings: Current image data enhancement methods rely solely on rotation, cropping, color perturbation, and random line overlay to generate samples, resulting in numerous defects in the generated insect tunnels that do not conform to the actual patterns of insect damage: the trajectory extends beyond the leaf area, crosses the main vein, the tunnel width abruptly changes, the edges are abruptly cut, and the color differs greatly from the actual leaf damage. Furthermore, existing random curve generation methods cannot simultaneously consider the three core constraints of insect tunnel movement inertia, leaf vein traction, and self-avoidance in already-fed areas. Relying solely on simple random walks to generate trajectories results in extremely low simulation accuracy, and the generalization ability of models trained using generated samples is weak.
[0005] Therefore, there is an urgent need for an automatic generation scheme for leafminer fly tunnel images that relies on healthy leaves, is constrained by leaf structure, and has high fidelity. Summary of the Invention
[0006] To address the shortcomings of existing insect tunnel image generation technologies in terms of realism, this paper proposes a method for generating leafminer fly tunnel images based on leaf constraints and multi-source probabilistic fusion. This method only requires a healthy leaf image and a mask of the leaf, veins, and midrib to automatically generate a simulated leaf image with shape, color, and edges that closely match the real insect infestation. This method also expands the deep learning training dataset at low cost.
[0007] To achieve the above objectives, this invention provides a method for generating leafminer fly tunnel images based on leaf constraints and multi-source probabilistic fusion, comprising the following steps: S1. Input the original RGB image of a healthy leaf, complete the grayscale conversion and proportional visualization scaling, and generate leaf region masks, branch vein masks, and main vein masks after preprocessing. Encapsulate the data to obtain the dataset. Pass the dataset to S2 and retain the intermediate mask for vein segmentation for parameter debugging. S2 receives the dataset from S1, randomly samples the starting point within the foreground pixels of the leaf region mask, samples the second control point in a circle with the starting point as the center, solves the initial direction angle, and constructs the initial trajectory state; then passes the initial trajectory state to S3. S3 receives the initial trajectory state from S2, iteratively reads adjacent trajectory points to calculate the historical travel angle, and calculates the inertial probability array based on the discrete von Mises distribution; the inertial probability array is passed to S6 to cache the historical travel angle for iterative reuse; S4. Receive the dataset from S1 and the current trajectory point from S3, calculate the distance from the current point to the branch vein and the distance from the vein to the main vein, construct a distance parameter set, and calculate the vein guidance probability by combining the distance decay; pass the vein guidance probability to S6 and the distance parameter set to step S7. S5. Receive the iteration count and the global historical trajectory mask, calculate the pixel ratio of the circular sector in stages to generate a suppression probability array, and combine them to obtain the historical trajectory suppression probability array; pass the historical trajectory suppression probability array to step S6 to update the historical trajectory mask cache for the next iteration. S6 receives the inertial probability array from S3, the leaf vein guidance probability from S4, and the suppression probability array from S5. It configures the weight set to complete weighted fusion, lower bound truncation, and normalization, and outputs the final sampling probability. The final sampling probability is then passed to S7, and the original three probability arrays are cached for parameter tuning and visualization. S7 receives the final sampling probability from S6, the distance parameter set from S4, and the step size parameter set. It generates candidate pixels along the sampling direction and performs three-level spatial constraint screening, outputting compliant trajectory points. After updating the global trajectory sequence and the global historical trajectory mask, it sends the compliant trajectory points back to S3 for iterative looping until the trajectory length reaches a preset threshold. After the complete trajectory point set is iterated, it is passed to S8. S8 receives the complete discrete trajectory point set output by S7, mirrors and expands the auxiliary interpolation points at the beginning and end of the trajectory, and generates a smooth center line by segmenting and using Catmull-Rom interpolation; calculates the point-by-point drawing width based on the time-series basic width and the segmented random scaling factor, and generates a binary worm tunnel mask; and synchronously transmits the smooth curve sampling points, gradient width parameters, and worm tunnel mask to S9. S9 receives the insect tunnel mask from S8 and the original leaf image from S1, constructs an independent Gaussian color model for the RGB three channels, samples damaged pixels, and replaces the pixels in the mask-covered area to obtain a preliminary synthesized image of the insect-damaged leaf; the preliminary synthesized image and the binary insect tunnel mask are passed to S10, and the Gaussian parameters and independent random seeds for each channel are stored. S10: Receive the preliminary composite image and insect tunnel mask output by S9, perform dilation and erosion on the mask and perform difference operation to extract the edge band, generate a normalized fusion weight map and a pixel-by-pixel weighted mixed image; output the final simulated leafminer fly infested leaf image, the edge weight map and blurred intermediate image are only used as local cache and are not passed to downstream steps.
[0008] Preferably, in S3, the discrete von Mises distribution is used to calculate the inertial probability array using the following step-by-step formula: Discrete candidate directions are calculated using the following formula: ; In the formula, For the first Discrete candidate directions of travel around the circle The value range is [0, 359]; The formula for calculating the shortest included angle of the historical travel angle is: ; In the formula, For the first The shortest circumferential angle between each candidate direction and the historical trajectory direction; For the first One discrete candidate direction angle; As a historical perspective; The original matching score in one direction is calculated based on the shortest included angle of the circumference. The calculation formula is as follows: ; In the formula, For the first Original angle matching score in each direction; The concentration factor of the von Mises distribution; The original matching score is shifted using a stable exponent, and the shift formula is as follows: ; In the formula, To ensure a stable score after translation; This represents the maximum value of the original scores for all 360 directions. Based on the normalized stable score after translation and the probability of inertial travel, the calculation formula is as follows: ; In the formula, It is a natural constant; This is an array of inertial probability numbers; To sum the traversal indices, all 360 discrete directions are traversed.
[0009] Preferably, in S4, the vein guidance probability is calculated using the following formula: ; In the formula, Probability guided by leaf veins; This is a truncation function; For the first The angle between the direction and the dominant direction of leaf vein traction; The distance in pixels from the current trajectory point to the nearest branch vein; This represents the pixel distance from the leaf vein point to the nearest main vein.
[0010] Preferably, in S6, the weight set completes weighted fusion to obtain the unnormalized raw score, calculated using the following formula: ; In the formula, For the first The original direction scores were not normalized after weighted fusion of each direction; For the probability weights of motion inertia; The probability weights for positive guidance of leaf veins; Weights are used to suppress historical overlap. This is an array of inertial probability numbers; Probability guided by leaf veins; This is a suppression probability array; The final sampling probability is obtained by normalizing the unnormalized raw score, and the calculation formula is as follows: ; In the formula, This is the normalized standard probability that can be used for random sampling.
[0011] Preferably, in S7, the resampling rejection probability of candidate points in the branch vein region during the three-level spatial constraint screening is calculated using the following formula: ; In the formula, This represents the rejection probability of resampling when a candidate point falls on a branch vein; This is the resampling coefficient, with a value of 1; The smaller it is, the closer it is to the main vein, and the higher the probability of it refusing to cross over.
[0012] Preferably, in S8, the formula for calculating the basic width of the normal sequence is: ; In the formula, For the first The time-based baseline width corresponding to each point on the smooth curve; This is the width growth magnification factor; Global index for points on the smooth curve; This represents the total number of control points for the original discrete trajectory. This represents the total number of sampling points for the complete smooth curve after interpolation. This represents the initial minimum basic width of the worm tunnel; Based on the time-series base width combined with the piecewise random scaling factor, the formula for calculating the target width after piecewise random scaling is as follows: ; In the formula, The target width after random scaling of the current segment; This is the width of the endpoint of the previous segment; The range is a random scaling factor. The final drawing width of the single curve point is obtained by combining the segmented target width linear interpolation, and the formula is: ; In the formula, For the first The final width is drawn for each curve point; The point number is the curve point number; This is a floor function; This is the offset number of the current point within the 50-point segment; The parameterized positions corresponding to the four control points of Catmull-Rom interpolation are calculated sequentially using the following formulas: ; In the formula, , , The parameterized positions of the four control points corresponding to the Catmull-Rom interpolation; This is the starting parameter for the first interpolation segment; , , , These are the pixel coordinates of four consecutive discrete trajectory control points; The distance between two adjacent points is expressed in Euclidean pixels. These are the Catmull-Rom tension parameters.
[0013] Preferably, in S9, the RGB three-channel independent mixing Gaussian color distribution satisfies the following formula: ; In the formula, In order to be in Channel retrieves pixel value The probability of; In order to be in Channel 1 The weights of the Gaussian distribution components; In order to be in Channel 1 The probability distribution of the Gaussian distribution components; Image channel identifiers, ; The grayscale value of the channel pixel; It is a one-dimensional Gaussian distribution. For channel No. Component mean For channel No. Component standard deviation.
[0014] Preferably, in S10, the formula for calculating the pixel fusion weight of the worm passage edge zone corresponding to the normalized fusion weight map is: ; In the formula, coordinates Weighting of edge regions; The grayscale pixel values after Gaussian blurring at the edges; These are the horizontal and vertical coordinates of the image pixels.
[0015] Therefore, the present invention employs the above-mentioned method for generating leafminer fly tunnel images based on leaf constraints and multi-source probability fusion. Compared with the prior art, the technical solution of the present invention has the following beneficial effects: (1) This invention uses leaf area, leaf vein, and main vein mask as basic constraints, and transforms the feeding inertia of leaf miners, leaf vein traction, and avoidance of already fed areas into three types of quantifiable directional probabilities and weighted fusion. Combined with three-level spatial constraints to screen trajectory candidate points, it effectively avoids problems such as insect tunnels passing through leaves, crossing the main vein, trajectory self-overlapping, and stiff curves in traditional generation methods. The generated trajectory completely conforms to the real growth path of leaf miners. (2) This invention uses mirror extension Catmull-Rom interpolation to generate a smooth, non-aliased insect tunnel centerline, and combines temporal growth width with segmented random scaling to achieve gradual changes in the width of the insect tunnel; constructs a real insect damage mixed Gaussian color model by dividing the RGB channels to fill the damaged area, and extracts the edge band by mask difference to perform local weighted blur fusion, eliminating the hard cutting boundary between the insect tunnel and the healthy leaf. The shape, color, and transition effect of the insect tunnel are highly consistent with the real insect damage leaf. (3) The leaf vein mask of the present invention is compatible with multiple input methods such as manual annotation, traditional image segmentation and deep learning segmentation, and is suitable for various crop leaf images. Only a small number of real insect tunnel samples are needed to fit the color model. Based on healthy leaves, a variety of insect pest simulation images can be generated in batches, solving the pain points of scarce real samples of leaf miners and high cost of manual annotation. It can be directly used for training deep learning models for agricultural pest detection.
[0016] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0017] Figure 1This is a flowchart of an embodiment of the leafminer fly tunnel image generation method based on leaf constraint and multi-source probability fusion of the present invention; Figure 2 This is a leaf input information diagram of an embodiment of the leafminer fly tunnel image generation method based on leaf constraint and multi-source probability fusion of the present invention. Figure 2 (a) in the text represents the blade area mask; Figure 2 (b) in the text represents a leaf vein mask; Figure 2 (c) in the text indicates the main vein of the leaf is covered by a membrane; Figure 3 This is a comparison of the leaf simulation effects of an embodiment of the leafminer fly tunnel image generation method based on leaf constraints and multi-source probability fusion according to the present invention. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, 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, not all embodiments. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention. Unless otherwise defined, the technical or scientific terms used in the present invention should have the ordinary meaning understood by those skilled in the art.
[0019] Example 1 like Figures 1-3 As shown, this embodiment provides a method for generating leafminer fly tunnel images based on leaf constraints and multi-source probabilistic fusion. It should be understood that the specific parameters, models and protocols mentioned in this embodiment are only examples to help those skilled in the art understand the present invention, and are not intended to limit the present invention.
[0020] The method for generating leafminer fly tunnel images based on leaf constraint and multi-source probability fusion of the present invention includes the following steps: S1. Receive the original healthy leaf image as input, perform grayscale conversion, scaling, interactive preprocessing, and layer segmentation, and output the leaf region mask. Leaf vein distribution mask Main vein mask The mask dataset, which is composed of the original image I, is passed to S2, and the intermediate mask for leaf vein segmentation is retained for parameter tuning.
[0021] In this step, a layered leaf structure mask is obtained by automatic segmentation with the assistance of manual marking. Unlike the traditional method of segmenting only a single leaf foreground, this step simultaneously distinguishes the two constraint regions of the main vein and branch veins, providing the underlying basis for the multi-dimensional spatial constraint of the insect tunnel trajectory.
[0022] The system reads the original color leaf image and converts it into a single-channel grayscale image. The ultra-large original image is scaled proportionally for visualization and interaction, while preserving the original pixel coordinate mapping relationship. It receives leaf vein guide lines drawn by dragging the mouse and maps them back to the pixel space of the original image according to the scaling ratio to generate a hand-drawn branch guide mask. Based on the guide mask, it expands to generate seed region and search region, filters leaf vein candidate pixels with grayscale threshold, and removes small noise blocks by filtering eight-neighbor connected components. Morphological processing through closing and opening operations is used to complete leaf vein breaks and remove isolated noise points. Three types of binary masks are extracted for the whole leaf area, branch veins, and thick main veins.
[0023] Construct a unified dataset for the three-layer structure mask of the blade, represented as follows: ; In the formula, The input dataset for the blade structure carries all the spatial constraints and original texture information of the blade. This is a mask for the leaf area, where pixel 255 represents the effective area of the leaf and 0 represents the background. Create a mask for the leaf vein distribution and mark all leaf vein pixel regions; As the main vein mask, extract the thick main veins that need to be forcibly avoided separately; This is the original RGB image of a healthy leaf, used for subsequent color compositing and rendering.
[0024] The grayscale threshold filtering parameters for leaf images are expressed as follows: ; In the formula, This is a set of grayscale segmentation parameters for leaf veins; This is the grayscale segmentation threshold used to distinguish leaf veins from ordinary leaf tissue; The minimum area threshold for connected components is used to filter out minor noise. The radius of expansion of the seed region; The radius of expansion of the leaf vein search area.
[0025] The system only scales the display of the leaf image, with no loss of precision in pixel coordinate mapping, and the segmentation process is performed entirely based on the original image resolution.
[0026] The original leaf image and three-layer structure mask output in this step provide all the underlying constraint inputs for subsequent selection of the initial point of the insect passage, multi-source direction probability calculation, and candidate point spatial screening. S2 receives the leaf three-layer mask dataset output by S1, samples the initial points of the insect tunnel within the effective area of the leaf, calculates the initial travel direction, and sets the starting point... Secondary trajectory points Initial direction angle The process is passed to S3, where the blade mask is reused as a boundary constraint to continue participating in subsequent iterations.
[0027] In this step, the range of the insect tunnel starting point is limited by the effective area of the leaf. Unlike the unconstrained generation method of global random sampling, this step only generates the initial trajectory point inside the leaf, thus avoiding the distortion problem of the insect tunnel leaving the leaf area from the source.
[0028] The system iterates through all foreground pixels of the leaf mask and randomly selects coordinates as the starting control points for the insect tunnel. ;by A circular sampling circumference is constructed with pixel coordinates as the center and a radius of 4 pixels. Any pixel on the circumference is then randomly and uniformly selected as a sample. ; Calculate vectors The included angle is used as the initial direction of travel. This completes the initial state initialization of worm tunnel growth.
[0029] Construct the initial trajectory state vector of the worm tunnel, represented as: ; In the formula, The initial state vector of the insect tunnel carries the trajectory starting point, the second control point, and the initial motion trend; The starting pixel coordinates of the worm tunnel; This is the second control point of the initial segment; The initial travel direction angle, with a value range of... .
[0030] The initial sampling point adopts a uniform random distribution without bias, ensuring that the starting point of the insect tunnel is diverse in distribution within the leaf.
[0031] The initial trajectory points and initial directions output in this step provide basic motion information for the continuous probability calculation of the direction in step three. S3 receives the initial trajectory point position and direction output by S2, iteratively reads the previous and subsequent trajectory points to calculate the historical travel angle, and generates a 360-dimensional continuous probability array of inertial direction based on the von Mises distribution. The information is passed to S6 fusion, and the historical travel direction angle is cached for iterative updates.
[0032] In this step, an inertial probability distribution is constructed based on the continuous motion angle. Unlike the method of uniform random direction selection, this step strengthens the probability weight of the original direction of travel and restores the motion inertial characteristics of the leafminer fly continuously feeding forward.
[0033] The system reads the coordinates of two points before and after the iteration trajectory and calculates the historical travel angle of the line connecting the two points. Divide the 0~2π circle into 360 discrete candidate directions, and calculate the relationship between each candidate direction and the surrounding environment. The shortest included angle of the circumference is used to eliminate the 0° / 360° boundary jump error; the original scores in each direction are calculated based on the discrete von Mises distribution, and the translation scores are uniformly shifted to ensure the stability of the exponential operation. After normalization, a one-dimensional probability array is obtained. .
[0034] The inertial probability array is calculated using the following step-by-step formula: Discrete candidate directions are calculated using the following formula: ; In the formula, For the first Discrete candidate directions of travel around the circle The value range is [0, 359].
[0035] The formula for calculating the shortest included angle of the historical travel angle is: ; In the formula, For the first The shortest circumferential angle between each candidate direction and the historical trajectory direction; For the first One discrete candidate direction angle; For the historical journey.
[0036] The original matching score in one direction is calculated based on the shortest included angle of the circumference. The calculation formula is as follows: ; In the formula, For the first Original angle matching score in each direction; is the concentration coefficient of the von Mises distribution.
[0037] The original matching score is shifted using a stable exponent, and the shift formula is as follows: ; In the formula, To ensure stable scoring after translation and prevent exponential overflow; This represents the maximum value of the original scores for all 360 directions.
[0038] Based on the normalized stable score after translation, the probability of inertial travel is calculated using the following formula: ; In the formula, It is a natural constant; This is an array of inertial probability numbers; To sum the indices, iterate through all 360 discrete directions; The inertial direction probability array output in this step serves as the basic positive constraint term for multi-source probability fusion. S4 receives the leaf vein and main vein mask from S1 and the current iteration trajectory point from S3. Calculate the distance between leaf veins and midrib and generate a 360-dimensional leaf vein guidance probability array. Input to S6, synchronously output distance parameters S7 is used for judging the release of branch veins.
[0039] In this step, the guidance probability is generated by combining the distance attenuation of the leaf veins and the main vein. It is not limited to the judgment of the distance of a single leaf vein. This step distinguishes the different guidance intensity of the main vein and the branch veins, and restores the true feeding preference of insects to be close to the branch veins and far away from the thick main vein.
[0040] System read , Binary mask, with the current point Traversal Foreground pixels, find the leaf vein pixel center corresponding to the minimum Euclidean distance. Calculate pixel distance ;by Traversal Foreground pixels obtain the nearest main vein point ,calculate to distance ,like If it falls in the main vein area, it will cause Construct vectors And taking the vertical direction as the dominant guiding direction of the leaf vein, the angle between each discrete direction and the dominant direction is calculated, combined with... Solve for the unidirectional guidance probability using the linear attenuation coefficient.
[0041] Construct a leaf vein distance parameter vector, represented as follows: ; In the formula, This is a set of parameters constraining the leaf vein distance. The distance in pixels from the current trajectory point to the nearest branch vein; The distance from the leaf vein point to the nearest midrib; This is the maximum effective distance threshold for leaf veins; once exceeded, the guidance probability resets to zero.
[0042] Formula for calculating the probability of unidirectional vein guidance: ; In the formula, Probability guided by leaf veins; This is a truncation function; For the first The angle between the direction and the dominant direction of leaf vein traction; The distance unit is uniformly set to pixels, and Euclidean distance is used to calculate the pixel spatial interval.
[0043] The leaf vein guidance probability array output in this step serves as the second layer of positive enhancement constraint terms for multi-source probability fusion. S5, Receive Iteration Count and Global History Trajectory Mask Calculate the 360-dimensional historical trajectory suppression probability array in stages. The data is fed into S6 and iteratively updated to provide the historical trajectory mask. Next iteration call.
[0044] In this step, regional suppression is activated only after the trajectory reaches a certain length. Unlike the method of full-process superposition suppression, this step retains sufficient turning randomness in the early stage and suppresses trajectory rewinding and overlap in the later stage, balancing trajectory diversity with the real insect tunnel's non-repetitive feeding characteristics.
[0045] The system reads the historical trajectory binary mask generated before the iteration. When the iteration count i is less than or equal to 4, directly generate a one-dimensional array of all zeros as... When i is greater than 4, take the current point as the reference. Center of the circle A circular statistical region is drawn using pixels. This region is then divided into 360 directional sectors. A 5×5 subsampling process is performed on the region to improve the accuracy of area statistics. The area within each sector is then statistically analyzed. The ratio of white foreground pixels to the total sector area; the higher the ratio, the stronger the suppression effect in the corresponding direction.
[0046] Construct a historical trajectory suppression probability array, represented as: ; In the formula, This is a probability array for suppressing overlap of historical trajectories; For the first The coefficient of overlap suppression in discrete directions. The larger the value, the more worm tunnels exist in that direction, and the lower the sampling weight.
[0047] Formula for calculating single sector coverage ratio: ; In the formula, For the first Historical overlap suppression probability in each direction; For the first Total number of foreground pixels of the historical worm tunnel mask within each sector; This represents the total number of pixels in a single sector.
[0048] The suppression probability array output in this step serves as a negative constraint term for multi-source probability fusion. S6 receives the outputs of S3, S4, and S5. 、 、 The three probability arrays are weighted, fused, lower bound truncated, and normalized to obtain the final sampling probability. The original three-class probability arrays are passed to S7 and cached for visualization and parameter tuning.
[0049] In this step, the probabilities of positive enhancement and negative suppression are differentiated and weighted differently. Instead of a simple superposition method, this step uses a lower bound constraint to prevent all directional probabilities from returning to zero, ensuring that the entire process of worm tunnel generation has random turning.
[0050] The system synchronously reads three sets of one-dimensional probability arrays of length 360 and configures fixed weights. 、 、 , Weighted calculations are performed index by index; for all original fusion probability values, those below the lower limit are evaluated. Forced assignment After summing all the values, normalize them so that the sum of all elements in the array equals 1, and output a standard probability distribution that can be used for random sampling.
[0051] Construct a probabilistic fusion weight parameter set, represented as: ; In the formula, For multi-source probability weighting parameter set; For the probability weights of motion inertia; The probability weights for positive guidance of leaf veins; Weights are used to suppress historical overlap. This is the lower bound for the lowest probability cutoff.
[0052] Unidirectional original fusion calculation formula: ; In the formula, For the first The original direction scores are not normalized after weighted fusion of each direction; the suppression probability is subtracted to achieve a negative constraint effect.
[0053] Normalization and unified operation: ; In the formula, This is the normalized standard probability that can be used for random sampling.
[0054] The weight parameters and probability lower bound are globally fixed and adjustable parameters to adapt to the leaf generation requirements of different crops.
[0055] The normalized final direction probability output in this step provides a random sampling basis for the generation of candidate trajectory points in step seven. S7, Receive the final direction probability distribution output from S6 and the distance parameter from S4. Candidate points are generated by sampling and three-level spatial constraint screening is performed to obtain compliant trajectory points. After updating the trajectory sequence and historical mask, it is fed back to S3 for iterative loop.
[0056] In this step, a three-level hierarchical constraint differential release logic is set up. Unlike the method of prohibiting leaf veins from crossing in one stroke, this step forcibly isolates the main vein and releases branch leaf veins with probability, taking into account both leaf structure constraints and the diversity of insect tunnel trajectory morphology.
[0057] The system according to A discrete distribution randomly selects a single direction of travel; using the current point... Starting from the candidate point, offset 5 pixels along the candidate direction to generate floating-point coordinates, rounded to integer pixel coordinates as candidate points; First-level verification: candidate points are either outside the image boundary or not within the specified range. Within the leaf area, resampling is performed; second-level verification: candidate points fall within... The foreground region of the main vein mask is resampled; third-layer verification: when the candidate point is located in the branch vein region, it is based on... The rejection probability is calculated to randomly determine whether to resample, and the non-vein area is the direct receiving point.
[0058] The candidate point generation basic parameter set is represented as follows: ; In the formula, For the trajectory iteration step size parameter set; This is the pixel step size for a single iteration, with a value of 5px, used to control the density of the trajectory.
[0059] Formula for rejection probability of branch vein resampling: ; In the formula, This represents the rejection probability of resampling when a candidate point falls on a branch vein; This is the resampling coefficient, with a value of 1; The smaller it is, the closer it is to the main vein, and the higher the probability of it refusing to cross over.
[0060] After filtering, update the trajectory point sequence and historical worm tunnel mask, and iterate until the trajectory reaches the preset length threshold.
[0061] This step outputs compliant new trajectory control points, continuously iterates and accumulates a complete insect tunnel trajectory sequence, and supplies it to step eight for mask generation; S8 receives the complete trajectory point set completed by S7 iteration, generates a smooth centerline through mirror expansion and Catmull-Rom interpolation, calculates the gradient width by combining time series and random factors, and outputs a smooth gradient insect channel binary mask, curve sampling point set, and width parameter to S9. The original discrete control points are cached for curve replay.
[0062] In this step, mirror extension interpolation is used to eliminate curve endpoint collapse, combined with time-series and random double-layer width gradient. Unlike the fixed line width drawing method, this step simultaneously simulates the widening of insect tunnel growth and local random width fluctuations to restore real insect feeding traces.
[0063] The system verifies the number of trajectory points; if the number of points is less than 2 or there are consecutive duplicate points, curve generation is terminated. Auxiliary control points are generated by mirroring the beginning and end of the trajectory, and the original points are spliced together to form an interpolation point series. Catmull-Rom piecewise interpolation is performed on every four consecutive control points as a group, and 5 curve points are evenly sampled between adjacent points to splice a complete and smooth center line. The base width that increases with growth is calculated based on the trajectory point sequence number. Every 50 consecutive curve points are evenly sampled in the interval [0.8, 1.2] and the scaling factor is linearly superimposed to obtain the actual drawing width that changes point by point. Line segments are drawn along the center line with the corresponding width to generate a binary worm tunnel mask with a foreground of 255 and a background of 0.
[0064] The parameter vector for calculating the worm tunnel width is represented as follows: ; In the formula, For the worm tunnel gradient width parameter group; This represents the initial minimum basic width of the worm tunnel; This is the width growth factor; This is the lower bound of the random scaling factor; This is the upper limit of the random scaling factor; The length of the random width segment is 50.
[0065] Catmull-Rom interpolation standard parameterized curve formula: ; In the formula, , , The parameterized positions of the four control points corresponding to the Catmull-Rom interpolation; This is the starting parameter for the first interpolation segment; , , , These are the pixel coordinates of four consecutive discrete trajectory control points; The distance between two adjacent points is expressed in Euclidean pixels. These are the Catmull-Rom tension parameters.
[0066] Formula for calculating the base width of timing sequence: ; In the formula, For the first The time-based baseline width corresponding to each point on the smooth curve; This is the width growth magnification factor; Global index for points on the smooth curve; This represents the total number of control points for the original discrete trajectory. This represents the total number of sampling points for the complete smooth curve after interpolation.
[0067] Formula for calculating the random gradient factor: ; ; In the formula, The target width after random scaling of the current segment; For the first The final width is drawn for each curve point; The point number is the curve point number; The width of the previous segment's end point is used as the starting width of this segment; This is a random scaling factor for the interval, with a value range of [0.8, 1.2]. This is a floor function; This is the offset number of the current point within the 50-point segment.
[0068] This step outputs a smooth gradient width binary mask for the worm tunnel, providing a regional positioning basis for color filling of worm tunnel damage. S9 receives the insect tunnel mask and the original image output by S8, constructs an independent mixed Gaussian color model for each RGB channel to fill damaged pixels, generates a preliminary synthesized insect damage image and sends it along with the insect tunnel mask to S10, and retains the Gaussian parameters of each channel and random seeds for color reproduction.
[0069] In this step, the RGB three channels are independently established to form a mixed Gaussian color distribution. Instead of using a single-channel unified color model, this step separates the red, green, and blue damage features for independent sampling, which highly matches the fading and yellowing color distribution patterns of real leaf insect tunnels.
[0070] The system replicates the original healthy leaf image as the synthetic base, and traverses the insect tunnel mask to count the total number of foreground pixels. It then constructs a Gaussian mixture color model for the R, G, and B channels, consisting of three sets of one-dimensional Gaussian weighted averages. The model parameters are fitted from real field leafminer insect tunnel pixels. Each of the three channels is assigned an independent random seed (B=42, G=43, R=44) and sampled accordingly. The pixel values are truncated if they exceed the 0~255 range; the RGB values of the insect tunnel mask-covered areas in the base image are replaced pixel by pixel, while the pixels in the healthy areas of the leaf remain unchanged.
[0071] Single-channel Gaussian color model expression: ; In the formula, In order to be in Channel to obtain pixel value The probability of; In order to be in Channel 1 The weights of the Gaussian distribution components; In order to be in Channel 1 The probability distribution of the Gaussian distribution components; Image channel identifiers, ; Independently configure random seeds for each channel ; The grayscale value of the channel pixel; It is a one-dimensional Gaussian distribution. For channel No. Component mean For channel No. Component standard deviation.
[0072] The color sampling configuration parameter group is represented as follows: ; In the formula, Use independent random seeds for each channel; Use G channels as independent random seeds; Use R channels as independent random seeds; The total number of pixels in the worm tunnel region determines the number of sampling times.
[0073] Pixel value constraint rules: Sample values less than 0 are uniformly set to 0, and values greater than 255 are uniformly set to 255 to ensure the legal range of image pixels.
[0074] This step outputs a preliminary composite leaf image filled with the damage colors, providing basic image material for the natural transition and fusion of the insect tunnel edges; S10: Receive the preliminary synthesized image and insect tunnel mask output by S9, extract the edge band through morphological operations and perform local weighted blur fusion, and directly output the final high-fidelity insect-damaged leaf image. The edge weight map and blur map are only used as intermediate buffers and are not passed down.
[0075] In this step, blurring and blending are applied only to the edge area of the insect tunnel. Unlike the method of global blurring of the entire image, this step fully preserves the texture of the healthy area of the leaf and only softens the hard cutting marks at the junction of the insect tunnel and the leaf tissue, taking into account both the simulation and the original details of the leaf.
[0076] The system converts the binary mask of the insect passage into a grayscale single-channel image, performs dilation and erosion operations on the two images respectively, and performs pixel difference operation on the two images to obtain the edge zone region that only covers the inner and outer boundaries of the insect passage. A Gaussian convolution kernel is used to perform global blurring on the preliminary synthesized image to obtain a blurred reference image. The edge zone image is subjected to Gaussian blurring and normalized to the 0~1 range to generate a pixel-by-pixel fusion weight map. The system traverses all pixels of the image and mixes the original synthesized image and the blurred image according to the weight map. The edge zone region is gradually blurred according to the weight, while the non-edge region completely retains the original leaf pixels.
[0077] Edge blending pixel calculation formula: ; In the formula, coordinates The fusion weight for edge regions, with a value range of [0,1]; The grayscale pixel values after Gaussian blurring at the edges; These are the horizontal and vertical coordinates of the image pixels.
[0078] In this embodiment, the Gaussian convolution kernel size is 9×9. The edge band only applies to a narrow area at the boundary of the insect passage; there is no blurring inside the leaf or on the leaf background.
[0079] This step outputs visually highly realistic images of leaf miner-infested leaves with natural color edge transitions, which can be directly used to construct deep learning training datasets.
[0080] Therefore, the present invention adopts the above-mentioned leafminer fly tunnel image generation method based on leaf constraint and multi-source probability fusion. This method only requires input of a healthy leaf image and a mask of leaf, leaf vein and main vein, and automatically generates a simulated leaf image whose shape, color and edge are consistent with the real pest, thus expanding the deep learning training dataset at low cost.
[0081] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0082] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit them. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the technical solutions of the present invention, and these modifications or equivalent substitutions cannot cause the modified technical solutions to deviate from the spirit and scope of the technical solutions of the present invention.
Claims
1. A method for generating leafminer fly tunnel images based on leaf constraints and multi-source probabilistic fusion, characterized in that, Includes the following steps: S1. Input the original RGB image of a healthy leaf, complete the grayscale conversion and proportional visualization scaling, and generate leaf region masks, branch vein masks, and main vein masks after preprocessing. Encapsulate the data to obtain the dataset. The dataset is passed to S2, and the intermediate mask for leaf vein segmentation is retained for parameter tuning. S2. Receive the dataset from S1, randomly sample the starting point within the foreground pixel of the mask in the leaf area, sample the second control point in a circle with the starting point as the center, solve the initial direction angle, and construct the initial trajectory state. Pass the initial trajectory state to S3; S3 receives the initial trajectory state from S2, iteratively reads adjacent trajectory points to calculate the historical travel angle, and calculates the inertial probability array based on the discrete von Mises distribution; the inertial probability array is passed to S6 to cache the historical travel angle for iterative reuse; S4. Receive the dataset from S1 and the current trajectory point from S3, calculate the distance from the current point to the branch vein and the distance from the vein to the main vein, construct a distance parameter set, and calculate the vein guidance probability by combining the distance decay; pass the vein guidance probability to S6 and the distance parameter set to step S7. S5. Receive the iteration count and the global historical trajectory mask, calculate the pixel ratio of the circular sector in stages to generate a suppression probability array, and combine them to obtain the historical trajectory suppression probability array; pass the historical trajectory suppression probability array to step S6 to update the historical trajectory mask cache for the next iteration. S6 receives the inertial probability array from S3, the leaf vein guidance probability from S4, and the suppression probability array from S5. It configures the weight set to complete weighted fusion, lower bound truncation, and normalization, and outputs the final sampling probability. The final sampling probability is then passed to S7, and the original three probability arrays are cached for parameter tuning and visualization. S7 receives the final sampling probability from S6, the distance parameter group from S4, and the step size parameter group, generates candidate pixels along the sampling direction, performs three-level spatial constraint screening, and outputs compliant trajectory points. After updating the global trajectory sequence and the global historical trajectory mask, the compliant trajectory points are sent back to S3 for iterative looping until the trajectory length reaches a preset threshold; after the complete trajectory point set is iterated, it is passed to S8. S8 receives the complete discrete trajectory point set output by S7, mirrors and expands the auxiliary interpolation points at the beginning and end of the trajectory, and generates a smooth center line by segmenting and using Catmull-Rom interpolation; calculates the point-by-point drawing width based on the time-series basic width and the segmented random scaling factor, and generates a binary worm tunnel mask; and synchronously transmits the smooth curve sampling points, gradient width parameters, and worm tunnel mask to S9. S9 receives the insect tunnel mask from S8 and the original leaf image from S1, constructs an independent Gaussian color model for the RGB three channels, samples damaged pixels, and replaces the pixels in the mask-covered area to obtain a preliminary synthesized image of the insect-damaged leaf; the preliminary synthesized image and the binary insect tunnel mask are passed to S10, and the Gaussian parameters and independent random seeds for each channel are stored. S10: Receive the preliminary composite image and worm tunnel mask output by S9, perform dilation and erosion on the mask and perform difference operation to extract edge bands, and generate a normalized fusion weight map and a pixel-by-pixel weighted mixed image. The final simulated leafminer fly infestation image is output. The edge weight map and blurred intermediate image are only used as local caches and are not passed to downstream steps.
2. The method for generating leafminer fly tunnel images based on leaf constraints and multi-source probabilistic fusion according to claim 1, characterized in that, In S3, the discrete von Mises distribution is used to calculate the inertial probability array using the following step-by-step formula: Discrete candidate directions are calculated using the following formula: ; In the formula, For the first Discrete candidate directions of travel around the circle The value range is [0, 359]; The formula for calculating the shortest included angle of the historical travel angle is: ; In the formula, For the first The shortest circumferential angle between each candidate direction and the historical trajectory direction; For the first One discrete candidate direction angle; As a historical perspective; The original matching score in one direction is calculated based on the shortest included angle of the circumference. The calculation formula is as follows: ; In the formula, For the first Original angle matching score in each direction; The concentration factor of the von Mises distribution; The original matching score is shifted using a stable exponent, and the shift formula is as follows: ; In the formula, To ensure a stable score after translation; This represents the maximum value of the original scores for all 360 directions. Based on the normalized stable score after translation and the probability of inertial travel, the calculation formula is as follows: ; In the formula, It is a natural constant; This is an array of inertial probability numbers; To sum the traversal indices, all 360 discrete directions are traversed.
3. The method for generating leafminer fly tunnel images based on leaf constraints and multi-source probability fusion according to claim 2, characterized in that, In S4, the vein guidance probability is calculated using the following formula: ; In the formula, Probability guided by leaf veins; This is a truncation function; For the first The angle between the direction and the dominant direction of leaf vein traction; The distance in pixels from the current trajectory point to the nearest branch vein; This represents the pixel distance from the leaf vein point to the nearest main vein.
4. The method for generating leafminer fly tunnel images based on leaf constraints and multi-source probabilistic fusion according to claim 3, characterized in that, In S6, the weight set is weighted and fused to obtain the unnormalized raw score, calculated using the following formula: ; In the formula, For the first The original direction scores were not normalized after weighted fusion of each direction; For the probability weights of motion inertia; The probability weights for positive guidance of leaf veins; Weights are used to suppress historical overlap. This is an array of inertial probability numbers; Probability guided by leaf veins; This is a suppression probability array; The final sampling probability is obtained by normalizing the unnormalized raw score, and the calculation formula is as follows: ; In the formula, This is the normalized standard probability that can be used for random sampling.
5. The method for generating leafminer fly tunnel images based on leaf constraints and multi-source probability fusion according to claim 4, characterized in that, In S7, the resampling rejection probability of candidate points in the branch vein region during the three-level spatial constraint screening is calculated using the following formula: ; In the formula, This represents the rejection probability of resampling when a candidate point falls on a branch vein; This is the resampling coefficient, with a value of 1; The smaller it is, the closer it is to the main vein, and the higher the probability of it refusing to cross over.
6. The method for generating leafminer fly tunnel images based on leaf constraints and multi-source probabilistic fusion according to claim 5, characterized in that, In S8, the formula for calculating the normal sequence base width is: ; In the formula, For the first The time-based baseline width corresponding to each point on the smooth curve; This is the width growth magnification factor; Global index for points on the smooth curve; This represents the total number of control points for the original discrete trajectory. This represents the total number of sampling points for the complete smooth curve after interpolation. This represents the initial minimum basic width of the worm tunnel; Based on the time-series base width combined with the piecewise random scaling factor, the formula for calculating the target width after piecewise random scaling is as follows: ; In the formula, The target width after random scaling of the current segment; This is the width of the endpoint of the previous segment; The range is a random scaling factor. The final drawing width of the single curve point is obtained by combining the segmented target width linear interpolation, and the formula is: ; In the formula, For the first The final width is drawn for each curve point; The point number is the curve point number; This is a floor function; This is the offset number of the current point within the 50-point segment; The parameterized positions corresponding to the four control points of Catmull-Rom interpolation are calculated sequentially using the following formulas: ; In the formula, , , The parameterized positions of the four control points corresponding to the Catmull-Rom interpolation; This is the starting parameter for the first interpolation segment; , , , These are the pixel coordinates of four consecutive discrete trajectory control points; The distance between two adjacent points is expressed in Euclidean pixels. These are the Catmull-Rom tension parameters.
7. The method for generating leafminer fly tunnel images based on leaf constraints and multi-source probabilistic fusion according to claim 6, characterized in that, In S9, the independent Gaussian color distribution of the RGB three channels satisfies the following formula: ; In the formula, In order to be in Channel retrieves pixel value The probability of; In order to be in Channel 1 The weights of the Gaussian distribution components; In order to be in Channel 1 The probability distribution of the Gaussian distribution components; Image channel identifiers, ; The grayscale value of the channel pixel; It is a one-dimensional Gaussian distribution. For channel No. Component mean For channel No. Component standard deviation.
8. The method for generating leafminer fly tunnel images based on leaf constraints and multi-source probabilistic fusion according to claim 7, characterized in that, In S10, the formula for calculating the pixel fusion weight of the worm passage edge zone corresponding to the normalized fusion weight map is: ; In the formula, coordinates Weighting of edge regions; The grayscale pixel values after Gaussian blurring at the edges; These are the horizontal and vertical coordinates of the image pixels.
9. A computer device, characterized in that, include: A processor configured to be coupled to memory, read and execute instructions and / or program code in the memory to perform the method as described in any one of claims 1-8.
10. A computer-readable medium, characterized in that, The computer-readable medium stores computer program code that, when executed on a computer, causes the computer to perform the method as described in any one of claims 1-8.