Cotton type identification method based on RGB image and random forest algorithm
Through the random forest algorithm based on RGB images, combined with background removal and feature extraction, a recognition model that is sensitive to the characteristics of cotton multi-growth period is constructed, which solves the problems of low efficiency and large errors in cotton species recognition in the prior art, and achieves higher identification accuracy and fault tolerance.
Patent Information
- Application Number
- CN202410928521.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-11
- Publication Date
- 2024-11-01
AI Technical Summary
In the cotton species recognition, the prior art has problems such as single training volume, low efficiency, large errors and inability to effectively deal with changes in cotton growth stages in cotton species recognition, especially lacking in-depth research on multi-growth period recognition.
The random forest algorithm based on RGB images is adopted to train models through color, appearance and growth phase features, and combine background removal, feature extraction and decision tree growth to build a cotton species recognition model, and optimize the feature data set using autonomous sampling method and ID3 algorithm. Achieve accurate identification of cotton multi-growth period.
The accuracy and fault tolerance of cotton species recognition are improved, the sensitivity of the identification model to growth phase characteristics is solved, and reliable identification of cotton multi-growth phase is achieved.
Smart Images

Figure CN118887540A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of machine learning, and in particular to a cotton variety recognition method based on RGB images and a random forest algorithm. Background Art
[0002] In the agricultural field, accurate crop identification and classification are of great significance for improving crop production efficiency, optimizing agricultural resource allocation, and realizing smart agriculture. Cotton is an important natural fiber crop with wide applications in the textile, pharmaceutical and other industries. The main cotton species grown worldwide include upland cotton, sea island cotton, Asian cotton and grass cotton. Different types of cotton have differences in morphology, color, fiber properties and other aspects during their growth. Accurate identification and differentiation of different types of cotton are of great significance for agricultural practices such as breeding, cultivation and pest and disease management, as well as all aspects of the textile industry. Traditional cotton species identification and management mainly rely on manual observation and empirical judgment, which have problems such as strong subjectivity, low efficiency and large errors, and cannot meet the needs of large-scale cotton planting. Therefore, exploring how to achieve accurate and automatic identification of cotton species has become one of the research hotspots. With the continuous development and progress of agricultural science and technology, image recognition technology has been increasingly widely used in the agricultural field, including plant species identification, yield prediction and growth status monitoring. However, due to the complex growth environment of cotton plants and the large number of morphological changes during their growth, traditional image recognition methods face challenges in cotton species identification. The random forest algorithm is an integrated learning method with high classification accuracy and anti-interference ability. The algorithm can effectively process high-dimensional data and has good effects on feature extraction and classification in digital images. Compared with the traditional single classifier, the random forest algorithm predicts and classifies by combining multiple decision trees. The final result is obtained by voting or taking the average, which can effectively avoid overfitting and has high generalization ability. It is widely used in medicine, agriculture, biology and other fields.
[0003] However, existing technologies mainly focus on the identification of crops such as vegetables, rice, and corn, and most studies have only explored a single growth stage or a single feature, lacking in-depth research on different growth and development periods and the comprehensive utilization of multiple characteristics. Summary of the invention
[0004] In order to overcome the shortcomings of the prior art, the purpose of the present invention is to provide a cotton variety recognition method based on RGB images and random forest algorithm, by using the color, appearance and growth period characteristics of the cotton RGB image as input to train the random forest model, a recognition model that is more sensitive to the color, appearance and growth period of the cotton to be identified is obtained.
[0005] To achieve the above object, the present invention provides the following solutions:
[0006] A cotton species recognition method based on RGB images and random forest algorithm, comprising:
[0007] Collect the RGB image of the target cotton to be identified;
[0008] Performing background removal and feature extraction on the RGB image to be identified to obtain feature data to be identified and target growth period features;
[0009] Inputting the target growth period characteristics and the feature data to be identified into the constructed cotton variety identification model to obtain a target variety identification result;
[0010] The construction process of the cotton variety identification model includes:
[0011] Perform background removal on a preset RGB image of preset cotton to obtain a standard RGB image;
[0012] Extract the three primary color data of the standard RGB image to obtain color features; the color features are a 256*3 data matrix;
[0013] Extracting the appearance data of the standard RGB image to obtain area features, perimeter features and roundness features; the area features, the perimeter features and the roundness features are all 256*1 data matrices;
[0014] The standard RGB image is used to identify the growth period characteristics of the preset cotton to be trained; the growth period characteristics to be trained include: bud stage and boll stage; the growth period characteristics to be trained are a 256*1 data matrix;
[0015] The color feature, the area feature, the perimeter feature, the roundness feature, the growth period feature to be trained and the type feature of the preset cotton corresponding to the preset cotton are combined in columns to obtain a feature data set; the type feature is a 256*1 data matrix;
[0016] Set the number of decision trees and the maximum number of features;
[0017] According to the maximum number of features, the feature data set is sampled using an autonomous sampling method to obtain a training data set;
[0018] According to the number of decision trees, the ID3 algorithm and the out-of-bag error are used to grow decision trees for the training data set to obtain the constructed cotton variety recognition model.
[0019] Preferably, the RGB image to be identified is a blue-background image.
[0020] Preferably, background removal is performed on a preset RGB image of a preset cotton to obtain a standard RGB image, including:
[0021] Using IPP image processing and analysis software to remove the blue background of the preset RGB image to obtain a background-free RGB image;
[0022] Using Gaussian filtering technology to reduce noise on the background-free RGB image to obtain a low-noise RGB image;
[0023] The resolution of the low-noise RGB image is converted to 600*600 to obtain a standard RGB image.
[0024] Preferably, extracting the three primary color data of the standard RGB image to obtain color features includes:
[0025] Using the preset OpenCV library to perform color channel separation on the standard RGB image to obtain a red channel image, a blue channel image, and a green channel image;
[0026] Channel data is extracted from the red channel image, the blue channel image, and the green channel image to obtain the three primary color data.
[0027] Preferably, according to the number of decision trees, the ID3 algorithm and the out-of-bag error are used to grow the decision tree on the training data set to obtain the constructed cotton variety recognition model, including:
[0028] When growing the decision tree, recursive feature elimination and cross-validation are used to control the number of features.
[0029] Preferably, the cotton variety identification model construction platform is: PyCharm.
[0030] Preferably, it also includes:
[0031] Using a preset test set to verify the cotton variety recognition model, and obtain a test recognition result;
[0032] Constructing a confusion matrix based on the test recognition results;
[0033] Calculate the overall accuracy, Kappa coefficient, producer accuracy, and user accuracy based on the confusion matrix;
[0034] When the overall accuracy, the Kappa coefficient, the producer accuracy, and the user accuracy meet the preset error threshold, the cotton variety identification model is output.
[0035] Preferably, the calculation formula of the overall accuracy is: The calculation formula of the Kappa coefficient is: The calculation formula of the producer precision is: The calculation formula of the user precision is: N is the total number of samples in the confusion matrix; n is the number of rows and columns in the confusion matrix; x ii is the number of samples corresponding to the i-th row and i-th column of the confusion matrix; x i+ is the total number of samples in the i-th row of the confusion matrix; x +i is the total number of samples in the i-th column of the confusion matrix.
[0036] The present invention discloses the following technical effects:
[0037] The present invention provides a cotton species recognition method based on RGB images and a random forest algorithm. The method solves the problem of a single training amount of a recognition model by taking the color, appearance and growth period characteristics of a cotton RGB image as input quantities to perform random forest model training, thereby realizing a cotton species recognition model with higher accuracy and fault tolerance. The method solves the problem of irrelevant data redundancy by removing background and realizes the extraction of cotton images. The method solves the problem of the recognition model being affected by the cotton growth stage by the growth period characteristics to be trained, thereby realizing reliable species recognition of cotton in multiple growth periods by the recognition model. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0039] Figure 1 A schematic diagram of the cotton variety identification process provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0040] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0041] The purpose of the present invention is to provide a cotton species recognition method based on RGB images and random forest algorithm, by using the color, appearance and growth period characteristics of the cotton RGB image as input to train a random forest model, a recognition model that is more sensitive to the color, appearance and growth period of the cotton to be identified is obtained.
[0042] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0043] Figure 1 A schematic diagram of a cotton variety identification process provided by an embodiment of the present invention is shown in FIG. Figure 1 As shown, the present invention provides a cotton species recognition method based on RGB images and random forest algorithm, comprising:
[0044] Step 100: collecting an RGB image of target cotton to be identified;
[0045] Step 200: performing background removal and feature extraction on the RGB image to be identified to obtain feature data to be identified and target growth period features;
[0046] Step 300: inputting the target growth period characteristics and the feature data to be identified into the constructed cotton variety identification model to obtain a target variety identification result;
[0047] The construction process of the cotton variety identification model includes:
[0048] Perform background removal on a preset RGB image of preset cotton to obtain a standard RGB image;
[0049] Extract the three primary color data of the standard RGB image to obtain color features; the color features are a 256*3 data matrix;
[0050] Extracting the appearance data of the standard RGB image to obtain area features, perimeter features and roundness features; the area features, the perimeter features and the roundness features are all 256*1 data matrices;
[0051] The standard RGB image is used to identify the growth period characteristics of the preset cotton to be trained; the growth period characteristics to be trained include: bud stage and boll stage; the growth period characteristics to be trained are a 256*1 data matrix;
[0052] The color feature, the area feature, the perimeter feature, the roundness feature, the growth period feature to be trained and the type feature of the preset cotton corresponding to the preset cotton are combined in columns to obtain a feature data set; the type feature is a 256*1 data matrix;
[0053] Set the number of decision trees and the maximum number of features;
[0054] According to the maximum number of features, the feature data set is sampled using an autonomous sampling method to obtain a training data set;
[0055] According to the number of decision trees, the ID3 algorithm and the out-of-bag error are used to grow decision trees for the training data set to obtain the constructed cotton variety recognition model.
[0056] Specifically, the cotton growth period recognition method of this embodiment adopts a cotton development period automatic recognition method based on image classification and target detection provided by patent CN 108647652A.
[0057] Optionally, the RGB image to be identified is a blue-background image.
[0058] Optionally, background removal is performed on a preset RGB image of a preset cotton to obtain a standard RGB image, including:
[0059] Using IPP (Image-Pro Plus, Image Expert Enhanced Edition) image processing and analysis software to remove the blue background of the preset RGB image to obtain a background-free RGB image;
[0060] Using Gaussian filtering technology to reduce noise on the background-free RGB image to obtain a low-noise RGB image;
[0061] The resolution of the low-noise RGB image is converted to 600*600 to obtain a standard RGB image.
[0062] Specifically, extracting the three primary color data of the standard RGB image to obtain color features includes:
[0063] Using the preset OpenCV library to perform color channel separation on the standard RGB image to obtain a red channel image, a blue channel image, and a green channel image;
[0064] Channel data is extracted from the red channel image, the blue channel image, and the green channel image to obtain the three primary color data.
[0065] Furthermore, according to the number of decision trees, the ID3 algorithm and the out-of-bag error are used to grow the decision tree for the training data set to obtain the constructed cotton variety recognition model, including:
[0066] When growing the decision tree, recursive feature elimination and cross-validation are used to control the number of features.
[0067] Specifically, the selected k features are input into the random forest classifier as the initial feature subset, the importance of each feature is calculated, and the classification accuracy of the initial feature subset is obtained by using the cross-validation method;
[0068] Remove the feature with the lowest feature importance from the current feature subset to obtain a new feature subset, which is input into the random forest classifier again, the importance of each feature in the new feature subset is calculated, and the classification accuracy of the new feature subset is obtained using the cross-validation method.
[0069] Repeat step 2 recursively until the feature subset is empty. Finally, we get a total of k feature subsets with different numbers of features. Select the feature subset with the highest classification accuracy as the optimal feature combination.
[0070] Furthermore, the importance calculation method for a feature X in a sample is as follows:
[0071] 1) For each decision tree in the random forest, use the OOB (out-of-bag error) data to test the decision tree model and calculate the test error errOOB1;
[0072] 2) Randomly add interference noise to the feature X of all samples in OOB, that is, randomly change the value of the sample at feature X, and then recalculate the generalization error errOOB2 of OOB;
[0073] 3) Take the number of random forest decision trees as k, and the importance calculation formula for feature X is:
[0074]
[0075] Among them, importanceX is the importance of feature X; errOOB1 i is the original out-of-bag error of the i-th decision tree; errOOB2 i is the out-of-bag error of the i-th decision tree after adding interference noise.
[0076] Optionally, the cotton variety identification model construction platform is: PyCharm.
[0077] Furthermore, it also includes:
[0078] Using a preset test set to verify the cotton variety recognition model, and obtain a test recognition result;
[0079] Constructing a confusion matrix based on the test recognition results;
[0080] Calculate the overall accuracy, Kappa coefficient, producer accuracy, and user accuracy based on the confusion matrix;
[0081] When the overall accuracy, the Kappa coefficient, the producer accuracy, and the user accuracy meet the preset error threshold, the cotton variety identification model is output.
[0082] Specifically, the calculation formula of the overall accuracy is: The calculation formula of the Kappa coefficient is: The calculation formula of the producer precision is: The calculation formula of the user precision is: N is the total number of samples in the confusion matrix; n is the number of rows and columns in the confusion matrix; x ii is the number of samples corresponding to the i-th row and i-th column of the confusion matrix; x i+ is the total number of samples in the i-th row of the confusion matrix; x +i is the total number of samples in the i-th column of the confusion matrix.
[0083] Specifically, in order to verify the feasibility of the above method, this example uses 98 different types of cotton materials (including 4 types of grass cotton, 8 types of sea island cotton, 72 types of upland cotton, and 14 types of Asian cotton) in a certain test field. Sowing was carried out on April 20, and each material was repeated 3 times. The test plots all used 10 rows, with a plot area of 8m*8m and a row spacing of 80cm. Irrigation (450m 3 / ha) and basal fertilizer (N: 225kg / ha, P2O5: 150kg / ha and K2O: 225kg / ha) to ensure normal seed germination. Other field managements were based on local conventional agronomic management standards.
[0084] Furthermore, 3-5 leaves were selected from the top three fruit branches of cotton at the bud stage and the boll stage, taken back to the laboratory, and photographed with an RGB camera under a blue background. The RGB images of leaves with different experimental treatments were processed using Image-ProPlus image analysis software to obtain their color features (Red, Green, Blue) and appearance features (Area, Perimeter and Roundness) for classification model construction. IPP image processing and analysis software is an image processing and analysis system software developed by Media Cybernetics, USA, with powerful 2D and 3D image acquisition, processing, enhancement and analysis functions.
[0085] Optionally, in order to improve the accuracy of the model, this study tuned the number of decision trees and the number of features contained in each tree during the model training process. This embodiment adopts an effective tuning method, which combines recursive feature elimination and cross-validation to determine the optimal number of features. First, set the number of decision trees parameter to 500, and then traverse the number of feature parameters step by step, and select the number of features that minimizes the out-of-bag error as the optimal value. Then, fix the number of features to the optimal value, traverse the number of decision trees again (from 1 to 500), and select the number of decision trees that minimizes the out-of-bag error as the optimal value. Through this process, the optimal combination of the number of decision trees and the number of features can be determined to ensure the performance and accuracy of the model.
[0086] The beneficial effects of the present invention are as follows:
[0087] The present invention uses the color, appearance and growth period characteristics of the cotton RGB image as input to train the random forest model, so that the obtained model is more sensitive to the color, appearance and growth period of the cotton to be identified, thereby improving the recognition accuracy and fault tolerance of the model.
[0088] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0089] The principles and implementation methods of the present invention are described in this article using specific examples. The description of the above embodiments is only used to help understand the method and core idea of the present invention. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.
Claims
1. A cotton species recognition method based on RGB image and random forest algorithm, characterized in that: include: Collect the RGB image of the target cotton to be identified; Performing background removal and feature extraction on the RGB image to be identified to obtain feature data to be identified and target growth period features; Inputting the target growth period characteristics and the feature data to be identified into the constructed cotton variety identification model to obtain a target variety identification result; The construction process of the cotton variety identification model includes: Perform background removal on a preset RGB image of preset cotton to obtain a standard RGB image; Extract the three primary color data of the standard RGB image to obtain color features; the color features are a 256*3 data matrix; Extracting the appearance data of the standard RGB image to obtain area features, perimeter features and roundness features; the area features, the perimeter features and the roundness features are all 256*1 data matrices; The standard RGB image is used to identify the growth period characteristics of the preset cotton to be trained; the growth period characteristics to be trained include: bud stage and boll stage; the growth period characteristics to be trained are a 256*1 data matrix; The color feature, the area feature, the perimeter feature, the roundness feature, the growth period feature to be trained and the type feature of the preset cotton corresponding to the preset cotton are combined in columns to obtain a feature data set; the type feature is a 256*1 data matrix; Set the number of decision trees and the maximum number of features; According to the maximum number of features, the feature data set is sampled using an autonomous sampling method to obtain a training data set; According to the number of decision trees, the ID3 algorithm and the out-of-bag error are used to grow decision trees for the training data set to obtain the constructed cotton variety recognition model.
2. The cotton species identification method based on RGB image and random forest algorithm according to claim 1, characterized in that: The RGB image to be identified is a blue background image.
3. The cotton species identification method based on RGB image and random forest algorithm according to claim 1, characterized in that: The background of the preset RGB image of the preset cotton is removed to obtain a standard RGB image, including: Using IPP image processing and analysis software to remove the blue background of the preset RGB image to obtain a background-free RGB image; Using Gaussian filtering technology to reduce noise on the background-free RGB image to obtain a low-noise RGB image; The resolution of the low-noise RGB image is converted to 600*600 to obtain a standard RGB image.
4. The cotton species identification method based on RGB image and random forest algorithm according to claim 1, characterized in that: Extracting the three primary color data of the standard RGB image to obtain color features includes: Using the preset OpenCV library to perform color channel separation on the standard RGB image to obtain a red channel image, a blue channel image, and a green channel image; Channel data is extracted from the red channel image, the blue channel image, and the green channel image to obtain the three primary color data.
5. The cotton species identification method based on RGB image and random forest algorithm according to claim 1, characterized in that: According to the number of decision trees, the ID3 algorithm and the out-of-bag error are used to grow the decision tree for the training data set to obtain the constructed cotton variety recognition model, including: When growing the decision tree, recursive feature elimination and cross-validation are used to control the number of features.
6. The cotton species identification method based on RGB image and random forest algorithm according to claim 1, characterized in that: The cotton variety identification model construction platform is: PyCharm.
7. The cotton species identification method based on RGB image and random forest algorithm according to claim 1, characterized in that: Also includes: Using a preset test set to verify the cotton variety recognition model, and obtain a test recognition result; Constructing a confusion matrix based on the test recognition results; Calculate the overall accuracy, Kappa coefficient, producer accuracy, and user accuracy based on the confusion matrix; When the overall accuracy, the Kappa coefficient, the producer accuracy, and the user accuracy meet the preset error threshold, the cotton variety identification model is output.
8. The cotton species identification method based on RGB image and random forest algorithm according to claim 7, characterized in that: The calculation formula of the overall accuracy is: The calculation formula of the Kappa coefficient is: The calculation formula of the producer precision is: The calculation formula of the user precision is: N is the total number of samples in the confusion matrix; n is the number of rows and columns in the confusion matrix; x ii is the number of samples corresponding to the i-th row and i-th column of the confusion matrix; x i+ is the total number of samples in the i-th row of the confusion matrix; x +i is the total number of samples in the i-th column of the confusion matrix.
Citation Information
Patent Citations
Cotton developmental phase automatic identification method based on image classification and target detection
CN108647652A
Method and device for grading and distinguishing nitrogen content deficiency of crops and electronic equipment
CN113284098A
Farmland weed identification method based on visible light image and improved random forest algorithm
CN116453000A
