Optical detection method for corn kernels based on dynamic and static classification uniform feeding
By analyzing static and dynamic grading and uniform material distribution, and motion vector field analysis, static posture frames were selected and a chromaticity and texture feature fusion discrimination tensor was constructed. This solved the problems of accuracy and stability in corn kernel detection under dynamic conditions, and achieved efficient quality grading.
Patent Information
- Application Number
- CN202611328143.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-31
- Publication Date
- 2026-11-06
- Estimated Expiration
- 2046-08-31
AI Technical Summary
Existing optical detection methods for corn kernels suffer from poor image quality due to motion blur and pose changes under dynamic conditions, affecting the accuracy and stability of color and texture feature extraction. Furthermore, existing feature fusion methods suffer from redundancy and insufficient class separability.
Static attitude frames are obtained through a dynamic and static grading and leveling mechanism. Clear frames are selected using motion vector field and divergence analysis. Multidimensional structural fusion of chroma and texture features is combined with singular value decomposition and Mahalanobis distance discrimination to construct a fusion discrimination tensor for quality inspection.
It improves the accuracy and robustness of corn kernel quality detection, eliminates the effects of motion blur and angle changes, and enhances the reliability of feature extraction and grading accuracy.
Smart Images

Figure CN122867147B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of optical detection technology for corn kernels, specifically to an optical detection method for corn kernels based on dynamic and static grading and homogenization. Background Technology
[0002] Online inspection of corn kernel quality typically relies on optical imaging to continuously capture and analyze the flowing kernels. To ensure inspection efficiency, the kernels need to be spread into a single layer using a leveling device, while a high-speed camera simultaneously acquires a sequence of images. In this type of dynamic inspection scenario, due to the continuous movement of the kernels and the complex posture changes such as spin and translation, the acquired sequence of images contains a large number of low-quality frames caused by motion blur or suboptimal viewing angles. Directly extracting a fixed frame from the sequence of images or relying on inter-frame averaging introduces too much interference information, resulting in insufficient accuracy and stability in the subsequent extraction of appearance features such as color and texture.
[0003] Existing methods for grain classification based on chromaticity features mostly use global color moments or color histogram statistics directly. These features have limited ability to describe the uneven distribution of grain surface color and are difficult to characterize local color spots and gradual transitions caused by differences in variety, mold, or maturity. Some methods supplement discriminative information by introducing texture features, but in the feature fusion stage, they often use simple splicing or weighted sequential combination without considering the differences in the distribution structure of different modal features in high-dimensional space. This results in redundancy in the fused feature space and weak class separability, affecting the classification accuracy in small samples or cases with subtle inter-class differences. In addition, conventional linear discriminant dimensionality reduction methods often flatten tensor-type fusion features into vectors when processing them, destroying the inherent inter-modal structural relationships of the features and limiting the effective extraction of useful discriminative information.
[0004] Selecting static frames with fixed postures and clear imaging from moving grain sequences, constructing a chromaticity description that can fully express the subtle differences on the grain surface based on these frames, and fusing and discriminating chromaticity and texture features in a way that preserves multidimensional structure are the problems that need to be solved to simultaneously improve detection stability and grading precision. Summary of the Invention
[0005] The purpose of this invention is to provide an optical detection method for corn kernels based on dynamic and static grading and uniform feeding, which can automatically determine the static posture frame with clear imaging and paused motion from the image sequence of dynamically moving kernels, and construct a discrimination feature based on the frame that integrates color space distribution characteristics and texture energy characteristics, thereby improving the accuracy and robustness of corn kernel quality grading under dynamic conveying conditions.
[0006] To achieve the above objectives, the present invention adopts the following technical solution: The present invention provides an optical detection method for corn kernels based on dynamic and static grading and homogenization. This method takes corn kernels in a single-layer flat-laying motion state generated by the dynamic and static grading and homogenization mechanism as the detection object, and achieves accurate and robust detection of kernel quality through motion analysis, posture optimization, multi-feature fusion and grading discrimination.
[0007] This method acquires a sequence of images of corn kernels moving in a single-layer flat state after dynamic and static grading and homogenization. Based on the brightness change rate of corresponding pixels in adjacent frames of the sequence images, the motion vector field of each kernel is calibrated. Preferably, for each frame, the brightness difference at the same pixel coordinates in adjacent frames is calculated, and this brightness difference is divided by the time interval between the two frames to obtain the brightness change rate. Pixels with a brightness change rate greater than a preset dynamic threshold are marked as moving pixels. The coordinate offset of these pixels is used as the motion vector, and all motion vectors are aggregated to generate the motion vector field of each kernel.
[0008] Based on the divergence distribution of the motion vector field, the divergence value is calculated for each pixel in the motion vector field to obtain a divergence distribution map. Connectivity analysis is performed on the divergence distribution map, and connected regions with absolute divergence values less than a preset divergence threshold are designated as static regions. The frame numbers corresponding to these static regions in the sequence images are then voted on, and the frame with the most votes is selected as the static pose frame for each seed. This divergence analysis automatically filters out relatively stationary and clearly oriented frames from the motion sequence, effectively suppressing the interference of motion blur on subsequent feature extraction.
[0009] The color space distribution moments of the seed region in the static pose frame are extracted, and a seed surface chromaticity feature vector is constructed based on the singular value decomposition results of these moments. In one implementation, the seed region in the static pose frame is converted from RGB space to CIELAB space. Pixel value matrices for the L, a, and b channels are extracted, and two-dimensional geometric moments are calculated for each channel and arranged into a third-order tensor. Singular value decomposition is performed on this third-order tensor, and the first few singular values of the decomposed singular value sequence constitute the seed surface chromaticity feature vector. This feature vector can compactly represent the chromaticity statistical characteristics and spatial distribution information of the seed surface.
[0010] Based on the cross-correlation coefficients between each component of the grain surface chromaticity feature vector and a preset standard chromaticity template, a quality membership sequence of grains is generated. Specifically, a standard chromaticity template vector corresponding to each quality category is obtained, with the same dimension as the grain surface chromaticity feature vector; the sum of the products of each component of the grain surface chromaticity feature vector and the corresponding component of each standard chromaticity template vector is calculated to obtain the cross-correlation coefficient; the average of the cross-correlation coefficients corresponding to all components under the same quality category is taken as the membership degree of that quality category, and the membership degrees of all quality categories are summarized to generate a quality membership sequence.
[0011] The quality membership sequence is sorted in descending order of numerical value. The quality categories corresponding to the top few memberships are selected as the initial screening results, while the memberships that are not truncated and their corresponding quality categories are discarded. This initial screening step uses colorimetric features to quickly eliminate obviously irrelevant categories, narrowing the range of fine discrimination and improving overall detection efficiency.
[0012] The texture energy spectrum of each category in the initial screening results is obtained, and the texture energy spectrum is concatenated with the color space distribution moment along the channel dimension to obtain the fused discriminant tensor. Preferably, gray-level co-occurrence matrix operation is performed on the seed region in the static pose frame, and contrast, correlation, and second-order angular moment are extracted from the gray-level co-occurrence matrix as texture parameters and combined to form the texture energy spectrum; the texture energy spectrum is fused with the previously obtained color space distribution moment to form the fused discriminant tensor, which takes into account the complementary discriminative information of chroma and texture.
[0013] The ratio of inter-class scatter to intra-class scatter of the fusion discriminant tensor along a preset projection direction is calculated. The projection direction that maximizes this ratio is then determined, and the fusion discriminant tensor is projected onto this projection direction for dimensionality reduction, yielding dimensionality-reduced features. In practice, the intra-class and inter-class covariance matrices of the fusion discriminant tensor corresponding to each category in the initial screening results are calculated. A generalized Rayleigh quotient expression is constructed, where the numerator is the product of the projection direction and the inter-class covariance matrix, and the denominator is the product of the projection direction and the intra-class covariance matrix. The projection direction that maximizes the generalized Rayleigh quotient is then determined, and this projection direction is used to reduce the dimensionality of the fusion discriminant tensor, obtaining dimensionality-reduced features with maximum class separability.
[0014] The quality detection result of the grains is output based on the Mahalanobis distance between the dimensionality-reduced features and the standard feature libraries of each quality category. The Mahalanobis distance between the dimensionality-reduced features and the mean vector of the standard feature library for each quality category in the initial screening results is calculated, where the covariance matrix used is the aforementioned intra-class covariance matrix. The Mahalanobis distances are compared, and the quality category corresponding to the smallest Mahalanobis distance is selected as the quality detection result of the grains. Further, when the smallest Mahalanobis distance is greater than a preset distance threshold, the grain is marked as an unknown category, and a command to reacquire static pose frames is triggered to select the optimal pose from the sequence for re-discrimination; when the smallest Mahalanobis distance is less than or equal to the preset distance threshold, the quality category is directly output as the final detection result. This mechanism enhances the method's tolerance to abnormal grains or edge poses, ensuring the reliability of the detection results.
[0015] By using dynamic and static grading and uniform feeding to ensure that the kernels are laid out in a single layer, and using motion vector field divergence analysis to accurately pick up static posture frames, and then using color space distribution moment singular value decomposition and texture energy spectrum fusion to construct a fusion feature with strong discriminative power, combined with membership degree initial screening and tensor projection to maximize the inter-class and intra-class dispersion ratio, and finally using Mahalanobis distance grading decision, efficient and accurate optical detection of corn kernel quality is achieved.
[0016] In summary, due to the adoption of the above technical solution, the beneficial effects of the present invention are: A motion vector field is constructed using the brightness change rate between adjacent frames in a sequence of images, and the divergence of the motion vector field is calculated pixel by pixel. When a seed enters a brief static or stable gliding state, the velocity field of its corresponding pixel region tends to be uniform, and the absolute value of the divergence decreases significantly. Static regions with an absolute divergence value below a preset threshold are detected through connected component analysis, and the distribution of static regions over time is statistically analyzed. The most stable frame is selected as the static pose frame. This processing no longer relies on external triggering or fixed frame selection strategies, and can adaptively capture the pose of the seed without relative slippage and rotational blur from continuous motion imaging. This ensures that the image frames on which subsequent feature extraction is based have consistent and definite observation conditions, eliminates chromatic distortion and texture misalignment caused by motion blur or angle changes, and guarantees the reliability of the feature data source.
[0017] For the color space distribution moments of the seed region in static pose frames, the three channels (L, a, b) are organized into a third-order tensor and then subjected to singular value decomposition. The singular values themselves describe the principal components of the energy distribution of the moment tensor in each mode. The first few singular values are used to construct the chromaticity feature vector of the seed surface. This vector preserves the non-uniform distribution characteristics of the seed surface color in spatial location and the coupling relationships between channels in a compact form. Compared with directly using the global color mean or histogram, this chromaticity feature vector has a stronger ability to express and distinguish visual differences related to quality, such as local color spots, gradient regions, and color unevenness.
[0018] Building upon this foundation, a quality membership sequence is generated by calculating the cross-correlation coefficient between the chromaticity feature vector and the standard chromaticity template. Based on the membership magnitude, the top few categories are truncated as initial screening results, limiting the subsequent extraction of texture energy spectra to a few high-probability categories and compressing the computational scale of full-class comparison. Furthermore, the texture energy spectrum and color space distribution moments are concatenated along the channel dimension into a fusion discriminant tensor, preserving the structural information of the two types of features in the modal dimension, rather than directly flattening them into long vectors. For this tensor, intra-class covariance matrices and inter-class covariance matrices are constructed, and the projection direction that maximizes the ratio of inter-class scatter to intra-class scatter is calculated, maintaining the internal correlation of each modality within the tensor during the projection process. The dimensionality-reduced features obtained through this projection take into account the joint discriminative ability of chromaticity distribution and texture energy in the low-dimensional space, enhancing the separation between different quality categories and improving the compactness of intra-class samples. Finally, based on the Mahalanobis distance metric of the intra-class covariance matrix, quality classification is completed in this low-dimensional feature space, effectively avoiding the negative impact of high-dimensional redundancy and modal structure destruction on the discrimination results. Attached Figure Description
[0019] Figure 1 This is a flowchart of an optical detection method for corn kernels based on dynamic and static grading and homogenization. Figure 2 This is a flowchart for generating grain quality membership degrees based on color space distribution moment features; Figure 3 This is a flowchart of corn kernel quality testing based on Mahalanobis distance; Figure 4 This is a schematic diagram of the brightness change rate distribution and dynamic threshold of the static and dynamic regions in the static and dynamic graded uniform material process; Figure 5 This is a distribution map of the membership degree of color characteristics of corn kernels of different quality categories; Figure 6 This is a distribution chart of the consistency rate of quality inspection under different candidate values of M; Figure 7 These are the iterative optimization curves of the generalized Rayleigh quotient under different initial projection directions. Detailed Implementation
[0020] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] See Figure 1This invention provides an optical detection method for corn kernels based on dynamic and static grading and homogenization, comprising: acquiring a sequence of images of corn kernels moving in a single-layer flat state after dynamic and static grading and homogenization; calibrating the motion vector field of each kernel based on the brightness change rate of corresponding pixels in adjacent frames of the sequence of images; extracting static posture frames of each kernel from the sequence of images based on the divergence distribution of the motion vector field; extracting the color space distribution moments of the kernel region in the static posture frames, and constructing a kernel surface chromaticity feature vector based on the singular value decomposition results of the color space distribution moments; generating the kernel surface chromaticity feature vector based on the cross-correlation coefficients of each component in the kernel surface chromaticity feature vector and the standard chromaticity template. The quality membership degree sequence is obtained; the quality membership degree sequence is sorted by numerical value, and the quality categories corresponding to the first few membership degrees are selected as the initial screening results; the texture energy spectrum of the grain region corresponding to each category in the initial screening results is obtained, and the texture energy spectrum is fused with the color space distribution moment to obtain the fused discriminant tensor; the ratio of the inter-class dispersion to the intra-class dispersion of the fused discriminant tensor on the preset projection direction is calculated, the projection direction that maximizes the ratio is found, and the fused discriminant tensor is projected onto the projection direction for dimensionality reduction to obtain the dimensionality reduction feature; the quality detection result of the grain is output according to the Mahalanobis distance between the dimensionality reduction feature and the standard feature library of each quality category.
[0022] In practice, the motion vector field of each kernel is calibrated based on the rate of change in brightness of pixels at corresponding positions in adjacent frames of the image sequence. The image sequence is acquired by an image acquisition device facing a single layer of corn kernels moving in a flat arrangement, with a fixed time interval between adjacent frames. The brightness difference between the i-th frame and the (i+1)-th frame at the same pixel coordinates is calculated. The absolute value of the brightness difference is taken, and the brightness change rate is obtained by dividing the brightness difference by the time interval between the two frames. The brightness value at the pixel coordinates can be the grayscale value at that pixel coordinate location or the brightness component after color space conversion.
[0023] The preset dynamic threshold is set by analyzing the statistical distribution of the brightness change rate of the image sequence in a static state. A background image sequence without seed movement is acquired, and the mean and standard deviation of the brightness change rate at each pixel coordinate in the background image sequence are calculated. The preset dynamic threshold is the mean plus three times the standard deviation. Pixels with a brightness change rate greater than the preset dynamic threshold are marked as moving pixels. For each moving pixel, local optical flow estimation is used to calculate the displacement of the moving pixel between two adjacent frames. The displacement includes horizontal and vertical components, and this displacement of the moving pixel is used as the motion vector. Local optical flow estimation can be performed using the Lucas-Kanade method, solving the optical flow constraint equation within a neighborhood window centered on the moving pixel to obtain the coordinate offset of the moving pixel.
[0024] The aggregated sequence of images contains all motion vectors, with each moving pixel corresponding to a two-dimensional vector. All motion vectors together form a motion vector field. Any point in the motion vector field can be represented as... ,in and For pixel coordinates, For horizontal motion components, This represents the vertical motion component.
[0025] Based on the divergence distribution of the motion vector field, static pose frames of each seed are extracted from the sequence images. The divergence value of the motion vector field at each pixel is calculated to obtain the divergence distribution map. The formula for calculating the divergence value is: , in, Represents the motion vector field in coordinates The divergence value at that point, Let be the rate of change of the horizontal motion component along the horizontal coordinate direction. This represents the rate of change of the vertical motion component along the vertical coordinate direction. In the discrete image domain, Using the central difference approximation, i.e. , Using the central difference approximation, i.e. .
[0026] Connectivity analysis is performed on the divergence distribution map. A preset divergence threshold is determined based on the statistical characteristics of divergence in static regions. Manually labeled static seed regions are collected, and the mean and standard deviation of the absolute divergence values of all pixels within these regions are calculated. The preset divergence threshold is the mean plus three times the standard deviation. Pixels with absolute divergence values less than the preset divergence threshold are assigned a first label value, and the remaining pixels are assigned a second label value, resulting in a binarized divergence map. Connected regions composed of the first label values are extracted from the binarized divergence map. Each connected region contains a set of pixels with continuous coordinates and absolute divergence values below the threshold, and each connected region is labeled as a static region.
[0027] A voting system is used to count the frame numbers corresponding to static regions in the image sequence. The image sequence contains multiple frames, each with a frame number. In the multi-frame sequence from which the divergence distribution map is obtained, the frame numbers appearing in each connected component identified as a static region are recorded. A voting counter is set for each frame number, and the counter corresponding to the frame number of each appearing static region is incremented. After the statistics are completed, the frame number with the most votes is selected, and the frame corresponding to that frame number is retrieved from the image sequence as the static attitude frame for each kernel. If multiple frame numbers have the same number of votes and all are the highest, the frame with the smallest frame number is selected as the static attitude frame. This yields the static attitude frames of the corn kernels in a relatively static state during their movement.
[0028] See Figure 4 The figure illustrates the effect of distinguishing between static and moving pixels based on the rate of change of brightness. The horizontal axis represents the rate of change of brightness, in pixels per second, ranging from 0.00 to 0.40; the vertical axis represents the probability density of the corresponding rate of change of brightness. In the figure, the solid blue line represents the probability density distribution of the rate of change of brightness in static areas, the dashed red line represents the probability density distribution of the rate of change of brightness in moving areas, and the dashed black line represents the preset dynamic threshold.
[0029] The brightness change rate in stationary areas is mainly concentrated between 0.00 and 0.04, with the probability density reaching its peak at around 50, indicating that the brightness change rate of pixels in stationary areas is low and concentrated. The brightness change rate in moving areas is mainly distributed in the range of 0.05 to 0.30, with a relatively low probability density but a wider distribution range, showing that the brightness change amplitude of pixels in moving areas is significantly higher than that in stationary areas.
[0030] A preset dynamic threshold is set at approximately 0.045, located between the right tail of the brightness change rate distribution in the static area and the left starting point of the distribution in the moving area, effectively separating static and moving pixels. This threshold is determined based on the mean brightness change rate of the background sequence and three times its standard deviation, ensuring that the brightness change rate of static pixels is mostly below this threshold, while the brightness change rate of moving pixels is mostly above this threshold.
[0031] In specific implementation, please refer to Figure 2 The color space distribution moments of the seed region in the static pose frame are extracted. The seed region is segmented from the static pose frame using an adaptive threshold segmentation algorithm to separate the seed region from the background, obtaining a mask region containing complete seed pixels. The RGB space of the seed region is converted to CIELAB space. The conversion process first converts the RGB pixel values to linear RGB through Gamma correction, then transitions them through CIEXYZ space, and finally calculates the pixel values of the L, a, and b channels. The pixel value matrices of the L, a, and b channels within the seed region are extracted. The size of the pixel value matrix is the height multiplied by the width of the bounding rectangle of the seed region, with pixel values outside the bounding rectangle set to zero.
[0032] Calculate the two-dimensional geometric moments for channels L, a, and b respectively. For each channel, calculate the two-dimensional geometric moments. The calculation formula is: , in, Indicates channel identification, The values are L, a, and b; This represents the total number of columns of pixels in the horizontal direction of the bounding rectangle of the seed region; This represents the total number of rows of pixels in the vertical direction of the bounding rectangle of the seed region. This represents the horizontal coordinate index of the pixel, with a value ranging from 1 to... ; This represents the vertical coordinate index of the pixel, with a value ranging from 1 to... ; Let be the order of the geometric moments in the horizontal direction, taken as a non-negative integer. (When calculating...) The maximum value is set to 2; Let be the order of the geometric moments in the vertical direction, taken as a non-negative integer. (When calculating...) The maximum value is set to 2; For channel In coordinates The pixel value at that location.
[0033] The two-dimensional geometric moment sets for channel L, channel a, and channel b are calculated. Each channel's two-dimensional geometric moment includes... From 0 to 2, There are 9 moment values ranging from 0 to 2. The two-dimensional geometric moments of all channels are arranged into a third-order tensor, with the three dimensions of the third-order tensor corresponding to the channel type, level order, and so on. and vertical order The size of the third-order tensor is 3×3×3.
[0034] Perform singular value decomposition on the third-order tensor. Expand the third-order tensor along the channel dimension to obtain a matrix, where each row of the matrix corresponds to a channel. and The two-dimensional vectors, after being straightened, form a 9-dimensional matrix with 3 rows and 9 columns. Singular value decomposition (SVD) is performed on the expanded matrix, yielding a left singular vector matrix, a right singular vector matrix, and a sequence of singular values, arranged in descending order. The cumulative energy ratio of the singular value sequence is calculated, which is the ratio of the sum of squares of the first k singular values to the sum of squares of all singular values. A preset cumulative energy threshold of 0.95 is set. The smallest integer k that makes the cumulative energy ratio first greater than or equal to 0.95 is selected, and the first k singular values of the singular value sequence are used to construct the grain surface color feature vector. When k is less than 2, the first two singular values are forcibly selected to ensure the lowest possible dimension.
[0035] Based on the cross-correlation coefficients between each component of the kernel surface chromaticity feature vector and the standard chromaticity template, a kernel quality membership sequence is generated. The standard chromaticity template vector is obtained as follows: Multiple corn kernel samples of known quality categories are collected. For each sample, the kernel surface chromaticity feature vector is extracted according to the aforementioned steps. All kernel surface chromaticity feature vectors belonging to the same quality category are subjected to K-means clustering, with the number of clusters set to 3. The cluster center vector of each cluster is taken as the standard chromaticity template vector for that quality category, with the dimension consistent with the dimension of the kernel surface chromaticity feature vector. Each quality category includes, but is not limited to, whole kernels, damaged kernels, moldy kernels, and insect-damaged kernels. Each quality category corresponds to multiple standard chromaticity template vectors.
[0036] For the surface chromaticity feature vector of the grain to be tested, calculate its cross-correlation coefficient with each standard chromaticity template vector. The cross-correlation coefficient is the sum of the products of the corresponding components of the grain surface chromaticity feature vector and the standard chromaticity template vector. Calculate the arithmetic mean of the cross-correlation coefficients corresponding to all standard chromaticity template vectors under the same quality category, and use the average value as the membership degree of that quality category. Summarize the membership degrees of all quality categories to generate a quality membership degree sequence, which contains each quality category and its corresponding membership degree value.
[0037] See Figure 5 The figure shows the distribution of quality membership degrees across different quality categories, generated by extracting the color space distribution moments of the grain region from static pose frames and constructing a chromaticity feature vector of the grain surface through singular value decomposition, and calculating the cross-correlation coefficient with a standard chromaticity template. The horizontal axis represents the quality category, including four types: intact grains, damaged grains, moldy grains, and insect-damaged grains. The vertical axis represents the membership degree value of the corresponding quality category, ranging from 0 to 1. The box plots and scatter plots corresponding to each quality category are overlaid to show the central tendency and dispersion of the sample membership degrees.
[0038] The membership degree distribution of intact grains is relatively concentrated, with a median of approximately 0.85 and a small interquartile range shown in the box plot. Most samples have a membership degree higher than 0.7, indicating a strong correlation between the chromatic feature vector of intact grains and their standard chromatic template, resulting in high membership values. The membership degree distribution of damaged grains is more dispersed, with a median of approximately 0.58, a large interquartile range, and membership degrees spanning a wide range from 0.1 to close to 1, reflecting significant variability in the chromatic features of damaged grains. The membership degree of moldy grains shows a clear downward skewed distribution, with a median of approximately 0.42, and the box plot range is mainly concentrated between 0 and 0.65. Some samples have low membership degrees, indicating a weak match between the chromatic features of moldy grains and the standard chromatic template. The membership degree of insect-damaged grains is the lowest, with a median of approximately 0.17, and most samples have a membership degree below 0.4, indicating a poor correlation between the chromatic feature vector of insect-damaged grains and their standard template, resulting in significantly lower membership values than other categories.
[0039] In practice, the quality membership degree sequence is sorted by numerical value, and the quality categories corresponding to the top few membership degrees are selected as the initial screening results. The quality membership degree sequence contains several elements, each consisting of a quality category identifier and a membership degree value corresponding to that quality category. The membership degree value is the arithmetic mean of the cross-correlation coefficients of all standard chromaticity template vectors and grain surface chromaticity feature vectors under that quality category. The membership degree values corresponding to each quality category in the quality membership degree sequence are extracted into a numerical list, which is then sorted in descending order. The quality category identifiers are then rearranged from highest to lowest membership degree value to obtain the sorted sequence.
[0040] The value of the preset positive integer M is determined through offline parameter optimization. In the offline optimization stage, a set of corn kernel samples with known quality categories are collected. For each corn kernel sample, the steps from constructing the surface chromaticity feature vector to generating a quality membership sequence are performed to obtain the sorted sequence of the sample. The candidate value set of M is set to all integers from 1 to the total number of quality categories. For each M candidate value, the quality category corresponding to the first M membership values in the sorted sequence is extracted as the initial screening result. Subsequent steps of texture energy spectrum acquisition, fusion discriminant tensor construction, dimensionality reduction, and Mahalanobis distance discrimination are then performed. The final output quality detection result is compared with the known quality categories of the corn kernel samples. The proportion of samples whose output results match the known quality categories is recorded as the detection consistency rate. The detection consistency rates corresponding to all M candidate values are compared, and the M candidate value that maximizes the detection consistency rate is selected. If multiple M candidate values result in a tie for the highest detection consistency rate, the smallest value among the tie-breaking M candidate values is selected as the value of M. After offline optimization, the value of M was selected as 3.
[0041] Extract the first M membership values (the first 3 membership values) from the sorted sequence, and obtain the quality category identifier corresponding to each of these 3 membership values. Mark the obtained quality category identifiers as the initial screening results. Other membership values in the quality membership sequence that are not within the extraction range, as well as the quality category identifiers corresponding to these membership values, are discarded and not involved in subsequent processing.
[0042] During the descending sorting process, if multiple quality categories have the same membership value, the quality categories with the same membership value are placed consecutively in the sorted sequence. When truncating the first M membership values, if the Mth position corresponds to multiple quality categories with completely equal membership values, the quality categories corresponding to the first M membership values are truncated strictly according to the order of the sorted sequence, and the quality categories corresponding to the equal membership values after the Mth position are discarded.
[0043] See Figure 6In the graph, the horizontal axis represents the candidate values of a preset positive integer M, ranging from 1 to 10, and the vertical axis represents the detection consistency rate for the corresponding M value, ranging from 0 to 1. The legend "Detection Consistency Rate" indicates that the data points and box plots in the graph represent the proportion of the final quality detection results that are consistent with the known quality categories when the top M quality categories are selected as the initial screening results after sorting based on the quality membership sequence under different M values.
[0044] Each horizontal axis point in the figure corresponds to a box plot and multiple scatter points. The box plot shows the distribution characteristics of the detection consistency rate, including the median (middle line of the box), upper and lower quartiles (edges of the box), and upper and lower whiskers (maximum and minimum non-outlier values). The scatter points represent the discrete values of the detection consistency rate for specific samples. The overall trend shows that the detection consistency rate increases significantly as the M value increases from 1 to 3, reaching its peak at M=3, with the median of the box plot approaching 0.9, indicating that the detection consistency rate is highest and the stability is relatively good at this point. After the M value exceeds 3, the detection consistency rate generally shows a downward trend, and as the M value further increases, the width of the box plot slightly increases, indicating that the fluctuation of the detection consistency rate increases and the stability decreases.
[0045] In the specific implementation, the texture energy spectrum of the seed region corresponding to each category in the initial screening results is obtained, and the texture energy spectrum is fused with the color space distribution moment to obtain the fused discriminant tensor. The initial screening results contain M quality category identifiers, where M is 3. For each quality category in the initial screening results, the seed region is extracted in the static pose frame, and gray-level co-occurrence matrix operation is performed. When extracting the seed region, the seed region in the static pose frame is converted from a color image to a grayscale image. The grayscale conversion adopts a weighted average method, and the grayscale value is obtained by combining the pixel values of the L channel, a channel, and b channel with weight coefficients of 0.299, 0.587, and 0.114 and then rounding them down. The gray-level co-occurrence matrix (GLCM) operation is performed on the gray-level image of the seed region. The spatial offset distance *d* between pixel pairs is set to 1 pixel, and the spatial offset direction *θ* takes four directions: 0 degrees, 45 degrees, 90 degrees, and 135 degrees. The pixel gray-level is compressed to 16 levels. This 16-level compression is achieved by uniformly dividing the original gray-level range of 0 to 255 into 16 intervals and mapping each interval to a gray-level. The GLCM is calculated for each of the four directions, resulting in four 16×16 GLCMs. The arithmetic mean of the corresponding elements of the four GLCMs is then taken to obtain the average GLCM.
[0046] Contrast, correlation, and angular second moment are extracted as texture parameters from the average gray-level co-occurrence matrix (AGM). Contrast reflects the distribution of elements far from the diagonal in the AGM; correlation reflects the linear dependence of elements in the AGM along the row and column directions; and angular second moment reflects the uniformity of element values in the AGM. These three values are combined into a three-dimensional vector, with the first component being contrast, the second being correlation, and the third being angular second moment. This three-dimensional vector represents the texture energy spectrum.
[0047] The color space distribution moments are represented by the aforementioned third-order tensor, which has a size of 3×3×3. These tensors correspond to 27 moment values for the L, a, and b channels when the horizontal order p takes 0, 1, and 2, and the vertical order q takes 0, 1, and 2. The texture energy spectrum and color space distribution moments are concatenated along the channel dimensions. The concatenation operation places a 3-dimensional texture energy spectrum vector of size 3 at the end of the channel dimension of the 3×3×3 third-order tensor. After concatenation, the channel dimension of the third-order tensor is expanded from 3 to 4, resulting in a fusion discriminant tensor with a size of 4×3×3.
[0048] The ratio of inter-class scatter to intra-class scatter of the fusion discriminant tensor along a preset projection direction is calculated. The dimensionality of the fusion discriminant tensor is then reduced based on the projection direction that maximizes this ratio, yielding dimensionality-reduced features. The preset projection direction is an iteratively optimized direction initialized as a random unit vector.
[0049] The fusion discriminant tensor is expanded into a one-dimensional vector. The expansion method is to arrange all elements sequentially according to the channel dimension priority. The size of the fusion discriminant tensor is 4×3×3, resulting in a one-dimensional vector of dimension 36 after expansion. Each quality category in the initial screening results corresponds to a seed sample set, and each seed sample has a 36-dimensional expanded vector. The intra-class covariance matrix and inter-class covariance matrix of the fusion discriminant tensor corresponding to each category in the initial screening results are calculated. The calculation process of the intra-class covariance matrix is as follows: For each quality category, the arithmetic mean of all 36-dimensional expanded vectors belonging to the same quality category is calculated as the mean vector of that category. The cross product of the difference between each 36-dimensional expanded vector of that category and the mean vector of the category is calculated and summed. Then, it is divided by the number of samples in that category to obtain the covariance matrix of that category. The covariance matrices of all M quality categories in the initial screening results are summed in a weighted form, with the weights being the proportion of the number of samples in each category in the total number of samples, to obtain a 36×36-dimensional intra-class covariance matrix. The calculation process of the inter-class covariance matrix is as follows: calculate the total mean vector of the 36-dimensional expanded vectors of all samples. For each quality category, calculate the cross product of the difference between the mean vector of that category and the total mean vector, and multiply it by the number of samples in that category. Sum the above products for all M quality categories and divide by the total number of samples to obtain the 36×36-dimensional inter-class covariance matrix.
[0050] Constructing a generalized Rayleigh quotient expression The expression is: , in, It is a 36-dimensional projection direction vector, with constraints The L2 norm is 1; It is a 36×36 dimensional inter-class covariance matrix; It is a 36×36 dimensional intraclass covariance matrix; Projection direction vector transpose; Projection direction The ratio of the inter-class dispersion to the intra-class dispersion.
[0051] Finding the projection direction that maximizes the generalized Rayleigh quotient is transformed into solving the generalized eigenvalue equation. The generalized eigenvector corresponding to the largest generalized eigenvalue. The within-class covariance matrix. Find the inverse and the inter-class covariance matrix. Multiplication yields a matrix The matrix is calculated, and all eigenvalues and eigenvectors are selected. The eigenvector corresponding to the largest eigenvalue is chosen as the optimal projection direction. The L2 norm of this optimal projection direction is normalized to 1 and used as the final projection direction. The 36-dimensional vector expanded from the fusion discriminant tensor is projected onto the final projection direction. The projection operation involves calculating the inner product of the 36-dimensional vector and the projection direction vector to obtain a scalar value, which is the dimensionality reduction feature.
[0052] See Figure 7 In the figure, the horizontal axis represents the "iteration number," ranging from 0 to 200; the vertical axis represents the "generalized Rayleigh quotient R(w)," ranging from 0 to 1. Ten curves are plotted, corresponding to the ten different randomly initialized projection directions used in the fusion discriminant tensor dimensionality reduction (labeled "initial direction 1" to "initial direction 10"). All curves show a trend where the generalized Rayleigh quotient R(w) gradually increases with the number of iterations.
[0053] As shown in the figure, the generalized Rayleigh quotient R(w) values for all initial directions are relatively dispersed in the early stages of iteration, ranging from a minimum of about 0.1 to a maximum of about 0.35. With increasing iteration count, the curves generally show a rapid upward trend, and around iteration 125, the generalized Rayleigh quotient R(w) begins to stabilize. Ultimately, all curves converge to a high value range of 0.95 to 1.0, indicating that iterative optimization can find the projection direction that maximizes the ratio of inter-class dispersion to intra-class dispersion. Specifically, the curves for initial directions 5 and 10 show faster growth rates, with the generalized Rayleigh quotient R(w) approaching or exceeding 0.9 after approximately 70 iterations; while the curves for initial directions 2 and 3 show relatively slower growth rates, only approaching or exceeding 0.85 after 100 iterations. Despite the different initial directions, all curves reach a relatively high convergence level of approximately 0.97 to 0.99 after more than 150 iterations, demonstrating good consistency and stability in the projection direction optimization results.
[0054] In specific implementation, please refer to Figure 3 Based on the Mahalanobis distance between the dimensionality-reduced features and the standard feature library for each quality category, the quality detection results of the kernels are output. The construction process of the standard feature library is as follows: a batch of corn kernel samples with known quality categories are collected, and for each corn kernel sample, all steps from acquiring the sequence image to obtaining the fusion discriminant tensor and projecting it to the final projection direction are performed to obtain the dimensionality-reduced features of each sample; the dimensionality-reduced features are grouped according to the quality category, and the arithmetic mean vector of all dimensionality-reduced features under each quality category is calculated. The arithmetic mean vector is used as the mean vector of the standard feature library for that category, and the dimension of the mean vector of the standard feature library is consistent with that of the dimensionality-reduced features.
[0055] The initial screening results contain M quality category identifiers, where M is a value of 3. For each quality category in the initial screening results, the corresponding standard feature library mean vector is extracted from the standard feature library. The Mahalanobis distance between the dimensionality-reduced features and the standard feature library mean vector of each quality category in the initial screening results is calculated. The formula for calculating the Mahalanobis distance is: , in, This is the quality category identifier, and its value is one of the M quality categories in the initial screening results. The dimension-reduced feature vector of the grain to be detected has a dimension of 1; For quality category The standard feature library mean vector, with a dimension of 1; It is the inverse of the intra-class covariance matrix, which is the inverse of the 1×1 dimensional intra-class covariance matrix obtained by dimensionality reduction projection of the aforementioned 36×36 intra-class covariance matrix; For vectors transpose; Dimensionality reduction features To quality category Standard feature library mean vector Mahalanobis distance.
[0056] Compare the Mahalanobis distances of the dimensionality reduction features with those of all quality categories in the initial screening results. Select the Mahalanobis distance with the smallest value from the M calculated Mahalanobis distances, and record the value of the smallest Mahalanobis distance and the quality category identifier corresponding to the smallest Mahalanobis distance.
[0057] The preset distance threshold was determined through offline statistical analysis. During the offline statistical analysis phase, a set of corn kernel samples with known quality categories were collected. For each corn kernel sample, the dimensionality-reduced feature was calculated, and the Mahalanobis distance was calculated between it and the mean vector of the standard feature library for the sample's quality category, resulting in a set of intra-class Mahalanobis distances. For each corn kernel sample, the dimensionality-reduced feature was calculated, and the Mahalanobis distance was calculated between it and the mean vector of the standard feature library for all other quality categories to which the sample did not belong, resulting in a set of inter-class Mahalanobis distances. Based on the distributions of intra-class and inter-class Mahalanobis distances, a threshold value was selected that balances the ratio of correctly identified samples of known quality categories with the ratio of incorrectly accepted samples of unknown categories. The preset distance threshold was chosen as the midpoint between the upper quartile of the intra-class Mahalanobis distance distribution and the lower quartile of the inter-class Mahalanobis distance distribution.
[0058] When the minimum Mahalanobis distance is greater than the preset distance threshold, it indicates that the distance between the dimensionality reduction features of the kernel to be detected and the mean vector of the standard feature library of all quality categories in the initial screening results exceeds the normal fluctuation range. The kernel to be detected is marked as an unknown category, and an instruction to reacquire the static attitude frame is generated and triggered. The instruction to reacquire the static attitude frame controls the image acquisition device to perform sequence image acquisition on the same batch or subsequent batches of corn kernels again, and re-extract the static attitude frame from the sequence image. Subsequently, based on the re-extracted static attitude frame, the complete detection process from extracting the color space distribution moment to calculating the Mahalanobis distance is executed again.
[0059] When the minimum Mahalanobis distance is less than or equal to the preset distance threshold, it indicates that the dimensionality reduction features of the grain to be detected are close enough to the mean vector of the standard feature library of a known quality category. The quality category identifier corresponding to the minimum Mahalanobis distance is directly used as the quality detection result of the grain, and the quality detection result is stored in the detection record in the form of quality category identifier.
[0060] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.
Claims
1. A method for optical detection of corn kernels based on dynamic and static classification of uniform material, characterized in that, include: A sequence of images of corn kernels moving in a single-layer flat state after being uniformly graded by dynamic and static methods is obtained. The motion vector field of each kernel is calibrated based on the brightness change rate of the corresponding pixels in adjacent frames of the sequence of images. Based on the divergence distribution of the motion vector field, the static pose frames of each seed are extracted from the sequence images; Extract the color space distribution moments of the seed region in the static pose frame, and construct the seed surface chromaticity feature vector based on the singular value decomposition results of the color space distribution moments; Based on the cross-correlation coefficients between each component of the grain surface chromaticity feature vector and the standard chromaticity template, a quality membership sequence of the grain is generated. The quality membership sequence is sorted by numerical value, and the quality categories corresponding to the first few membership degrees are selected as the initial screening results. Obtain the texture energy spectrum of the seed region corresponding to each category in the initial screening results, and fuse the texture energy spectrum with the color space distribution moment to obtain the fused discriminant tensor; Calculate the ratio of the inter-class scatter to the intra-class scatter of the fused discriminant tensor on a preset projection direction, solve for the projection direction that maximizes the ratio, and project the fused discriminant tensor onto this projection direction to reduce the dimensionality and obtain the dimensionality-reduced features. Based on the Mahalanobis distance between the reduced-dimensional features and the standard feature library of each quality category, the quality detection results of the grains are output.
2. The method according to claim 1, wherein, The step of calibrating the motion vector field of each seed grain based on the brightness change rate of corresponding pixels in adjacent frames of the image sequence includes: Calculate the brightness difference between the i-th frame and the (i+1)-th frame in the sequence of images at the same pixel coordinates, and divide the brightness difference by the time interval between the two frames to obtain the brightness change rate; Pixels whose brightness change rate is greater than a preset dynamic threshold are marked as moving pixels, and the coordinate offset of the moving pixels is used as the motion vector. By aggregating all motion vectors in the sequence images, a motion vector field for each seed is generated.
3. The method according to claim 2, wherein, The extraction of static pose frames for each seed from the sequence images based on the divergence distribution of the motion vector field includes: Calculate the divergence value of the motion vector field at each pixel to obtain a divergence distribution map; Connectivity analysis is performed on the divergence distribution map, and connected regions with absolute divergence values less than a preset divergence threshold are defined as static regions; The frame number corresponding to the static region in the sequence image is voted on, and the frame with the most votes is selected as the static posture frame of each seed.
4. The method according to claim 1, wherein, The step of extracting the color space distribution moments of the seed region in the static pose frame and constructing the seed surface chromaticity feature vector based on the singular value decomposition results of the color space distribution moments includes: The seed region in the static pose frame is converted from RGB space to CIELAB space, and the pixel value matrix of L channel, a channel and b channel is extracted. Calculate the two-dimensional geometric moments of the L channel, the a channel, and the b channel respectively, and arrange the two-dimensional geometric moments into a third-order tensor; The third-order tensor is subjected to singular value decomposition, and the first few singular values of the decomposed singular value sequence are used to form the surface color feature vector of the grain.
5. The optical detection method for corn kernels based on dynamic and static grading and homogenization according to claim 4, characterized in that, The step of generating a quality membership sequence for the grains based on the cross-correlation coefficients between each component of the grain surface chromaticity feature vector and the standard chromaticity template includes: Obtain the standard chromaticity template vector corresponding to each quality category, wherein the dimension of the standard chromaticity template vector is the same as the dimension of the chromaticity feature vector of the grain surface; The cross-correlation coefficient is obtained by summing the products of each component of the grain surface chromaticity feature vector with the corresponding component of each standard chromaticity template vector. The average of the cross-correlation coefficients of all components under each quality category is used to obtain the membership degree of that quality category. The membership degrees of all quality categories are then summed to generate the quality membership degree sequence.
6. The optical detection method for corn kernels based on dynamic and static grading and homogenization according to claim 1, characterized in that, The step of sorting the quality membership sequence by numerical value and selecting the quality categories corresponding to the first few membership degrees as the initial screening results includes: The membership values in the quality membership sequence are sorted in descending order to obtain the sorted sequence. Extract the first M membership values from the sorted sequence, where M is a preset positive integer; The quality categories corresponding to the first M membership values are marked as the initial screening results, and the other membership values and their corresponding quality categories that were not truncated in the quality membership sequence are discarded.
7. The optical detection method for corn kernels based on dynamic and static grading and homogenization according to claim 6, characterized in that, The step of obtaining the texture energy spectrum of the seed region corresponding to each category in the initial screening results, and fusing the texture energy spectrum with the color space distribution moment to obtain the fused discriminant tensor includes: A gray-level co-occurrence matrix operation is performed on the seed region in the static pose frame. Contrast, correlation, and second angular moment are extracted from the gray-level co-occurrence matrix as texture parameters, and the texture parameters are combined into the texture energy spectrum. The texture energy spectrum and the color space distribution moment are spliced along the channel dimension to obtain the fusion discriminant tensor.
8. The optical detection method for corn kernels based on dynamic and static grading and homogenization according to claim 7, characterized in that, The calculation of the ratio of inter-class scatter to intra-class scatter of the fused discriminant tensor along a preset projection direction, and the dimensionality reduction of the fused discriminant tensor based on the projection direction that maximizes the ratio, to obtain dimensionality reduction features, includes: Calculate the intra-class covariance matrix and inter-class covariance matrix of the fusion discriminant tensor corresponding to each category in the initial screening results; Construct a generalized Rayleigh quotient expression, wherein the numerator of the generalized Rayleigh quotient expression is the product of the projection direction and the inter-class covariance matrix, and the denominator is the product of the projection direction and the intra-class covariance matrix; Find the projection direction that maximizes the generalized Rayleigh quotient, and project the fusion discriminant tensor onto this projection direction to obtain the dimensionality reduction feature.
9. The optical detection method for corn kernels based on dynamic and static grading and homogenization according to claim 8, characterized in that, The step of outputting the quality detection result of the grain based on the Mahalanobis distance between the dimensionality reduction features and the standard feature library of each quality category includes: Calculate the Mahalanobis distance between the reduced-dimensional features and the mean vector of the standard feature library for each quality category in the initial screening results, wherein the covariance matrix used in the Mahalanobis distance is the intra-class covariance matrix; The quality category corresponding to the smallest Mahalanobis distance is selected as the quality detection result of the grain by comparing the dimensionality reduction feature with the Mahalanobis distance of each quality category.
10. The optical detection method for corn kernels based on dynamic and static grading and homogenization according to claim 9, characterized in that, The step of outputting the quality detection result of the grain based on the Mahalanobis distance between the dimensionality reduction features and the standard feature library of each quality category also includes: When the minimum Mahalanobis distance is greater than a preset distance threshold, the seed is marked as an unknown category, and an instruction to reacquire the static pose frame is triggered. When the minimum Mahalanobis distance is less than or equal to the preset distance threshold, the quality category corresponding to the minimum Mahalanobis distance is directly output as the quality detection result of the grain.
Citation Information
Patent Citations
Gaussian neural field dynamic scene reconstruction system based on depth consistency constraint
CN121708189A
Image processing apparatus, image processing method, imaging apparatus
US20100079624A1
