Portable hyperspectral animal-derived food quality nondestructive testing method based on mobile phone
By combining a portable hyperspectral camera with a smartphone and utilizing the XGBoost regression model for food quality testing, the problem of inconvenient equipment, insufficient accuracy, and cumbersome procedures has been solved. This approach enables rapid and accurate evaluation of multiple indicators and is suitable for on-site testing.
Patent Information
- Application Number
- CN202511002709.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-21
- Publication Date
- 2025-10-31
AI Technical Summary
Existing hyperspectral nondestructive testing technology equipment is not portable, lacks precision, has a cumbersome testing process, and poor real-time performance, failing to meet the needs of rapid on-site testing. Furthermore, existing methods have not constructed multiple index models for specific foods such as mutton, affecting the accuracy and reliability of the test results.
Animal-derived food image data are acquired using a portable hyperspectral camera, preprocessed and 3D feature extracted using a smartphone, and predicted using an XGBoost regression model. Combined with an improved sparrow algorithm and a Bayesian optimized hyperparameter model, rapid and non-destructive testing of food quality is achieved.
It enables rapid and accurate detection of food quality, simplifies the operation process, is suitable for on-site applications, and can simultaneously evaluate multiple key indicators, improving detection efficiency and accuracy.
Smart Images

Figure CN120870004A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of quality testing technology for animal-derived foods, and particularly relates to a portable, non-destructive testing method for the quality of animal-derived foods based on a mobile phone using hyperspectral imaging. Background Technology
[0002] Hyperspectral imaging technology, with its unique advantages, has garnered significant attention and widespread application in the field of food testing. This technology captures reflected light signals from hundreds of consecutive wavelengths on the surface of food, generating three-dimensional data containing both spatial and chemical composition. Combined with machine learning / deep learning algorithms, it enables rapid and non-destructive detection. Its core advantage lies in the integration of image and spectrum, allowing analysis of both the appearance characteristics of food, such as color and shape, and the identification of differences in chemical composition through spectral features, providing multidimensional information support for food safety and quality assessment. Currently, the application of hyperspectral imaging technology in food testing mainly covers multiple aspects, including quantitative component analysis, contaminant detection, and freshness and quality assessment. Related research continues to emerge, yielding a series of results and providing strong support for the development of food testing technology.
[0003] However, existing hyperspectral nondestructive testing technologies suffer from numerous problems. On the one hand, the testing methods and equipment are fragmented, requiring sampling and data processing using various devices before data integration and modeling to construct predictive models—a cumbersome and inefficient process. On the other hand, existing testing equipment is not portable enough. While laboratory hyperspectral equipment offers high precision and good results, its application scenarios are limited, failing to meet the needs of rapid on-site testing. Portable hyperspectral equipment, although mobile for sampling, cannot match the precision of laboratory equipment and still faces many limitations in practical applications. Furthermore, current technologies lack real-time performance. Although hyperspectral images and information can be extracted in real time, predicting food-related indicators using hyperspectral results still requires lengthy processing times, failing to meet the requirements for rapid detection. For specific foods such as mutton, existing methods and models are not specifically designed for multiple indicators, failing to meet the needs of precise detection and impacting the accuracy and reliability of test results. These problems severely restrict the further development and application of hyperspectral nondestructive testing technology in the field of food testing.
[0004] To address the aforementioned issues, this invention proposes a portable, non-destructive testing method for the quality of animal-derived foods based on mobile phones using hyperspectral imaging. Summary of the Invention
[0005] To address the aforementioned technical problems, this invention proposes a portable, non-destructive testing method for the quality of animal-derived food based on a mobile phone, thereby resolving the issues present in the prior art.
[0006] To achieve the above objectives, this invention provides a portable, non-destructive method for detecting the quality of animal-derived foods using a mobile phone, comprising:
[0007] Hyperspectral image data of animal-derived food was acquired using a portable hyperspectral camera, and the hyperspectral image data was transmitted to a smartphone via Bluetooth for preprocessing to obtain preprocessed data.
[0008] Three-dimensional features are extracted based on the preprocessed data, and the three-dimensional features are then reduced in dimension to obtain dimensionality-reduced features; wherein, the three-dimensional features include: spectral features, wavelet features, and texture features;
[0009] An XGBoost regression model is constructed, the dimensionality reduction features are input into the XGBoost regression model to obtain the prediction results, and the prediction results are output via a smartphone.
[0010] Optionally, the preprocessing of the hyperspectral image data includes:
[0011] The hyperspectral image data is converted to a TIFF file format to obtain hyperspectral image data.
[0012] The hyperspectral image data in the TIFF file format is standardized and normalized to obtain preprocessed data.
[0013] Optionally, the process of extracting three-dimensional features based on the preprocessed data includes: using an image processing algorithm to extract the region of interest from the preprocessed data, and obtaining three-dimensional features based on the region of interest;
[0014] The process of extracting the region of interest from the preprocessed data using image processing algorithms includes:
[0015] The 90th, 95th, and 120th bands in the hyperspectral image were selected as the R, G, and B channels, respectively, to generate a pseudo-color image;
[0016] The pseudo-color image is processed using an HSV dual-threshold segmentation strategy to obtain the filtered target region;
[0017] Morphological closing operations are performed on the filtered target regions to obtain the denoised regions.
[0018] The ROIs in the four quadrants of the denoised region are located and numbered by spatial topological sorting to obtain the regions of interest.
[0019] Optionally, the process of processing the pseudo-color image using the HSV dual-threshold segmentation strategy to obtain the filtered target region includes:
[0020] After converting the pseudo-color image to the HSV color space, the target region is filtered based on a dual threshold range set according to the hue value to obtain the filtered target region.
[0021] The first threshold range is 0°-15°, the second threshold range is 165°-180°, and the saturation threshold and brightness threshold are set to >50% to exclude interference areas.
[0022] Optionally, the process of performing morphological closing operations on the filtered target region to obtain the denoised region includes: using a 15×15 elliptic kernel closing operation to eliminate discrete noise.
[0023] Optionally, the process of reducing the dimensionality of the three-dimensional features to obtain dimensionality-reduced features includes:
[0024] The three-dimensional features are initially screened using the variance filtering method to obtain the initial screened features;
[0025] The F-test was used to select significant features from the initial screening.
[0026] Principal component analysis was used to reduce the dimensionality of the salient features, resulting in dimensionality-reduced features.
[0027] Optionally, the process of inputting the dimensionality-reduced features into the XGBoost regression model to obtain the prediction results includes:
[0028] The XGBoost regression model is obtained by improving the Sparrow Algorithm and Bayesian optimization of hyperparameters. The dimensionality reduction features are then processed based on the optimized XGBoost regression model to obtain the prediction results.
[0029] Compared with the prior art, the present invention has the following advantages and technical effects:
[0030] This invention, through an innovative system integration scheme, organically combines hyperspectral imaging, intelligent algorithms, and mobile terminals to achieve rapid and non-destructive testing of food quality. The system adopts an integrated design, with all data acquisition and analysis / prediction completed on a mobile device, making operation simple and quick, and significantly improving testing efficiency. The unique automatic analysis algorithm can simultaneously and accurately evaluate multiple key quality indicators, overcoming the limitation of traditional methods that can only detect a single indicator. The portable design removes site restrictions for testing, making it particularly suitable for on-site rapid testing needs. Attached Figure Description
[0031] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0032] Figure 1 This is a flowchart of a mobile phone-based portable hyperspectral non-destructive testing method for the quality of animal-derived food, according to an embodiment of the present invention.
[0033] Figure 2This is a diagram illustrating the ROI selection effect in an embodiment of the present invention.
[0034] Figure 3 This is a schematic diagram of spectral data according to an embodiment of the present invention;
[0035] Figure 4 This is a schematic diagram of the first chemical information visualization according to an embodiment of the present invention;
[0036] Figure 5 This is a schematic diagram of the second chemical information visualization according to an embodiment of the present invention;
[0037] Figure 6 This is a schematic diagram of the third chemical information visualization according to an embodiment of the present invention;
[0038] Figure 7 This is a schematic diagram of the process of combining the method and the apparatus according to an embodiment of the present invention. Detailed Implementation
[0039] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0040] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.
[0041] Example 1
[0042] like Figure 1 As shown, this embodiment provides a portable hyperspectral non-destructive testing method for animal-derived food quality based on a mobile phone, including the following steps: acquiring hyperspectral image data of animal-derived food using a portable hyperspectral camera, and transmitting the hyperspectral image data to a smartphone via Bluetooth for preprocessing to obtain preprocessed data; extracting three-dimensional features based on the preprocessed data, and performing dimensionality reduction on the three-dimensional features to obtain dimensionality-reduced features; wherein, the three-dimensional features include: spectral features, wavelet features, and texture features; constructing an XGBoost regression model, inputting the dimensionality-reduced features into the XGBoost regression model to obtain prediction results, and outputting the prediction results through the smartphone.
[0043] This invention establishes a predictive model for four indicators of mutton. For example... Figure 1As shown, sampling is first performed using a hyperspectral imager. The acquired data, along with relevant conventionally measured indicators, are input into the model. These conventionally measured indicators include four items: volatile basic nitrogen (TVB-N), pH value, total bacterial count, and flesh color (L*, a*, b*). The model preprocesses the image and spectral information from the input hyperspectral files to obtain preprocessed data. Since hyperspectral image SPE files cannot be easily read in Python and machine vision, they are first batch-transformed into TIFF files before being read. Standardization and normalization are used for spectral preprocessing to obtain preprocessed data. (The text repeats itself here.) Figure 3 As shown.
[0044] After preprocessing, the ROI (Region of Interest) is automatically selected using methods such as double threshold segmentation. After selection, three-dimensional features are extracted, including spectral features, wavelet features, and texture features.
[0045] Furthermore, image processing algorithms are used to extract the regions of interest (ROIs) from the preprocessed data, and three-dimensional features are obtained based on the ROIs. The process of extracting the ROIs from the preprocessed data using image processing algorithms includes: selecting bands 90, 95, and 120 in the hyperspectral image as R, G, and B channels respectively to generate pseudo-color images; processing the pseudo-color images using an HSV dual-threshold segmentation strategy to obtain filtered target regions; performing morphological closing operations on the filtered target regions to obtain denoised regions; and locating and numbering the ROIs in the four quadrants of the denoised regions using spatial topological sorting to obtain the regions of interest.
[0046] like Figure 2As shown, the process of automatically selecting ROI (Region of Interest) using methods such as double threshold segmentation includes: batch extraction of ROI from samples using the Python OpenCV library. ROI extraction mainly consists of three steps. First, to increase the color difference between the meat and the background after grayscale image transformation, bands 120, 95, and 90 are selected as the R, G, and B layers of the hyperspectral image, and then the RGB spectral color image is converted to a grayscale image. Then, the OpenCV library is used to read the hyperspectral TIFF file. Based on the actual sampling situation, the top 15% area of the image (black and white calibration band) is first cropped, and then the pseudo-color map is re-rendered after cropping. Based on the pseudo-color image, this invention utilizes an HSV dual-threshold segmentation strategy to process the pseudo-color image to obtain the filtered target regions. Two thresholds define the hue (H) range: covering the two extremes of red on the hue circle (0° = pure red, 180° = magenta); the saturation (S) lower limit: >50 excludes low-saturation areas (such as fat / fascia); and the brightness (V) lower limit: >50 excludes dark areas (such as blood clots / shadows). After dual-threshold filtering, a 15×15 elliptic kernel closure operation is used to eliminate discrete noise and remove atypical areas with a contour area <5000 pixels², resulting in denoised regions. Due to the sampling method, each hyperspectral image has four samples, so precise localization is required. After selecting the four unlocalized ROI regions, spatial topological sorting is used to locate and name the four ROIs based on their quadrant positions in the image center, thus obtaining strictly ordered individual sample ROIs.
[0047] The process of reducing the dimensionality of the three-dimensional features to obtain dimensionality-reduced features includes: using variance filtering to initially screen the three-dimensional features to obtain initial screening features; using F-test to select features from the initial screening to obtain significant features; and using principal component analysis to reduce the dimensionality of the significant features to obtain dimensionality-reduced features.
[0048] Furthermore, after extracting the three-dimensional features, variance thresholding and F-tests are used to select indicators with significant differences. Data fusion modeling is then performed using these dimensionality-reduced indicators. The extracted features still have a large dimensionality; for example, spectral features alone have 300 features per sample based on spectral values alone, and there are many more other features. Therefore, feature selection and filtering are necessary. Common methods used include variance filtering and F-tests. Variance filtering removes most of the identical features, retaining only those whose variance meets our set threshold, thus significantly reducing the feature dimensionality. After variance filtering, correlation filtering is performed, such as using F-tests. F-tests are typically used for continuous variables to look for potential linear relationships between data, thereby selecting dimensionality-reduced features.
[0049] The modeling process leverages the advantages of machine learning by embedding an improved sparrow algorithm and Bayesian optimization of hyperparameters. The main body of the model uses XGBoost regression to predict four indicators, ultimately obtaining predicted values. This establishes an accurate prediction model for the four indicators. In the preceding steps, dimensionality reduction features were obtained. The feature values of these dimensionality reduction features were mapped to the actual measured indicator values. The model learns the latent relationship between the feature values and the true predicted values, ultimately using this learned relationship to predict the true values. Throughout the prediction process, XGBoost regression, the prediction model within the mathematical model, is used. Bayesian optimization and the improved sparrow algorithm are employed to optimize the hyperparameters of the decision tree in the regression model, achieving more accurate predictions. The model has been validated and performs well; therefore, the prediction model has been embedded into the completed device.
[0050] The device is implemented using a portable hyperspectral camera with built-in Bluetooth version 5.4 to achieve high-speed transmission from the camera to a smart device. A mobile app is developed that incorporates a pre-built model, enabling data reading and model prediction within the device.
[0051] like Figure 7 As shown, the front-end and back-end are finally integrated. After collecting information using a portable device, it is directly transmitted to a mobile phone via Bluetooth. The smartphone app calls the transmitted data and uses the embedded model to predict and output results.
[0052] like Figures 4-6 As shown, the method of this invention can directly and accurately predict the values of four indicators (flesh color, pH, volatile basic nitrogen, and total bacterial count). Currently, there are many methods for predicting freshness, but freshness can only be categorized into a few simple types, such as fresh, slightly stale, and spoiled, which cannot accurately represent the true state of each indicator. Furthermore, existing multi-indicator prediction methods often require integration with other devices, such as high-throughput sequencing, electronic noses, and electronic tongues, significantly increasing costs and equipment requirements.
[0053] The device of this invention integrates the front and back ends, simplifying the operation process. For the corresponding food products, the final index values can be obtained through simple operations (capturing hyperspectral images), reducing the need for professional personnel. The final results can be obtained through a single software process, reducing the learning cost of different processing software.
[0054] As a specific implementation method in this embodiment, multidimensional quality prediction of mutton is performed. The detection targets are mutton color (L*a*b* value), pH value, TVB-N content, and total bacterial count (CFU / g). The equipment is configured with a spectral range of 400-1000nm.
[0055] The sample processing procedure included: taking the longissimus dorsi muscle from 8 fresh sheep, removing fat and connective tissue, and then uniformly dividing it into 6cm×6cm×1cm slices. These slices were divided into 8 groups, each sealed in a plastic bag, and used for the determination of 4 indicators and the collection of hyperspectral data. Each group contained 12 samples, which were numbered and stored in a refrigerator at 4°C for 14 days without compression, with measurements taken every other day. Therefore, the total number of chilled fresh mutton samples prepared was 12 (number of samples per group) × 8 (number of groups) = 96. Each group of samples was first placed indoors for 25 minutes to evaporate surface moisture and stabilize the surface color of the meat, and then the values of TVB-N, pH value, total bacterial count, and meat color were measured.
[0056] Data acquisition: Scan the surface (15 seconds per sample).
[0057] Modeling and prediction: Improved sparrow algorithm and Bayesian optimization of hyperparameters. The main body of the model uses XGBoot regression to predict four indicators, and finally obtain the predicted values.
[0058] Results analysis: The R² for volatile basic nitrogen value was greater than 0.88, the R² for meat color L*a*b* value was greater than 0.9, and the R² for pH value and total bacterial count was greater than 0.95. This system shows good performance in mutton testing and is suitable for real-time detection both on-site and in slaughterhouses.
[0059] As a specific implementation method in this embodiment, multidimensional quality prediction of chicken is performed.
[0060] Targets for testing: meat color (L*a*b* value), pH value, TVB-N content, and total bacterial count (CFU / g) of chicken.
[0061] Equipment configuration: spectral range: 400-1000nm.
[0062] Sample Processing: Purchase 100 chickens and collect chicken breast meat. Using a sterile knife, trim the surface fat tissue of the chicken breast meat and cut 30mm × 30mm × 20mm cubes (as regular as possible) from the center of the meat to obtain at least 320 fresh chicken samples (reserve samples were stored under the same conditions). Place each sample in a sterile disposable plastic box. Refrigerate the samples at 4°C for 14 days, and randomly select (remove) 40 samples on days 0, 2, 4, 6, 8, 10, 12, and 14 for spectral acquisition. Then, simultaneously measure four indicators (on days with excessively large differences in overall data, correct using reserve samples).
[0063] Data acquisition: Scan the surface (15 seconds per sample).
[0064] Modeling and prediction: Improved sparrow algorithm and Bayesian optimization of hyperparameters. The main body of the model uses XGBoot regression to predict four indicators, and finally obtain the predicted values.
[0065] As a specific implementation method in this embodiment, multidimensional quality prediction of pork is performed.
[0066] Targets for testing: meat color (L*a*b* value), pH value, TVB-N content, and total bacterial count (CFU / g) of pork.
[0067] Equipment configuration: spectral range: 400-1000nm.
[0068] Sample Processing: Longissimus dorsi muscle portions from 5 fresh pigs were selected. Intramuscular fat and connective tissue were removed using mechanical cutting to prepare baseline meat samples. These baseline samples were precisely divided into 6cm × 6cm × 1cm slices and assigned to 8 treatment groups according to the experimental design. Each group contained 16 independent samples (total sample size = 16 × 8 = 128 samples). After numbering, the samples from each treatment group were vacuum-sealed in aseptic polyethylene bags and stored flat at 4°C for 14 days without compression. From the start of storage, systematic index measurements were conducted every 48 hours (days 0, 2, 4, 6, 8, 10, 12, and 14). Before each test, the samples were placed in a standard laboratory environment for 25 minutes to allow for natural evaporation of surface moisture and color stabilization. Each test consisted of 16 meat samples.
[0069] Data acquisition: Scan the surface (15 seconds per sample).
[0070] Modeling and prediction: Improved sparrow algorithm and Bayesian optimization of hyperparameters. The main body of the model uses XGBoot regression to predict four indicators, and finally obtain the predicted values.
[0071] The above are merely preferred embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A portable, non-destructive method for quality detection of animal-derived food based on mobile phone hyperspectral imaging, characterized in that, Includes the following steps: Hyperspectral image data of animal-derived food was acquired using a portable hyperspectral camera, and the hyperspectral image data was transmitted to a smartphone via Bluetooth for preprocessing to obtain preprocessed data. Three-dimensional features are extracted based on the preprocessed data, and the three-dimensional features are then reduced in dimension to obtain dimensionality-reduced features; wherein, the three-dimensional features include: spectral features, wavelet features, and texture features; An XGBoost regression model is constructed, the dimensionality reduction features are input into the XGBoost regression model to obtain the prediction results, and the prediction results are output via a smartphone.
2. The portable hyperspectral non-destructive testing method for animal-derived food quality based on a mobile phone according to claim 1, characterized in that, The preprocessing of the hyperspectral image data includes: The hyperspectral image data is converted to a TIFF file format to obtain hyperspectral image data. The hyperspectral image data in the TIFF file format is standardized and normalized to obtain preprocessed data.
3. The portable hyperspectral non-destructive testing method for animal-derived food quality based on a mobile phone according to claim 1, characterized in that, The process of extracting three-dimensional features based on the preprocessed data includes: using image processing algorithms to extract the region of interest from the preprocessed data, and obtaining three-dimensional features based on the region of interest; The process of extracting the region of interest from the preprocessed data using image processing algorithms includes: The 90th, 95th, and 120th bands in the hyperspectral image were selected as the R, G, and B channels, respectively, to generate a pseudo-color image; The pseudo-color image is processed using an HSV dual-threshold segmentation strategy to obtain the filtered target region; Morphological closing operations are performed on the filtered target regions to obtain the denoised regions. The ROIs in the four quadrants of the denoised region are located and numbered by spatial topological sorting to obtain the regions of interest.
4. The portable hyperspectral non-destructive testing method for animal-derived food quality based on a mobile phone according to claim 3, characterized in that, The process of processing the pseudo-color image using the HSV dual-threshold segmentation strategy to obtain the filtered target region includes: After converting the pseudo-color image to the HSV color space, the target region is filtered based on a dual threshold range set according to the hue value to obtain the filtered target region. The first threshold range is 0°-15°, the second threshold range is 165°-180°, and the saturation threshold and brightness threshold are set to >50% to exclude interference areas.
5. The portable hyperspectral non-destructive testing method for animal-derived food quality based on a mobile phone according to claim 3, characterized in that, The process of performing morphological closing operations on the screened target region to obtain the denoised region includes: using a 15×15 elliptic kernel closing operation to eliminate discrete noise.
6. The portable hyperspectral non-destructive testing method for animal-derived food quality based on a mobile phone according to claim 1, characterized in that, The process of reducing the dimensionality of the three-dimensional features to obtain the dimensionality-reduced features includes: The three-dimensional features are initially screened using the variance filtering method to obtain the initial screened features; The F-test was used to select significant features from the initial screening. Principal component analysis was used to reduce the dimensionality of the salient features, resulting in dimensionality-reduced features.
7. The portable hyperspectral non-destructive testing method for animal-derived food quality based on a mobile phone according to claim 1, characterized in that, The process of inputting the dimensionality-reduced features into the XGBoost regression model to obtain the prediction results includes: The XGBoost regression model is obtained by improving the Sparrow Algorithm and Bayesian optimization of hyperparameters. The dimensionality reduction features are then processed based on the optimized XGBoost regression model to obtain the prediction results.