An egg dark spot detection method based on a machine learning random forest algorithm
The egg spot detection method based on the random forest algorithm of machine learning solves the problems of low efficiency, poor accuracy and high cost in the existing technology. It realizes efficient and accurate automatic identification and detection of egg spots, is applicable to a variety of eggshell colors, reduces hardware requirements and provides a new type of automated detection solution.
Patent Information
- Application Number
- CN202310628118.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-30
- Publication Date
- 2026-01-09
- Estimated Expiration
- 2043-05-30
AI Technical Summary
Existing methods for detecting dark spots on eggs are inefficient, have poor accuracy and consistency, and are costly. They are also difficult to adapt to diverse eggshell colors and hardware requirements, and cannot achieve automated and objective quality evaluation.
An egg spot detection method based on machine learning random forest algorithm is adopted, including image acquisition, preprocessing, feature extraction and model building. The random forest algorithm is used to automatically identify and calculate the area ratio of dark spots.
It achieves efficient and accurate detection of dark spots on eggs, reduces hardware costs, is applicable to various eggshell colors, has high consistency and ease of use, can replace manual grading methods, and provides a new type of automated detection method.
Smart Images

Figure CN116958960B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of chicken egg dark spot detection, and in particular to a chicken egg dark spot detection method based on a machine learning random forest algorithm. BACKGROUND
[0002] Chicken egg dark spots are gray spots on the surface of a chicken egg that can be observed by the naked eye under natural light. Chicken egg dark spots can reduce the appearance quality of the egg and affect the purchasing desire of consumers, causing potential economic losses to egg producers.
[0003] Currently, the main method for detecting chicken egg dark spots is the manual grading method. This method uses manual inspection to detect eggs. First, a dark spot quality evaluation grading standard chart is manually selected and developed. Then, the detector subjectively evaluates the test egg based on the matching degree of the dark spot of the test egg with the standard chart. The manual evaluation method requires a long detection time, has high labor intensity for the detector, and is greatly affected by the personal subjective factors of the detector. Therefore, it is often difficult to accurately, objectively and consistently obtain the evaluation result of the quality of the dark spot of the egg.
[0004] In order to overcome the defects of low efficiency, poor accuracy and consistency in the manual grading process, an egg quality detection method based on image feature acquisition and machine learning has been researched.
[0005] Minlan Jiang et al. collected chicken egg transmission image samples and applied a GoogLeNet convolutional neural network model to grade the dark spots of the eggs (Minlan Jiang, Peilun Wu, Fei Li. Detecting dark spot eggs based on CNN GoogLeNet model[J]. Wireless Networks, 2021 (prepublish).); Yang Hang et al. used a visual sensor to obtain pictures of pigeon eggs and used a YOLOv5s network model to distinguish fertilized eggs of the pigeon eggs (CN20211083875.6, a pigeon egg quality identification method). The above research has tried to automate the evaluation of egg quality, but still has many shortcomings. For example, the GoogLeNet convolutional neural network model used has problems of overcorrection and gradient dispersion, which requires a large number of image samples to be collected for training during the construction of the initial training set, resulting in a large loss of samples. The image acquisition system of the above method has high requirements for hardware, and it is difficult for general egg production bases to meet the standards, so the ease of use is poor. In addition, in order to cater to the diversified consumer demand for eggshell color, the eggshell color sometimes has great differences, and the existing detection method cannot be applied to the automatic detection of green shell eggs.
[0006] How to overcome the above-mentioned defects existing in the prior art, develop a kind of detection efficiency, accuracy and consistency is good, universality is strong, and cost is low to the dark spot of egg shell automatic identification and detection method is the key problem that the person skilled in the art pays attention to. SUMMARY
[0007] The purpose of the present application is to provide a chicken egg dark spot detection method based on machine learning random forest algorithm to solve the problems proposed in the background art.
[0008] The chicken egg dark spot detection method based on machine learning random forest algorithm provided by the present application comprises the following steps:
[0009] A chicken egg dark spot detection method based on machine learning random forest algorithm, the detection method comprises the following steps:
[0010] Step 1, build an egg image acquisition system, collect egg dark spot image samples of the egg to be tested;
[0011] Step 2, pretreat the egg dark spot image sample;
[0012] Step 3, extract feature values from the egg dark spot image sample;
[0013] Step 4, input the feature values into the random forest algorithm, and build a random forest model;
[0014] Step 5, input the image sample to be tested, use the random forest algorithm to complete the automatic identification of dark spot, and calculate the area ratio.
[0015] Optionally, the egg dark spot image sample of the egg to be tested is collected, which comprises:
[0016] The single parameter acquisition method is used for dark spot egg, wherein the photosensitivity parameter of the fixed egg acquisition is ensured to be the same to ensure that the transmittance of the image sample is the same, and one image sample is collected for each dark spot egg.
[0017] Optionally, the pretreatment of the egg dark spot image sample comprises:
[0018] The linear scaling algorithm is used to convert the egg dark spot image sample into an 8-bit image.
[0019] Optionally, the pretreatment of the egg dark spot image sample further comprises:
[0020] On the basis of 8-bit image, the Gaussian blur algorithm is used to select the dark spot boundary;
[0021] The obtained dark spot boundary image is enhanced by using a linear enhancement algorithm, and then the dark spot boundary image is added to the original 8bit image by using a linear light fusion mode, so as to meet the prerequisite of rapid establishment and test of the random forest algorithm model.
[0022] Optionally, the pre-processing of the egg dark spot image sample comprises:
[0023] Step 2.1, automatically color threshold screening of the obtained dark spot image sample, selecting the complete egg into the ROI, and performing reverse selection, setting the pixel value of the region after reverse selection to 0, and removing the background noise;
[0024] Step 2.2, using the dark spot image sample after removing the background noise, using a bilinear interpolation algorithm to scale the original image to 1 / 4 of the original size, and performing three sample copying, after copying, sample 1 is named as 8bit, sample 2 is named as dealing, and sample 3 is named as origin, and the RGB color space is converted to 8bit for subsequent processing;
[0025] Step 2.3, Gaussian blur algorithm processing is performed on the image sample 2-dealing, and the sigma value is fixed as 2; using subtraction operation to subtract the sample 2-dealing image after Gaussian blur from the sample 1-8bit, and using multiplication operation on the subtraction operation result, and the enhancement value is fixed as 15, to obtain the dark spot contour feature image of the dark spot image sample;
[0026] Step 2.4, adding the obtained dark spot contour feature image and sample 3-origin to obtain a dark spot image sample after the dark spot contour is enhanced, and performing 8bit operation on the sample to automatically identify the dark spot region.
[0027] Optionally, the feature value extraction from the egg dark spot image sample comprises:
[0028] An image sample obtained after pre-processing is subjected to image feature extraction, and five different image feature filters including Gaussian blur, Gaussian function difference, membrane projection, Hessian matrix and Sobel filter are used to extract image features in the image sample, so as to meet the single decision tree basic structure unit of the random forest algorithm.
[0029] Optionally, the feature value extraction from the egg dark spot image sample comprises:
[0030] 3.1, inputting the 8bit image sample obtained after pre-processing into the weka algorithm, to use Gaussian blur, Hessian matrix, Sobel filter, Gaussian difference and membrane projection to collect feature data;
[0031] 3.2, Gaussian blur is performed on the image, n times of independent convolution are performed on each pixel with n sigma changes, the larger the radius, the more blurred the image, until the pixel homogenization stops;
[0032] 3.3, the approximate value of the image intensity gradient of each pixel is calculated, Gaussian blur with sigma value changes is performed before filtering, and then a Sobel filter is applied to perform pixel value differentiation in the horizontal and vertical directions, so that the approximate value of the image gradient can be obtained, and the influence of noise can be reduced when operating around the pixel to obtain the contour feature;
[0033] 3.4, the feature value is extracted, a 2x2 Hessian matrix is calculated at each pixel, Gaussian blur with sigma value changes is performed before filtering, and the following features are obtained at each pixel through matrix operation: mode, trace, determinant, first eigenvalue, second eigenvalue, maximum direction value of second derivative, gamma normalized square eigenvalue difference, square of gamma normalized eigenvalue difference;
[0034] 3.5, two Gaussian blurred images are calculated from the original image, and one is subtracted from the other; the sigma value changes as usual, so n(n-1) / 2 feature images are added to the features;
[0035] 3.6, membrane projection enhances the membrane structure of the image by directional filtering; the initial kernel of this operation is hard-coded as a 19x19 zero matrix, with the middle column entries set to 1; by rotating the original kernel by 6 degrees at most 180 degrees, 30 kernels are generated, thereby creating multiple kernels; each kernel is convolved with the image, and then the 30 images Z are projected into a single image by the following 6 methods, including the sum, average, standard deviation, median, maximum pixel and minimum pixel of the pixels in each image.
[0036] Optionally, the model construction of the random forest includes:
[0037] An 8-bit dark spot image sample with obvious dark spot features is selected and imported into the Trainable Weka Segmentation platform to implement the random forest algorithm and the dark spot image modeling process.
[0038] Optionally, the feature value is input into the random forest algorithm, and the model construction of the random forest includes:
[0039] 4.1, the generation of decision tree; input all the feature values into the stack, and independently generate a decision tree for each feature category; the type of decision tree is a CART tree, for each value a of each feature A, according to the test of sample points for A=a, D is divided into D1 and D2, and the Gini index of A=a is calculated;
[0040] 4.2, in all features A and all possible split points a, the feature and the split point with the minimum Gini index are selected, and the data set is distributed to two sub-nodes; the above operation is repeated until all sub-nodes are generated, and a CART tree is generated;
[0041] 4.3, bagging is applied to the whole feature sample, the size of the training set is N, for each tree, N training samples are randomly and with replacement from the training set, and this sampling method is called bootstrap sample method, as the training set of the tree;
[0042] 4.4, if the feature dimension of each sample is M, a constant m << M is specified, m feature subsets are randomly selected from M features, and the optimal feature is selected from the m features during each tree splitting;
[0043] 4.5, each tree is grown to the maximum extent, and there is no pruning process.
[0044] Optionally, the input image sample to be tested is automatically identified by using the random forest algorithm, and the area ratio is calculated, comprising:
[0045] The image sample to be tested is substituted into the random forest algorithm, the decision tree selection and binary calculation are performed through the feature bagging process, and the output result is output;
[0046] 5.1, for each image sample to be tested, input the random forest model for prediction, and calculate the classification of the tree as an oob sample, 1 / 3 of the tree, and then take a simple majority vote as the classification result of the sample;
[0047] 5.2, the selected image is converted to 8 bits, and image binarization and gap filling are performed to obtain a dark spot area standard image, and statistical analysis is performed to obtain the dark spot area ratio.
[0048] The technical effects that can be obtained by the application are as follows:
[0049] (1) The labor intensity of the detection personnel in the current egg dark spot manual grading method is high, and the detection personnel is easily affected by personal subjective factors, so that the egg dark spot quality evaluation cannot be objectively, accurately and consistently reflected.
[0050] (2) In order to obtain the feature image of dark spots, the present invention has built an egg candling image acquisition system to collect samples of dark spot images; it solves the problems of high system construction cost, insufficient sample quantity, and model overfitting in previous studies on egg dark spot detection.
[0051] (3) This invention applies the machine learning random forest algorithm to the automatic measurement of dark spots on eggs. It can efficiently perform regression, classification and predictive analysis on a large number of samples. The rank correlation P value of the experiment for measuring dark spots on eggs with various eggshell colors is less than 0.001, which proves that the egg dark spot detection method based on the machine learning random forest algorithm can replace the manual rating method, with high accuracy and ease of use.
[0052] (4) This method requires far fewer samples to build the model than other algorithms, and only requires CPU hardware. It is fully automatic, highly feasible, and has extremely strong correlation. This invention provides a new method for detecting dark spots on eggs, which will play a significant role in egg quality testing in my country. Attached Figure Description
[0053] Figure 1 This is a flowchart illustrating the egg spot detection method based on the machine learning random forest algorithm used in this invention.
[0054] Figure 2 This is a schematic diagram illustrating the principle of the random forest algorithm used in this invention;
[0055] Figure 3 These are the automatic measurement results of dark spots in two groups of samples from embodiments of the present invention;
[0056] Figure 4 shows the linear regression analysis of the automatic measurement results of dark spots and the artificial dark spot level scores of the samples in the embodiment of the present invention.
[0057] Figure 5 This is a standard rating chart for artificial dark spots. Detailed Implementation
[0058] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it.
[0059] like Figure 1 The flowchart shown is a method for detecting dark spots on eggs based on the random forest algorithm of machine learning. The method may include the following steps:
[0060] S100. Set up an egg candling image acquisition system to collect dark spot image samples of the eggs to be tested.
[0061] Specifically, the egg image acquisition system can be composed of a camera unit, an illumination unit and a device support. The camera unit can use a common commercially available camera device, for example, the camera adjustable parameter mode of a smart phone can be used. The camera unit uses the camera adjustable parameter mode of the smart phone, and the adjustable parameter fixed value is respectively ISO 200, shutter speed 1 / 20, and white balance 2800K. The illumination unit can use a common commercially available light source, for example, a white LED point light source is used. The illumination unit uses a white LED point light source with a diameter of 135 mm and a luminous flux of 1000 lm.
[0062] Specifically, a single parameter acquisition mode is used for dark spot eggs, wherein the ISO parameter for collecting the eggs is fixed to ensure that the light transmittance of the image samples is the same, one image sample is collected for each dark spot egg, and one image sample is collected for each normal egg.
[0063] S110, pre-processing the dark spot image samples of the eggs.
[0064] Considering that the colors of the collected dark spot egg images are different, and the colors of the dark spot features of each egg are also different, the linear scaling algorithm can be used to convert the dark spot image samples of the eggs into 8-bit images. Since the collected dark spot image samples are red images, the dark spot color of the eggs is yellowish red, and the color difference between them is not significant. In order to improve the color difference, the dark spot image samples are pre-processed. On the basis of the 8-bit image, the dark spot boundary is selected by using the Gaussian blur algorithm, the dark spot boundary image is enhanced by using the linear enhancement algorithm, and then the dark spot boundary image and the original 8-bit image are added by using the linear light fusion mode, so as to meet the prerequisite for quickly establishing and testing the random forest algorithm model.
[0065] Specifically:
[0066] Step one: automatically color threshold screening of the obtained dark spot image samples, selecting complete eggs into ROI, and performing reverse selection. The pixel value of the region after reverse selection is set, and the set value is fixed as 0, so as to remove background noise.
[0067] Step two: using the dark spot image sample after removing the background noise, using the bilinear interpolation algorithm to scale the original image to 1 / 4 of the original size, and performing three sample copying. After copying, sample 1 is named 8bit, sample 2 is named dealing, and sample 3 is named origin, and the RGB color space is converted to 8bit for subsequent processing.
[0068] Step three: Gaussian blur algorithm is processed to the image sample 2-dealing, and the sigma value is fixed as 2. The sample 1-8bit is subtracted from the sample 2-dealing image after Gaussian blur using subtraction operation, and the subtraction result is multiplied to obtain the dark spot profile feature image of the dark spot image sample, and the enhancement value is fixed as 15.
[0069] Step four: the obtained dark spot profile feature image is added to the sample 3-origin to obtain a dark spot image sample after the dark spot profile is enhanced, and the sample is subjected to 8bit operation to automatically identify the dark spot region.
[0070] S120, extracting feature values from the dark spot image sample of the egg.
[0071] An image sample obtained after pretreatment is subjected to image feature extraction, and image features in the image sample are extracted through five different image feature filters including Gaussian blur, Gaussian function difference, membrane projection, Hessian matrix and Sobel filter to meet the single decision tree basic structure unit of the random forest algorithm.
[0072] Specifically:
[0073] Step five: the 8bit image sample obtained after pretreatment is input into the weka algorithm to collect feature data using Gaussian blur, Hessian matrix, Sobel filter, Gaussian difference and membrane projection;
[0074] Step six: Gaussian blur is performed on the image, n times of independent convolution are performed on each pixel with n sigma normal changes, the larger the radius, the more blurred the image, until the pixel homogenization stops;
[0075] Step seven: the approximate value of the image intensity gradient of each pixel is calculated. Gaussian blur with sigma normal change is performed before filtering, and then Sobel filter is applied to difference the pixel values in the horizontal and vertical directions to obtain the approximate value of the image gradient, which can reduce the influence of noise when operating around the pixel to obtain the profile feature.
[0076] Step eight: extracting feature values. A 2x2 Hessian matrix is calculated at each pixel, Gaussian blur with sigma normal change is performed before filtering, and the following features are obtained at each pixel through matrix operation: module, track, determinant, first eigenvalue, second eigenvalue, maximum direction value of second derivative, gamma normalized square eigenvalue difference, square of gamma normalized eigenvalue difference;
[0077] Step nine: Two Gaussian blurred images are computed from the original image and one is subtracted from the other. The sigma values vary as usual, so n(n-1) / 2 feature images are added to the features;
[0078] Step ten: Membrane projection enhances the membrane-like structure of the filtered image by directional filtering. The initial kernel for this operation is hard-coded as a 19x19 zero matrix with the middle column entries set to 1. By rotating the original kernel by 6 degrees up to 180 degrees, 30 kernels are produced, creating multiple kernels. Each kernel is convolved with the image and then the 30 images Z are projected into a single image by the following 6 methods, including the sum, mean, standard deviation, median, maximum pixel, and minimum pixel of the pixels in each image.
[0079] S130, input the feature values into the random forest algorithm, and perform model construction of the random forest.
[0080] An 8-bit dark spot image sample with obvious dark spot features is selected and imported into the Trainable Weka Segmentation platform to implement the random forest algorithm and the dark spot image modeling process.
[0081] Specifically:
[0082] Step eleven: Generation of decision tree. All feature values calculated in step S120 are input into the stack, and a decision tree is independently generated for each feature category. The type of decision tree is CART tree. For each value a of each feature A, the sample points are tested for A=a as yes or no, D is divided into D1 and D2, and the Gini index of A=a is calculated;
[0083] Step twelve: In all features A and all possible split points a, the feature and split point with the smallest Gini index are selected to divide the data set into two child nodes. Repeat the above operation until all child nodes are generated to generate a CART tree;
[0084] Step thirteen: Apply bagging to the entire feature sample, and the training set size is N. For each tree, N training samples are randomly and with replacement from the training set, which is called bootstrap sample method, as the training set of the tree;
[0085] Step fourteen: If the feature dimension of each sample is M, specify a constant m << M, and randomly select a subset of m features from the M features. Each time the tree is split, the optimal feature is selected from the m features;
[0086] Step fifteen: Each tree is grown to the maximum extent and there is no pruning process.
[0087] S140, input the image sample to be tested, utilize the random forest algorithm to complete automatic identification of the dark spot, and calculate the area ratio thereof.
[0088] The image sample to be tested is substituted into the random forest algorithm, decision tree selection and binary calculation are performed through a feature bagging process, and an output result is obtained.
[0089] Specifically, the obtained training model, the sample to be tested and the label are brought into the random forest algorithm input and output for calculation, a bagging algorithm is adopted to correct and avoid overfitting. After obtaining the selection result, the obtained selected image is converted into 8 bits, image binarization and gap filling are performed, a dark spot area standard image is obtained, and statistical analysis is performed to obtain the dark spot area ratio.
[0090] The principle diagram of the random forest algorithm adopted in the application is shown in Figure 2 The machine learning random forest algorithm is applied to automatic measurement of egg dark spots, can efficiently perform regression, classification and prediction analysis on a large number of samples, and the rank correlation P value of the experiment for measuring dark spots of eggs with various eggshell colors is less than 0.001 (see the embodiment for details), proving that the egg dark spot detection method based on the machine learning random forest algorithm can replace the artificial grading method, has high accuracy and strong usability. The sample quantity required for model construction of the method is much less than that of other algorithms, and only CPU hardware requirements are needed, and the method is fully automatic, has high feasibility and strong correlation. The application provides a new method for egg dark spot detection, and will play a great role in egg quality detection in China. Specific embodiment: dark spot detection of eggs with different eggshell colors
[0091] According to the egg dark spot detection method based on the machine learning random forest algorithm, the dark spot area ratio of Jingfen No. 6 egg samples and green shell egg samples from a certain chicken farm is calculated.
[0092] Collection of egg dark spot image samples: 60 eggs are used for collection of dark spot image samples, and the adjustable parameters are fixed at a value of 200 for sensitivity, 1 / 20 for shutter speed, and 2800K for white balance. The illumination unit adopts a white LED point light source with a diameter of 135mm and a luminous flux of 1000lm. The single sample collection method is used for dark spot eggs, and one image sample is collected for each normal egg.
[0093] Feature pre-processing of dark spot image samples: The collected dark spot image samples of eggs are red images, and the dark spot color of eggs is yellowish red, which has no significant color difference. Therefore, the dark spot image samples are pre-processed as follows: a. The obtained dark spot image samples are automatically color threshold screened, the complete eggs are selected into the ROI, and the reverse selection is performed. The pixel value of the region after reverse selection is set to 0, and the background noise is removed; b. The dark spot image sample after removing the background noise is scaled using the bilinear interpolation algorithm, the original image is scaled to 1 / 4 of the original size, and three samples are copied. After copying, sample 1 is named 8bit, sample 2 is named dealing, and sample 3 is named origin, and the RGB color space is converted to 8bit for subsequent processing; c. The image sample 2-dealing is processed by the Gaussian blur algorithm, and the σ value is fixed at 2. The sample 1-8bit is subtracted from the sample 2-dealing image after Gaussian blur using subtraction operation, and the subtraction result is multiplied by 15 to obtain the dark spot profile feature image of the dark spot image sample; d. The obtained dark spot profile feature image and sample 3-origin are added to obtain a dark spot image sample with enhanced dark spot profile, and the sample is subjected to 8bit operation for automatic dark spot region recognition;
[0094] Feature extraction and modeling of dark spot region: select an 8bit dark spot image sample with obvious dark spot features, and import it into the Trainable Weka Segmentation platform to realize the random forest algorithm and the dark spot image modeling process. a. The pre-processed dark spot image sample is input, part of the dark spot feature image is selected and classified into class1, and the normal eggshell region feature image and the background pixel value of 0 region are selected and classified into class2; b. The training sample and its features obtained in step a are brought into the random forest algorithm, five feature filters including Gaussian blur, Gaussian function difference, membrane projection, Hessian matrix and Sobel filter are used to extract the image feature values in the image sample, and the model result is output and saved.
[0095] Dark spot region ratio measurement: the obtained training model, test sample and label are input into the random forest algorithm for calculation, and the bagging algorithm is used for correction to avoid overfitting. After obtaining the selected results, the selected image is converted to 8bit, and image binarization and gap filling are performed to obtain a dark spot region standard image, and statistical analysis is performed to obtain the dark spot area ratio.
[0096] Grouping of test samples:
[0097] A: 60 Jingfen 6 unfertilized eggs from a commercial layer farm in Beijing;
[0098] B: 30 green-shelled eggs from the experimental farm of China Agricultural University.
[0099] Figure 3 are the automatic measurement results of dark spots of two groups of samples, where a is Jingfen No. 6 powder-shelled egg, and b is green-shelled egg of green-shelled egg chicken.
[0100] Figure 4a and Figure 4b are the linear regression analysis results of automatic measurement results of dark spots and artificial dark spot grade scoring of two groups of samples, where Figure 4a is the linear regression analysis result of automatic measurement results of dark spots and artificial dark spot grade scoring of Jingfen No. 6 powder-shelled egg, Figure 4b is the linear regression analysis result of automatic measurement results of dark spots and artificial dark spot grade scoring of green-shelled egg of green-shelled egg chicken.
[0101] Rank correlation analysis, also known as rank correlation analysis, is a statistical quantity obtained by arranging the rank of two sample values according to the size of the data and replacing the actual data with the rank of each individual. It is a statistical analysis index reflecting the degree of rank correlation. The results of Spearman rank correlation analysis between the egg dark spot detection method based on machine learning random forest algorithm and the artificial grading method show that the R values of Jingfen No. 6 powder-shelled egg and green-shelled egg of green-shelled egg chicken are 0.941 and 0.919 respectively, and the p values are less than 0.0001 (see Table 1), which has statistical significance, indicating that there is a strong correlation between the egg dark spot detection method based on machine learning random forest algorithm and the artificial grading method in the detection of dark spots of eggs with different shell colors.
[0102] Table 1, Rank correlation analysis of two groups of samples
[0103] Chicken egg samples N M SD R P Beijing powder No. 6 30 12.72 8.45 0.941 ** ]] <0.0001 Green shell egg chicken 30 34.23 22.67 0.919 ** ]] <0.0001
[0104] Comparative Example: Comparison of Different Detection Methods for Egg Dark Spots
[0105] (1) Artificial dark spot grade scoring method
[0106] Under dark conditions, use LED light to irradiate the egg, fix the photographing equipment, and take photos at the same distance. According to the severity of the light transmission spot under light, the egg shell is divided into 6 levels, and the dark spot scoring standard chart is shown in Figure 5Wherein, 1st grade is excellent, only a few tiny bright spots, no black spots on the eggshell surface under outdoor conditions; 2nd grade is good, a small number of tiny bright spots are distributed, no black spots on the eggshell surface under outdoor conditions; 3rd grade is better, more tiny bright spots are distributed, no black spots on the eggshell surface under outdoor conditions; 4th grade is moderate, a large number of tiny bright spots are distributed, a small number of black spots are on the eggshell surface under outdoor conditions; 5th grade is severe, the surface is densely covered with tiny bright spots and large bright spots, more black spots are on the eggshell surface under outdoor conditions; 6th grade is extremely severe, the surface is densely covered with various bright spots, a large number of black spots are on the eggshell surface under outdoor conditions.
[0107] (2) Convolutional neural network dark spot evaluation method
[0108] The dark spot egg is collected in multiple angles, and after the egg image is collected, the egg is turned over by 90 degrees and collected repeatedly. If there is no dark spot on the eggshell at a certain angle, the egg is not collected, and a normal egg is collected as a single image sample. The above collection is repeated every 1 day, and the sampling period is about 20 days;
[0109] The collected egg transmission light image is yellow close to red, and the egg dark spot color is dark red, and the color contrast between the two is not high. The G component in the RGB space of the egg sample is enhanced by 4 times; then the size of the G enhanced image is reduced to 1 / 8 of the original sample by using the interpolation algorithm, so as to meet the rapid training and testing of GoogLeNet model;
[0110] A total of 1200 dark spot egg images and 8850 normal egg images are obtained. The number of training set and test set is selected according to the ratio of 1:3. In this paper, 900 samples are randomly selected from each category as model training samples, and 300 as test samples. The labels of dark spot eggs and normal eggs are encoded as 0001 and 0010 by one-hot. Then, the training samples and labels are substituted into the input and output of the CNN GoogLeNet model for training, and the stochastic gradient descent algorithm (SGD) is used for weight update. When the error or iteration number reaches the threshold value, the training stops. Finally, the test samples are substituted into the trained network to obtain the test results.
[0111] (3) Eggshell dark spot evaluation method based on machine vision
[0112] The eggs are placed on the image collection device to simulate the workflow of the egg grading process. The whole grading process consists of three key links: feeding, image collection and sorting. When the image is collected, the image of the egg is taken during the transportation process following the egg roller. Therefore, the background of the image will contain part of the conveying device. In order to facilitate subsequent statistical analysis, the background of the image must be removed first, so as to obtain an image containing only the egg.
[0113] In the egg image after removing the background, the contrast of dark spots and normal eggshell has not reached the requirement of completely distinguishing dark spots. Therefore, the non-sharpening mask method is used to further enhance the contrast of dark spots in the present disclosure, and then the image is converted into a binary image to more clearly visualize the distribution of dark spots on the eggshell. Since dark spots are mostly irregular polygons, it is difficult to statistically count dark spots from a geometric perspective. In a two-dimensional image, pixels within an eight-connected region belong to the same object. By counting the number of eight-connected regions in the binary image, dark spot evaluation is achieved.
[0114] (4) Eggshell dark spot evaluation method based on gray scale recognition
[0115] First, it is confirmed that the long diameter of the eggshell is parallel to the y-axis, and the shortest distance between the two tangent lines parallel to the y-axis of the eggshell is the short diameter of the eggshell. Knowing the actual length of the short diameter, the number of pixels of the short diameter in the image can be counted to determine the ratio of the actual length of the eggshell to the length of the image. The dark spots on the eggshell are painted black using Photoshop CS6 software. The spots on the eggshell are extracted using Image-Pro Plus 6.0 software, and the non-transparent area of the eggshell is removed. The contours of the moisture spots and the non-transparent area on the eggshell are extracted by Image-Pro Plus software.
[0116] (5) Eggshell dark spot evaluation method based on color threshold
[0117] The LAB color model is selected for color threshold selection. After collecting the egg images for gray scale recognition, the L, A, and B values of each egg at three locations (blunt head, middle, and sharp head) are measured using a portable spectrophotometer. L represents luminosity, ranging from 0 to 100, corresponding to a change in color from black to white; A ranges from -120 to 120, corresponding to a change in color from green to red; and B ranges from -120 to 120, corresponding to a change in color from blue to yellow.
[0118] The effects of various egg dark spot detection methods are compared in Table 2. As shown in Table 2, the machine learning random forest algorithm proposed in the present disclosure has significant advantages in recognition quality, recognition efficiency, and operability compared to other methods.
[0119] Table 2: Comparison of effects of various egg dark spot detection methods
[0120]
[0121] The above is only a preferred embodiment of the present disclosure and does not limit the present disclosure. Any modifications, equivalent replacements, and improvements made within the spirit and principles of the present disclosure should be included in the protection scope of the present disclosure.
[0122] The computer program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other processing devices to cause a series of operational steps to be performed on the computer, other programmable apparatus or other processing devices to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions specified in the flowchart block or blocks. Figure 1 The flowchart and / or block diagram in the Figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments. In this regard, each flowchart block and / or combination of flowchart blocks can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart block or blocks. Figure 1 These computer program instructions can also be stored in a computer- readable medium that can direct a computer, other programmable data processing apparatus, or other devices to function in a particular manner, such that the instructions stored in the computer-readable medium produce an article of manufacture including instructions which implement the function specified in the flowchart block or blocks.
[0123] In a typical configuration, the device includes one or more processors (CPUs), memory, and a bus. The device can also include input / output interfaces, network interfaces, and the like.
[0124] The memory can include non-persistent memory, random access memory (RAM), and / or non-volatile memory, such as read only memory (ROM) or flash memory, among others, in a computer readable medium. The memory includes at least one memory chip. The memory is an example of a computer readable medium.
[0125] Computer readable media includes permanent and non-permanent, removable and non-removable media implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital versatile disc (DVD), or other optical storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible to a computing device. According to the definition herein, computer readable media does not include transitory media, such as modulated data signals and carrier waves.
[0126] Those skilled in the art will appreciate that embodiments of the present application can be devised for a variety of other systems which are currently developed or later developed. Practice of the embodiments disclosed herein employs, unless otherwise indicated, conventional techniques of the computer and data processing arts. Those skilled in the art will readily recognize a variety of ways of implementing the embodiments described herein, and the application encompasses all such variations and equivalents that fall within the scope of the appended claims. Accordingly, the application should not be limited to only the above described embodiments.
[0127] It has to be understood that any reference to both a first and a second entity or action, for example, does not only imply that these two entities or actions are directly related or connected to each other but it can also mean that, there can be one or several intermediate entities or actions between those two. It has also to be understood that the word "comprise", "comprising" or other forms of this word as used in this text are only meant for the purpose of indicating the presence of the stated features, elements, actions, properties, steps or components and do not exclude the presence of one or more other features, elements, actions, properties, steps or components nor the possibility to add one or more other features, elements, actions, properties, steps or components unless stated otherwise.
[0128] Each of the embodiments described in this specification has been described in a related manner, and the same or similar parts between the embodiments can be mutually referred to. Each of the embodiments focuses on the difference from the other embodiments. In particular, the system embodiments are described in a relatively simple manner because they are basically similar to the method embodiments, and the relevant parts can be referred to the description of the method embodiments.
[0129] The above merely describes the embodiments of the present application and is not intended to limit the present application. The present application can have various modifications and changes for those skilled in the art. Any modification, equivalent replacement, improvement, etc. within the spirit and principle of the present application shall be included in the scope of the claims of the present application.
Claims
1. A method for detecting dark spots in eggs based on a machine learning random forest algorithm, characterized in that the method comprises the following steps: Step 1: Set up an egg image acquisition system to collect dark spot image samples of the eggs to be tested; Step 2: Preprocess the dark spot image samples of the eggs; Step 3: Extract feature values from the dark spot image samples of the eggs; Step 4: Input the feature values into the random forest algorithm to build a random forest model; Step 5: Input the image samples to be tested and use the random forest algorithm to automatically identify the dark spots and calculate their area ratio. The preprocessing of the dark spot image samples of the eggs includes converting the dark spot image samples into 8-bit images using a linear scaling algorithm. Step 3: Extract feature values from the dark spot image samples of the eggs, including: 3.1: Input the 8-bit image samples obtained after preprocessing into the weka algorithm to use Gaussian blur, Hessian matrix, Sobel filter, Gaussian difference, and membrane projection to collect feature data; 3.2: Perform Gaussian blur on the image, and use n sigma changes to perform n independent convolutions on each pixel. The larger the radius, the more blurred the image, until the pixel is uniformized; 3.3: Calculate the approximate value of the image intensity gradient of each pixel. Before filtering, perform Gaussian blur with sigma changes, then apply the Sobel filter to differentiate the pixel values in the horizontal and vertical directions to obtain the approximate value of the image gradient. When operating around the pixel, the influence of noise is reduced, and the contour feature is obtained; 3.4: Extract feature values by calculating a 2x2 Hessian matrix at each pixel. Before filtering, perform Gaussian blur with sigma changes. Through matrix operations, the following features are obtained at each pixel: modulus, trace, determinant, first eigenvalue, second eigenvalue, maximum direction value of second derivative, gamma normalized square feature value difference, and square of gamma normalized feature value difference; 3.5: Calculate two Gaussian blur images from the original image and subtract one from the other; The sigma value changes as usual, so n(n-1) / 2 feature images are added to the features; 3.6: Membrane projection enhances the membrane structure of the image through directional filtering. The initial kernel of this operation is hard-coded as a 19x19 zero matrix with the middle column entries set to 1. By rotating the original kernel by 6 degrees up to 180 degrees, 30 kernels are generated, creating multiple kernels. Each kernel is convolved with the image, and then the 30 images Z are projected into a single image through the following 6 methods, including the sum, average, standard deviation, median, maximum pixel, and minimum pixel of each pixel in the image. The collection of dark spot image samples of the eggs to be tested includes:
2. The method for detecting dark spot of egg based on machine learning random forest algorithm according to claim 1, characterized in that, Using a single parameter collection method for dark spot eggs, where the photosensitivity parameter for collecting eggs is fixed to ensure that the transmittance of the image samples is the same, and one image sample is collected for each dark spot egg. The preprocessing of the dark spot image samples of the eggs also includes: 3.The method of claim 1, wherein the method comprises: On the basis of the 8bit image, a Gaussian blur algorithm is used to select a dark spot boundary; A linear enhancement algorithm is used to enhance the obtained dark spot boundary image, and then a linear light fusion mode is used to perform addition operation on the dark spot boundary image and the original 8bit image, so as to meet the prerequisite for rapid establishment and test of the random forest algorithm model.
4. The method for detecting dark spot of egg based on machine learning random forest algorithm according to claim 1, characterized in that, The preprocessing of the egg dark spot image sample includes: Step 2.1, automatically color threshold screening of the obtained dark spot image sample, selecting the complete egg into the ROI, and performing reverse selection, setting the pixel value of the region after reverse selection to 0, and removing the background noise; Step 2.2, using a bilinear interpolation algorithm to scale the dark spot image sample after removing the background noise, scaling the original image to 1 / 4 of the original size, and performing three sample replication, after replication, sample 1 is named 8bit, sample 2 is named dealing, and sample 3 is named origin, and the RGB color space is converted to 8bit for subsequent processing; Step 2.3, Gaussian blur algorithm processing is performed on the image sample 2-dealing, and the sigma value is fixed at 2; Using subtraction operation to subtract sample 1-8bit from the Gaussian blurred sample 2-dealing image, multiplying the subtraction operation result, and the enhancement value is fixed at 15, to obtain the dark spot contour feature image of the dark spot image sample; Step 2.4, performing addition operation on the obtained dark spot contour feature image and sample 3-origin, to obtain a dark spot image sample with enhanced dark spot contour, and performing 8bit operation on the sample to automatically identify the dark spot region.
5. The method for detecting dark spot of egg based on machine learning random forest algorithm according to claim 1, characterized in that, The feature value extraction from the egg dark spot image sample includes: An image sample obtained after preprocessing is subjected to image feature extraction, and five different image feature filters including Gaussian blur, Gaussian function difference, membrane projection, Hessian matrix and Sobel filter are used to extract image features in the image sample, so as to meet the single decision tree basic structure unit of the random forest algorithm.
6. The method for detecting dark spot of egg based on machine learning random forest algorithm according to claim 1, characterized in that, The random forest model construction includes: An 8bit dark spot image sample with obvious dark spot features is selected and imported into the Trainable WekaSegmentation platform to realize the random forest algorithm and the dark spot image modeling process.
7. The detection method as described in claim 1, characterized in that, The feature value input into the random forest algorithm for random forest model construction includes: 4.1, generation of decision tree; all the feature values are input into the stack, and a decision tree is independently generated for each feature type; the type of decision tree is CART tree, for each value a of each feature A, according to the test of sample point A=a as yes or no, D is divided into D1 and D2, and the Gini index of A=a is calculated; 4.2, among all the features A and all the possible split points a, the feature and the split point with the smallest Gini index are selected, and the data set is distributed to two child nodes; repeat the above operation until all the child nodes are generated, and a CART tree is generated; 4.3, bagging is applied to the whole feature sample, the training set size is N, for each tree, N training samples are randomly and with replacement drawn from the training set, this sampling method is called bootstrap sample method, as the training set of the tree; 4.4, if the feature dimension of each sample is M, a constant m << M is specified, m feature subsets are randomly selected from M features, and the optimal feature is selected from the m features each time the tree is split; 4.5, each tree is grown to the maximum extent and there is no pruning process.
8. The method for detecting dark spot of egg based on machine learning random forest algorithm according to claim 1, characterized in that, Step 5 inputs the image sample to be tested, uses the random forest algorithm to complete automatic identification of the dark spot, and calculates the area ratio, including: The image sample to be tested is substituted into the random forest algorithm, the decision tree selection and binary calculation are performed through the feature bagging process, and the output result is obtained; 5.1, for each image sample to be tested, input the random forest model for prediction, and calculate the classification of the tree as an oob sample, 1 / 3 of the tree, and then take a simple majority vote as the classification result of the sample; 5.2, the selected image is converted to 8bit, and image binarization and gap filling are performed to obtain a dark spot area standard image, and statistical analysis is performed to obtain the dark spot area ratio.
Citation Information
Patent Citations
Visual characteristic-based bionic adaptive fuzzy edge detection method
CN105654496A
Dark spot egg detection method based on convolutional neural network GoogLeNet model
CN112164120A