A machine vision-based traditional Chinese medicinal material defect detection method
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-04
- Publication Date
- 2026-08-11
AI Technical Summary
[0005]针对现有技术的不足,本发明公开了一种基于机器视觉的中药材缺陷检测方法,旨在复杂批次条件和高分辨率分块检测场景下保持判定阈值的稳定性与缺陷统计的一致性,克服现有技术中检测标准波动与统计口径失真的问题
本发明通过在批次域构建参考区域并提取批次描述符,对原始缺陷分数建立分段单调映射进行校准,使得不同批次的分数在进入判定环节前被统一到稳定的参照系中,从而避免了现有技术中分数与阈值对应关系随产地、季节、干燥度等批次差异整体漂移的情况,减少了因阈值不可迁移而产生的过剔或漏检,并保证跨批次检测结果具有可比性。
Smart Images

Figure CN121685376B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent detection technology, and more specifically to a method for detecting defects in Chinese medicinal materials based on machine vision. Background Technology
[0002] Chinese medicinal herbs are diverse and exhibit significant individual differences. Roots, tubers, root slices, and leaves naturally differ in morphology, cross-sectional structure, and surface color. Furthermore, factors such as processing techniques, harvesting period, origin (authenticity), moisture content, and slice thickness can cause systematic shifts in color, texture, and microstructure. Common appearance defects include, but are not limited to, surface mold spots, mold cores, insect holes, longitudinal and transverse cracks, mechanical abrasions, browning, foreign matter inclusions (mud, mixed roots), and uneven slices. Because defects range in size from tiny mold spots to large damaged slices and are often related to the histological characteristics of the medicinal material (such as vascular bundles, fiber arrangement, and xylem exposure), purely manual visual inspection is time-consuming and subject to subjective influences. Detection rates and consistency fluctuate significantly with the inspector's experience, visual fatigue, and inspection conditions, making it difficult to meet the requirements of high throughput and traceable release in online production lines.
[0003] The industry is gradually adopting machine vision for online inspection and batch release. Current practices typically use two-dimensional images as a basis, performing preprocessing and morphological / color / texture feature analysis, or outputting defect scores or quality grades after multi-view / temporal alignment. For example, CN119693343A proposes a comprehensive scoring and archiving method based on morphology, color, and texture, aiming to reduce human intervention and improve the method's versatility and accuracy; CN120374870A improves judgment stability by using timed acquisition, pixel alignment, and multi-view geometric constraints to suppress offsets caused by lighting and jitter. While these existing methods are effective in typical scenarios, in actual production, whether it's single-image scoring based on color / texture / morphology or similarity / classification scores obtained through alignment and multi-view fusion, the final decision for release must fall within a fixed or limited threshold. The inter-batch distribution drift of Chinese medicinal materials (origin, harvesting season, moisture content, cleanliness, cutting thickness, and processing differences) can cause the overall score to shift or shrink, resulting in missed or over-detection of the same threshold in different batches. This affects the consistency of AQL control and release, forcing inspection and maintenance personnel to frequently adjust thresholds or rebuild reference sets, thus reducing the cross-batch comparability of quality traceability.
[0004] Furthermore, to balance field of view and resolution, production lines often divide large images into several tiles and stitch them together after reasoning about each tile. Medicinal herb slices are often slightly stacked or irregularly shaped, causing context truncation at the seams: tiny mold spots or fine cracks are more easily misjudged or fragmented at tile edges, causing "tears" in the semantic segmentation mask at the stitching points. Even slight deviations in post-processing merging can merge two adjacent small defects into a single large defect or lead to duplicate counting. In stacked structures, upper-layer defects are mistakenly recorded as lower-layer good products, and simple statistics based on defect percentage amplify the defect rate. Even with multi-view geometric constraints to suppress biases caused by lighting and jitter, images still require block segmentation, cross-view fusion, and instance alignment. Instance merging at seams, cross-window adjacency, and defect attribution still rely on post-processing strategies and heuristic rules. Different stitching strategies or merging thresholds introduce systematic statistical biases, further amplifying FAR / FRR jumps and batch-to-batch distortions caused by threshold instability. Summary of the Invention
[0005] To address the shortcomings of existing technologies, this invention discloses a machine vision-based method for detecting defects in Chinese medicinal materials. The method aims to maintain the stability of the judgment threshold and the consistency of defect statistics under complex batch conditions and high-resolution block detection scenarios, thereby overcoming the problems of fluctuation in detection standards and distortion of statistical caliber in existing technologies.
[0006] To achieve the above-mentioned technical effects, the present invention adopts the following technical solution: A machine vision-based method for detecting defects in traditional Chinese medicinal materials includes: Step 1: Acquire continuous frame images of Chinese medicinal materials, generate a set of sub-windows according to a fixed window and overlap width, and establish a seam index; Step 2: Within the sub-window set, filter the anchor region set based on gradient variance, texture energy, and color entropy, and remove the seam neighborhood. Step 3: Extract color histogram statistics, power spectral moments, and gray-level co-occurrence moments from the anchor region set, construct a batch domain descriptor, and read the reference descriptor and reference quantile group; Step 4: Score all sub-windows for defects, obtain the original score set, and count the reference area quantiles as the calibration benchmark. Step 5: Based on the difference between the batch domain descriptor and the reference descriptor, construct a monotonic segmented mapping for the fraction domain, set quantile constraints, obtain mapping parameters, calibrate the original fractions, and set a fixed threshold in the calibration domain. Step 6: Calculate the structural tensor direction and the difference in strength across the joint on both sides of the joint strip, generate the joint continuity field and establish a boundary mask; Step 7: Perform connected component labeling based on calibration score and threshold within each sub-window and map it to global coordinates to construct a cross-window adjacency graph composed of seam continuity and shape compatibility, and generate a global defect instance set through merging and nonmaximum suppression. Step 8: Generate the foreground response map of the medicinal material slices, obtain the set of slice instances through distance transformation and watershed method, and repair the seam contour according to the seam continuity field cost; Step 9: Construct a bipartite graph of defect instances and sheet instances. The edge weights are given by the region intersection-union ratio, boundary direction difference, and seam continuity integral. Solve for the maximum weight matching to obtain the defect attribution mapping. Step 10: Generate defect statistical labels based on the defect attribution mapping, write the batch domain descriptor, mapping parameters, reference quantile group, judgment threshold and seam continuity summary into the batch file, and monitor drift trigger parameter updates within the sliding time window.
[0007] Based on the above technical solution, the positive and beneficial effects of the present invention are as follows: This invention constructs a reference region in the batch domain and extracts batch descriptors to calibrate the original defect scores by establishing a segmented monotonic mapping. This ensures that the scores of different batches are unified into a stable reference system before entering the judgment stage. This avoids the situation in the prior art where the correspondence between scores and thresholds drifts as a whole with batch differences such as origin, season, and dryness. It also reduces over-rejection or under-rejection caused by non-transferable thresholds and ensures the comparability of cross-batch detection results.
[0008] This invention introduces a seam continuity field during image segmentation reasoning and result stitching, and establishes an adjacency graph based on directional consistency and seam difference to perform defect connectivity fusion, thereby suppressing false defects in the boundary region and ensuring that the defect mask remains coherent at the stitching point, avoiding the situation where the same defect is counted repeatedly or adjacent small defects are mistakenly merged; at the same time, by matching the defect with the bipartite graph of the sheet, the problem of small defects being mistakenly assigned to the lower layer of good products in stacked samples is solved. Attached Figure Description
[0009] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort, wherein: Figure 1 This is a flowchart of the steps of the present invention; Figure 2 A schematic diagram illustrating the construction of the batch field descriptor of this invention; Figure 3 This is a schematic diagram illustrating the foreground response and watershed correction of the present invention; Figure 4 This is a schematic diagram of the seam tape of the present invention. Detailed Implementation
[0010] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this invention, and not all embodiments. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.
[0011] To facilitate understanding of this invention, a machine vision-based method for detecting defects in traditional Chinese medicinal materials disclosed in this application is described in detail below. Please refer to [link to relevant documentation]. Figure 1 The diagram illustrates the steps of a machine vision-based method for detecting defects in Chinese medicinal materials. The method includes the following steps: Step 1: Acquire continuous frame images of Chinese medicinal herbs, generate a set of sub-windows according to a fixed window and overlap width, and establish a seam index; In this step, the acquisition module continuously acquires frames of medicinal herbs on the moving carrier at a resolution of not less than 2048×2048 pixels and a frame rate of not less than 15 frames / second at a fixed imaging calibration position. Please refer to [link to relevant documentation]. Figure 4 The schematic diagram of the seam tape shown is denoted as the grayscale or color image obtained from the acquisition. Where t is the time frame index, and x, y are the pixel coordinates; the camera's extrinsic and intrinsic parameters are calibrated to obtain the homography matrix H or intrinsic parameter matrix K, which serves as the basis for subsequent global coordinate mapping. The pixel-to-physical coordinate transformation is performed according to... Completed. The meanings of all symbols in the formula will be explained uniformly below. A set of sub-windows is generated based on the acquired images, with equal row and column spacing. The sub-window size... The recommended value range is 64×64 to 512×512 pixels, with a sub-window overlap rate r ∈ [0.10, 0.40] and a step size. The number of windows is calculated both horizontally and vertically. Each child window is uniquely identified by an ID (i,j,t), which records its top-left pixel coordinates and the corresponding global coordinate window range. The seam index is based on the length of the child window's shorter side. Determine bandwidth Where α ranges from 0.05 to 0.20, the seam strip is extended along the short side, and the cross-seam sub-windows are recorded as entries using an adjacency list structure { Relative offset The initial value of the confidence level c is determined by the inter-frame structural similarity. The estimation is performed together with the gradient distribution consistency. For dynamic acquisition scenarios, the conditions for triggering the reconstruction sub-window set and seam index when adding a new batch or changing the type of medicinal material are: batch switching signal, and the change in average brightness of consecutive frames exceeding the threshold. Or the inter-frame structural similarity is below a threshold Image coordinates to global coordinates mapping uses online RANSAC estimation of four-point singularity updates when perturbation or camera micro-movement is present. If the estimated inlier ratio is lower than... If a warning is triggered, the system will be recalibrated. To facilitate subsequent calculations of cross-window adjacency graphs and seam continuity integrals, the sub-window index is also stored in a local fast-access index file. Its fields include sub-window ID, pixel range, physical coordinate range, seam band identifier, list of adjacent sub-windows, and acquisition time window. Specifically, it can be stored in a key-value database or binary serialization format to meet real-time access requirements.
[0012] It should be noted that, in this application, a sub-window refers to a discrete sampling unit pre-gridized across the entire frame with a fixed size and overlap rate, which facilitates the establishment of stable cross-frame and cross-window adjacency relationships; the seam band refers to a pixel band of a certain width extending along the short side of the sub-window boundary and serves as the spatial domain for cross-window continuity analysis; and a batch refers to a collection of images acquired within the same production batch under different lighting, variety, and transportation conditions. Specific parameters such as resolution and frame rate can be determined based on the production line speed, camera performance, and type of medicinal materials, and are not strictly limited in this regard.
[0013] Step 2: Within the sub-window set, filter the anchor region set based on gradient variance, texture energy, and color entropy, eliminating seam neighborhoods. In practice, Step 2 first performs local normalization on each sub-window; the normalization result is called the fundamental matrix and serves as the input for subsequent index calculations. Gradient variance is calculated by first calculating the gradient magnitude. Obtain regional indicators ,in The response is either a Sobel or Scharr operator; texture energy is obtained through a set of Gabor filters or a multi-band fast Fourier transform, where the center frequency and direction are set according to common textures on the surface of medicinal materials; color entropy is defined according to Shannon. For the probability distribution of the K bins in the color histogram, K is recommended to be 16-64. Calculate the quantile distribution and take the quantile points for the above three types of indicators within the current sub-window set or the current batch. As an adaptive threshold, it is recommended to select 75% or 90% of the quantile to adjust the sensitivity.
[0014] Candidate region extraction first generates a preliminary saliency map based on pixel-level local thresholding and then extracts connected components. For each connected component, an R-test is performed as a joint criterion. and And require minimum boundary distance Area constraints It represents the distance from the nearest pixel in the connected region to the boundary or seam of the sub-window. 5-30 pixels is recommended. and Based on the particle size of the medicinal materials, candidates located within the seam zone index coverage area were all eliminated. Hierarchical connectivity analysis was performed on the retained candidates, employing a multi-threshold, tree-like merging strategy. Connectivity segmentation is performed at each intensity threshold, and overlapping nodes are merged according to IoU, generating a primary anchor region set. Cross-frame consistency detection is then performed on the primary anchor region set, and temporal correlation is calculated. Average and require Or Number of occurrences within consecutive frames suggestion suggestion Recommendation 2: Items not meeting this requirement are considered transient noise and discarded. Finally, spatial uniformity correction is performed on the selected anchor regions using morphological hole filling, merging of small connected patches, and region boundary smoothing (e.g., curvature-based multiple sampling and fitting). An attribute vector is output for each anchor region, including region mask, centroid coordinates, area, principal direction, etc. Along with the timestamp, it is written to a local index for subsequent steps. Texture energy refers to the cumulative energy spectrum across frequency bands, reflecting the fiber direction and periodic texture characteristics of the medicinal material; seam neighborhood refers to the pixel band covered by the seam index established in step 1, which becomes the candidate rejection area. Specific parameters can be adjusted according to camera resolution, transport speed, and medicinal material variety.
[0015] Step 3: Extract color histogram statistics, power spectral moments, and gray-level co-occurrence moments from the anchor region set, construct batch domain descriptors, and read reference descriptors and reference quantile groups. Specifically, the process of step 3 includes: processing the anchor region set output in step 2 one by one; first, transforming each anchor region image block from camera space to CIELab space through linear color space transformation; quantizing the three channels into 32 levels at preset intervals and performing L1 normalized histogram statistics; and then concatenating the normalized histogram array in channel order to form color histogram subvectors. Grayscale patch for anchor area Apply two-dimensional fast Fourier transform, amplitude spectrum With frequency domain center For the path center pair Perform radial piecewise integration, and define the first and second order power spectral moments as follows: ,Will After normalization, the power spectral vector is formed. For grayscale patches, press Constructing a gray-level co-occurrence matrix using linear quantization Take pixel spacing With direction Normalize each matrix into a probability matrix. Calculate the four types of statistics: Contrast Correlation ,energy Uniformity .
[0016] Four sets of quantities in four directions are concatenated in a fixed order to form a GLCM vector. Color histogram (H), power spectrum Concatenate them sequentially into a single-anchor description vector. After performing column centering and variance normalization on all anchor vectors in the current batch, principal component analysis is used to reduce the dimensionality to... Dimension, as a processing step for batch internal stability and computational reversibility, This can be set to maintain 95% variance or fixed at 64, whichever you determine best. Then, based on the anchor area... Calculate the area quantile By interval The anchors were assigned to the four quantile groups. Within-group statistic is the mean. With covariance .
[0017] If the sample size of a certain quantile Less than the threshold Then, according to the time sliding window, anchor samples are accumulated in the most recent K frames until... Alternatively, guided contraction covariance estimation can be used. To obtain a numerically stable inverse matrix, Estimate according to the Ledoit–Wolf rule. Divide each quantile group... This serves as the reference descriptor for this batch and is written into the batch file; simultaneously, the historical reference descriptor set is read, and inter-group difference measures are calculated. This information is then returned to the subsequent score domain calibration module as the assigned weight. The trigger condition is defined as: when the total number of anchors... or any quantile When this occurs, a time accumulation mechanism or a dimensionality reduction threshold adjustment strategy is triggered; when compared with the maximum historical reference... Exceeding the threshold At that time, the batch was labeled as "domain drift" for use in subsequent steps to re-evaluate the fractional domain mapping parameters.
[0018] It should be noted that, in this application, the batch domain descriptor refers to a statistical representation of several anchor sets, used to capture the overall apparent differences of the current batch of materials.
[0019] In one implementation of this invention, multiple Chinese medicinal materials were collected for defect assessment, and a constraint model was constructed that reflects the intrinsic physicochemical properties of the medicinal materials based on their image features. This model is based on batch-domain feature constraints using the content of ginsenosides Re, Rg1, and Rb in ginseng (cultivated ginseng) as a reference. The ginseng shape is selected as follows: the main root is spindle-shaped or cylindrical and straight, with a grayish-yellow surface. The upper part or the entire root has sparse, shallow, discontinuous coarse transverse lines and obvious longitudinal wrinkles. The lower part has branch roots and numerous slender fibrous roots, often with inconspicuous small wart-like protrusions. The rhizome is slender, with a few short and thick ones, and sparse or dense, deeply sunken stem scars in the upper and middle parts. The texture is relatively hard, the cross-section is pale yellowish-white, powdery, the cambium ring is brownish-yellow, and the cortex has yellowish-brown dotted resin ducts and radial fissures. Among them, 20 branches are plump and robust, with the largest diameter main root, shaped like a short, thick cylinder or cone. The rhizome is thick and long, with dense and clearly defined stem scars. The texture is tight and deep, with tough fibrous roots and obvious pearl-like nodules. The average diameter of the main root is >2.0 cm, with a small length-to-width ratio, making it appear robust. The epidermis is dark grayish-yellow with a stable color. 30 stems are symmetrical, with a main root diameter of 1.7-2.0 cm, a distinct rhizome, and clear stem scars. The texture is clear, and pearl-like nodules are visible on the fibrous roots. The color is normal, grayish-yellow. 40 stems are of moderate size, slightly thinner than 30 stems, but still relatively full overall, with a main root diameter of approximately 1.4-1.7 cm. More slender individuals begin to appear. The texture is clear, but the depth may be slightly shallower. The color is similar to 30 stems. 50-60 stems: Significantly slender, with a small main root diameter (<1.4 cm), possibly with more branches or a relatively high proportion of fibrous roots. The rhizome is relatively short and thin. Increased morphological diversity with relatively shallower texture and less pronounced iron wire patterns. Slightly lighter color. 70 branches: Slender build with a thin taproot. Commonly branchesed, with potentially numerous and disordered fibrous roots. Possibly relatively light in texture. Mostly irregular in shape, slender and small. Shallow and sparse texture. Light color and weak texture.
[0020] Analysis of physicochemical test results from samples from multiple sources revealed a clear statistical regularity between the number of ginseng (cultivated ginseng) pieces and slice diameter and the content of the main active ingredients. Based on continuous sampling experiments, the ginsenoside content in samples with different indices and slice diameters showed the following patterns: Ginsenoside Rg1 showed a pattern of "40 pieces > 20 pieces > 50 pieces > 30 pieces > 70 pieces > 60 pieces" and "0.6 slices > 1.6 slices > 1.0 slices > 1.4 slices > 0.8 slices". The sum of ginsenoside Rg1 and ginsenoside Re showed a pattern of "40 pieces > 50 pieces > 70 pieces > 20 pieces > 30 pieces > 60 pieces" and "0.6 slices > 1.0 slices > 1.0 slices > 0.8 slices". The data shows the distribution trend of ginsenoside Rb content as follows: "60 > 40 > 70 > 30 > 50 > 20" and "1.6 > 0.8 > 1.6 > 1.0 > 1.4".
[0021] In the implementation of this invention, in order to ensure that the image features of Chinese medicinal materials can accurately reflect their intrinsic physicochemical properties, a batch domain feature constraint model is established with the content of Astragalus membranaceus isoflavone glucoside and total flavonoids as references.
[0022] Both wild-simulated and cultivated Astragalus membranaceus are cylindrical, thicker at the top, and some have branches with irregular longitudinal wrinkles or grooves. They are hard and tough, not easily broken, with a highly fibrous and powdery cross-section. The bark is yellowish-white, the wood is pale yellow, and there are radial striations. The difference between wild-simulated and cultivated Astragalus membranaceus lies in the roughness of the epidermis, the toughness of the root bark, the presence of cracks in the cross-section of the bark, the yellowish wood core, the loose texture, and the decayed, dark brown, or hollow center of the cut surface of older roots, but the area of the cavity is no more than one-third of the cross-section. Cultivated Astragalus membranaceus has a smooth epidermis, a more flexible root bark, a dense cross-section, a yellowish-white central wood core, and a firm texture. In the experiment, parallel determinations of the physicochemical properties of wild-simulated and cultivated Astragalus membranaceus samples were conducted. The experimental results are as follows: Wild-like Sample A ≥1.4 0.0956 6.2954 Special Class Wild-like Sample B ≥1.3 0.0922 5.8456 First Class Wild-like sample C ≥1.2 0.0981 5.8163 Wild-like sample D ≥1.1 0.0779 5.1314 Second Class Wild-like sample E ≥1.0 0.0664 5.1013 Cultivation Sample F ≥1.2 0.0333 4.6592 Selection of goods Cultivation Sample G ≥1.1 0.05367 4.5754 Cultivation Sample H ≥1.0 0.06164 4.1948 Mixed goods As shown in the table, the content of verrucoside glucoside and total flavonoids in the simulated wild samples were generally higher than those in the cultivated samples, and showed a positive correlation with the increase of diameter. Based on this characteristic, when constructing the batch domain descriptor for Chinese medicinal materials, the segmented intervals of color histogram statistics, power spectral moments, and gray-level co-occurrence moments were mapped to this physicochemical distribution. Specifically, after extracting the anchor region features, the system normalizes and maps the mean texture energy of each sample to its corresponding verrucoside glucoside content, and uses the total flavonoid content as the texture gradient constraint term, so that the distribution of visual feature space maintains a one-to-one correspondence with the physicochemical space.
[0023] Analysis of physicochemical test results from multiple sources revealed a clear statistical regularity between the diameter of Astragalus membranaceus and the content of its main active ingredients. Based on continuous sampling experiments, the diameter distribution of verbenafiloside glucoside and total flavonoids in the samples showed a trend of: "wild-simulated sample 1.4cm > wild-simulated sample 1.3cm > wild-simulated sample 1.2cm > wild-simulated sample 1.1cm > wild-simulated sample 1.0cm > cultivated sample 1.2cm > cultivated sample 1.1cm > cultivated sample 1.0cm."
[0024] The above patterns indicate that within a group of medicinal materials with a uniform macroscopic appearance, structural compactness and color distribution can reflect changes in the internal chemical composition. In the implementation design of this invention, the correspondence between ginseng and astragalus is used for adaptive correction of the algorithm's feature layer to achieve synchronous changes in physicochemical and visual characteristics.
[0025] During the descriptor training phase, the texture responses of samples of different grades were compared and analyzed. The surface texture ROIs of premium, first, and second-grade samples were selected for spectral decomposition. The results showed that the high-frequency power spectrum peak of premium samples was significantly higher than that of lower-grade samples, and the gray-level co-occurrence moments were more concentrated in the variance range of the energy channels. This indicates that the higher the content of the intrinsic active substances in the medicinal material, the higher the directional consistency and energy concentration of its microscopic surface texture. Based on this, this invention established a content-texture bivariate regression model. By dynamically adjusting the standardized parameters of the power spectrum moments, the visual response curve of the sample grade maintained a linear fit with the chemical content within a 0.95 confidence interval (R²). 2 (≥0.93), achieving collaborative modeling of physicochemical indicators and machine vision features. Step 4: Score all sub-windows for defects, obtain the original score set, and statistically analyze the reference area quantiles as the calibration benchmark; please refer to the schematic diagram of batch domain descriptor construction as shown in Figure 2. In specific implementation, each sub-window... The feature vector has been obtained from step 3. (Statistical analysis of color histograms, frequency band power spectral moments, and gray-level co-occurrence moments, etc., based on the fixed order of splicing). Classified by the quantile group to which the sub-window area belongs. (See step 3 for dividing the area into 25%, 50%, and 75%) Calculate the within-group sample mean vector. With covariance matrix When the number of samples in a group Less than the preset threshold At this time, triggering time-accumulated or contraction covariance estimation guarantees matrix invertibility. To obtain a sub-window difference measure, a weighted quadratic form is defined. ,in, For the first Sub-window feature vector; This is the vector of the mean values of the area quantile group to which the sub-window belongs; The regularized covariance matrix is defined as follows: ,in , For the feature dimension, This is the contraction coefficient (which can be estimated using Ledoit-Wolf or set as an empirical value, such as 0.05–0.2). For an identity matrix, regularization ensures that the matrix condition number is controlled and avoids singularities. —A diagonal weight matrix used to weight frequency bands / features according to signal-to-noise ratio. Weights The construction is as follows: First, the "band-type" characteristics (energy of power spectrum in several frequency bands) are indexed by frequency band. Estimating signal-to-noise ratio The recommended estimation formula is: ,in In frequency band For energy measures (e.g., the integral of the squared amplitude spectrum), the variances or variance-class statistics of the numerator and denominator are calculated on the anchor region set and the non-anchor background set, respectively. To prevent zero items. Then... Normalization yields the frequency band weights Map the frequency band weights to the corresponding dimensions of the feature vectors (set the positions of the frequency band class dimensions to the corresponding dimensions). For non-band features (such as color histogram and GLCM), after generalization by applying an inverse ratio to the intra-class variance or setting a constant baseline weight, the following results are obtained: (Diagonal element). The weighting design aims to amplify the spectral characteristics with higher signal-to-noise ratio in the current batch and suppress the interference of noise-dominated frequency bands on the metric.
[0026] In obtaining Then, compute the spatial-temporal local "quantile rank". This reflects the rarity of the sub-window within its neighborhood. Defined as the four neighboring sub-windows of the same frame and the corresponding sub-windows in the preceding and following T frames after spatial alignment (in the registered coordinate system), calculate the weight for each neighboring sample j: ,in Distance between the centers of space The number of frames in the time interval. Define the spatial / temporal scale parameter (in engineering, this can be set as a certain ratio of the sub-window half-width to the frame number window); then define the weighted quantile rank. ,in Since it is an indicator function, therefore This rank naturally suppresses instantaneous noise in both space and time, and ensures stronger neighbor influence through distance attenuation.
[0027] raw fractions Using an amplitude-rarity fusion approach: , Measure the degree (magnitude) of deviation from the within-group statistical model. Reflecting local rarity (quantile ratio), taking the square root of their product maintains numerical scale stability and balances deviation strength and local significance in statistical interpretation. If real distance is required, it can be replaced with... Variants, etc.; when implementing them, they should be uniformly selected within the system and recorded in the batch file to facilitate reproducibility.
[0028] In implementation: When The number of conditions exceeds the threshold or When, shrink the covariance or add a regularization term; when Extremely larger than other samples in the batch (exceeding) Trigger an anomaly alarm and record it; when the number of valid samples in the neighborhood is lower than hour, It degenerates into local empirical quantiles or adopts global quantile compensation.
[0029] quantiles in the reference region From a subset of anchor regions with high cross-frame persistence and seamless neighborhood (e.g., average IoU in the most recent K frames) Extract the original score set from the anchor. The required quantile (e.g., the 90th or 95th percentile) is calculated as the calibration baseline and written to the batch file. Triggering conditions include: when the total number of anchors in the batch... If the sample size of any quantile group is insufficient, a time window accumulation strategy can be initiated or the confidence level of the quantile can be reduced to avoid unstable calibration.
[0030] It should be noted that in this application, "weighted Mahalanobis distance" specifically refers to a quadratic measure after applying a signal-to-noise ratio driven diagonal weight matrix W to the feature dimension, thereby enhancing the spectrum class discrimination capability.
[0031] Step 5: Based on the difference between the batch domain descriptor and the reference descriptor, construct a monotonic piecewise mapping for the fractional domain, set quantile constraints, obtain mapping parameters, calibrate the original scores, and set a fixed threshold in the calibration domain; specifically, first define batch difference quantization. Assume the batch domain descriptor is numbered according to the area quantile group. The current batch is in the The group's description vector is The historical reference descriptor is the mean vector. With covariance matrix Calculate the Mahalanobis distance scalar for each group. Constructing a difference vector .when or any If the mapping parameters are re-evaluated, the previous batch of mapping parameters will be used; otherwise, the trigger threshold will be used. It is set by engineering requirements.
[0032] The mapping function is implemented using a piecewise cubic polynomial under monotonic constraints, and the initial values of the node evaluation points are set as several quantiles of the original fractions in the anchor region. , corresponding target value Calculated from the reference quantile group mapping target. Within the interval Above, define a standardized parameter for any input score s. The spline interpolation expression is: Hermite basis functions .in, For node function values, Let be the nodal derivative (i.e., the slope at the interval endpoints). Monotonicity constraints are expressed using linear inequalities: for any node, must satisfy... and To avoid oscillations caused by excessively steep derivatives, additional constraints are applied. ,constant Take between 2 and 5. I won't go into details.
[0033] The node-solving problem is formulated as a constrained quadratic programming problem, with decision variables being vectors. and The objective function is ,in This represents the original set of quantiles used for constraints (e.g., 25%, 50%, 75%, 90%). Weights corresponding to the reference quantile values Based on the sample size or confidence level of this quantile in the anchor set, the smoothing regularization term penalizes derivative oscillations, and the prior term... Provides conservative backoff (prior can be an identity mapping or parameters from the previous batch). The constraint set includes monotonicity and upper bound of derivatives, and adjustable range constraints for node positions. (When fine-tuning of node positions is allowed), and numerical stability constraints. .
[0034] When the anchor sample size is finite, the contraction strategy is activated: if the number of samples in a certain quantile group is... Then the weight according to Reduce, and shift the target value of the node towards the prior. To win over, or to smooth out the regularization coefficient Increase to the preset upper limit. Solving the listed constraint quadratic programming problem can be performed in parallel on GPU / CPU using the standard QP solver. If infeasibility is found during the solution process, the fallback strategy is to perform isentropic monotonic regression on Y to obtain a monotonic least squares solution, and then use finite difference estimation to estimate the initial value of M.
[0035] After obtaining the node parameters, perform a full analysis of all the original scores. Calculate calibration score Define the mapping residual metric. Perform iterative calibration: if And the number of iterations is less than Then use the current Recalculation of anchor points Update target The weighted terms are then used to solve the new QP; when or reach The process terminates at the designated time, and the parameters are recorded in the batch file.
[0036] Fixed judgment threshold In the calibration domain, the quantile constraint is determined. A common strategy is to take the first reference anchor from the set of reference anchors. Percentile calibration score. Parameter Based on an acceptable recall / precision tradeoff (e.g., 95%), when the anchor sample size is insufficient to reach the target threshold, a prior threshold is linearly mixed with the current batch threshold, with the mixing coefficient proportional to the anchor sample size.
[0037] In implementation, to avoid scoring bias caused by traditional algorithms relying solely on visual differences, this step constructs a monotonically piecewise mapping function based on quantile constraints, using physicochemical content as a reference. Samples with a content ≥0.058% of verrucoside glucoside are designated as the high-confidence interval, corresponding to the upper segment of the mapping function; samples in the 0.027%–0.058% range are designated as the medium-confidence interval; and samples below 0.027% are designated as the low-confidence interval. The system introduces a chemical content gradient term into this function, forming a continuously differentiable score correction curve. When the visual characteristics of a sample are inconsistent with its chemical indicators, the mapping function automatically adjusts the bias Δθ, ensuring monotonically consistent scoring results. This method ensures that although different batches and sources of medicinal materials may have visual differences, a unified judgment standard can still be obtained after correction based on the chemical benchmark.
[0038] To verify the effectiveness of the calibration method, the classification accuracy was compared between two approaches: traditional fractional mapping and the introduction of a physicochemical calibration model. The results showed that the overall accuracy without physicochemical calibration was 87.3%, while the accuracy increased to 96.1% using the method of this invention. Particularly in samples with uneven illumination and significant color deviations, the misclassification rate decreased from 12.7% to 3.9%. This demonstrates that the introduction of physicochemical data significantly improves the stability and robustness of the model in complex sample environments.
[0039] Step 6: Calculate the structural tensor direction and the difference in cross-seam strength on both sides of the seam strip to generate the seam continuity field and establish a boundary mask. Specifically, this step receives the seam strip centerline L and sub-window index generated in step 1, and performs discrete sampling of the seam strip along the short axis direction. It calculates the continuity metric of each sampling point and generates a spatialized mask for subsequent reliability ranking of the cross-window adjacency graph and seam neighborhood removal.
[0040] The working principle is as follows: a sequence of uniformly discrete sampling points is performed on the centerline L along the seam strip. The sampling step size is recorded as (pixels), the recommended value range is 1 / 20 to 1 / 5 of the sensor resolution. For each sampling point, local sub-regions are cropped to the left and right along the short axis. Sub-region size set to (short axis width) For a multiple of several sampling step sizes, the major axis (Covering several adjacent sampling points), the sub-regions are rotated and aligned relative to the center line in the same direction to ensure that texture statistics are compared in the same local coordinate system.
[0041] Local sub-region grayscale image First calculate the horizontal gradient with vertical gradient The formula is: To suppress noise, the squared gradient term is Gaussian smoothed to construct the structure tensor field. Among them, Gaussian kernel ,parameter Recommendation Pixel range, increase It brings stronger smoothness and scale invariance but sacrifices local orientation sensitivity.
[0042] For each pixel, calculate the eigenvalues and principal direction of the 2×2 symmetric matrix J. The eigenvalue expression is as follows: main direction use ,in Return angle at Interval; due to the 180° period of the direction, the subsequent spatial average is represented by a double angle (the following average of the direction uses the double angle method). Construct the local consistency coefficient. The coefficient ranges from [0,1). A value close to 1 indicates strong local anisotropy (with a clear main direction), while a value close to 0 indicates isotropic texture or noise.
[0043] Statistical gradient intensity field for each sampling point in the left and right sub-regions The mean and robust standard deviation are defined as follows: Similarly, we can conclude that The normalized cross-joint strength difference is defined as... This quantity measures the degree of deviation in strength distribution on both sides. The larger the value, the more severe the sudden change in strength across the joint, which is commonly seen in joint artifacts or material fracture.
[0044] The directional difference is calculated by directional weighting within the left and right sub-regions, for each pixel direction. Calculate double angle vectors According to its corresponding consistency coefficient Weighted summation restores the average direction: , respectively obtained . direction difference Standardization to Post-construction direction consistency factor The factor is set to 1 to indicate that the directions are consistent, and 0 indicates that the structure is orthogonal or strongly inconsistent in the opposite direction.
[0045] The smaller of the left-right consistency coefficients is taken and combined with the direction factor and intensity attenuation to form the sampling point continuity coefficient. If both sides have stable main directions and consistent directions with small intensity differences, a high CF value indicates good continuity at the joint. Conversely, a low CF value indicates that the joint may be an artifact or an actual fracture, and the reliability weight of this joint segment needs to be reduced in subsequent processing.
[0046] Integral along the centerline to accumulate continuity lines This scalar reflects the total continuity of the entire joint segment; the smaller the value, the less reliable the entire joint segment is. Threshold setting rule: If or more than the seam sampling points This triggers the unreliable joint flag. Typical parameters: This is the empirical value of the 10th percentile within the sample. Take 0.2–0.5, Use a value of 0.2–0.4, which can be adjusted according to the material texture and on-site noise.
[0047] The process for generating a binary boundary mask for the continuity coefficient field of the sampling points is as follows: First, thresholding is performed on the CF map to extract the low-value range. Marked as discontinuous segments, then morphological closing operations are performed to fill small gaps, followed by removing segments with areas smaller than [the specified area]. The isolated fragments were then subjected to a mask dilation process to obtain the width. The seam influence zone. The recommended size for the morphological structural element is 3–11 pixels, depending on the width of the sub-window and the seam. The mask output fields include the center position, length, local minimum CF value, and percentage of each discontinuous segment. These are used in step 7 to perform reliability sorting and weighted suppression of adjacent edges across windows, and in step 2 to accurately remove seam neighborhoods when filtering anchor areas.
[0048] As one possible implementation method: gradient and Gaussian convolution are accelerated using separable filtering and integer convolution; pixel features of the structure tensor are stored using single-precision floating-point and... Upper / lower bound pruning is performed to avoid numerical overflow; directional averaging uses double-angle representation to handle 180° periodicity; statistics Incremental windows or integral plots are used for rapid updates, facilitating online processing. If the seam covers a large portion of the image area, or... If the value remains low for multiple consecutive frames, a higher-level domain drift process is triggered (see the domain drift determination in step 5), such as reconstructing the seam index or adjusting the threshold set. The specific strategy can be set according to the process requirements. It should be noted that the structural tensor consistency coefficient in this application characterizes the directional clarity of the local texture and provides directional average weighting; the directional consistency factor can uniformly measure the reverse and forward directions.
[0049] Step 7: Within each sub-window, perform connected component labeling based on the calibration score and threshold, and map it to global coordinates. Construct a cross-window adjacency graph composed of seam continuity and shape compatibility, and generate a global defect instance set through merging and nonmaximum suppression. The specific working principle is as follows: It starts from the sub-window level. For any sub-window i, the input is the calibration score field corresponding to the sub-window. (Outputs from steps 4 and 5) and the global decision threshold (Step 5 definition). Sub-window binarization uses the following rule: binary mask. To suppress isolated noise, after binarization... Perform morphological opening and closing operations (structural element radius) (A resolution of 1–5 pixels is recommended, but can be adjusted based on resolution). Connectivity component labeling uses the 8-connectivity rule to obtain a set of local candidate regions. For each connected component Computational geometry and statistical properties: Area ,perimeter Boundary polygon (outline) center of gravity convex hull area entity rate The spindle length ratio AR (based on the second-order central moment), Hu invariant moment, etc., are calculated simultaneously, along with the average calibration score within the region. .like or or If the defect is removed, the remaining area is considered as a candidate for local defect.
[0050] The local to global coordinate mapping uses the sub-window indexing and registration transformation from step 1. Let the pixel coordinates of the origin (top left corner) of sub-window i in the original frame be... If the sub-window undergoes affine transformation during registration... (For example, the affine matrix generated by sub-pixel registration), then the boundary points of the connected components will be... Mapped to global coordinates The centroids, boundaries, and polygons of connected components are all transformed using the above mapping to obtain the global initial node set. Each node Vector with attributes .
[0051] Window adjacency graph The construction is based on spatial proximity, overlap / proximity, seam continuity, and shape compatibility. For any node pair... (Usually limited to adjacent child windows or global distance less than) Calculate the following metrics for the node pairs and normalize them to [0,1]: Shape compatibility It uses the Intersection over Union (IoU) ratio as its core and supplements it with boundary similarity. Definition , , (where the length is the diagonal of the boundary), then take ,in A positive weight is used to control the penalty for differences in boundary and shape proportions. This design balances area overlap with contour consistency.
[0052] Seam continuity factor Take the mean of the continuity function CF (output of step 6) along the ridge segment crossing the seam between the two nodes. If the segment belongs to the "unreliable zone" of the seam mask, then let Reduce weights (multiply by a factor of 0–1). Set after normalization. .
[0053] Score similarity Alternatively, a correlation coefficient can be used to reflect the consistency of calibration scores within the region.
[0054] The above sub-items are linearly or convexly combined to form edge weights. parameter and normalize it. Typical value range: ,and When any node crosses the seam and the seam mask is marked as strongly discontinuous, it is forced to... Reduce the value to a low value or set it to zero to avoid accidental merging across seams.
[0055] The merging strategy uses a "restricted disjoint-set data structure" to merge edges in descending order of weight on the weighted graph: all edges are merged according to... Sort the edge set in descending order, traverse the edge set, and check the weights. The edges attempt to merge the sets to which the nodes at both ends belong; constraints are checked before merging: area of the merged set. Not exceeding (To prevent mistakenly merging large backgrounds as defects), merging must not cross unreliable segments with seams (i.e., if the merging path must cross seams marked as "unreliable," then merging is rejected), and the average shape compatibility of the merged set must not be lower than [a certain value]. If the constraints are met, perform a union operation and update the set properties (area, boundary, average score, convex hull, etc.). This union-find set strategy is equivalent to merging based on local reliability, which can retain high-confidence cross-window instances while avoiding erroneous merging caused by seam artifacts.
[0056] After unifying the search set and obtaining the initial global candidate set, weighted intersection-union ratio (IURR) nonmaximum suppression is performed. The weighted IURR of two candidate instances A and B is defined. ,in The average CF corresponding to the overlapping region of the two instances. The adjustment coefficient is used. The NMS process is as follows: Candidates are sorted in descending order of their confidence scores (e.g., the ensemble average calibration score plus area-weighted sum). The candidate set is traversed, and for the current candidate c, its maximum value with the set of selected instances is calculated. ;like Then compare scores: if score c > the maximum score of the selected instance that intersects with it, then keep c and remove all instances that intersect with it. Instances of c; otherwise, discard c. This rule is equivalent to "retaining the highest scorer in the local overlap group, while allowing newcomers to replace previously selected ones when necessary," thus balancing detection sensitivity and deduplication effectiveness. Parameters The initial engineering recommendations are 0.5–0.7, 0.3–0.6, 0.5, and 0.5, which can be adjusted according to materials and false alarm tolerance.
[0057] When the number of initial candidates is abnormally large Or the total number of instances after merging < At that time, the activation threshold is adaptive: increase Increase Or switch to a more conservative approach. Parameters; if the seam continuity field is below the threshold on a large number of adjacent edges, backtrack to step 6 to reconstruct the seam mask or trigger the domain drift notification in step 5.
[0058] The final output is a global set of defect instances. Each instance contains: a global polygon mask, boundary chains, area, average calibration score, shape features, cross-window component node indexes, and a seam reliability summary. This output serves as input for steps 8 / 9 (attribution mapping, carrier-level statistics) and is also written to the batch archive for retrospective fine-tuning of mapping parameters for subsequent batches.
[0059] Step 8: Generate the foreground response map of the medicinal herb slices. Obtain the set of slice instances using distance transformation and watershed methods, and repair the seam contour according to the seam continuity field cost; please refer to [link / reference]. Figure 3 The diagram shown illustrates foreground response and watershed correction. The input for this step is the original registration frame image. Step 7 outputs a global defect instance mask set. The seam continuity field CF(x) output from step 6 (defined on the seam ridge or its neighborhood). Foreground enhancement first removes static background noise using the temporal background model B(x,y): the median of the pixels in the nearest K frames is used as the background reference. Or use a weighted recursive background As an alternative; parameter K is recommended to be 3–7. A value of 0.85–0.98 is recommended, but this can be adjusted based on transmission rate and scenario variations. The original difference in foreground response is defined as... Then, local normalization filtering and contrast enhancement are performed: local mean is calculated. Standard deviation (window radius) (typically 8–32 pixels), to obtain the normalized response. And apply restricted histogram equalization (CLAHE) or Gaussian smoothing (radius) to R. To generate the final foreground response map To suppress the influence of the global defect mask, first... Regions are masked during background modeling or weighted less in the final foreground response to avoid interference from defective areas in sheet segmentation.
[0060] based on Generate binary foreground mask The steps are as follows: Use Otsu or adaptive local thresholding get And on Perform morphological cleanup (opening operation for noise reduction, closing operation for hole filling, structuring element radius adjustment) The distance transformation uses Euclidean distance transformation (EDT) to calculate the distance from each foreground pixel to the nearest background pixel. This transformation can be implemented using Felzenszwalb's linear-time EDT algorithm or the classic Euclidean DT. Interior point seed set. The set of local maxima from D: first smooth D (Gaussian radius) ), then extract the satisfaction {if and only if} .
[0061] in Set the minimum interior point distance threshold (it is recommended to be proportional to the minimum radius of the target, such as 4–12 pixels). For local neighborhood windows (radius) At the same time, nonmaximum suppression ensures that the distance between any two sub-subs is greater than 1. (Avoid overly fine segmentation). Apply a rejection rule to seeds near the seam mask area: if the seed is far from the seam centerline... And corresponding seam points If the seed is not found, it will be removed to prevent seam artifacts from generating incorrect slices.
[0062] Watershed segmentation uses a gradient map G(x,y) as a damping field. The gradient is calculated from the input brightness or foreground response and is defined as follows: Or use nonlinear transformation of edge magnitudes Adjust sensitivity to deep textures. Mark watersheds to... To label the fragments, run the label watershed algorithm to obtain a preliminary set of fragment instances. For each Calculate area ,boundary Average prospect response Remove or The pseudo-film.
[0063] When the watershed boundary crosses the seam neighborhood (i.e., the boundary overlaps with the seam influence zone), calculate the cost of that boundary segment. in For discrete points of the boundary segment, The sampling step size is used to construct the joint projection continuity field. Diffusion of CF along the ridge line into the two-dimensional neighborhood: in Control the impact bandwidth and define pixel cost mapping The boundary replacement problem is transformed into a problem involving a graph composed of pixels. Find the minimum cost path. For the endpoints p and q of the watershed boundary to be repaired (located at both ends of the boundary segment), solve using Dijkstra's algorithm or A* on the subgraph containing the joint influence zone. If the cost of the replaced path satisfy To replace the penalty term and avoid minor oscillations, it is recommended to use a term related to boundary smoothing. Then, replace the original boundary segment with p*, followed by boundary smoothing (B-spline or curve fitting) and pixel-level redistribution. Merge or segment adjacent sheets to restore a coherent sheet mask. This repair process can be performed in parallel on all cross-seam boundaries, or preferentially on local segments where low seam continuity is found. The iteration criterion is: if the replacement leads to a decrease in the total boundary cost... Then continue iterating, or until the maximum number of iterations is reached. Stop; Recommend .
[0064] After boundary repair, merge adjacent overlapping sheets. And apply hole filling and small piece removal (area threshold) Output the final collection of slice instances. The modified boundary mask set, with each piece having a repair summary field (whether it is a cross-seam repair, the original cost, the new cost, and the cost reduction amount), is written to the batch file for auditing and subsequent parameter fine-tuning.
[0065] It should be noted that the foreground response map represents a normalized and enhanced continuous response field, which is beneficial for stabilizing seed detection and gradient calculation; the interior point seed refers to the local maximum of the distance transformation, which serves as a watershed marker to ensure that the segmentation granularity is consistent with the physical sheet; the seam continuity field (CF) is different from a simple seam mask. It is a field with a numerical continuity metric, which can be projected onto the two-dimensional pixel domain and drive the minimum cost path algorithm.
[0066] Step 9: Construct a bipartite graph of defect instances and sheet instances. The edge weights are given by the region intersection-union ratio, boundary direction difference, and seam continuity integral. Solve for the maximum weight matching to obtain the defect attribution mapping. Specifically, in the candidate pairing generation stage, for any defect node... With sheet body node First, calculate the Euclidean distance between the centroids. Only for those that satisfy The pairing constructs a candidate set (where (Can be set according to typical film size or pixel scale). Three types of raw quantities are calculated for each candidate pair: The first type, the intersection-union ratio of regions, is defined as... in This represents pixel area or a continuous area measure. To compensate for the difference in expected overlap caused by area imbalance, a kernel regression based on batch anchor samples is used to estimate the expected overlap function. Let the area ratio... Batch anchor sample set Estimate using Nadaraya–Watson kernel regression: The kernel function is a Gaussian kernel. The bandwidth h can be determined according to the Silverman rule or cross-validation (in engineering practice, it can be initially set to 0.05–0.2). The normalized adjusted intersection-union ratio is denoted as... in To prevent zero items.
[0067] The second type calculates boundary normal similarity using a weighted cosine average of the normal vectors at contact / coincident boundaries. This involves sampling a set of points at the overlapping or nearest-neighbor boundaries of the two regions. Calculate the boundary normal vector of the defect and the sheet body at each point. (The contour tangent is estimated using the difference between adjacent points, and the normal is the tangent rotated counterclockwise) (and normalize), and take the joint continuity coefficient output from step 6. As a weight, we define weighted cosine similarity. The value of this quantity is approximately in the range of [-1, 1]. For subsequent linear combinations, it needs to be mapped to [0, 1]. This can be achieved using... .
[0068] The third type involves sampling the line integral of the seam continuity along the coincident boundary or crossing path between the two. in The sampling step size (pixels) is numerically normalized to average continuity, reflecting the reliability of the joint across the boundary segment.
[0069] After obtaining the three types of raw quantities, construct the training matrix. (M is the number of high-confidence anchor samples within the batch), each row contains The normalized value of the target vector Indicate the true / false labels for the pairings (true matches with high confidence are automatically labeled as 1, or manual / historical matches are used as supervision). Solve the restricted least squares problem, i.e.: This problem can be solved using nonnegative least squares or quadratic programming with equality constraints (numerical solution: active set method or using the standard QP solver); if the sample size is insufficient, NNLS can be used. Post-normalization The resulting weight vector It is the linear combination coefficient of the three types of quantities, and is archived with each batch to achieve batch adaptation.
[0070] The edge weights are constructed as a linear combination: To avoid the creation of isolated, low-quality edges, a dynamic thresholding rule is adopted: the edge weight distribution for a certain defect or local candidate set. Calculate the median With absolute median Take dynamic threshold Where the constant Version 1.0–2.0 is recommended. This is a preset lower limit (e.g., 0.1). Only when... and When constructing edges on a bipartite graph and empower .
[0071] Constructed bipartite graph The maximum weighted matching algorithm is used to find the optimal one-to-one assignment. The graph is then transformed into a weight matrix. For entries without edges, set the weight to 0 or a minimum value, and use the Hungarian algorithm or a general maximum weight matching algorithm to solve the problem of maximizing the total matching weight. To handle cases with unequal numbers of nodes, add virtual nodes with weights of 0 on the side with the smaller weight, thus obtaining one-to-one matching or partial matching results.
[0072] Detailed rules for matching: If a defect Two optimal candidates and suboptimal Matching weight difference Less than the discrimination threshold This is considered a fuzzy match, and the integrals of the seam continuity lines are compared sequentially according to priority. Boundary normal similarity Make a final attribution decision; if it still cannot be determined, mark the pairing as "difficult," write it to the batch file, and trigger manual review or further judgment based on subsequent frame accumulation. Default Take 0.05–0.15.
[0073] Once all affiliations are determined, a mapping set is formed. And calculate the attribution confidence (e.g.) (Ranking after normalization), unmatched defects are retained as isolated instances and marked as "unassigned"; if a piece is matched by multiple defects, a one-to-one match ensures uniqueness. If it is necessary to support scenarios where a piece corresponds to multiple defects, multiple edges with lower thresholds can be added to the same piece in the post-processing stage and multiple assignments can be recorded.
[0074] Step 10: Generate defect statistical labels based on the defect attribution mapping, write the batch domain descriptor, mapping parameters, reference quantile group, decision threshold, and seam continuity summary into the batch file, and monitor drift trigger parameter updates within a sliding time window. In implementation, defect category counting... Summarized by category index. Defect area percentage. The percentage of this type of defect area to the total foreground area of the medicinal material: The centroid spatial distribution is based on the sample mean vector. With covariance matrix The principal direction and eigenvalues of the covariance are represented as label fields. The slice overlap rate is defined as the defect coverage rate at the slice level: for each slice... Calculate coverage ratio The overall overlap rate is archived in quantile statistics (25%, 50%, 75%) and mean form. Defect continuity scoring uses normalized online joint continuity integrals: for each defect instance... Calculate the set of boundary sampling points Continuous scoring The minimum, mean, and standard deviation are recorded simultaneously as quantitative indicators of subsequent segmentation and repair quality. All of the above statistics are used to form a vector tag set in the batch-level summary and written into the archive.
[0075] Batch archives are organized by timestamp and version number, and each record contains a set of fields: batch number, timestamp, and snapshot mapping parameters. Reference quantile information, judgment threshold Batch domain descriptor The archive includes a seam continuity summary (e.g., seam line integral distribution), anchor sample statistics, trigger flags, and manual verification annotations. The archive uses a verifiable format (JSON or relational table rows) and calculates the signature hash and version chain number upon writing to support rollback. Specific details can be determined based on actual needs.
[0076] Drift monitoring is performed on a sliding window frame, where the sliding window contains either the most recent W batches or the most recent N tens of thousands of frames, and the monitoring sequence includes a set of key quantiles in the anchor region. (e.g., 25%, 50%, 75%, 90%) and empirical distribution of calibration scores. The test statistic is defined as follows: Significance level Recommended value: 0.01 or 0.05. The distribution difference is then determined to be significant, triggering an update. CUSUM change point detection is used to detect mean shift: [The text then abruptly shifts to a different topic:] ...take the sequence... Let the target mean be the anchor median or a certain quantile. Buffer constant k, decision threshold h, rising cumulative cumulative decline ,when or Alarm. Formula for tracking Exponentially Weighted Moving Average. Control limits adopt The corresponding lower bound and the recommended parameter range The monitoring logic is as follows: any statistical test exceeding its confidence threshold triggers a parameter update process.
[0077] The parameter update process is based on constrained weighted incremental least squares fitting. Abstractly, it involves the mapping function parameter vector... Solving the weighted least squares problem: objective function Where X is the anchor sample feature matrix (the original score of the anchor, etc.), y is the target mapping value (referencing the quantile target), and the weight matrix... Reflecting sample confidence and time decay, the decay strategy employs exponential decay. Attenuation factor Recommended value: 0.90–0.995; Ridge regularity coefficient Choose from 1e-4 to 1e-1, adjusting according to the number of problem conditions. For constraints, monotonicity and nodal slope constraints can be written as linear inequalities. The solution process employs incremental updates: if a new batch of observations provides matrix increments... Solve using regularized normal equations Incremental updates of the inverse matrix are performed using the Sherman–Morrison–Woodbury formula to improve online performance; when constraints are active, a constrained quadratic programming solver (active set method or projected gradient method) is used. After solving, the mapping function is simulated and replayed: the new parameters are applied to historical anchor samples to calculate the new calibration score sequence. Thresholds are determined based on quantile reestimation. And introduce smoothing to the threshold. .
[0078] After the update, key performance indicators (recall, precision, false positive rate) are calculated on a short-term validation set or retention window. If any key indicator decreases by more than a preset threshold compared to before the update, it is marked as a failure and automatically rolled back to the previous parameter. Rollback records include trigger time, trigger statistic, sample summary, version number, and rollback flag. All change records are written to the batch file with the following fields: old parameter snapshot, new parameter snapshot, trigger reason, test statistic, sample summary, version number, rollback flag, and manual review annotation.
[0079] In the design of this invention, the aforementioned physicochemical standards and grading information are written into the batch file for long-term drift monitoring and automatic updates. Specifically, the system statistically analyzes the average content of isoflavone glucoside and total flavonoids in 30 consecutive batches within a sliding time window. When a trend deviating from the predetermined reference range is detected (e.g., for top-grade samples, d ≥ 1.4 cm, total flavonoid content ≥ 6.2954%), the system automatically triggers model retraining and threshold resetting processes. In this way, the system can adaptively track changes in physicochemical properties caused by the source of the medicinal material, cultivation environment, or storage conditions, maintaining consistency between the detection threshold and the actual quality of the medicinal material.
[0080] In the batch domain descriptor storage, the system also stores the corresponding average physicochemical content. and variance And based on this, a drift statistics matrix is constructed. When the Euclidean distance between M(t) and the historical mean M0 Exceeding the preset threshold At this time, the system automatically executes a self-closed-loop correction process of "fractional domain remapping - threshold recalibration - descriptor recalibration". This mechanism effectively prevents recognition bias caused by model aging and ensures the stability and traceability of long-term monitoring of defects in Chinese medicinal materials. It should be noted that the batch archives in this application can fully record batch-level domain descriptions, mapping parameters, thresholds, seam summaries, trigger logs, and version history for reference in traceability, auditing, and subsequent fine-tuning. Drift triggering refers to the parameter update triggering process determined by a combination of sliding window statistical tests.
[0081] Finally, one possible implementation of the image acquisition method for consecutive frames and overlapping windows in this invention is as follows: camera resolution ≥ 2048×2048, sub-window size preferably 128×128 pixels, sub-window overlap rate r is 0.10–0.30 (0.20 recommended); frame rate and transmission line speed must meet pixel displacement constraints. ,exposure According to motion blur limit Pixel calculation; the seam width is set according to the ratio of α to the short side of the sub-window, with α ranging from 0.05 to 0.15 (0.10 recommended). The purpose of this imaging method is to ensure that films of different thicknesses and colors appear at least once in several consecutive frames and overlapping sub-windows, facilitating subsequent anchor point association across windows and frames.
[0082] As one possible implementation method, in the specific implementation of the machine vision-based method for detecting defects in traditional Chinese medicine materials described in this invention, Ligusticum chuanxiong was selected as a representative medicinal material for joint verification experiments. Ligusticum chuanxiong has a typical rhizome structure, and its appearance, internal components, and storage stability vary significantly, which can comprehensively reflect the adaptability of the method in morphological discrimination, optical feature recognition, and batch drift calibration.
[0083] A total of 21 batches of Ligusticum chuanxiong samples from different origins and storage times were collected for the experiment. The content of ligustilide I and the transfer rate of ligustilide in the extract were determined according to different origins. The samples were divided into a fresh sampling group and a stored group based on storage time; the fresh sampling group consisted of newly harvested samples, while the stored group covered samples stored for 1-8 months. To ensure image acquisition consistency, a high-resolution industrial camera was used for continuous frame shooting at a resolution of 4096×2160 pixels. The light source was a constant color temperature 5000K area array light source, and the distance was fixed at 45cm. Images were segmented using a sliding window with a window size of 512×512 pixels and an overlap width of 20%. A seam index was established for subsequent continuity correction.
[0084] B01 0.9 70% Nodular, fist-shaped clumps, 5–6 cm in diameter. The surface is brown, rough, and wrinkled, with a sunken, nearly circular stem scar at the apex. The cut surface is yellowish-white and nearly circular, with distinct wavy rings and dense yellowish-brown oil. B05 1.1 74% It is multinodular and spindle-shaped, with numerous parallel raised nodes at the top. The surface is grayish-brown, rough, and wrinkled, with a sunken, nearly circular stem scar at the apex. The cut surface is yellowish-white and irregularly shaped. It has distinct irregular textures and scattered yellowish-brown oil dots, fewer than those in B01 and B05. B09 0.22 52% Nodular, fist-shaped clumps, 5–6 cm in diameter. The surface is brown, rough, and wrinkled, with a sunken, nearly circular stem scar at the apex. The cut surface is yellowish-white and nearly circular, with distinct wavy rings and dense yellowish-brown oil. B13 0.34 56% It is multinodular and spindle-shaped, with numerous parallel raised nodes at the top. The surface is grayish-brown, rough, and wrinkled, with a sunken, nearly circular stem scar at the apex. The cut surface is yellowish-white and irregularly shaped. It has distinct irregular textures and scattered yellowish-brown oil dots, fewer than those in B01 and B05. The content of ligustrazine I in each batch of medicinal slices was determined, and time-series data were generated. The measured data are shown in the table below: Experimental results showed that the content of ligustilide I in Ligusticum chuanxiong from different origins and the transfer rate of ligustilide I in the extract varied significantly. The content of ligustilide I changed over different storage periods. Both the content and the transfer rate of ligustilide I in the extract showed an increasing trend in the first six months, with a faster increase in content between 4 and 6 months. After 6 months of storage, both levels tended to stabilize.
[0085] Based on the above experimental data, to further verify the effectiveness of the machine vision-based method for detecting defects in traditional Chinese medicine in terms of physicochemical index calibration, the change in the content of ligustrazine I was used as the main external reference parameter to construct a batch-domain reference curve. Experiments showed that the content of ligustrazine I varied within the range of 0.22–1.10 mg / g in ligustrazine samples from different origins and with different storage periods. The content increased significantly in the first six months of storage and then stabilized after six months. This trend was used to establish a quantile mapping model to correct the bias caused by storage effects on visual scores. Through quantile modeling, the ligustrazine I content at 0.32 mg / g, 0.46 mg / g, 0.61 mg / g, and 0.69 mg / g was mapped to the 25%, 50%, 75%, and 90% nodes of the score domain, respectively, forming a batch-domain calibration baseline. This mapping was used to correct score fluctuations caused by storage time or surface color differences, ensuring that the score domain distribution reflects the true changing trend of the intrinsic active components of the medicinal material.
[0086] In the image preprocessing stage, the system performs sliding window segmentation on consecutive frames of all captured samples and filters based on gradient variance, texture energy, and color entropy to remove splicing gaps and boundary interference regions. To ensure the stability of feature extraction, regions with rich details and uniform reflection features are selected as anchor regions. The selection criteria are shown in the table below: gradient variance > 70% percentile Preserve rich details in the area Texture Energy > 60% percentile Preserve areas rich in structural information Color Entropy < 90th percentile Excluding high-noise chroma regions The selected anchor regions were used to extract color histogram statistics, power spectral moments, and gray-level co-occurrence moments, and combined with storage period information to generate batch domain descriptors. The descriptor has a dimension of 128, incorporating time-series variation parameters corresponding to the content of ligustilide I to ensure comparability of feature differences between different batches after standardization.
[0087] All sub-windows are processed by the defect detection model to generate an original score set. To eliminate the systematic offset of scores due to storage conditions, this invention introduces a monotonic piecewise mapping function based on batch domain descriptor differences to map the original score set to the calibration score space. The mapping nodes are shown in the table below: 10% 0.12 0.30 0.11 25% 0.20 0.32 0.17 50% 0.35 0.46 0.30 75% 0.58 0.61 0.46 90% 0.81 0.69 0.68 This piecewise mapping function automatically adjusts the weights during the intermediate storage phase when content changes significantly, ensuring that samples with high content correspond to higher score responses, while samples whose surfaces become dark or oil spots become blurred due to storage still maintain the correct ranking relationship after calibration. After calibration, the average score of samples after two months increased by approximately 7% compared to the initial samples, samples after four months by approximately 18%, and samples after six months by approximately 20%, demonstrating that the model effectively eliminates false alarms caused by changes in appearance.
[0088] During image stitching, the seam area is a concentrated area of stitching errors across multiple frames, often leading to structural pseudo-cracks. Therefore, this embodiment calculates the principal vector difference of the structural tensor across the seam. and strength difference Define continuity The system generates a continuity field based on this. Regions with a continuity value below 0.5 are automatically enlarged to a mask half-width of 20px to avoid false detections. This continuity field is also used in subsequent segmentation and repair processes. When the watershed algorithm encounters a fracture boundary, the system automatically repairs it based on the shortest path constraint of the continuity field, enabling the differentiation between crack-like defects and natural texture fractures.
[0089] During the matching phase between the sheet body and the defect instance, the system constructs a bipartite graph for the sheet body and the defect instance. The edge weight w is determined by the region intersection-union ratio (IoU), the boundary direction difference Δφ, and the seam continuity integral. Composed of: .
[0090] Parameters α=0.5, β=0.3, γ=0.2.
[0091] To adapt to the typical morphology of Ligusticum chuanxiong, a "shape compatibility S" constraint term is added. Matching is rejected when S is below 0.6. The shape compatibility is derived from a typical fist-shaped sheet contour template, with shape frequency domain features extracted using Fourier descriptors. This template originates from the morphological measurement results of the medicinal material, ensuring that the attribution logic conforms to the natural morphological distribution pattern of Ligusticum chuanxiong.
[0092] To verify the stability of the calibration strategy, the average calibration score and the change in the content of ligustrazine I in samples with different storage periods were compared and analyzed. The results are shown in the table below: 0 0.18 0.30 0 2 0.25 0.46 +0.07 4 0.36 0.61 +0.18 6 0.49 0.68 +0.31 8 0.62 0.69 +0.44 The results showed a significant positive correlation between fractional drift and changes in the content of ligustrolactone I. The system was designed with drift triggering conditions within a sliding time window: when the median calibration score deviated from the baseline by more than 12%, while the change in ligustrolactone I content was less than 0.01 mg / g, model drift was identified, and automatic re-estimation of the mapping function was triggered; otherwise, it was considered a natural physicochemical change in the medicinal material. This strategy enabled the system to distinguish between storage-induced appearance degradation and model drift, ensuring long-term robustness.
[0093] To evaluate the consistency of the model output, 100 sets of samples were selected, and the defect areas were determined by human experts and compared with the model output. The consistency rate is as follows: G1 12 11 91.7 G2 15 14 93.3 G3 18 17 94.4 G4 14 13 92.9 average — — 93.1 Comparative results show that the model's detection results are highly consistent with manual judgment standards under different storage periods and appearance conditions. Through the synergistic effects of feature extraction, calibration mapping, and shape restoration, the system can accurately reflect the visual response patterns of *Ligusticum chuanxiong* during physicochemical changes. Experimental results regarding storage period and *Ligusticum chuanxiong* lactone I content provide a reliable basis for fractional calibration and drift monitoring, while the combination of morphological templates and texture descriptors ensures the model's adaptability and stability in structurally complex samples. Overall, the results verify the robustness and consistency of the method under different batches and physicochemical conditions, demonstrating its promising industrial application potential in the field of intelligent quality detection of traditional Chinese medicine.
[0094] It should be noted that the mathematical formulas, derivations, symbol definitions, and parameter calculation methods used in this specification are all for the purpose of further clarifying and demonstrating the technical content of this invention, so that those skilled in the art can more intuitively and accurately understand the working mechanism and technical effects of this invention. These formulas are only used as quantitative expressions or illustrative examples of technical features and do not constitute limiting conditions of the claims of this invention. Those skilled in the art should understand that, without changing the core idea of this invention, the parameter forms, calculation methods, numerical ranges, and even symbol representations involved in the formulas can be equivalently replaced or simplified in engineering according to the actual application environment. The specifics can be determined according to the actual situation, and no limitation is imposed. It should also be emphasized that the formulas in this specification are not theoretical derivations in the style of academic research papers, but rather an engineering description of the embodiments of this invention. Their purpose is to enhance the understandability and implementability of this invention, rather than to increase redundancy and complexity. Those skilled in the art can choose whether to use such quantitative tools when reading this specification, or can achieve the same technical effects through other equivalent methods.
[0095] While specific embodiments of the present invention have been described above, those skilled in the art should understand that these specific embodiments are merely illustrative. Those skilled in the art can omit, substitute, and modify the details of the above methods and systems in various ways without departing from the principles and essence of the present invention. For example, combining the above method steps to perform substantially the same function and achieve substantially the same result according to substantially the same method falls within the scope of the present invention. Therefore, the scope of the present invention is defined only by the appended claims.
Claims
1. A method for detecting defects in Chinese medicinal materials based on machine vision; characterized in that: include: Step 1: Collect continuous frame images of Chinese medicinal materials, generate a set of sub-windows of medicinal materials according to fixed window and overlap width, and establish an index of the seam band of medicinal materials; Step 2: Within the set of medicinal herb sub-windows, filter the set of medicinal herb anchor regions based on gradient variance, texture energy, and color entropy, and remove the neighboring regions of medicinal herb seams. Step 3: Extract the color histogram, power spectral moment and gray-level co-occurrence moment of the Chinese medicinal materials anchor region set, construct the batch domain descriptor of Chinese medicinal materials, and read the reference Chinese medicinal materials descriptor and reference quantile group; Step 4: Score the defects of all medicinal materials in the sub-windows, obtain the original score set, and count the reference area quantiles as the calibration benchmark. Step 5: Based on the difference between the batch domain descriptor of the Chinese medicinal materials and the reference Chinese medicinal materials descriptor, construct a monotonically segmented mapping of the fractional domain, set quantile constraints, obtain mapping parameters, calibrate the original fractions, and set a fixed judgment threshold in the calibration domain; the monotonically segmented mapping process of the fractional domain is as follows: A quantized difference vector is obtained by using Mahalanobis distance to measure the batch domain descriptor of Chinese medicinal materials and the reference Chinese medicinal materials descriptor. A piecewise response function is generated by fitting the correspondence between the quantized difference vector and the original score set of the sub-window using a B-spline piecewise interpolation algorithm. A mapping parameter set is obtained by solving the node positions and interval slopes of the piecewise response function using anchor region area quantile constraints, thus generating a mapping function. All original scores are numerically transformed using the mapping function to obtain a calibration score sequence. Iterative updates of the node slopes are triggered by quantile back-substitution constraints, stopping when the mapping residual is less than a set convergence threshold. A fixed Chinese medicinal materials judgment threshold is generated based on the calibration score sequence, and this fixed judgment threshold is determined by the quantile position constraint method of the calibration score distribution. Step 6: Calculate the structural tensor direction and the difference in cross-joint strength on both sides of the joint of the medicinal material, generate the continuity field of the joint of the medicinal material and establish a boundary mask; Step 7: Within each herb sub-window, perform connected component labeling based on calibration score and threshold and map it to global coordinates. Construct a cross-window adjacency graph composed of herb seam continuity and shape compatibility, and generate a global set of herb defect instances through merging and non-maximum suppression. Step 8: Generate the foreground response map of the medicinal herb slices, obtain the set of medicinal herb slice instances through distance transformation and watershed method, and repair the joint contour according to the continuity field cost of the medicinal herb joints. Step 9: Construct a bipartite graph of defect instances and medicinal material slice instances. The edge weights are given by the region intersection-union ratio, boundary direction difference, and seam continuity integral. Solve the maximum weight matching to obtain the defect attribution mapping of Chinese medicinal materials. Step 10: Generate defect statistical labels based on defect attribution mapping, write the batch domain descriptor, mapping parameters, reference quantile group, judgment threshold and joint continuity summary of Chinese medicinal materials into the batch file of Chinese medicinal materials, and monitor drift within the sliding time window to trigger parameter updates.
2. The method for detecting defects in Chinese medicinal materials based on machine vision according to claim 1, characterized in that: The working process of step 2 includes: The image data of medicinal materials within the sub-window are locally normalized in the spatial domain to generate a basic matrix of medicinal materials with balanced contrast. Based on the aforementioned fundamental matrix, three types of indicators related to the surface texture of Chinese medicinal materials are calculated: gradient variance, texture energy, and color entropy. Adaptive thresholds are set according to quantile distribution for joint screening. During the screening process, the candidate region is constrained by the minimum boundary distance to eliminate abnormal regions located at the outer edge of the medicinal material and on the stacked thin slices of the medicinal material. The retained candidate regions are used to generate a primary set of Chinese medicinal herb anchor regions through hierarchical connectivity analysis, and cross-frame consistency detection is performed on the primary set of Chinese medicinal herb anchor regions to remove transient noise patches. Output the set of anchor regions for Chinese medicinal materials after spatial uniformity constraint correction.
3. The method for detecting defects in Chinese medicinal materials based on machine vision according to claim 1, characterized in that: The working process of step 3 includes: Within the anchor region of Chinese medicinal materials, the image is converted to the CIELab color space, and a 32-level normalized color histogram is generated for each channel as the statistical histogram of Chinese medicinal materials color. A two-dimensional fast Fourier transform is performed on the grayscale image of the anchor region. The amplitude spectrum is integrated piecewise along the radial direction, and the first and second order power spectral moments are extracted to characterize the surface spectral features of Chinese medicinal materials. A gray-level co-occurrence matrix with a pixel spacing of 1 and orientations of 0°, 45°, 90° and 135° was constructed, and four statistical measures, namely contrast, correlation, energy and homogeneity, were calculated to characterize the micro-texture of Chinese medicinal materials. The histogram statistics, power spectral moments, and gray-level co-occurrence features are spliced together in a fixed order to form a batch domain descriptor for Chinese medicinal materials. Based on the 25%, 50%, and 75% quantiles of the anchor region area, quantile groups are divided, and the mean and covariance matrix of each quantile group are calculated as reference Chinese medicinal material descriptors.
4. The method for detecting defects in Chinese medicinal materials based on machine vision according to claim 1, characterized in that: The working principle of step 4 is as follows: For each sub-window, extract a feature vector composed of the histogram of the color of the Chinese medicinal materials, the power spectral moments of the frequency bands, and the gray-level co-occurrence moments. Calculate the mean vector within the corresponding area quantile group. With covariance matrix Calculating the sub-window difference score of Chinese medicinal materials based on weighted Mahalanobis distance The calculation formula is: in, Indicates the first Feature vectors of sub-windows This represents the characteristic mean of the area quantile group to which the sub-window belongs. For the inverse of the corresponding covariance matrix, This is a diagonal matrix weighted by signal-to-noise ratio for frequency band features, and its diagonal elements... Indicates the first Signal-to-noise ratio estimates for each frequency band; Next, the quantile rank of each sub-window in its four neighboring frames and the two frames before and after it is calculated, and these quantile ranks are fused into the original score according to the geometric mean rule. The fusion weight is guided by the signal-to-noise ratio estimate to reflect the credibility of each frequency band. Finally, the quantile points of the reference region are counted and recorded to obtain the original score set and corresponding reference quantile points of all sub-windows.
5. The method for detecting defects in Chinese medicinal materials based on machine vision according to claim 1, characterized in that: The method for calculating the structural tensor direction and the difference in strength across the joint in step 6 is as follows: Acquire images of the seam tape area, sampling the seam tape along its minor axis on both sides at a fixed step size. Extracting local sub-regions ; Grayscale images of each local sub-region Input the structure tensor calculation module to calculate the horizontal gradient. with vertical gradient And through the Gaussian kernel function The weighted generation structure tensor is calculated using the following formula: in, Represents the structure tensor matrix. and Representing pixels Horizontal gradient and vertical gradient , Indicates the smoothness scale. Indicates the convolution operation; right Eigenvalue decomposition yields With the main direction Calculate the local consistency coefficient ,in, To prevent division by zero of small constants; Calculate the mean intensity along the left and right sub-regions respectively with standard deviation Generate normalized cross-joint strength difference ; Calculate the difference in direction And construct the direction consistency factor ;Will 、 and The joint continuity coefficient is obtained by fusion. The formula is: in This is the attenuation weighting coefficient. These represent the consistency coefficients of the left and right sub-regions, and the discrete sampling points along the seam ridge. Calculate the continuous line integral The formula is: And based on a preset threshold Morphological processing is performed to generate boundary masks, which are used for seam reliability ranking in the cross-window adjacency graph.
6. The method for detecting defects in Chinese medicinal materials based on machine vision according to claim 1, characterized in that: The process of step 7 includes: Within each medicinal material sub-window, the calibration score sequence is binarized using a threshold comparison algorithm to generate a preliminary defect mask for the medicinal material. The preliminary defect mask is clustered using a connected component labeling algorithm to obtain candidate regions for local defects in the medicinal material. The geometric center and boundary of the local defect candidate region are mapped to the global coordinate system to obtain an initial global node set; For any defect node in an adjacent sub-window, calculate the continuity integral of the medicinal material joint and the shape compatibility index, and use them as the edge weights of the cross-window adjacency graph. By merging connected nodes on the cross-window adjacency graph according to the edge weight threshold using the restricted disjoint-set data structure algorithm, a preliminary global instance of medicinal material defects is generated. The preliminary global medicinal material defect instances are subjected to non-maximum suppression processing of the weighted cross-union ratio, wherein the weighted cross-union ratio index is calculated by combining the edge weight with the seam continuity integral and the shape compatibility. If the weighted intersection-union ratio of a candidate instance is lower than the maximum value of its neighborhood, the instance is retained and overlapping areas are removed, generating the final global set of medicinal material defect instances and the corresponding instance mask.
7. The method for detecting defects in Chinese medicinal materials based on machine vision according to claim 1, characterized in that: Step 8, the process of generating the foreground response map of the medicinal material slice and performing watershed segmentation, includes: The global defect instance mask and the original sub-window image are input into the foreground enhancement module, and the foreground response map of the medicinal material slice is generated through adaptive background subtraction and normalization filtering. The distance transformation is performed on the foreground response map of the medicinal material slice to calculate the Euclidean distance from each foreground pixel to the nearest background pixel, thus obtaining the distance mapping matrix. ; based on Local maxima extraction interior point seed set ,use and gradient plot The watershed segmentation algorithm generates a preliminary set of medicinal herb slices as labeled input; for the segmentation boundary across the seam region, a seam continuity field is used. Calculate the boundary cost function The boundary curves segmented by the watershed are iteratively corrected, and the formula for calculating the boundary cost function is as follows: in, The sampling step size, This serves as an index for discrete sampling points along the watershed boundary or joint contour. These are the coordinates of discrete sampling points along the seam or dividing boundary. This represents the continuity coefficient value of the seam corresponding to the sampling point; the final output is a set of medicinal material slice instances and a corrected boundary mask.
8. The method for detecting defects in Chinese medicinal materials based on machine vision according to claim 1, characterized in that: The working principle of step 9 is as follows: Establish a defect node set D and a medicinal material slice node set P in the global coordinate system; for any candidate pairing... and Three types of raw quantities are calculated: the first type is the region intersection-union ratio; the second type is the weighted mean of the cosine of the angle between the boundary normals, with the weight being the joint continuity coefficient at the corresponding boundary sampling point; the third type is the line integral of the joint continuity along the overlapping boundary of the two, and normalized according to the overlap length. A kernel regression mapping from the area ratio to the expected overlap is constructed through batch-level statistics, and the intersection-union ratio of the regions is normalized and adjusted accordingly. Based on batch anchor samples, the non-negative normalized weight vector is solved using restricted least squares. and form a comprehensive border power It is a linear combination of three standardized quantities; When the distance between the centroids of the nodes is less than or equal to a preset threshold and w is not less than the dynamic threshold determined by the local distribution parameters of the candidate edge weights. When creating edges on a bipartite graph; The maximum weight matching is used to determine the assignment mapping of the constructed bipartite graph. When the matching weight difference does not exceed the discrimination threshold, the line integral of the seam continuity is compared first, and then the similarity of the boundary normal is compared to determine the assignment mapping. Attribution mapping and , The relevant batch calibration parameters are recorded in the batch file.
9. The method for detecting defects in Chinese medicinal materials based on machine vision according to claim 1, characterized in that: The working process of step 10 includes: A set of statistical labels for defects in Chinese medicinal materials is generated based on the attribution mapping. The labels include defect category count, defect area ratio, centroid spatial distribution, weight overlap rate of medicinal material slices, and defect continuity score. Write the batch descriptor of Chinese medicinal materials, the set of fractional field mapping parameters, the reference quantile group, the judgment threshold, and the summary of the continuity of the joint of the medicinal materials into the batch archive of Chinese medicinal materials according to the timestamp and version. Within a sliding time window, the anchor region quantiles and calibration score distributions of Chinese medicinal materials are subjected to two-sample KS test, CUSUM change point detection, and exponential weighted moving average tracking. If any detection statistic exceeds the preset confidence limit, the parameter update process is triggered. The parameter update process uses restricted weighted incremental least squares fitting to solve the score domain mapping parameters. Ridge regularization and anchor sample weight decay constraints are introduced in the fitting, and the calibration score quantiles are re-estimated accordingly to update the judgment threshold. Write the parameter differences before and after the update, the trigger logs, and the sample statistics used for testing into the batch file of Chinese medicinal materials, and record the version and rollback identifier.
Citation Information
Patent Citations
Traditional Chinese medicinal material production quality analysis system and method based on machine vision
CN119693343A
Vision-based traditional Chinese medicinal material defect detection method
CN120374870A
Film surface defect detection method and system
CN120629174A
Pill identification and counterfeit detection method
US8712163B1