A nondestructive detection method and device for fruit sugar content and a storage medium
By employing segmentation and flow processing and spectral demixing techniques, combined with a base learner and temperature compensation, accurate and non-destructive detection of fruit sugar content was achieved. This solved the problems of model applicability and temperature error in existing technologies, and improved detection accuracy and versatility.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- AOPU TIANCHENG (WUHAN) OPTOELECTRONICS TECHNOLOGY CO LTD
- Filing Date
- 2025-12-19
- Publication Date
- 2026-05-26
AI Technical Summary
Existing methods for detecting the sugar content of fruits are destructive, inefficient, and the models are difficult to apply to fruits of different colors, varieties, or origins. Changes in ambient temperature introduce measurement errors, and there is a lack of effective temperature compensation mechanisms.
A partitioned processing architecture is adopted. Visible and near-infrared spectral data are preprocessed by Savitzky-Golay smoothing and continuum removal. Color feature vectors are constructed by combining spectral unmixing and spectral index calculation. Sugar content is predicted using a base learner and a temperature compensation module.
It achieves accurate and non-destructive detection of fruit sugar content, improves the model's versatility and prediction accuracy, overcomes differences between different varieties and origins, and effectively eliminates the influence of temperature.
Smart Images

Figure CN121347428B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of material composition detection technology, specifically relating to a non-destructive detection method, device, and storage medium for fruit sugar content. Background Technology
[0002] Fruit sugar content is a core indicator for evaluating its ripeness, flavor, and commercial value. Accurate detection of fruit sugar content is crucial in modern agricultural production, fruit grading, warehousing, logistics, and retail. Traditional methods for fruit sugar content detection, such as handheld saccharimeters, are destructive, requiring juice extraction, which is cumbersome, inefficient, and damages sample integrity, making it impossible to test large batches of fruit individually. Therefore, developing rapid, non-destructive, and portable detection technologies has become a research hotspot in this field. Among these, visible / near-infrared spectroscopy is widely recognized as one of the most promising non-destructive technologies for detecting the intrinsic quality of fruits due to its ability to rapidly acquire spectral information related to the vibrational absorption of molecules within substances (such as CH and OH groups in sugars and water). This technology achieves rapid prediction of unknown samples by establishing a mathematical model between spectral data and the internal sugar content of the fruit.
[0003] Existing technical solutions typically follow a unified process of spectral acquisition, unified preprocessing, and global modeling. The core problem lies in this one-size-fits-all approach, which fails to effectively distinguish and utilize information from different regions and types within the spectrum. Specifically, the visible light region is strongly influenced by peel color (pigmentation), while the near-infrared region truly reflects internal sugar content. The variable signals of peel color severely interfere with the weak sugar signals in the near-infrared region. Existing technologies treat these two aspects interchangeably, making models built for one variety difficult to apply to fruits of different colors, varieties, or origins. Secondly, existing methods simply treat peel color information as noise and attempt to eliminate it, wasting the maturity information contained in the color that is highly correlated with sugar accumulation. This results in a weak correlation between model input features and sugar content, limiting the upper limit of prediction accuracy. Finally, changes in ambient temperature cause spectrometer performance drift and alter water absorption characteristics, introducing measurement errors. Most existing solutions lack an effective temperature compensation mechanism, leading to model instability outside the laboratory.
[0004] It is clear that there is an urgent need for an accurate method to detect the sugar content of fruits. Summary of the Invention
[0005] To improve the accuracy of non-destructive testing of fruit sugar content, in a first aspect, this invention proposes a non-destructive testing method for fruit sugar content, the method comprising:
[0006] Acquire sample reflectance spectral data, and divide the sample reflectance spectral data into visible light region spectrum and near-infrared region spectrum according to wavelength;
[0007] The visible light spectrum is subjected to a first preprocessing to obtain visible light spectral data that highlights the pigment absorption characteristics; and the near-infrared spectrum is subjected to a second preprocessing to obtain near-infrared spectral data for sugar content modeling. The first preprocessing includes Savitzky-Golay smoothing and continuum removal processing, and the second preprocessing includes Savitzky-Golay differentiation, as well as standard normal variable transformation or multivariate scattering correction.
[0008] Based on the visible light spectral data, a color feature vector is constructed through spectral unmixing and spectral index calculation; wherein, the spectral unmixing includes establishing and optimizing the reference endmember spectrum to obtain the optimized endmember spectrum, and using a constrained linear regression algorithm to solve for the contribution coefficient of each pigment.
[0009] The near-infrared spectral data is input into a first base learner, which outputs a first sugar content prediction mean and a first variance; the color feature vector and temperature data are input into a second base learner, which outputs a second sugar content prediction mean and a second variance; the temperature data is a reference temperature used when calibrating the second base learner;
[0010] Input the first sugar content prediction mean, the first variance, the second sugar content prediction mean, and the second variance into the meta-model to obtain the final sugar content prediction value;
[0011] Based on the difference between the real-time measured temperature and the reference temperature, the final predicted sugar content is physically compensated for temperature, and the compensated sugar content value is output.
[0012] In one possible embodiment, acquiring the sample reflectance spectral data includes:
[0013] The reflected light intensity spectrum of a standard diffuse whiteboard was continuously collected and arithmetically averaged at least 15 times to obtain the reference light intensity spectrum I1;
[0014] The reflected light intensity spectra of the samples were continuously collected and arithmetically averaged at least 15 times to obtain the sample light intensity spectrum I2;
[0015] The sample light intensity spectrum I2 is calibrated using the reference light intensity spectrum I1 to obtain the sample reflectance spectrum data S = I2 / I1.
[0016] In one possible implementation, the continuum removal process includes:
[0017] All local reflectance maxima were identified in the visible light spectrum after Savitzky-Golay smoothing.
[0018] The local reflectivity maxima are connected by piecewise linear interpolation or spline interpolation to form a continuum curve.
[0019] The original reflectance value of each wavelength point λ in the visible light region is removed by the reflectance value of the corresponding wavelength point on the continuum curve to obtain the visible light spectral data after continuum removal processing.
[0020] In one possible implementation, the process of optimizing the reference endmember spectrum includes:
[0021] The reflectance spectral data of K samples are considered as vectors in M-dimensional space; using the reference endmember spectrum as the initial endmember set, an iterative search is conducted to find N spectral samples that maximize the volume of the simplex body composed of N endmember spectral vectors; wherein, the volume V of the simplex body is calculated according to the following formula:
[0022] ;
[0023] Where A is a matrix composed of the endmember spectral vectors;
[0024] When the iterative search fails to increase the volume of the simplex, the spectra of the N spectral samples that currently constitute the vertices of the simplex are determined as the optimized endmember spectra.
[0025] In one possible implementation, the base learner is trained using the following process:
[0026] Obtain a training sample set including feature vectors and true sugar content values, wherein the feature vectors include color feature vectors and near-infrared spectral data;
[0027] The number of training rounds T is determined by cross-validation, and the base learner is trained T times. Each training round includes:
[0028] For each sample, calculate the current mean and the negative gradient of the mean predicted under the current variance;
[0029] Train a new mean-based decision tree to fit the negative gradient of the mean;
[0030] The prediction result of the mean decision tree is multiplied by the learning rate and added to the mean model;
[0031] For each sample, calculate the current mean and the negative gradient of variance under the current variance prediction;
[0032] Train a new variance decision tree to fit the negative variance gradient;
[0033] The prediction result of the variance decision tree is multiplied by the learning rate and added to the variance model.
[0034] In one possible implementation, the constrained linear regression algorithm is used to solve for the contribution coefficients of each pigment. The optimization objective is to minimize the residual between the reconstructed spectrum and the true spectrum, while ensuring that the contribution coefficients of each pigment are non-negative. This is achieved by solving the following mathematical expression:
[0035] ;
[0036] in, The visible light spectral data after the first preprocessing, For the optimized end-member spectrum of the i-th pigment, a i Let be the contribution coefficient of the i-th pigment to be solved, and k be the total number of pigments.
[0037] Secondly, embodiments of this application provide a non-destructive testing device for fruit sugar content, the device comprising:
[0038] The acquisition module is used to acquire sample reflectance spectral data and divide the sample reflectance spectral data into visible light spectrum and near-infrared spectrum according to wavelength;
[0039] The preprocessing module is used to perform a first preprocessing on the visible light spectrum to obtain visible light spectral data that highlights the pigment absorption characteristics; and to perform a second preprocessing on the near-infrared spectrum to obtain near-infrared spectral data for sugar content modeling. The first preprocessing includes Savitzky-Golay smoothing and continuum removal processing, and the second preprocessing includes Savitzky-Golay differentiation, as well as standard normal variable transformation or multivariate scattering correction.
[0040] The visible light processing module is used to construct a color feature vector based on the visible light spectral data through spectral unmixing and spectral index calculation; wherein, the spectral unmixing includes establishing and optimizing the reference endmember spectrum to obtain the optimized endmember spectrum, and using a constrained linear regression algorithm to solve for the contribution coefficient of each pigment.
[0041] The base learner prediction module is used to input the near-infrared spectral data into a first base learner and output a first sugar content prediction mean and a first variance; input the color feature vector and temperature data into a second base learner and output a second sugar content prediction mean and a second variance; the temperature data is a reference temperature used when calibrating the second base learner;
[0042] The meta-model prediction module is used to input the first sugar content prediction mean, the first variance, the second sugar content prediction mean, and the second variance into the meta-model to obtain the final sugar content prediction value.
[0043] The temperature compensation module is used to perform temperature physical compensation on the final sugar content prediction value based on the difference between the real-time measured temperature and the reference temperature, and output the compensated sugar content value.
[0044] In one possible implementation, the acquisition module is specifically used for:
[0045] The reflected light intensity spectrum of a standard diffuse whiteboard was continuously collected and arithmetically averaged at least 15 times to obtain the reference light intensity spectrum I1;
[0046] The reflected light intensity spectra of the samples were continuously collected and arithmetically averaged at least 15 times to obtain the sample light intensity spectrum I2;
[0047] The sample light intensity spectrum I2 is calibrated using the reference light intensity spectrum I1 to obtain the sample reflectance spectrum data S = I2 / I1.
[0048] In one possible implementation, the continuum removal process includes:
[0049] All local reflectance maxima were identified in the visible light spectrum after Savitzky-Golay smoothing.
[0050] The local reflectivity maxima are connected by piecewise linear interpolation or spline interpolation to form a continuum curve.
[0051] The original reflectance value of each wavelength point λ in the visible light region is removed by the reflectance value of the corresponding wavelength point on the continuum curve to obtain the visible light spectral data after continuum removal processing.
[0052] Thirdly, the present invention provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the non-destructive detection method for sugar content in any of the above-mentioned fruits.
[0053] The non-destructive detection method for fruit sugar content provided in this application includes: acquiring sample reflectance spectral data; dividing the sample reflectance spectral data into visible light spectrum and near-infrared spectrum according to wavelength; performing a first preprocessing on the visible light spectrum to obtain visible light spectral data highlighting pigment absorption characteristics; and performing a second preprocessing on the near-infrared spectrum to obtain near-infrared spectral data for sugar content modeling. The first preprocessing includes Savitzky-Golay smoothing and continuum removal, and the second preprocessing includes Savitzky-Golay differentiation and standard normal variable transformation or multivariate scattering correction. Based on the visible light spectral data, a color feature vector is constructed through spectral unmixing and spectral index calculation. The spectral unmixing process includes establishing and optimizing a reference endmember spectrum to obtain an optimized endmember spectrum, and using a constrained linear regression algorithm to solve for the contribution coefficients of each pigment. The near-infrared spectral data is input into a first base learner, which outputs a first sugar content prediction mean and a first variance. The color feature vector and temperature data are input into a second base learner, which outputs a second sugar content prediction mean and a second variance. The temperature data is a reference temperature used during the calibration of the second base learner. The first sugar content prediction mean, the first variance, the second sugar content prediction mean, and the second variance are input into a meta-model to obtain a final sugar content prediction value. Based on the difference between the real-time measured temperature and the reference temperature, temperature physical compensation is performed on the final sugar content prediction value, and the compensated sugar content value is output. This method enables accurate and non-destructive detection of fruit sugar content. Attached Figure Description
[0054] Figure 1 This is a schematic diagram of the first process for non-destructive detection of fruit sugar content provided in an embodiment of the present invention;
[0055] Figure 2 This is a schematic diagram of the training process of the base learner provided in an embodiment of the present invention;
[0056] Figure 3 This is a schematic diagram of a second process for non-destructive testing of fruit sugar content provided in an embodiment of the present invention. Detailed Implementation
[0057] The present invention will be described in detail below through embodiments.
[0058] Fruit sugar content is a core indicator for evaluating its ripeness, flavor, and commercial value. Accurate detection of fruit sugar content is crucial in modern agricultural production, fruit grading, warehousing, logistics, and retail. Traditional methods for fruit sugar content detection, such as handheld saccharimeters, are destructive, requiring juice extraction, which is cumbersome, inefficient, and damages sample integrity, making it impossible to test large batches of fruit individually. Therefore, developing rapid, non-destructive, and portable detection technologies has become a research hotspot in this field. Among these, visible / near-infrared spectroscopy is widely recognized as one of the most promising non-destructive technologies for detecting the intrinsic quality of fruits due to its ability to rapidly acquire spectral information related to the vibrational absorption of molecules within substances (such as CH and OH groups in sugars and water). This technology achieves rapid prediction of unknown samples by establishing a mathematical model between spectral data and the internal sugar content of the fruit.
[0059] Existing technical solutions typically follow a unified process of spectral acquisition, unified preprocessing, and global modeling. The core problem lies in this one-size-fits-all approach, which fails to effectively distinguish and utilize information from different regions and types within the spectrum. Specifically, the visible light region is strongly influenced by peel color (pigmentation), while the near-infrared region truly reflects internal sugar content. The variable signals of peel color severely interfere with the weak sugar signals in the near-infrared region. Existing technologies treat these two aspects interchangeably, making models built for one variety difficult to apply to fruits of different colors, varieties, or origins. Secondly, existing methods simply treat peel color information as noise and attempt to eliminate it, wasting the maturity information contained in the color that is highly correlated with sugar accumulation. This results in a weak correlation between model input features and sugar content, limiting the upper limit of prediction accuracy. Finally, changes in ambient temperature cause spectrometer performance drift and alter water absorption characteristics, introducing measurement errors. Most existing solutions lack an effective temperature compensation mechanism, leading to model instability outside the laboratory.
[0060] It is clear that there is an urgent need for an accurate method to detect the sugar content of fruits.
[0061] Firstly, see [the following] Figure 1 This application provides a non-destructive testing method for fruit sugar content, the method comprising:
[0062] S101, acquire the sample reflectance spectral data, and divide the sample reflectance spectral data into visible light spectrum and near-infrared spectrum according to wavelength.
[0063] The non-destructive testing method for fruit sugar content provided in this application embodiment can be implemented using a handheld testing device. This device includes a light source, a miniature spectrometer, a processor unit, and a display interface. It acquires the sample reflectance spectral data by placing a standard diffuse reflectance white plate and the fruit sample to be tested below the device's probe. Specifically, it can be:
[0064] The reflected light intensity spectrum of a standard diffuse whiteboard was continuously collected and arithmetically averaged at least 15 times to obtain the reference light intensity spectrum I1;
[0065] The reflected light intensity spectra of the samples were continuously collected and arithmetically averaged at least 15 times to obtain the sample light intensity spectrum I2;
[0066] The sample light intensity spectrum I2 is calibrated using the reference light intensity spectrum I1 to obtain the sample reflectance spectrum data S = I2 / I1.
[0067] The calibrated sample light intensity spectrum is divided into visible light spectrum (400-700nm) and near-infrared spectrum (700-1000nm), and a customized preprocessing procedure is performed.
[0068] S102, the visible light spectrum is preprocessed in the first stage to obtain visible light spectral data that highlights the pigment absorption characteristics; and the near-infrared spectrum is preprocessed in the second stage to obtain near-infrared spectral data for sugar content modeling.
[0069] The first preprocessing includes Savitzky-Golay smoothing and continuum removal, and the second preprocessing includes Savitzky-Golay differentiation, as well as standard normal variable transformation or multivariate scattering correction.
[0070] The process of continuous system removal includes:
[0071] In the visible light spectrum after Savitzky-Golay smoothing, all local reflectance maxima were identified; these local reflectance maxima, or peaks, together constitute the upper envelope boundary of the spectral curve.
[0072] The local reflectance maxima are connected by piecewise linear interpolation or spline interpolation to form a continuum curve; the continuum curve represents the background reflectance baseline of the spectrum in the absence of absorption characteristics.
[0073] The original reflectance value of each wavelength point λ in the visible light region is removed by the reflectance value of the corresponding wavelength point on the continuum curve to obtain the visible light spectral data after continuum removal processing.
[0074] Continuum removal is a normalization method designed to enhance absorption peaks. Through this process, the bottoms of all absorption valleys are normalized to similar levels, greatly highlighting the depth, width, and positional information of absorption features caused by different pigments, and providing optimized spectral data for subsequent accurate color feature extraction.
[0075] Savitzky-Golay differentiation includes Savitzky-Golay second-order differentiation or Savitzky-Golay first-order differentiation.
[0076] S103, Based on the visible light spectral data, a color feature vector is constructed through spectral demixing and spectral index calculation.
[0077] The spectral unmixing process includes establishing and optimizing a reference endmember spectrum to obtain an optimized endmember spectrum, and using a constrained linear regression algorithm to solve for the contribution coefficients of each pigment.
[0078] First, let's discuss the first part: optimizing the endmember spectrum, which includes obtaining the reference endmember matrix and data-driven optimization of the reference endmember matrix. Specifically, this involves the following process:
[0079] First, obtain the pure spectral curves of the main pigments that make up the color of the fruit peel by consulting authoritative scientific literature or under laboratory conditions. These pigments include, but are not limited to, chlorophyll, carotenoids, anthocyanins (for apples), and flavonoids (for pears). This can be done by measuring high-purity chemical standard solutions or by citing publicly published, widely accepted standard spectral data.
[0080] Apple Library: Contains spectral characteristics of chlorophyll (Chl), carotenoids (Car), and anthocyanins (Anth).
[0081] Pear extract: Spectral characteristics containing chlorophyll (Chl), carotenoids (Car), and flavonoids (Flav).
[0082] Chlorophyll: Its spectral curve has strong absorption valleys in the blue and red light regions, resulting in low reflectance.
[0083] Carotenoids: Their spectral curves have a broad absorption band in the blue-green light region, so their reflectivity is low in this region.
[0084] Anthocyanins: Their spectral curves have absorption valleys in the green light region, resulting in low reflectivity.
[0085] Flavonoids: Their absorption characteristics are usually in the ultraviolet and blue light regions, and their spectral morphology is affected in the visible light region (especially 400-500 nm).
[0086] Based on the above, an initial reference endmember matrix was established:
[0087] ;
[0088] Where M is the total number of wavelength channels in the spectrum, and N is the total number of endmembers. Each column represents a reference spectrum for a pigment; the spectrum is a function whose value varies with wavelength.
[0089] Since the pure spectra in real data should be located at the vertices of the multidimensional point cloud formed by all spectral data, the process of optimizing the reference endmember spectrum includes:
[0090] The reflectance spectral data of K samples are considered as vectors in M-dimensional space; using the reference endmember spectrum as the initial endmember set, an iterative search is conducted to find N spectral samples that maximize the volume of the simplex body composed of N endmember spectral vectors; wherein, the volume V of the simplex body is calculated according to the following formula:
[0091] ;
[0092] Where A is a matrix composed of the endmember spectral vectors;
[0093] When the iterative search fails to increase the volume of the simplex, the spectra of the N spectral samples that currently constitute the vertices of the simplex are determined as the optimized endmember spectra.
[0094] The reflectance spectral data for each sample is represented as S. j , j=1,2…K, are regarded as vectors in M-dimensional space. In order to simplify the calculation, principal component analysis (PCA) is usually performed on the spectral data to reduce the original spectral space from M-dimensional to N-1-dimensional before volume calculation.
[0095] The algorithm iteratively searches for a spectral vector {S} consisting of N endmembers. 1, S 2… S N The algorithm finds a set of N spectra that maximizes the volume of the simplex. Specifically, it iterates through all K spectral samples, replacing one vertex of the current simplex one by one. If the replacement increases the volume of the simplex, the replacement is accepted, and the iteration continues. The algorithm stops when no replacement increases the volume of the simplex; the resulting N spectra are the optimized endmember spectra.
[0096] In the formula for calculating the volume V of a simplex volume, matrix A is an N x N matrix, represented as:
[0097] ;
[0098] The S here 1, S 2… S N It is an N-1 dimensional vector.
[0099] The above process identified N samples that best represent the extreme spectral characteristics of the dataset. Since we use reference endmember spectra as guides, these N optimized spectra are mathematically the vertices of the data cloud and physically highly correlated with our target pigments.
[0100] The optimized endmember matrix is as follows:
[0101] ;
[0102] Each column here is selected and optimized from real spectral data. It retains the biochemical significance of the original pigment spectra while correcting the spectral morphology under real fruit peel conditions. This greatly improves the accuracy of subsequent unmixing.
[0103] The constrained linear regression algorithm is used to solve for the contribution coefficients of each pigment. The optimization objective is to minimize the residual between the reconstructed spectrum and the true spectrum, while ensuring that the contribution coefficients of each pigment are non-negative. This is achieved by solving the following mathematical expression:
[0104] ;
[0105] in, The visible light spectral data after the first preprocessing, For the optimized end-member spectrum of the i-th pigment, a i Let be the contribution coefficient of the i-th pigment to be solved, and k be the total number of pigments. The constrained linear regression algorithm can be non-negative least squares, or it can be replaced by other algorithms that can solve for the mixing coefficients, such as sparse non-negative matrix factorization or fully constrained least squares.
[0106] The second part concerns calculating traditional spectral indices for fruits. For apples, the difference in peel color is mainly controlled by anthocyanin accumulation and chlorophyll degradation. Therefore, the 550–700 nm range is crucial, especially for red apples, where the anthocyanin index must be selected.
[0107] ;
[0108] ;
[0109] ;
[0110] ;
[0111] ;
[0112] REP (Red Edge Position, peak reflectance wavelength in the range of 680–750 nm).
[0113] For pears, since their peel lacks anthocyanin signals, a red enhancement index is not needed; the focus is on extracting the characteristics of the change from green to yellow:
[0114] ;
[0115] ;
[0116] CIRE, NDIRG, NDVI* are compatible with Apple products.
[0117] General index:
[0118] ;
[0119] ;
[0120] Where R represents reflectance, mean 650-700 This represents the average reflectance at wavelengths from 650 to 700 nm.
[0121] The pigment contribution coefficient 'a' quantified in the above steps i The calculated spectral indices are combined to construct a comprehensive color feature vector C.
[0122] C apple =[ARI,RI,NDIRG,CIRE,REP, NDVI*,WBI, mean 650-700 , a i ];
[0123] C pear =[GI,YR, NDIRG,CIRE, NDVI*,WBI, mean 650-700 , a i ].
[0124] S104, input the near-infrared spectral data into the first base learner, and output the first sugar content prediction mean and the first variance; input the color feature vector and temperature data into the second base learner, and output the second sugar content prediction mean and the second variance.
[0125] The temperature data is the reference temperature used during the calibration of the second base learner.
[0126] In one example, the base learner is trained using the following process:
[0127] Obtain a training sample set including feature vectors and true sugar content values, wherein the feature vectors include color feature vectors and near-infrared spectral data;
[0128] The number of training rounds T is determined by cross-validation, and the base learner is trained T times. Each training round includes:
[0129] For each sample, calculate the current mean and the negative gradient of the mean predicted under the current variance;
[0130] Train a new mean-based decision tree to fit the negative gradient of the mean;
[0131] The prediction result of the mean decision tree is multiplied by the learning rate and added to the mean model;
[0132] For each sample, calculate the current mean and the negative gradient of variance under the current variance prediction;
[0133] Train a new variance decision tree to fit the negative variance gradient;
[0134] The prediction result of the variance decision tree is multiplied by the learning rate and added to the variance model.
[0135] Each base learner is trained using a Bayesian gradient boosting decision tree algorithm. Decision trees continuously split the data through a series of questions (or split points) until a prediction is given for each sample. The advantage of decision trees is their intuitiveness and ease of interpretation, but their disadvantages include limited predictive power and a tendency to overfit. Gradient boosting decision trees (GBDT) correct the errors of the previous model by continuously training a series of weak learners. It accumulates the predictions of many simple decision trees to form a more powerful model. The workflow of GBDT is as follows:
[0136] Start with a simple prediction, such as the average sugar content of all samples.
[0137] Calculate the residual (gradient): Calculate the error between the current predicted value and the true value. This error is the negative gradient, which represents the direction and magnitude in which the model needs to be improved.
[0138] Training a new tree: Train a new decision tree, but this time its target is no longer the original sugar content value, but the previously calculated error. The task of this tree is to learn how to correct the errors of the previous model.
[0139] Cumulative model: The prediction results of the new tree are added to the current model and multiplied by a learning rate.
[0140] Repeat: Repeat this process hundreds of times, each time training a new tree to make up for the deficiencies of all the previous trees.
[0141] By progressively correcting errors, GBDT combines many simple decision trees into a highly predictive model. However, it still only outputs a single predicted value and cannot quantify the confidence level of the prediction.
[0142] Traditional GBDT models predict only a single value, while Bayesian GBDT models predict both a mean and a variance. They are concerned not only with the accuracy of the prediction but also with the level of confidence in the prediction. This process is achieved by minimizing the negative log-likelihood loss.
[0143] Assume the actual sugar content Y follows a normal distribution with parameters of our predicted mean and variance. The loss function L we want to minimize is as follows, consisting of two parts:
[0144] ;
[0145] Part One This encourages the model to be more confident when it is certain (predicting smaller variance). If the model consistently predicts a large variance, it will be penalized.
[0146] Part Two This is a weighted mean squared error. If the model confidently predicts a small variance, but there is an error between the predicted mean and the true value Y, it will be heavily penalized. Conversely, if the model predicts a large variance, even with errors, the penalty will not be too great.
[0147] The training process is described below using an example. Suppose we have a training dataset D={(X1,Y1), (X2,Y2)…(X…)} N ,Y N )}, where X is the feature vector and Y is the actual sugar content value.
[0148] 1. Initialization:
[0149] Mean prediction: Initialize with the average sugar content of all samples, μ0=mean(Y).
[0150] Variance prediction: Initialize with a constant (e.g., the logarithm of the variance of all sample sugar content values).
[0151] ;
[0152] 2. Iterative training (e.g., T iterations in total):
[0153] For t=1 to T:
[0154] a. Train the mean-based model (to improve predictions):
[0155] Calculate the negative gradient (residual): For each sample i, calculate the negative gradient under the current mean and variance prediction. This gradient represents the distance between the current predicted mean and the true value Y. i How far is it? And it's weighted by variance. When the variance is very small, even a small error will produce a large gradient, forcing the model to be more accurate.
[0156] ;
[0157] Train a new decision tree to fit this negative gradient. Add the predictions from the new tree to the mean model and multiply by a learning rate.
[0158] ;
[0159] b. Training the variance model (improving confidence):
[0160] Calculate the negative gradient: For each sample i, calculate the negative gradient with respect to the variance. This gradient indicates that if the prediction error is large, the model should increase its variance, indicating that it is less certain; if the error is small, the model should decrease its variance, becoming more confident.
[0161] ;
[0162] Train another new decision tree to fit this negative gradient. Add the predictions from the new tree to the variance model. To ensure that the variance is always positive, we typically manipulate its logarithm.
[0163] ;
[0164] Furthermore, in combination Figure 2 The above process is described as follows: At the beginning of the t-th iteration, training data X and Y are input, and the mean model and variance model are trained using the current mean model and the current variance model, respectively. For the training of the mean model, the negative gradient of the mean under the current mean and variance is calculated, a new mean decision tree is trained to fit the negative gradient of the mean, and the mean model is updated. For the training of the variance model, the negative gradient of the variance under the current mean and variance is calculated, a new variance decision tree is trained to fit the negative gradient of the variance, and the variance model is updated. The updated mean model and variance model are used to make model predictions, and the predicted mean and variance are output. At this point, the t-th iteration ends, and the process returns to the step of inputting training data X and Y to execute the (t+1)-th iteration.
[0165] The first and second base learners will each undergo the above training process independently to obtain their respective final mean and variance models.
[0166] S105, input the first sugar content prediction mean, the first variance, the second sugar content prediction mean, and the second variance into the meta-model to obtain the final sugar content prediction value.
[0167] Cross-validation is used to obtain the predicted mean and variance for each sample from each base learner.
[0168] Create a new dataset: Its characteristic is that these predictions have mean and variance, while the target value remains the original sugar content value Y. iTraining a second-level model (meta-learner) can be a simple linear regression model or another GBDT model on a new dataset Z. i Modeling is performed.
[0169] The meta-model learns how to predict the final sugar content based on input features, including uncertainty. When the variance of a base learner is high, the meta-model learns to reduce the weight of its corresponding mean, thus relying on more reliable channels. This approach elevates traditional stacked generalization methods by introducing uncertainty as a key element, achieving smarter and more robust multi-source data fusion.
[0170] S106, Based on the difference between the real-time measured temperature and the reference temperature, perform temperature physical compensation on the final sugar content prediction value, and output the compensated sugar content value.
[0171] To eliminate the influence of temperature in the actual measurement environment, the model's predictions were finalized. The final predicted sugar content was calculated using the following formula:
[0172] ;
[0173] Where T is the temperature measured in real time, T ref This is the reference temperature used during the calibration of the second base learner, and α is the temperature compensation coefficient obtained through experimental calibration. The final sugar content prediction is then compensated for by applying the temperature physical compensation using the above formula, resulting in the compensated sugar content value.
[0174] The non-destructive detection method for fruit sugar content provided in this application includes: acquiring sample reflectance spectral data; dividing the sample reflectance spectral data into visible light spectrum and near-infrared spectrum according to wavelength; performing a first preprocessing on the visible light spectrum to obtain visible light spectral data highlighting pigment absorption characteristics; and performing a second preprocessing on the near-infrared spectrum to obtain near-infrared spectral data for sugar content modeling. The first preprocessing includes Savitzky-Golay smoothing and continuum removal, and the second preprocessing includes Savitzky-Golay differentiation and standard normal variable transformation or multivariate scattering correction. Based on the visible light spectral data, a color feature vector is constructed through spectral unmixing and spectral index calculation. The spectral unmixing process includes establishing and optimizing a reference endmember spectrum to obtain an optimized endmember spectrum, and using a constrained linear regression algorithm to solve for the contribution coefficients of each pigment. The near-infrared spectral data is input into a first base learner, which outputs a first sugar content prediction mean and a first variance. The color feature vector and temperature data are input into a second base learner, which outputs a second sugar content prediction mean and a second variance. The temperature data is a reference temperature used during the calibration of the second base learner. The first sugar content prediction mean, the first variance, the second sugar content prediction mean, and the second variance are input into a meta-model to obtain a final sugar content prediction value. Based on the difference between the real-time measured temperature and the reference temperature, temperature physical compensation is performed on the final sugar content prediction value, and the compensated sugar content value is output. This achieves accurate detection of fruit sugar content.
[0175] See Figure 3 This is a schematic diagram of a process for detecting fruit sugar content according to an embodiment of this application. The first step is spectral data acquisition and standardization, including reference spectrum acquisition, sample spectrum acquisition, and reflectance calculation.
[0176] The second major step is the segmented and flow-based dual-channel processing architecture, which includes reflectance spectral partitioning, divided into visible light color feature channels and near-infrared absorption feature channels. The visible light color feature channels are processed by Savitzky-Golay smoothing and continuum removal to obtain visible light spectral data; the near-infrared absorption feature channels are processed by Savitzky-Golay differentiation and standard normal variable transformation to obtain near-infrared spectral data.
[0177] The third step is to process the visible light spectral data, including spectral demixing and spectral index calculation. For spectral demixing, reference endmember spectra are established one by one, and the reference endmember spectra are optimized (to obtain optimized endmember spectra). The contribution coefficients of each pigment are solved using the mixing coefficients. For traditional spectral index calculation, the spectral index of apple / pear is calculated, and a color feature vector is constructed based on the contribution coefficients of each pigment and the spectral index.
[0178] The fourth step is to perform multi-source feature fusion prediction. Based on the color feature vector and near-infrared spectral data obtained in the third step, a fused feature vector is constructed. The trained base learner can receive near-infrared spectral data and color feature vector + temperature data respectively, and output two sets of sugar content prediction mean and variance. The meta-model will output the final predicted sugar content value based on these two sets of sugar content prediction mean and variance.
[0179] The fifth step involves temperature physical compensation. By using the difference between the real-time measured temperature and the reference temperature, the final sugar content prediction value is compensated for temperature physical compensation, and the compensated sugar content value is output.
[0180] This application's solution, through a partitioned-by-stream preprocessing architecture and color feature quantification, transforms the main interference source—fruit peel color—that causes poor model versatility into an effective feature for accurate modeling. This allows the final fusion model to effectively overcome differences in variety, origin, and maturity, achieving universal detection for both apples and pears. Furthermore, through spectral unmixing and spectral indices, color information related to fruit maturity and sugar accumulation is deeply mined. An advanced multi-level ensemble learning framework is used to optimally fuse color features with near-infrared absorption features, resulting in higher information utilization and significantly improved prediction accuracy compared to existing technologies. Unlike traditional black-box models, the pigment contribution coefficient obtained through spectral unmixing in this invention can intuitively reflect the biochemical state of the fruit, providing a partial physical explanation for the model's prediction results and contributing to understanding the fruit ripening process.
[0181] Secondly, embodiments of this application provide a non-destructive testing device for fruit sugar content, the device comprising:
[0182] The acquisition module is used to acquire sample reflectance spectral data and divide the sample reflectance spectral data into visible light spectrum and near-infrared spectrum according to wavelength;
[0183] The preprocessing module is used to perform a first preprocessing on the visible light spectrum to obtain visible light spectral data that highlights the pigment absorption characteristics; and to perform a second preprocessing on the near-infrared spectrum to obtain near-infrared spectral data for sugar content modeling. The first preprocessing includes Savitzky-Golay smoothing and continuum removal processing, and the second preprocessing includes Savitzky-Golay differentiation, as well as standard normal variable transformation or multivariate scattering correction.
[0184] The visible light processing module is used to construct a color feature vector based on the visible light spectral data through spectral unmixing and spectral index calculation; wherein, the spectral unmixing includes establishing and optimizing the reference endmember spectrum to obtain the optimized endmember spectrum, and using a constrained linear regression algorithm to solve for the contribution coefficient of each pigment.
[0185] The base learner prediction module is used to input the near-infrared spectral data into a first base learner and output a first sugar content prediction mean and a first variance; input the color feature vector and temperature data into a second base learner and output a second sugar content prediction mean and a second variance; the temperature data is a reference temperature used when calibrating the second base learner;
[0186] The meta-model prediction module is used to input the first sugar content prediction mean, the first variance, the second sugar content prediction mean, and the second variance into the meta-model to obtain the final sugar content prediction value.
[0187] The temperature compensation module is used to perform temperature physical compensation on the final sugar content prediction value based on the difference between the real-time measured temperature and the reference temperature, and output the compensated sugar content value.
[0188] In one possible implementation, the acquisition module is specifically used for:
[0189] The reflected light intensity spectrum of a standard diffuse whiteboard was continuously collected and arithmetically averaged at least 15 times to obtain the reference light intensity spectrum I1;
[0190] The reflected light intensity spectra of the samples were continuously collected and arithmetically averaged at least 15 times to obtain the sample light intensity spectrum I2;
[0191] The sample light intensity spectrum I2 is calibrated using the reference light intensity spectrum I1 to obtain the sample reflectance spectrum data S = I2 / I1.
[0192] In one possible implementation, the continuum removal process includes:
[0193] All local reflectance maxima were identified in the visible light spectrum after Savitzky-Golay smoothing.
[0194] The local reflectivity maxima are connected by piecewise linear interpolation or spline interpolation to form a continuum curve.
[0195] The original reflectance value of each wavelength point λ in the visible light region is removed by the reflectance value of the corresponding wavelength point on the continuum curve to obtain the visible light spectral data after continuum removal processing.
[0196] Thirdly, the present invention provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements any of the above-mentioned methods for non-destructive detection of fruit sugar content.
[0197] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0198] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0199] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0200] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make changes to the above embodiments within the scope of the present invention without departing from the principles and spirit of the present invention.
Claims
1. A non-destructive method for detecting sugar content in fruits, characterized in that, The method includes: Acquire sample reflectance spectral data, and divide the sample reflectance spectral data into visible light region spectrum and near-infrared region spectrum according to wavelength; The visible light spectrum is subjected to a first preprocessing to obtain visible light spectral data that highlights the pigment absorption characteristics; and the near-infrared spectrum is subjected to a second preprocessing to obtain near-infrared spectral data for sugar content modeling. The first preprocessing includes Savitzky-Golay smoothing and continuum removal processing, and the second preprocessing includes Savitzky-Golay differentiation, as well as standard normal variable transformation or multivariate scattering correction. Based on the visible light spectral data, a color feature vector is constructed through spectral unmixing and spectral index calculation. The spectral unmixing includes establishing and optimizing a reference endmember spectrum to obtain an optimized endmember spectrum, and using a constrained linear regression algorithm to solve for the contribution coefficient 'a' of each pigment. i ; For apples, the spectral indices are: ARI, RI, NDIRG, CIRE, REP, NDVI*, WBI, mean. 650-700 ; Apple's color feature vector C apple =[ARI,RI,NDIRG,CIRE,REP, NDVI*,WBI, mean 650-700 , a i ]; For pears, the spectral indices are: GI, YR, NDIRG, CIRE, NDVI*, WBI, mean. 650-700 ; The color feature vector C of the pear pear =[GI,YR, NDIRG,CIRE, NDVI*,WBI, mean 650-700 , a i ]; ; ; ; ; ; The red edge position of REP is the peak wavelength of reflectivity in the range of 680–750 nm; ; ; ; ; Where R represents reflectance, mean 650-700 This represents the average reflectance at wavelengths from 650 to 700 nm. The near-infrared spectral data is input into a first base learner, which outputs a first sugar content prediction mean and a first variance; the color feature vector and temperature data are input into a second base learner, which outputs a second sugar content prediction mean and a second variance; the temperature data is a reference temperature used when calibrating the second base learner; Input the first sugar content prediction mean, the first variance, the second sugar content prediction mean, and the second variance into the meta-model to obtain the final sugar content prediction value; Based on the difference between the real-time measured temperature and the reference temperature, the final predicted sugar content is physically compensated for temperature, and the compensated sugar content value is output.
2. The method according to claim 1, characterized in that, The acquisition of sample reflectance spectral data includes: The reflected light intensity spectrum of a standard diffuse whiteboard was continuously collected and arithmetically averaged at least 15 times to obtain the reference light intensity spectrum I1; The reflected light intensity spectra of the samples were continuously collected and arithmetically averaged at least 15 times to obtain the sample light intensity spectrum I2; The sample light intensity spectrum I2 is calibrated using the reference light intensity spectrum I1 to obtain the sample reflectance spectrum data S = I2 / I1.
3. The method according to claim 1, characterized in that, The process of the continuum removal treatment includes: All local reflectance maxima were identified in the visible light spectrum after Savitzky-Golay smoothing. The local reflectivity maxima are connected by piecewise linear interpolation or spline interpolation to form a continuum curve. The original reflectance value of each wavelength point λ in the visible light region is removed by the reflectance value of the corresponding wavelength point on the continuum curve to obtain the visible light spectral data after continuum removal processing.
4. The method according to claim 1, characterized in that, The process of optimizing the reference endmember spectrum includes: The reflectance spectral data of K samples are considered as vectors in M-dimensional space; using the reference endmember spectrum as the initial endmember set, an iterative search is conducted to find N spectral samples that maximize the volume of the simplex body composed of N endmember spectral vectors; wherein, the volume V of the simplex body is calculated according to the following formula: ; Where A is a matrix composed of the endmember spectral vectors; When the iterative search fails to increase the volume of the simplex, the spectra of the N spectral samples that currently constitute the vertices of the simplex are determined as the optimized endmember spectra.
5. The method according to claim 1, characterized in that, The base learner is trained using the following process: Obtain a training sample set including feature vectors and true sugar content values, wherein the feature vectors include color feature vectors and near-infrared spectral data; The number of training rounds T is determined by cross-validation, and the base learner is trained T times. Each training round includes: For each sample, calculate the current mean and the negative gradient of the mean predicted under the current variance; Train a new mean-based decision tree to fit the negative gradient of the mean; The prediction result of the mean decision tree is multiplied by the learning rate and added to the mean model; For each sample, calculate the current mean and the negative gradient of variance under the current variance prediction; Train a new variance decision tree to fit the negative variance gradient; The prediction result of the variance decision tree is multiplied by the learning rate and added to the variance model.
6. The method according to claim 1, characterized in that, The constrained linear regression algorithm is used to solve for the contribution coefficients of each pigment. The optimization objective is to minimize the residual between the reconstructed spectrum and the true spectrum, while ensuring that the contribution coefficients of each pigment are non-negative. This is achieved by solving the following mathematical expression: ; in, The visible light spectral data after the first preprocessing, For the optimized end-member spectrum of the i-th pigment, a i Let be the contribution coefficient of the i-th pigment to be solved, and k be the total number of pigments.
7. A non-destructive testing device for fruit sugar content, characterized in that, The device includes: The acquisition module is used to acquire sample reflectance spectral data and divide the sample reflectance spectral data into visible light spectrum and near-infrared spectrum according to wavelength; The preprocessing module is used to perform a first preprocessing on the visible light spectrum to obtain visible light spectral data that highlights the pigment absorption characteristics; and to perform a second preprocessing on the near-infrared spectrum to obtain near-infrared spectral data for sugar content modeling. The first preprocessing includes Savitzky-Golay smoothing and continuum removal processing, and the second preprocessing includes Savitzky-Golay differentiation, as well as standard normal variable transformation or multivariate scattering correction. The visible light processing module is used to construct a color feature vector based on the visible light spectral data through spectral unmixing and spectral index calculation; wherein, the spectral unmixing includes establishing and optimizing a reference endmember spectrum to obtain an optimized endmember spectrum, and using a constrained linear regression algorithm to solve for the contribution coefficient 'a' of each pigment. i ; For apples, the spectral indices are: ARI, RI, NDIRG, CIRE, REP, NDVI*, WBI, mean. 650-700 ; Apple's color feature vector C apple =[ARI,RI,NDIRG,CIRE,REP, NDVI*,WBI, mean 650-700 , a i ]; For pears, the spectral indices are: GI, YR, NDIRG, CIRE, NDVI*, WBI, mean. 650-700 ; The color feature vector C of the pear pear =[GI,YR, NDIRG,CIRE, NDVI*,WBI, mean 650-700 , a i ]; ; ; ; ; ; The red edge position of REP is the peak wavelength of reflectivity in the range of 680–750 nm; ; ; ; ; Where R represents reflectance, mean 650-700 This represents the average reflectance at wavelengths from 650 to 700 nm. The base learner prediction module is used to input the near-infrared spectral data into a first base learner and output a first sugar content prediction mean and a first variance; input the color feature vector and temperature data into a second base learner and output a second sugar content prediction mean and a second variance; the temperature data is a reference temperature used when calibrating the second base learner; The meta-model prediction module is used to input the first sugar content prediction mean, the first variance, the second sugar content prediction mean, and the second variance into the meta-model to obtain the final sugar content prediction value. The temperature compensation module is used to perform temperature physical compensation on the final sugar content prediction value based on the difference between the real-time measured temperature and the reference temperature, and output the compensated sugar content value.
8. The apparatus according to claim 7, characterized in that, The acquisition module is specifically used for: The reflected light intensity spectrum of a standard diffuse whiteboard was continuously collected and arithmetically averaged at least 15 times to obtain the reference light intensity spectrum I1; The reflected light intensity spectra of the samples were continuously collected and arithmetically averaged at least 15 times to obtain the sample light intensity spectrum I2; The sample light intensity spectrum I2 is calibrated using the reference light intensity spectrum I1 to obtain the sample reflectance spectrum data S = I2 / I1.
9. The apparatus according to claim 7, characterized in that, The process of the continuum removal treatment includes: All local reflectance maxima were identified in the visible light spectrum after Savitzky-Golay smoothing. The local reflectivity maxima are connected by piecewise linear interpolation or spline interpolation to form a continuum curve. The original reflectance value of each wavelength point λ in the visible light region is removed by the reflectance value of the corresponding wavelength point on the continuum curve to obtain the visible light spectral data after continuum removal processing.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method of any one of claims 1-6.