Tea foreign matter detection method and system
Through the combination of hyperspectral imaging technology and superpixel segmentation, the SVM algorithm is used to accurately identify tea foreign objects in automated tea production, solving the problem of difficult to identify foreign objects similar in shape and color in the existing technology, improving the classification accuracy and ensuring Improvement of tea quality.
Patent Information
- Application Number
- CN202411561760.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-05
- Publication Date
- 2024-12-06
AI Technical Summary
Existing computer vision methods are difficult to accurately identify tea foreign objects with similar shapes and colors in automated tea production, resulting in a decline in tea quality.
Hyperspectral imaging technology is used to construct a classification model in combination with support vector machine (SVM) algorithm, and the prediction results are corrected through superpixel segmentation, and most voting strategies are used to correct misclassified pixels to improve classification accuracy.
It significantly improves the accuracy of tea foreign matter detection, ensures the improvement of tea quality, and provides feasible identification and removal solutions for automated tea production.
Smart Images

Figure CN119091231A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of computer vision, and in particular relates to a method and system for detecting foreign matter in tea leaves. Background Art
[0002] Tea is one of the most common beverages today and is loved by people all over the world. Therefore, the quality of finished tea has always been widely concerned by the public. With the continuous improvement of the level of industrialization, the tea picking and production process has gradually tended to be automated. However, in this process, foreign matter often mixes in, which in turn contaminates the tea raw materials and causes quality degradation. For example, when the machine is picking tea leaves, its cutting position is difficult to accurately control in real time, which easily leads to the mixing of tea stems. Therefore, the accurate identification of tea foreign matter has become the key to automated tea production.
[0003] In recent years, many researchers have used computer vision methods to detect foreign matter in food. The detection principle is mainly based on shape and color differences. However, this method cannot distinguish foreign matter that is similar in shape and color to tea leaves, and there are still foreign matter residues in the tea leaves after sorting. Therefore, it is very necessary to develop new methods to accurately identify foreign matter in tea leaves. Summary of the invention
[0004] The purpose of the embodiment of the present invention is to provide a method for detecting foreign matter in tea leaves, aiming to solve the problem of inaccurate identification of foreign matter in tea leaves.
[0005] The embodiment of the present invention is implemented as follows: a method for detecting foreign matter in tea leaves, the method comprising: Obtain the hyperspectral image of the tested tea leaves and construct a classification model using the SVM algorithm; Using superpixel segmentation to guide and correct the prediction results of the classification model; The corrected classification model is used to detect foreign matter in tea leaves.
[0006] Preferably, before collecting the hyperspectral image, black and white correction needs to be performed.
[0007] Preferably, the method of acquiring the hyperspectral image of the tested tea leaves and constructing a classification model using a SVM algorithm specifically comprises the following steps: Performing normalization processing on the hyperspectral image; Performing dimensionality reduction processing on the hyperspectral image; The hyperspectral image classification in the original space is realized by using the SVM algorithm.
[0008] Preferably, the dimensionality reduction processing of the hyperspectral image specifically comprises the following steps: The hyperspectral image is screened using the CARS algorithm to remove irrelevant data within the full spectral band; The characteristic bands screened by the CARS algorithm are screened again using the GA algorithm, the SPA algorithm and / or the UVE algorithm.
[0009] Preferably, the GA algorithm is used to perform secondary screening on the characteristic bands screened by the CARS algorithm.
[0010] Preferably, the method of guiding and correcting the prediction result of the classification model by using superpixel segmentation specifically comprises the following steps: Selecting M hyperspectral bands from the full bands of the hyperspectral image to form a pseudo-color image, where M is a natural number; Performing superpixel segmentation on the pseudo-color image to generate K superpixel blocks, where K is a natural number; The misclassified pixels are corrected by using the majority voting strategy in the superpixel block to complete the correction of the entire hyperspectral image.
[0011] Preferably, the step of performing superpixel segmentation on the pseudo-color image to generate K superpixel blocks specifically includes the following steps: The SLIC algorithm is used to initialize the cluster center, and a fixed-size neighborhood is set around the cluster center to generate a cluster point set; Use the gradient ascent method to improve and iterate each tentative cluster point set until the convergence criteria are met; A set of similar pixels are grouped into the same area to form the superpixel block.
[0012] Preferably, the superpixel segmentation method is a multi-scale superpixel segmentation method, the number of hyperspectral bands selected is 3, and the number of segmentation blocks K is set to 6000-8000.
[0013] Preferably, the number of segmentation blocks K is set to 6000.
[0014] Another object of the embodiment of the present invention is a tea foreign body detection system, the tea foreign body detection system executes the tea foreign body detection method, the tea foreign body detection system comprises: The classification module obtains the hyperspectral image of the tested tea leaves and constructs a classification model using the SVM algorithm; A correction module, using superpixel segmentation to guide correction of the prediction results of the classification model; The detection module uses the calibrated classification model to detect foreign matter in the tea leaves.
[0015] A method for detecting foreign matter in tea leaves provided by an embodiment of the present invention utilizes the spatial information of a hyperspectral image and adopts superpixel segmentation combined with a majority voting strategy to correct misclassified pixels. After superpixel-guided correction, the classification effect is further improved, the classification accuracy is improved, and a feasible solution is provided for the identification and removal of foreign matter in tea leaves. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 A diagram of the application environment of the tea foreign body detection method provided by an embodiment of the present invention; Figure 2 A flow chart of a method for detecting foreign matter in tea leaves provided by a first embodiment of the present invention; Figure 3 A flow chart of a method for detecting foreign matter in tea leaves provided by a first embodiment of the present invention; Figure 4 The tea leaves and foreign matter images provided by the second embodiment of the present invention; Figure 5 The average spectral curve of tea leaves and foreign matter after pretreatment provided by the second embodiment of the present invention; Figure 6 The second embodiment of the present invention provides a method for screening characteristic bands using CARS; Figure 7 The second embodiment of the present invention provides a method for screening characteristic bands using CARS-SPA; Figure 8 The second embodiment of the present invention provides a method for screening characteristic bands using CARS-UVE; Fig. 9 The result of screening the original spectral characteristic bands based on CARS-GA provided in the second embodiment of the present invention; Fig.10 A confusion matrix of the prediction results of the model established using four characteristic bands provided in the second embodiment of the present invention; Fig.11 A pixel-level classification diagram of a hyperspectral image of a mixture of tea leaves and foreign objects using CARS-GA-SVM provided in the second embodiment of the present invention; Fig.12 A local enlarged view of the segmentation result provided by the second embodiment of the present invention; Fig.13 A pixel category correction result diagram provided by the second embodiment of the present invention; Fig.14 This is a structural diagram of a tea foreign body detection system provided in the third embodiment of the present invention. DETAILED DESCRIPTION
[0017] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0018] Figure 1 The application environment diagram of the tea foreign body detection method provided by the embodiment of the present invention is as follows: Figure 1 As shown, in this application environment, a hyperspectral imaging system and computer equipment are included.
[0019] The sample came from a tea company in Fujian. The sample contained white tea and foreign objects commonly found in its production process, including tea branches, miscellaneous leaves and flat silk (residues of woven bags).
[0020] The hyperspectral imaging system consists of a conveyor belt, a halogen lamp light source, and a hyperspectral camera located above the conveyor belt. The hyperspectral camera uses a line-scan hyperspectral camera FX17 (Oulu, Finland). The wavelength range of the collected spectral images is 900-1700nm, the number of spectral bands is 224 bands, and the spectral resolution is 8nm.
[0021] The computer device may be a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto. The hyperspectral imaging system and the computer device may be connected via a network, and the present invention does not limit this.
[0022] like Figure 2 As shown, in the first embodiment, a method for detecting foreign matter in tea leaves is proposed. This embodiment applies this method to the above Figure 1 A method for detecting foreign matter in tea leaves may include the following steps: Step S202, obtaining a hyperspectral image of the tea leaves to be tested, and constructing a classification model using a SVM algorithm.
[0023] In this embodiment, based on the principle of spectroscopy, different substances will present different spectral characteristics, so this characteristic can be used to detect foreign matter in tea leaves that is similar in color and shape. Hyperspectral imaging (HSI) technology is a new technology that combines optical imaging and spectroscopy technology. This technology can simultaneously obtain spectral information and image information of the object being tested. Among them, spectral information can be used to distinguish foreign matter with similar shapes and colors, and image information can be used to determine the specific location of foreign matter. Support vector machine (SVM) is a supervised machine learning method. This embodiment uses SVM to establish a classification model for tea leaves and foreign matter.
[0024] Step S204: Use superpixel segmentation to guide and correct the prediction results of the classification model.
[0025] In this embodiment, due to the variability of the production environment, the complexity of the surface of the object to be measured, and the spectral distortion of edge pixels, the classification method that only relies on spectral information often produces a large number of misclassified pixels. When these misclassified pixels are distributed within the contour of the positive sample, if only the abnormal pixels are used as the basis for locating foreign objects, the positive sample will be regarded as a foreign object and removed. Therefore, whether the pixel category within the contour of the object to be measured is pure will directly affect the accuracy of foreign object removal. The prior art does not optimize the pixel-level classification results, and the classification results are difficult to directly apply to the actual production process. In response to the above problems, this embodiment applies a method combining hyperspectral imaging technology with superpixel segmentation to white tea foreign body detection, uses superpixel segmentation to guide the classification model, and optimizes the pixel-level classification results to significantly improve the accuracy of foreign body detection, providing a feasible idea for locating and removing foreign objects in food.
[0026] Step S206: using the calibrated classification model to detect foreign matter in the tea leaves.
[0027] In this embodiment, the spatial information of the hyperspectral image is utilized, and superpixel segmentation is used to correct the misclassified pixels. After the superpixel-guided correction, the classification effect is further improved, thereby increasing the classification accuracy.
[0028] In the first embodiment, if Figure 2 and 3 As shown, step S202 also includes step S302: before collecting the hyperspectral image, black and white correction needs to be performed.
[0029] In this embodiment, in order to reduce the spectral error caused by temperature fluctuation, preheating for about 20 minutes was performed before data collection. The tea leaves and various foreign matter samples were scanned 20 times in total, and 20 hyperspectral data cubes with a size of 640×1000×224 (width×height×spectral band) were obtained. Among them, there were 20 images of tea leaves and three kinds of foreign matter. Since the first and last bands of the data had considerable noise, the first and last 12 bands were removed, and the middle 200 spectral bands were selected for subsequent analysis.
[0030] Hyperspectral data is easily affected by factors such as spectral fluctuations and background noise during the acquisition process, so black and white correction is performed before processing the hyperspectral image. Whiteboard data is obtained by scanning a standard calibration whiteboard, while blackboard images are obtained by covering the camera lens with a black cover. The calculation formula for black and white correction is as follows:
[0031] in, I is the original hyperspectral image, I black is the dark current data;I white For whiteboard data, I correct is the corrected hyperspectral data.
[0032] In the first embodiment, if Figure 2 and 3 As shown, step S202 specifically includes the following steps S402 to S406: Step S402: normalize the hyperspectral image.
[0033] In this embodiment, spectral samples are selected from the corrected hyperspectral images to construct a data set. Pixels are randomly selected from 20 hyperspectral images as spectral samples, and a total of 1600 pixels are selected, among which the number of spectral samples of tea leaves, branches, miscellaneous leaves, flat silk and background are 570, 432, 302, 136 and 160 respectively. Since there are certain differences in the spectral intensity of different pixels, it is necessary to normalize the extracted spectral data to improve the interpretability and comparability of the spectral data. The normalization calculation formula is as follows:
[0034] Among them, X i is the spectral data, X min is the minimum value of the spectral data, X max is the maximum value of the spectral data, X new is the spectral data obtained after normalization.
[0035] The spectral curve will be jagged due to various noises during the acquisition process. In order to reduce this interference, the spectral data is filtered using the Savitzky-Golay (SG) smoothing filter. After preprocessing, the average spectral curves of tea leaves and foreign matter are as follows: Figure 5 As shown, different types of substances exhibit distinct spectral differences, which can serve as the basis for classification algorithms.
[0036] In order to train and test the model, the selected 1600 spectral sets need to be divided into two parts. The Kennard-Stone (KS) algorithm is used to divide the spectral data into 6:4 parts, 60% of the spectral data is used to train the classification model, and 40% of the spectral data is used as a test set, finally obtaining 960 training samples and 640 test samples.
[0037] The performance of the model is evaluated using terms such as accuracy, precision, and recall as follows:
[0038] Among them, TP, TN, FP and FN represent the number of positive examples identified as positive examples, the number of negative examples identified as negative examples, the number of negative examples identified as positive examples and the number of positive examples identified as negative examples, respectively.
[0039] Step S404: performing dimensionality reduction processing on the hyperspectral image.
[0040] In this embodiment, it is essential to perform dimension reduction processing on the spectral data. The dimension reduction process can not only remove data redundancy, but also extract the most representative features for model building.
[0041] Step S406: using the SVM algorithm to implement the classification of the hyperspectral image in the original space.
[0042] In this embodiment, the classification principle of the SVM algorithm is to find an optimal hyperplane in n-dimensional space as the decision surface for classification, so as to maximize the distance between each class and a single data point. As a kernel-based classifier, SVM is good at processing high-dimensional data. Through the kernel trick, SVM can find the best classification hyperplane in the high-dimensional feature space of hyperspectral data, realize the effective classification of nonlinear data in the original space, and has good robustness.
[0043] In the first embodiment, step S404 may specifically include steps S502 to S504: Step S502, using the CARS algorithm to screen the hyperspectral image and remove irrelevant data in the full spectrum band; Step S504: perform secondary screening on the characteristic bands screened by the CARS algorithm using the GA algorithm, the SPA algorithm and / or the UVE algorithm.
[0044] In this embodiment, the competitive adaptive reweighting algorithm (CARS) can quickly remove irrelevant data in the full spectrum band and retain the most valuable spectrum band. However, the number of bands screened by the CARS algorithm often accounts for a large proportion, accounting for about 1 / 3 of the total number of bands, and too redundant characteristic bands will reduce real-time performance. To this end, on the basis of CARS band selection, GA, SPA and UVE are introduced to perform secondary screening of the characteristic bands screened by the CARS algorithm to further reduce the redundancy of information. Preferably, this embodiment preferentially uses the GA algorithm to perform secondary screening of the characteristic bands screened by the CARS algorithm. The specific experiment and proof process refer to the second embodiment described below.
[0045] In the first embodiment, if Figure 2 and 3 As shown, step S204 specifically includes steps S602 to S606: Step S602 , selecting M hyperspectral bands from the full bands of the hyperspectral image to form a pseudo-color image, where M is a natural number.
[0046] Step S604, performing super-pixel segmentation on the pseudo-color image to generate K super-pixel blocks, where K is a natural number.
[0047] Step S606, correcting misclassified pixels in the superpixel block using a majority voting strategy to complete the correction of the entire hyperspectral image.
[0048] In this embodiment, in order to solve the problem of a large number of misjudged pixels in the contour of the measured object, this embodiment uses superpixel blocks to guide the correction of misjudged pixels. Specifically, three bands are selected from the full band of the hyperspectral data to form a pseudo-color image, and then the pseudo-color image is segmented into superpixels to generate K superpixel blocks.
[0049] Superpixels are obtained by segmenting according to the sample contour boundary, so there is only one spectrum of the object being measured in each superpixel, that is, all pixels in each superpixel block should be of the same category. Based on this principle, the majority voting strategy can be used to correct misclassified pixels in the superpixel block. The superpixel segmentation map is mapped to the pixel-level classification result. Assume that a superpixel block S i contains N pixels, with {P 1 ,⋯,P N} means that each pixel corresponds to a classification label y j (where j = 1, 2, ..., N), statistical superpixel block S i The number of pixels of each label in is calculated as follows:
[0050] Among them, δ() is the indicator function, k is the category of existence, when y j = k, δ(y j ,k)=1; otherwise δ(y j ,k)=0;n k (S i ) is the super pixel block S i The number of pixels of class k in .
[0051] After counting the number of pixels in each category, the category with the largest number of pixels is taken as the final category of the entire superpixel:
[0052] The left side of the equation represents the superpixel block S i After all K super-pixel blocks are corrected, the correction of the entire hyperspectral image is completed.
[0053] In the first embodiment, step S604 specifically includes steps S702 to S706: Step S702: Use the SLIC algorithm to initialize the cluster center, and set a neighborhood of a fixed size around the cluster center to generate a cluster point set.
[0054] Step S704, using the gradient ascent method to iterate each tentative cluster point set until the convergence criterion is met.
[0055] Step S706: grouping a set of similar pixels into the same area to form the super pixel block.
[0056] In this embodiment, the superpixel segmentation method uses a simple linear iterative clustering algorithm (SLIC). SLIC first initializes the cluster center and sets a fixed-size neighborhood around the cluster center to generate a cluster point set. Then, the gradient ascent method is used to improve the iteration for each tentative cluster point set until some convergence criteria are met. Finally, a set of similar pixels are grouped into the same area to form a superpixel block.
[0057] In the first embodiment, the superpixel segmentation method is adopted in steps S602 to S606, which is a multi-scale superpixel segmentation method, specifically step S802: the number of hyperspectral bands is selected as 3, and the number of segmentation blocks K is set to 6000 to 8000. Preferably, the number of segmentation blocks K is set to 6000. The preferred setting of the number of segmentation blocks K in this embodiment is 6000, and the specific experiment and proof process refer to the second embodiment below.
[0058] In the second embodiment, a tea foreign body detection experiment is proposed, which is a specific practice of the first embodiment. The specific method is as follows: 1. Hyperspectral image acquisition and correction The sample came from a tea company in Fujian. The sample contained white tea and foreign objects commonly found in its production process, including tea branches, miscellaneous leaves and flat silk (residues of woven bags).
[0059] Before collecting data, preheating was performed for about 20 minutes. The tea leaves and various foreign matter samples were scanned 20 times to obtain 20 hyperspectral data cubes with a size of 640×1000×224 (width×height×spectral band). 20 images of tea leaves and three kinds of foreign matter were collected. Figure 4 As shown in the figure, (a) is tea leaves, (b) is miscellaneous leaves, (c) is branches, and (d) is flat silk. Since the first and last bands of the data have considerable noise, the first and last 12 bands are removed, and the middle 200 spectral bands are selected for subsequent analysis.
[0060] 2. Pixel selection and spectral data preprocessing Pixels were randomly selected from 20 hyperspectral images as spectral samples, and a total of 1600 pixels were selected, of which the number of spectral samples for tea leaves, branches, miscellaneous leaves, flat silk and background were 570, 432, 302, 136 and 160 respectively. The extracted spectral data were normalized.
[0061] In order to train and test the model, the selected 1600 spectral sets need to be divided into two parts. The Kennard-Stone (KS) algorithm is used to divide the spectral data into 6:4 parts, 60% of the spectral data is used to train the classification model, and 40% of the spectral data is used as a test set, finally obtaining 960 training samples and 640 test samples.
[0062] 3. Discussion of Dimensionality Reduction Results The process of selecting characteristic bands using CARS is as follows: Figure 6 As shown in the figure, the root mean square error RMSECV and the regression path coefficient will continue to change with the increase in the number of sampled variables. When the number of sampling runs reaches 13 times, the RMSECV value reaches the minimum value of 0.6046 (corresponding to the vertical asterisk line at the bottom), and a total of 65 characteristic bands are extracted, accounting for 29% of the total number of spectral variables. In order to further reduce the data dimension and improve the real-time detection, the SPA, UVE and GA methods are used to perform secondary screening on the characteristic variables extracted by CARS.
[0063] The results of secondary screening using the SPA algorithm are as follows Figure 7 As shown in Figure 2, when the root mean square error value RMSECV tends to be stable, the number of bands screened is 37, accounting for about 16.5% of the total number of bands. The process of extracting characteristic bands using the UVE method is as follows: Figure 8 As shown in the figure, the variables in the middle of the dotted line are irrelevant information that needs to be eliminated, and the 34 characteristic variables outside the dotted line are selected characteristic bands, accounting for about 15.2% of the total number of bands. The GA algorithm is used for secondary characteristic band selection, where the population number is set to 50, the genetic generation is set to 40, the crossover probability is set to 0.5, and the mutation probability is set to 0.1. After the secondary band screening by the genetic algorithm, 36 characteristic bands are finally selected, accounting for about 16.1% of the total number of bands. Fig. 9 This is the result of the characteristic bands selected by CARS-GA, where the dotted line corresponds to the selected characteristic bands.
[0064] 4. Discussion on SVM model classification results The bands selected by CARS, CARS-GA, CARS-SPA and CARS-UVE are used as input variables of SVM for discriminant model analysis. The confusion matrix obtained is as follows: Fig.10By comparing the classification results of the models, we found that the classification accuracy of the model using CARS-GA was the highest, and only 3 of the 228 tea spectra in the test set were misclassified as miscellaneous leaves.
[0065] The prediction accuracy and number of bands used by each band selection method are statistically analyzed, and the statistical results are shown in Table 1. By comparing the model results, we found that the CARS-GA-SVM model performed best, with the accuracy of tea leaves, miscellaneous leaves, and branches being 98.7%, 92.5%, and 91.7%, respectively, all higher than other models. The number of feature bands extracted by the CARS-GA method is 36. Compared with the band selection method using only CARS, the CARS-GA method not only achieves further dimensionality reduction, but also improves the prediction accuracy. Although the number of feature bands extracted by the CARS-UVE method is slightly less than that of the CARS-GA method, it sacrifices a certain degree of accuracy, indicating that some information is lost.
[0066] Table 1: Classification results of tea foreign matter by SVM model based on four band selection methods
[0067] The CARS-GA-SVM model is used to predict the hyperspectral images of tea leaves and foreign objects placed randomly, such as Fig.11 (a) and performs pixel-level classification to visualize the accuracy of the model classification. Fig.11 Figure (b) is the pixel-level classification result, where different grayscale represents different predicted categories.
[0068] It can be seen from the prediction graph that there are many misclassified pixels in the contour of the object under test. By analyzing the sample status and comparing the spectral information, the main reasons affecting the classification effect are the following three points: (1) The resolution of the hyperspectral image is low, and there are a large number of mixed pixels at the contour edge. The spectrum at these mixed pixels is distorted, and the category judgment is prone to errors; (2) There are tiny holes on the surface of tea leaves (often caused by insects gnawing). The spectral information of these defective positions is not the spectral information of tea leaves. It will be judged as other categories during prediction. Therefore, we also regard the pixels in the tiny holes as misclassified pixels. (3) The classification algorithm has a certain false detection rate, so the model prediction error will cause some pixels to be misjudged. The above three problems will directly lead to the inclusion of multiple pixel categories in the contour of the object under test, which will affect the subsequent automatic removal of foreign matter.
[0069] 5. Multi-scale superpixel segmentation results In order to obtain the best correction effect, this embodiment compares the superpixel segmentation effects of different scales to obtain the best segmentation scale, which is used for image segmentation and subsequent correction. First, three hyperspectral bands are selected to form a pseudo-color image, and then the SLIC method is used to perform multi-scale superpixel segmentation on the pseudo-color image. The number of segmentation pixel blocks K is set to 2000, 4000, 6000, and 8000 respectively. Fig.12 The following are partial magnified images of tea leaves and branches after segmentation at different scales. In tea foreign body detection, tea leaves are used as positive samples in this study, and the accuracy of their segmentation is crucial to the effect of subsequent pixel correction. However, branches are thin in shape, and their segmentation effect is often the worst among all kinds of foreign bodies. Therefore, the segmentation effect of tea leaves and branches is one of the key criteria for measuring the segmentation effect of the entire image. It can be seen from the partial magnified image that when the number of segmentation blocks K is set to 2000, part of the outline of tea leaves and branches is divided into the superpixel blocks of the background, which means that 2000 superpixel blocks cannot accurately segment the image by contour. When the number of segmentation blocks K is set to 4000, the segmentation of tea leaves is improved, but the outline of branches is still segmented incorrectly. When the number of segmentation blocks K is set to 6000 and 8000, the edges of tea leaves and branches in the local image are accurately aligned with the edges of superpixel blocks, and the segmentation is good. Therefore, by comparing the segmentation results, it can be obtained that at least 6000 superpixel blocks need to be segmented to accurately segment the image by contour.
[0070] 6. Pixel category correction results The superpixel segmentation map is mapped to the pixel-level classification result, and the superpixel is used to correct the pixel-level classification result. The corrected result is as follows: Fig.13 When the number of segments K is set to 2000 and 4000, the segmentation effect of some branches and flat wires is poor, and the pixels of these parts are incorrectly corrected to background pixels during calibration. When the number of segments is set to 6000, except for a slight deformation of the outline of a flat wire sample, the shapes of other tea leaves and foreign objects are basically unchanged, indicating that the segmentation effect is good when the K value is 6000. Fig.13 In Figure (e), except for a mixed leaf, the contours of the other objects under test contain only one "pure" pixel category. The reason why the contour of this mixed leaf contains pixels of other categories is that there are too many misclassified pixels, which cannot be improved by pixel category correction. Through spectral comparison, we found that the spectrum of the misclassified pixels is very similar to the spectrum of tea leaves. Therefore, a large number of misclassified pixels are caused by the "different objects with the same spectrum" phenomenon. When the number of segmentation blocks is set to 8000, some smaller misjudgment areas are not correctly corrected, which means that the segmentation scale is too small at this time, and the misjudged pixel information occupies a complete superpixel block. In summary, when the number of segmentation blocks K is set to 6000, the classification effect map performs best.
[0071] In order to more accurately illustrate the effectiveness of the correction method and the rationality of setting K to 6000, we counted the number of misjudged pixels before and after correction. Before counting the number of pixels, it is necessary to calculate the correct number of pixels for each substance. We manually labeled the hyperspectral images using ENVI5.3. The labeling results are shown in the figure below. Fig.13 As shown in (b) in the figure. We compared the correction results with the labeled pixel categories, and recorded the pixels with inconsistent comparison results as misclassified pixels. The statistical results are shown in Table 2. When the pixel-level classification results were not corrected, the overall accuracy was 96.48%, which was very close to the prediction accuracy of the test set of 95.9%. When the number of segments K was set to 2000 and 4000, the number of misclassified pixels of tea leaves was significantly reduced, but the number of misclassified pixels of branches and flat silk was significantly increased, which was caused by the excessive segmentation scale. When the number of segments K was set to 6000, the number of misclassified tea pixels was reduced from 1885 to 62. In the classification Fig.13 In (e), we did not observe these 62 pixels within the tea leaf contour, indicating that these 62 misclassified pixels were corrected to background pixels and therefore would not affect the subsequent foreign body removal process. When the number of segmentation blocks K was set to 8000, the accuracy dropped to 98.43%, and the number of misclassified pixels of miscellaneous leaves increased to 2014 compared to when K=6000. This was mainly due to the reduction in the superpixel segmentation scale, and the holes on the miscellaneous leaves and the pixels within some edge contours were not corrected.
[0072] Table 2: Number of misclassified pixels and overall accuracy before and after pixel correction
[0073] In summary, this embodiment combines hyperspectral imaging technology with superpixel segmentation method to quickly and accurately detect foreign matter in white tea. Four methods, CARS, CARS-GA, CARS-SPA and CARS-UVE, are used for band selection, and the extracted feature bands are input into SVM for modeling and analysis. By comparing the classification accuracy of different models, the optimal model for detecting tea foreign matter is obtained: CARS-GA-SVM, with a discrimination accuracy of 95.9%. On the basis of using this model for pixel-level classification, superpixels are used to guide and correct the pixel-level classification results. The experimental results show that after superpixel correction, the number of misclassified pixels of tea leaves is reduced to 62, and the classification accuracy is increased to 98.9%. There is only one pixel category in the white tea outline in the final classification result diagram, which effectively avoids the problem of incorrect removal of positive samples due to the presence of misclassified pixels. Although the classification effect has been improved after superpixel correction, there are still a few large misclassified areas that are difficult to accurately correct. This embodiment not only provides a classification model for detecting foreign matter in white tea, but also uses superpixels to correct misclassified pixels, ensuring that only one pixel category exists within the contours of most detected objects. This method is highly practical and helps promote the application of hyperspectral imaging technology in the online sorting of foreign matter in tea leaves.
[0074] In a third embodiment, if Fig.14 As shown, a tea foreign body detection system is provided, and the tea foreign body detection system comprises: The classification module obtains the hyperspectral image of the tested tea leaves and constructs a classification model using the SVM algorithm; A correction module, using superpixel segmentation to guide correction of the prediction results of the classification model; The detection module uses the calibrated classification model to detect foreign matter in the tea leaves.
[0075] In this embodiment, the tea foreign body detection system can execute all the steps and sub-steps of the method in the first embodiment. The technical features and effects are the same as those in the first embodiment and are not repeated here.
[0076] It should be understood that, although each step in the flow chart of each embodiment of the present invention is shown in sequence according to the indication of the arrow, these steps are not necessarily performed in sequence according to the order indicated by the arrow. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be performed in other orders. Moreover, at least a portion of the steps in each embodiment may include a plurality of sub-steps or a plurality of stages, and these sub-steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these sub-steps or stages is not necessarily performed in sequence, but can be performed in turn or alternately with at least a portion of other steps or sub-steps or stages of other steps.
[0077] The technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0078] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for detecting foreign matter in tea leaves, characterized in that: The tea foreign body detection method comprises: Obtain the hyperspectral image of the tested tea leaves and construct a classification model using the SVM algorithm; Using superpixel segmentation to guide and correct the prediction results of the classification model; The corrected classification model is used to detect foreign matter in tea leaves.
2. The method for detecting foreign matter in tea leaves according to claim 1, characterized in that: Before collecting the hyperspectral image, black and white correction needs to be performed.
3. The method for detecting foreign matter in tea leaves according to claim 1, characterized in that: The method of obtaining a hyperspectral image of the tea leaves to be tested and constructing a classification model using a SVM algorithm specifically includes the following steps: Performing normalization processing on the hyperspectral image; Performing dimensionality reduction processing on the hyperspectral image; The hyperspectral image classification in the original space is realized by using the SVM algorithm.
4. The method for detecting foreign matter in tea leaves according to claim 3, characterized in that: The dimensionality reduction processing of the hyperspectral image specifically comprises the following steps: The hyperspectral image is screened using the CARS algorithm to remove irrelevant data within the full spectral band; The characteristic bands screened by the CARS algorithm are screened again using the GA algorithm, the SPA algorithm and / or the UVE algorithm.
5. The method for detecting foreign matter in tea leaves according to claim 4, characterized in that: The GA algorithm is used to perform secondary screening on the characteristic bands screened by the CARS algorithm.
6. The method for detecting foreign matter in tea leaves according to claim 1, characterized in that: The method of guiding and correcting the prediction result of the classification model by using superpixel segmentation specifically includes the following steps: Selecting M hyperspectral bands from the full bands of the hyperspectral image to form a pseudo-color image, where M is a natural number; Performing superpixel segmentation on the pseudo-color image to generate K superpixel blocks, where K is a natural number; The misclassified pixels are corrected by using the majority voting strategy in the superpixel block to complete the correction of the entire hyperspectral image.
7. The method for detecting foreign matter in tea leaves according to claim 6, characterized in that: The super-pixel segmentation of the pseudo-color image to generate K super-pixel blocks specifically includes the following steps: The SLIC algorithm is used to initialize the cluster center, and a fixed-size neighborhood is set around the cluster center to generate a cluster point set; Use the gradient ascent method to improve and iterate each tentative cluster point set until the convergence criteria are met; A set of similar pixels are grouped into the same area to form the superpixel block.
8. The method for detecting foreign matter in tea leaves according to claim 7, characterized in that: The superpixel segmentation method is a multi-scale superpixel segmentation method. The number of hyperspectral bands is selected as 3, and the number of segmentation blocks K is set to 6000~8000.
9. The method for detecting foreign matter in tea leaves according to claim 8, characterized in that: The number of partition blocks K is set to 6000.
10. A tea foreign body detection system, characterized in that: The tea foreign body detection system implements the tea foreign body detection method according to any one of claims 1 to 9, and the tea foreign body detection system comprises: The classification module obtains the hyperspectral image of the tested tea leaves and constructs a classification model using the SVM algorithm; A correction module, using superpixel segmentation to guide correction of the prediction results of the classification model; The detection module uses the calibrated classification model to detect foreign matter in the tea leaves.
Citation Information
Patent Citations
Fresh tea leaf classification method based on multiple features and multiple classifiers
CN111861103A
Tea classification method based on hyperspectral image and deep learning
CN113158980A
Hyperspectral classification identification method based on superpixel segmentation
CN115937685A
Super-pixel level information fusion-based hyperspectral image classification method and system
WO2018045626A1
