A ginseng seed vigor category detection model construction method and system
Patent Information
- Application Number
- CN202611191146.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-07
- Publication Date
- 2026-09-04
AI Technical Summary
中国专利CN117351285A公开了一种“一种基于深度学习的高光谱种子活力无损检测方法”,其通过改进ResNet18网络构建Focal-SAResNet端到端模型,以FocalLoss解决样本不均衡问题,实现了对玉米种子高光谱图像的二分类(有活力/无活力)检测,但使用的高光谱成像设备成本极其昂贵,操作复杂,且该模型以玉米种子为研究对象,输出仅为二分类;其光谱特征和模型架构完全未针对人参种子进行适配,而人参种子在种皮特性、内部成分和光谱响应等方面与玉米存在本质差异玉米、大豆这类粮食种子结构简单,储存淀粉,老化后整体均匀变色缩水,拍照成像稳定,但人参是药用多年生植物种子,外皮分层复杂,表面有脂质层等特殊结构,储存养分以脂类为主,老化局部变色塌陷;表皮脂质层结构会造成复杂反光,图像噪声与干扰信息多、外观特征特殊
(1)现有种子活力分级及检测研究多针对玉米、大豆等常规作物开展,针对人参种子活力分级与精准检测的研究仍然空白。
Smart Images

Figure CN122695407A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of seed testing technology, specifically to a method for detecting the vigor category of ginseng seeds. Background Technology
[0002] As a perennial plant, ginseng has a long growth cycle and relatively demanding environmental requirements. Seed vigor is a core indicator for measuring ginseng seed quality, directly affecting germination rate, growth vigor, disease resistance, and final yield, and is a key aspect of standardized ginseng cultivation.
[0003] With technological advancements, emerging technologies such as spectral analysis and RGB image analysis have provided non-destructive and efficient alternatives for seed vigor detection. Chinese patent CN117351285A discloses a "non-destructive detection method for hyperspectral seed viability based on deep learning." It constructs an end-to-end Focal-SAResNet model by improving the ResNet18 network and uses FocalLoss to address sample imbalance, achieving binary classification (viable / non-viable) detection of hyperspectral images of corn seeds. However, the hyperspectral imaging equipment used is extremely expensive and complex to operate. Furthermore, the model, based on corn seeds, only outputs binary classification. Its spectral features and model architecture are completely unsuitable for ginseng seeds. Ginseng seeds differ fundamentally from corn in seed coat characteristics, internal components, and spectral response. Corn and soybean seeds have simple structures, store starch, and undergo uniform discoloration and shrinkage upon aging, resulting in stable imaging. In contrast, ginseng is a medicinal perennial plant seed with a complex layered outer skin, including a lipid layer and other special structures. It stores nutrients primarily in lipids, and undergoes localized discoloration and collapse upon aging. The lipid layer structure causes complex reflections, resulting in numerous image noises and interferences, and unique appearance characteristics. Therefore, general image segmentation algorithms, color and texture recognition methods, and simple binary models designed for grain seeds are not applicable to the three vigor levels of ginseng seeds. This invention, based on the aforementioned biological characteristics of ginseng seeds, designs a multi-dimensional feature combination and multi-branch weighted fusion classification strategy to detect ginseng seed vigor. However, this approach is difficult for those skilled in the art to directly apply, and it cannot meet the refined requirements of agricultural production for high, low, and no vigor levels. Therefore, developing a rapid and non-destructive testing technology for ginseng seed vigor that is low in equipment cost, fast in detection speed, high in accuracy, and highly targeted, to fill the technological gap in this field, has extremely important practical significance and application value. Summary of the Invention
[0004] This invention proposes a method and system for detecting the vigor category of ginseng seeds, filling a technological gap in the field of ginseng seed vigor detection.
[0005] The technical solution provided by this invention: Option 1: A method for constructing a ginseng seed vigor category detection model, comprising the following steps: S1: Acquire RGB images of ginseng seeds with known vigor categories, perform data processing on the RGB images, and obtain a normalized feature matrix; the vigor categories include high vigor, low vigor, and no vigor. S2: Divide the normalized feature matrix into three feature subsets, which include a geometric feature subset, a color feature subset, and a texture feature subset; S3: Input the geometric feature subset, color feature subset and texture feature subset into three independent classifiers for training to obtain the original predicted values of the geometric feature subset, the color feature subset and the texture feature subset. S4: Calculate the fusion weights of the geometric feature subset, color feature subset, and texture feature subset, and then weight and fuse the original predicted values of the geometric feature subset, color feature subset, and texture feature subset according to the fusion weights to obtain the fused comprehensive predicted value. S5: Input the comprehensive predicted value into the softmax function to obtain the predicted probability of the ginseng seed vigor category. Take the vigor category corresponding to the maximum predicted probability as the final prediction result to complete the construction of the ginseng seed vigor category detection model.
[0006] In a further preferred embodiment, the data processing in step S1 includes: S11: Perform image preprocessing and seed threshold segmentation on the RGB image to obtain a seed region mask; S12: Extract seed image features within the seed region mask to construct a ginseng seed image feature dataset. The image features include geometric features, color features, and texture features. S13: Preprocess the image feature dataset, including normalization and outlier removal.
[0007] In a further preferred embodiment, in step S11, the image preprocessing includes converting the RGB image to a grayscale image and performing Gaussian filtering on the grayscale image; The seed threshold segmentation includes OTSU adaptive threshold segmentation, foreground-background correction, morphological operations, and region feature-based filtering.
[0008] In a further preferred embodiment, the geometric features in step S12 include 15 dimensions of ginseng seed features: area, perimeter, principal axis length, minor axis length, aspect ratio, roundness, eccentricity, robustness, elongation, orientation angle, equivalent diameter, shape factor, Freette diameter, convex hull area, and roundness.
[0009] In a further preferred embodiment, in step S12, the color feature includes: In the RGB image corresponding to the seed region mask, the mean, standard deviation and skewness of the R, G and B channels are extracted respectively, resulting in a total of 9-dimensional features; The RGB image was converted to the HSV color space, and the mean, standard deviation, and skewness of the hue component (H), saturation component (S), and lightness component (V) were extracted, resulting in a total of 9-dimensional features. The color features total 18 dimensions.
[0010] In a further preferred embodiment, in step S12, the texture features include six-dimensional features extracted using the gray-level co-occurrence matrix: contrast, homogeneity, energy, correlation, dissimilarity, and GLCM variance. The grayscale histogram was used to extract seven features: entropy, standard deviation, skewness, kurtosis, grayscale mean, grayscale standard deviation, and grayscale skewness.
[0011] The texture features total 13 dimensions; In a further preferred embodiment, in step S4, the weighted fusion is any one of variance-weighted fusion, CCA-weighted fusion, information entropy-weighted fusion, and mutual information-weighted fusion.
[0012] Option 2: A system for constructing a ginseng seed vigor category detection model, the system being used to implement the steps of any of the methods described in this invention, the system comprising: The data acquisition and preprocessing module is used to acquire RGB images of ginseng seeds with known vigor categories, perform data processing on the RGB images, and obtain a normalized feature matrix; the vigor categories include high vigor, low vigor, and no vigor. The multi-branch feature partitioning module is used to divide the normalized feature matrix into three feature subsets, which include a geometric feature subset, a color feature subset, and a texture feature subset; The three-branch classification module includes three independent classifiers, which are used to train the geometric feature subset, color feature subset and texture feature subset respectively, and obtain the original predicted values of the geometric feature subset, the color feature subset and the texture feature subset respectively. The multi-branch weighted fusion module is used to calculate the fusion weights of the geometric feature subset, color feature subset, and texture feature subset, and to perform weighted fusion of the original predicted values of the geometric feature subset, color feature subset, and texture feature subset according to the fusion weights to obtain the fused comprehensive predicted value. The vitality classification output module inputs the comprehensive predicted value into the softmax function to obtain the predicted probability of the vitality category of ginseng seeds. The vitality category corresponding to the maximum predicted probability is taken as the final prediction result, thus completing the construction of the ginseng seed vitality category detection model.
[0013] Option 3: A computer system comprising a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps of any of the methods described in this invention.
[0014] Option 4: A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the methods described in this invention.
[0015] Option 5: A computer program product comprising a computer program that, when executed by a processor, implements the steps of any of the methods described in this invention.
[0016] The beneficial effects of this invention compared to the prior art are as follows: (1) Existing research on seed vigor grading and detection mainly focuses on conventional crops such as corn and soybeans, while research on seed vigor grading and precise detection for ginseng is still lacking.
[0017] (2) Traditional general seed vigor detection technology has significant limitations. Although hyperspectral imaging technology has achieved good results in detecting the seed vigor of some crops, the equipment is extremely expensive. A set of hyperspectral imaging systems costs hundreds of thousands or even millions of yuan, which is unaffordable for ordinary farmers. Data processing is also complex. Hyperspectral data contains hundreds of bands and the amount of data is huge, requiring professional technicians to process and analyze it.
[0018] (3) Existing RGB image detection technology does not fully utilize its features. Ordinary RGB image technology equipment is low-cost and easy to operate, but most existing technologies only extract single or a few features, failing to fully explore the information closely related to the vitality of ginseng seed texture, color, and geometry. The fusion method is simple, generally adopting the method of directly splicing features, ignoring the complementarity and weight differences between different features.
[0019] This invention can be applied to fields such as agricultural breeding auxiliary analysis, seed quality testing, and agricultural production guidance. Attached Figure Description
[0020] Figure 1 This is a flowchart illustrating the method for constructing a ginseng seed vigor category detection model according to the present invention.
[0021] Figure 2 This is a graph showing the threshold segmentation results for ginseng seeds.
[0022] Figure 3 A scatter plot comparing the average values of each dimension of the seed before outlier removal.
[0023] Figure 4 A scatter plot comparing the average values of each dimension of the seed after outlier removal.
[0024] Figure 5 This is a structural diagram of the seed vigor detection model described in this invention.
[0025] Figure 6 This paper presents a performance comparison of the seed vitality detection model under four weight allocation strategies of this invention.
[0026] Figure 7 This is a schematic diagram of the cross-validation results of the four weighted fusion methods described in this invention.
[0027] Figure 8 This is a schematic diagram of the confusion matrix of the seed vigor grading model detection results of the present invention. Detailed Implementation
[0028] To facilitate understanding of the technical solutions claimed in this invention, the following specific embodiments are provided in conjunction with the accompanying drawings. These embodiments are merely used to explain the technical principles of the embodiments of this application and are not intended to limit the scope of protection of this application. Those skilled in the art can make reasonable adjustments to the embodiments given in the following specific embodiments based on their general knowledge in the art to adapt them to specific application scenarios.
[0029] Implementation method one, see Figure 1 This embodiment describes a method for constructing a ginseng seed vigor category detection model, comprising the following steps: S1: Acquire RGB images of ginseng seeds with known vigor categories, perform data processing on the RGB images, and obtain a normalized feature matrix; the vigor categories include high vigor, low vigor, and no vigor. S2: Divide the normalized feature matrix into three feature subsets, which include a geometric feature subset, a color feature subset, and a texture feature subset; S3: Input the geometric feature subset, color feature subset and texture feature subset into three independent classifiers for training to obtain the original predicted values of the geometric feature subset, the color feature subset and the texture feature subset. S4: Calculate the fusion weights of the geometric feature subset, color feature subset, and texture feature subset, and then weight and fuse the original predicted values of the geometric feature subset, color feature subset, and texture feature subset according to the fusion weights to obtain the fused comprehensive predicted value. S5: Input the comprehensive predicted value into the softmax function to obtain the predicted probability of the ginseng seed vigor category. Take the vigor category corresponding to the maximum predicted probability as the final prediction result to complete the construction of the ginseng seed vigor category detection model.
[0030] The classifier is the XGBoost classifier.
[0031] Plump, intact, and undamaged ginseng seeds were selected. Through artificial aging and standard germination experiments, high-viability, low-viability, and non-viability seed samples were obtained, and the viability category of each seed sample was determined. The artificial aging experiment was conducted in a constant temperature and humidity chamber, maintaining an accelerated aging environment of 42.0℃±0.5℃ and 95%±2% relative humidity. The standard germination experiment was conducted in a constant temperature and humidity chamber under strictly maintained conditions of 20℃, 85% relative humidity, and complete darkness.
[0032] During image acquisition, strictly consistent shooting conditions were maintained: the seed position was fixed in the center of a black background, the RGB camera was fixed 15cm away from the seed, the image resolution was 224×224 pixels, and the image format was PNG, JPG, or JPEG. More than 2000 images were collected in total, with a balanced number of samples for each class.
[0033] In this embodiment, the data processing in step S1 includes: S11: Perform image preprocessing and seed threshold segmentation on the RGB image to obtain a seed region mask; S12: Extract seed image features within the seed region mask to construct a ginseng seed image feature dataset. The image features include geometric features, color features, and texture features. S13: Preprocess the image feature dataset, including normalization and outlier removal.
[0034] In this embodiment, the image preprocessing in step S11 includes converting the RGB image to a grayscale image and performing Gaussian filtering on the grayscale image. The seed threshold segmentation includes OTSU adaptive threshold segmentation, foreground-background correction, morphological operations, and region feature-based filtering.
[0035] The core of image preprocessing and seed thresholding segmentation lies in segmenting individual seed regions from the background. Let the input RGB image be... The height of the RGB image =224, the width of the RGB image =224, 3 indicates the 3 channels of the RGB image.
[0036] First, convert the RGB image to a grayscale image. : , in, The pixel values of the resulting grayscale image, i.e., brightness or grayscale intensity. For the red channel pixel values of an RGB image, For the green channel pixel values of an RGB image, This represents the blue channel pixel value of the RGB image.
[0037] The grayscale values calculated in this way are closest to the actual brightness of the image perceived by the human eye, rather than simply the average value of the RGB channels.
[0038] For grayscale images A two-dimensional Gaussian kernel is used for Gaussian filtering and noise reduction. The Gaussian kernel function is defined as follows: , in, Two-dimensional Gaussian kernel function at point The weight value at that location, This is the coordinate offset relative to the center of the convolution kernel. The standard deviation of the Gaussian distribution is 1.0 in this invention, and the kernel size is 5×5.
[0039] The filtered image is obtained as follows: , in, The image is after Gaussian filtering for noise reduction and smoothing. This is a normalized 5×5 convolution kernel generated based on the Gaussian kernel function above. This represents the convolution operation.
[0040] The specific steps of seed threshold segmentation are as follows: [The text abruptly ends here, likely due to an incomplete sentence or a formatting error.] The optimal segmentation threshold is obtained by calculating the inter-class variance using the OTSU adaptive threshold segmentation traversal. ;based on right Perform binarization to generate an initial binarization mask. ;based on Use foreground / background correction statistical mask for white areas Black area Average grayscale and contrast brightness: If the brightness of the foreground and background is reversed, the entire mask is inverted. Output the corrected mask Then, a 3x3 elliptical structural element K is constructed through morphological operations to apply to the corrected mask. By performing closing and opening operations sequentially, a morphological processing mask is obtained. ; for connected domain labeling is performed to obtain N connected regions , the area of each region is extracted , roundness , aspect ratio three features are obtained, effective regions are screened, and a seed region mask is generated .
[0041] The said OTSU adaptive threshold segmentation is specifically: the optimal segmentation threshold is automatically determined by maximizing the inter-class variance , and the specific implementation is as follows: let the grayscale level range be , the total number of pixels be , the number of pixels with grayscale level i be , and the probability be .
[0042] a threshold t divides pixels into a background and a target
[0043] the inter-class variance calculation formula is: , wherein: , , wherein, is the proportion of background pixels in the whole image, is the proportion of target pixels in the whole image, and L is the total number of grayscale levels of the image.
[0044] the optimal segmentation threshold , argmax represents finding the value of t that maximizes the inter-class variance within the range of 0≤t<L.
[0045] based on , binarization is performed on to generate an initial binary mask , and the algorithm design is as follows: , wherein, represents the pixel coordinates of the x-th column and y-th row in the image. If the condition is met, the pixel value is set to 255, which is white, representing the target region; otherwise, the pixel value is set to 0, which is black, representing the background region.
[0046] The Otsu algorithm mathematically guarantees only the maximum separation between two classes, without pre-defining which class is the seed region. Given that ginseng seeds typically appear as a dark brown color against a photographic background, with an average grayscale value lower than the background, this invention automatically identifies the class with the lower grayscale value as the seed region by comparing the average grayscale values of the two classes. This ensures that the segmentation result is consistent with visual perception, i.e., foreground-background correction.
[0047] The foreground / background correction is specifically as follows: If the average gray value of the seed region is less than that of the background region, then the mask is inverted. The algorithm is as follows: if: , but, otherwise,
[0048] in To statistically analyze the white area of the mask, i.e. This is the background area.
[0049] The morphological operation is as follows: First, construct the elliptical structural element. The dimensions are 3×3. , Next, perform the closing and opening operations in sequence: Closing operation is The process involves expansion followed by corrosion, filling holes and connecting adjacent areas to make the target area more complete without significantly altering its overall size. Opening operation is The process involves first corroding and then expanding to remove minute noise and burrs, and smooth the target edges without significantly altering the overall size of the target. in, This indicates an expansion operation, specifically meaning that the white area (target) expands outward by one ring, connecting small holes and broken areas; This represents the erosion operation, specifically meaning that the white area "shrinks" inward by one ring, bringing back the expanded edges that appeared during expansion; Ultimately, a relatively clean morphological processing mask is obtained. ; The region-based feature-based filtering specifically refers to: First, morphological processing mask Connectivity labeling is performed to obtain N connected components. ; Secondly, for each connected region Extract the following features and determine whether they are valid seed regions. =1, 2…N: (1) The area is The effective range is [500, 300000], used to filter out noise that is too small and invalid regions that are too large. Represents each connected region The number of elements in the region, which is the total number of pixels contained within the region; (2) Roundness is This measure assesses how close a region is to a circle, with an effective threshold ≥0.1. It filters out highly irregularly shaped regions based on the principle that a perfect circle has a roundness of 1, and the more irregular the shape, the lower the roundness. This is the perimeter of the region, which is the pixel length of the outline boundary; (3) The aspect ratio is This measures the elongation or thinness of the region, with an effective range of [0.5, 2.0]. Excessively long or flat regions are filtered out. This is the length of the major axis of the circumscribed ellipse of this region. This is the length of the minor axis of the circumscribed ellipse of this region; The final seed region was obtained through screening. : , in, The meaning is to traverse all connected components. Find the region that maximizes the value of the expression that follows. For indicator functions, when The value is 1 when all three conditions (area, roundness, and aspect ratio) are met; the value is 0 when none of these conditions are met. (Seed region) The inner value is 255, and the rest are 0, to obtain the final seed region mask. .
[0050] Finally, mask the final seed region. From the original RGB image In the process, the target image obtained by retaining only the pixels of the seed region is: grayscale image .
[0051] In this embodiment, the geometric features in step S12 include 15 dimensions of ginseng seeds: area, perimeter, principal axis length, minor axis length, aspect ratio, roundness, eccentricity, robustness, elongation, orientation angle, equivalent diameter, shape factor, Freret diameter, convex hull area, and roundness.
[0052] area: , These are the pixel coordinates of the image; perimeter: , Let R be the contour boundary of the connected region, with perimeter... Reflects the length of the target boundary; Spindle length: , The zeroth-order central moment is equal to the area of the region and the length of the principal axis. This represents the maximum extension length of the region in the main direction; minor axis length: minor axis length The length of the region in the direction perpendicular to the principal axis; This indicates the degree to which region pixels are dispersed horizontally (X-axis) around the centroid. It measures the extent of the region's extension in the width direction; a larger value indicates that the region extends further horizontally. This represents the degree to which region pixels are dispersed around the centroid in the vertical direction (Y-axis). It measures the extent of the region's extension in the height direction; a larger value indicates that the region extends further in the vertical direction.
[0053] Aspect Ratio: The aspect ratio represents the ratio of the length of the main axis to the length of the minor axis, reflecting whether the overall shape of the seed is more round or more elongated. Uneven shrinkage during aging can cause a slight shift in the aspect ratio.
[0054] Roundness: Roundness Also known as the shape factor, it measures how close a region is to a circle. A perfect circle has a roundness of 1, and the more irregular the shape, the smaller the value. It is used to quantify the smoothness and regularity of the edges of a seed region. This index is sensitive to jagged edges and burrs in the contour, and is designed to reflect damage or cracks on the seed coat surface.
[0055] Eccentricity: Eccentricity indicates the degree to which the seed region deviates from a circle; a value closer to 0 indicates a closer approximation to a circle, while a value closer to 1 indicates a more elongated shape. Local collapse caused by aging will increase the eccentricity.
[0056] Durability: Seed firmness is the ratio of the actual area of the seed to the area of its convex hull, reflecting the degree of indentation at the seed boundary. The more severe the aging and indentation, the lower the seed firmness value.
[0057] Elongation: , The width of the bounding rectangle of the region. The height of the bounding rectangle of the region reflects the degree to which the seed fills its bounding rectangle. Aging deformation will reduce elongation.
[0058] Direction angle: The orientation angle represents the angle between the seed's principal axis and the horizontal axis, reflecting the seed's spatial orientation. When the seed's center of gravity shifts due to local collapse, the orientation angle will change accordingly.
[0059] Equivalent diameter: equivalent diameter The target size is equivalent to the diameter of a circle with the same area. A circle is used to describe the target size. Aging shrinkage will cause the equivalent diameter to decrease.
[0060] Shape factor: The ratio of area to principal axis length is used to describe the shape of the target, reflecting the "fatness" or "thinness" of the target; Ferrette diameter: , , For any two points on the boundary of the region, To find the Euclidean distance between two points, the maximum distance between any two points on the boundary of the region reflects the maximum span of the target.
[0061] Convex hull area: ConvArea is a geometric concept representing the area enclosed by the convex hull of the seed region. Specifically, it refers to the area enclosed by the smallest convex polygon containing the seed region R. This convex polygon is composed of the set of boundary points of the seed region R, and all pixels within the seed region are located inside or on the boundary of this convex polygon.
[0062] Circularity: This metric is used to quantify the overall compactness and elongation of the seed region. It aims to reflect the overall deformation of the seed due to shriveling or poor development.
[0063] In this embodiment, the color feature in step S12 includes: In the RGB image corresponding to the seed region mask, the mean, standard deviation and skewness of the R, G and B channels are extracted respectively, resulting in a total of 9-dimensional features; The RGB image was converted to the HSV color space, and the mean, standard deviation, and skewness of the hue component (H), saturation component (S), and lightness component (V) were extracted, resulting in a total of 9-dimensional features. The color features total 18 dimensions.
[0064] In the RGB image color space, for each channel Extract the following three types of statistical features from ∈{R,G,B}: Mean: , Standard deviation: , Skewness: , in, The seed connected region is , This represents the total number of pixels within the region; For seed region image In the passage Above, pixels The pixel value at that location.
[0065] Convert an RGB image to the HSV color space. Let the normalized RGB values R′, G′, B′ ∈ [0, 1], then: Luminance component:
[0066] Saturation component: , Tone components: , In this embodiment, the texture features in step S12 include six-dimensional features extracted using the gray-level co-occurrence matrix: contrast, homogeneity, energy, correlation, dissimilarity, and GLCM variance. The grayscale histogram was used to extract seven features: entropy, standard deviation, skewness, kurtosis, grayscale mean, grayscale standard deviation, and grayscale skewness.
[0067] The texture features total 13 dimensions; First, the grayscale image Quantized into a 64-level grayscale image Then, in four directions... Calculate the distance separately The pixel pairs yield 4 matrices. Next, each matrix is normalized to obtain four probability matrices. Finally, from these four probability matrices, seven texture features are calculated, and the average of the features in the four directions is taken to obtain the final seven-dimensional texture feature vector.
[0068] First, quantize the grayscale image to 64 levels: , in, The quantized grayscale level. The coordinates of pixels in the image, This indicates rounding down to the nearest integer.
[0069] Next, construct four GLCM matrices. These represent the distance between two pixels. direction Above, grayscale and grayscale The number of times they appear together.
[0070] in, It is a 64×64 counting matrix. This indicates the grayscale level of the current pixel. Indicates the gray level of adjacent pixels; Next, regarding After normalization, the probability matrix is obtained; .
[0071] This step is to convert "occurrence frequency" into "occurrence probability", so that the sum of all elements in the matrix is 1, and the eigenvalues fall within a uniform numerical range, which facilitates subsequent processing.
[0072] Next, based on the probability matrix, the following 7 features are extracted, and the mean values in 4 directions are taken as the final features: (1) Contrast ratio: , Contrast describes the local grayscale difference in an image. The coarser the texture (e.g., more edges, more noise), the higher the probability of pixel pairs with large grayscale differences appearing. The greater the contrast, the smoother the texture (e.g., solid colors, gradients). The smaller the grayscale difference, the smaller the contrast.
[0073] (2) Homogeneity: , Describes the local gray-level similarity of an image; the smoother the texture (the closer the gray levels of adjacent pixels), the better. The smaller the value, the greater the weight, the higher the homogeneity, the coarser the texture (larger differences in grayscale between adjacent pixels), and the lower the homogeneity.
[0074] (3) Energy: , Describing the uniformity and regularity of texture: the more uniform and simple the texture (such as solid color, regular texture), the more likely a few gray-level pairs will appear, and the closer the energy value is to 1; the more complex and random the texture (such as noise, irregular texture), the more dispersed the gray-level pairs will be, and the closer the energy value is to 0.
[0075] (4) Correlation: , Describes the degree of linear correlation between the gray levels of adjacent pixels. (5) Dissimilarity: , (6) GLCM variance: , in, , Marginal probability, The grayscale mean is... This represents the standard deviation of the corresponding gray level.
[0076] The grayscale histogram feature extraction specifically involves: Calculate a 32-level grayscale histogram: , Extract the following features: (1) Entropy: , (2) Standard deviation: , (3) Skewness: , (4) Kurtosis: , (5) Gray-scale mean: , (6) Standard deviation of gray level: , (7) Gray-scale skewness: , In summary, the gray-level co-occurrence matrix features and gray-level histogram features together constitute a 13-dimensional texture feature.
[0077] The normalization is as follows: Let the original feature matrix be ,in For the sample size, =46 is the feature dimension. The label vector is... These represent high vitality, low vitality, and no vitality, respectively.
[0078] First, grouping and correcting Z-score outlier removal is performed, specifically as follows: For each category Let the feature subset of this category of samples be... For each feature dimension : Calculate the median: , Calculate the absolute median: , Calculate the corrected Z-score for each sample: Where ε = 1e-6, Then the sample It was marked as an outlier and removed.
[0079] The feature matrix after removing outliers Perform Min-Max normalization: , After normalization, all eigenvalues are mapped to the interval [0,1].
[0080] In this embodiment, the weighted fusion in step S4 is any one of variance-weighted fusion, CCA-weighted fusion, information entropy-weighted fusion, and mutual information-weighted fusion.
[0081] The normalized feature matrix is divided into three feature subsets: Geometric feature subset:
[0082] Color feature subset:
[0083] Texture feature subset:
[0084] Train three independent XGBoost classifiers, each with the following objective function: , in, For multi-class cross-entropy loss: For regularization.
[0085] Each model outputs raw predicted values (logits).
[0086] Original predicted values for the geometric feature subset: , Original predicted values for the color feature subset: , Original predicted values for the texture feature subset: , in, The number of samples in the test set is 3, which represents the three types of viability: high viability, low viability, and no viability.
[0087] Variance-weighted fusion: Suppose there are K=3 feature branches (geometric feature subset, color feature subset, and texture feature subset), and let the training set feature matrix of the k-th branch be denoted as . Then the weight of this branch is:
[0088] Where k=1 represents the geometric feature subset, k=2 represents the color feature subset, k=3 represents the texture feature subset, Cov(X) represents the covariance matrix of the feature matrix, Tr(A) represents finding the trace of matrix A, which is the sum of all elements on the main diagonal of the matrix, and the denominator is the sum of the total variances of the features of all branches.
[0089] The original predicted values after fusion: Let the predicted output of the k-th branch model be... The final prediction result after fusion for: , CCA weighted fusion: Assume there is a total = There are 3 feature branches (geometric feature subset, color feature subset, and texture feature subset), and let the training set feature matrix of the k-th branch be denoted as . Convert the tags to one-hot encoding; the tag matrix is as follows: Then the weight of this branch can be uniformly expressed as: , in, For the first Normalized canonical correlation coefficients of each feature group For the first Feature groups and labels The maximum canonical correlation coefficient represents the strength of the association between the feature group and the classification task. It is obtained by solving the following optimization problem: , in, For the first The autocovariance matrix of each feature group Let be the autocovariance matrix of the label. , for the first The cross-covariance matrix between each feature group and the label. The feature matrix of the training set for the geometric feature subset. The feature matrix of the training set for the color feature subset. The training set feature matrix is a subset of the texture features. This indicates the calculation of the covariance matrix of a matrix.
[0090] The fusion prediction output is: Let the prediction output of the k-th branch model be... The final prediction result after CCA weighted fusion for: , Information entropy weighted fusion: Let the i-th test sample be in the i-th... The predicted probability distribution on each feature branch is as follows: ,in =1, 2, 3 are category indices.
[0091] First, calculate the information entropy of the predicted probability for this branch: , in, >0 is a smoothing constant to prevent the value from becoming zero. For the first The sample at the th The information entropy of the predicted probability distribution on each branch model reflects the uncertainty of the model's prediction of the current sample: the lower the entropy value, the more certain the model's prediction of the sample, and the higher the corresponding weight. Then, the dynamic weight of this branch is calculated based on information entropy: , in, For the first The sample at the th Dynamic weights on each branch, through... Normalization is performed to ensure ; Finally, sample-level weighted fusion is performed: , in, For the first The sample at the th The prediction results (probability vectors) from each branch model, fused together This is the final prediction result for this sample.
[0092] Assume there is a total =3 feature branches (geometric feature subset, color feature subset, and texture feature subset), let the training set feature matrix of the k-th branch be . If the label is y, then the weight of this branch can be uniformly represented as: , in, No. The normalized mutual information weights of the feature branches are: For the first Feature groups and labels The mutual information value represents the information gain of the feature set for the classification task: the higher the mutual information value, the stronger the correlation between the feature set and the label, and the richer the classification information it contains; the calculation formula is: , Eigenvalues With tags The joint probability, Eigenvalues The marginal probability, For tags The marginal probability; The fusion formula is: .
[0093] Furthermore, the integrated predicted value after fusion... Input the softmax function to obtain the predicted probability of the viability class of ginseng seeds: , in, For the first The sample at the th The fusion prediction value on the class.
[0094] Finally, the prediction category: , The category corresponding to the highest probability is taken as the final prediction result.
[0095] A system for constructing a ginseng seed vigor category detection model, the system being used to implement the above method, the system comprising: The data acquisition and preprocessing module is used to acquire RGB images of ginseng seeds with known vigor categories, perform data processing on the RGB images, and obtain a normalized feature matrix; the vigor categories include high vigor, low vigor, and no vigor. The multi-branch feature partitioning module is used to divide the normalized feature matrix into three feature subsets, which include a geometric feature subset, a color feature subset, and a texture feature subset; The three-branch classification module includes three independent classifiers, which are used to train the geometric feature subset, color feature subset and texture feature subset respectively, and obtain the original predicted values of the geometric feature subset, the color feature subset and the texture feature subset respectively. The multi-branch weighted fusion module is used to calculate the fusion weights of the geometric feature subset, color feature subset, and texture feature subset, and to perform weighted fusion of the original predicted values of the geometric feature subset, color feature subset, and texture feature subset according to the fusion weights to obtain the fused comprehensive predicted value. The vitality classification output module inputs the comprehensive predicted value into the softmax function to obtain the predicted probability of the vitality category of ginseng seeds. The vitality category corresponding to the maximum predicted probability is taken as the final prediction result, thus completing the construction of the ginseng seed vitality category detection model.
[0096] Implementation Method Two: This implementation method is an effect verification of the ginseng seed vigor category detection model construction method and system of Implementation Method One.
[0097] Image acquisition is performed according to the method in Implementation Method 1. The RGB image is read and converted into a grayscale image. Gaussian filtering is performed using a Gaussian kernel of size 5×5 to effectively remove random noise and texture interference in the image, thereby improving image quality and ensuring subsequent segmentation accuracy.
[0098] The Otsu method is used for adaptive threshold binarization, which automatically calculates the optimal segmentation threshold and converts the grayscale image into a black and white binary mask, thus initially achieving the separation of the seed foreground region and the background region.
[0099] Subsequently, elliptical structural elements are constructed, and opening and closing operations are performed sequentially on the initial mask: the opening operation is used to remove tiny noise and irrelevant interference areas in the seed region mask, and the closing operation is used to fill tiny holes inside the seed region mask and repair defects in the seed edge contour.
[0100] Next, connected component analysis was performed on the segmented seed mask. Based on preset thresholds for area (500-300,000 pixels), roundness (not less than 0.1), aspect ratio (0.5-2.0), and position (seed centroid located within 10%-90% of the image width and height), valid seed connected regions were selected, and invalid interference regions were removed. See the ginseng seed threshold segmentation result image for reference. Figure 2 As shown.
[0101] Seed image features are extracted within the seed region mask to construct a ginseng seed image feature dataset. The image features include geometric features, color features, and texture features. For each vitality category sample, calculate the corrected Z-score for each feature, and remove outlier samples whose corrected Z-score absolute value is greater than the threshold of 3.5. The formula for calculating the corrected Z-score is: , in, is the median, and MAD is the absolute median difference.
[0102] After removing outliers, the data is normalized using Min-Max to map the feature values to the [0,1] interval, thus obtaining the ginseng seed image feature dataset.
[0103] contrast Figure 3 Figure 4 It can be clearly seen that the presence of outliers significantly skews the class mean, and the distinction between high-viability, low-viability, and non-viability samples becomes blurred under some feature dimensions. After outlier removal by Modified Z-score grouping, the feature mean distribution of the three types of samples becomes smoother, and the feature's distinguishability of seed viability is improved to a certain extent.
[0104] The ginseng seed vigor category detection model is constructed according to the methods described in steps S1 to S5. The model is as follows: Figure 5 As shown, XGBoost is used as the base classifier, and three independent branch models are constructed, trained based on geometric features, color features, and texture features respectively. Four different weighting fusion strategies are employed: variance weighting, CCA weighting, information entropy weighting, and mutual information weighting. The weighting fusion weights for each branch are as follows: Figure 6 As shown, the final trained ginseng seed viability category detection model is obtained.
[0105] Implementation Method 3 is an experimental verification of the ginseng seed vitality category detection model constructed in Implementation Method 1 and Implementation Method 2.
[0106] In this implementation, over 500 ginseng seeds were selected as experimental samples. The sample data was input into a trained ginseng seed viability category detection model, and a five-fold cross-validation method was used to test and validate four weighted fusion strategies. The results of each fold cross-validation are as follows: Figure 7 As shown.
[0107] After completing the five-fold cross-validation and comparative tests with four weighted strategies, the final performance results of the model are shown in Table 1: Table 1
[0108] Experimental results show that all weighted fusion strategies proposed in this invention outperform the benchmark full-feature direct input model in classification performance. Among them, the three-branch mutual information weighted fusion strategy has the best effect, with an accuracy of 94.17%, which is 9.05 percentage points higher than the benchmark model. The accuracy of the other fusion strategies is between 2.91 and 5.75 percentage points higher than the benchmark model. The above experimental results fully demonstrate the effectiveness of the multi-branch weighted feature fusion method proposed in this invention.
[0109] The confusion matrix results for the six models are as follows: Figure 8 As shown in the figure, the multi-branch weighted fusion method proposed in this invention achieves higher recognition accuracy in the three-class classification detection of ginseng seed vigor compared with existing technologies such as full feature splicing. It also reduces the misclassification rate of each category, improves the accuracy of ginseng seed vigor detection, and provides a reliable technical solution for ginseng seed quality grading.
[0110] To address the issue of stray light noise during ginseng seed imaging due to the complex seed coat structure and the dense resin ducts and micropores on its surface, this method first uses Gaussian filtering to eliminate image interference caused by pores, then uses adaptive thresholding to separate the seed from the background; combined with morphological processing to repair damaged seed contours and clean surface debris, ensuring complete seed extraction.
[0111] Based on the characteristics of ginseng seeds during aging, such as shrinkage, local discoloration, and damage to the seed coat microstructure, this invention designs a feature extraction scheme comprising 46 indicators across three categories: shape, color, and texture. The shape indicators, namely the geometric features (15 items), correspond to the characteristics of ginseng seeds after aging, such as pitted outer skin and deformed shape. The degree of seed damage is quantified by data such as size and roundness. Color indicators refer to the color characteristics (18 items). Ginseng seeds mainly store lipids and other substances, and local color changes occur when they age. These local color differences are captured through different color channels. Texture indicators, or texture features (13 items), include structures such as the lipid layer of the seed epidermis that cause reflection. By using grayscale texture statistics, we can capture the changes in surface roughness and texture disorder after aging.
[0112] The three categories of indicators correspond to the external damage, internal material changes, and surface microstructure alterations caused by seed aging. This invention scientifically designs and assigns weights to each characteristic, rather than simply averaging them, enabling the classification of ginseng seeds into three levels: high, low, and no viability. While common grain seeds like corn and soybeans are only classified as good or bad, this mature technology cannot be directly applied to ginseng seed viability grading.
[0113] The principles and implementation methods of this invention are illustrated through specific examples. These embodiments are merely illustrative of the methods and core concepts of this invention. Those skilled in the art can make corresponding modifications and adjustments to the specific implementation methods and application scope based on the technical ideas of this invention.
Claims
1. A method for constructing a ginseng seed vigor category detection model, characterized in that, Includes the following steps: S1: Acquire RGB images of ginseng seeds with known vigor categories, perform data processing on the RGB images, and obtain a normalized feature matrix; the vigor categories include high vigor, low vigor, and no vigor. S2: Divide the normalized feature matrix into three feature subsets, which include a geometric feature subset, a color feature subset, and a texture feature subset; S3: Input the geometric feature subset, color feature subset and texture feature subset into three independent classifiers for training to obtain the original predicted values of the geometric feature subset, the color feature subset and the texture feature subset. S4: Calculate the fusion weights of the geometric feature subset, color feature subset, and texture feature subset, and then weight and fuse the original predicted values of the geometric feature subset, color feature subset, and texture feature subset according to the fusion weights to obtain the fused comprehensive predicted value. S5: Input the comprehensive predicted value into the softmax function to obtain the predicted probability of the ginseng seed vigor category. Take the vigor category corresponding to the maximum predicted probability as the final prediction result to complete the construction of the ginseng seed vigor category detection model.
2. The method for constructing a ginseng seed vigor category detection model according to claim 1, characterized in that, In step S1, the data processing includes: S11: Perform image preprocessing and seed threshold segmentation on the RGB image to obtain a seed region mask; S12: Extract seed image features within the seed region mask to construct a ginseng seed image feature dataset. The image features include geometric features, color features, and texture features. S13: Preprocess the image feature dataset, including normalization and outlier removal.
3. The method for constructing a ginseng seed vigor category detection model according to claim 2, characterized in that, In step S11, the image preprocessing includes converting the RGB image to a grayscale image and performing Gaussian filtering on the grayscale image. The seed threshold segmentation includes OTSU adaptive threshold segmentation, foreground-background correction, morphological operations, and region feature-based filtering.
4. The method for constructing a ginseng seed vigor category detection model according to claim 2, characterized in that, In step S12, the geometric features include 15 dimensions of ginseng seeds: area, perimeter, principal axis length, minor axis length, aspect ratio, roundness, eccentricity, robustness, elongation, orientation angle, equivalent diameter, shape factor, Freret diameter, convex hull area, and roundness.
5. The method for constructing a ginseng seed vigor category detection model according to claim 2, characterized in that, In step S12, the color features include: In the RGB image corresponding to the seed region mask, the mean, standard deviation and skewness of the R, G and B channels are extracted respectively, resulting in a total of 9-dimensional features; The RGB image was converted to the HSV color space, and the mean, standard deviation, and skewness of the hue component (H), saturation component (S), and lightness component (V) were extracted, resulting in a total of 9-dimensional features. The color features total 18 dimensions.
6. The method for constructing a ginseng seed vigor category detection model according to claim 2, characterized in that, In step S12, the texture features include six-dimensional features extracted using the gray-level co-occurrence matrix: contrast, homogeneity, energy, correlation, dissimilarity, and GLCM variance. The entropy, standard deviation, skewness, kurtosis, gray mean, gray standard deviation, and gray skewness are extracted using the gray histogram, totaling 7 features. The texture features total 13 dimensions.
7. The method for constructing a ginseng seed vigor category detection model according to claim 1, characterized in that, In step S4, the weighted fusion can be any one of variance-weighted fusion, CCA-weighted fusion, information entropy-weighted fusion, and mutual information-weighted fusion.
8. A system for constructing a ginseng seed vigor category detection model, characterized in that, The system is used to implement the method according to any one of claims 1 to 7, the system comprising: The data acquisition and preprocessing module is used to acquire RGB images of ginseng seeds with known vigor categories, perform data processing on the RGB images, and obtain a normalized feature matrix; the vigor categories include high vigor, low vigor, and no vigor. The multi-branch feature partitioning module is used to divide the normalized feature matrix into three feature subsets, which include a geometric feature subset, a color feature subset, and a texture feature subset; The three-branch classification module includes three independent classifiers, which are used to train the geometric feature subset, color feature subset and texture feature subset respectively, and obtain the original predicted values of the geometric feature subset, the color feature subset and the texture feature subset respectively. The multi-branch weighted fusion module is used to calculate the fusion weights of the geometric feature subset, color feature subset, and texture feature subset, and to perform weighted fusion of the original predicted values of the geometric feature subset, color feature subset, and texture feature subset according to the fusion weights to obtain the fused comprehensive predicted value. The vitality classification output module inputs the comprehensive predicted value into the softmax function to obtain the predicted probability of the vitality category of ginseng seeds. The vitality category corresponding to the maximum predicted probability is taken as the final prediction result, thus completing the construction of the ginseng seed vitality category detection model.
9. A computer system comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes a computer program to implement the steps of the method according to any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method described in any one of claims 1-7.
Citation Information
Patent Citations
Hyperspectral seed vigor nondestructive testing method based on deep learning
CN117351285A
