An Improved Multi-Level Set C-V Model for Grading of Korean Pine Seeds

An improved multi-level set C-V model for non-destructive grading of Korean pine seeds is presented in this paper. On the basis of improved Ostu and rough segmentation results of expansion operation, the improved C-V model is used to extract the target contour of Korean pine seeds; the characteristic parameters of fruit length and maximum transverse diameter are extracted by mathematical morphology method, and polynomial fitting is carried out with the actual measured values to construct a mathematical model with better quality; according to the extracted characteristic parameters, a comprehensive evaluation and grading standard for Korean pine seeds is established. The experimental results show that this method can achieve simultaneous classification of multiple Korean pine seeds, and the average accuracy of classification can be up to 97.2%.


Introduction
Korean pine seeds have been sold to more than 20 countries and regions all over the world. The output benefit of planting Korean pine seeds is becoming increasingly prominent. Korean pine seeds have become one of the characteristic cash crops for farmers to increase their income and can bring good economic benefits to our country. But at present, the development and utilization of Korean pine seeds in China is not deep enough, and the market of Korean pine seeds is still in the growth stage. At present, there are the following problems in the Korean pine seed market in China: the commercialization degree of Korean pine seeds is low, and there is no unified standard for the quality division of Korean pine seeds, which makes it difficult to distinguish the quality of Korean pine seeds; the development and utilization of Korean pine seeds and processing depth of Chinese enterprises are not enough, and the high value-added products of Korean pine seeds are few. Korean pine seeds can only be commercialized after postpartum to create greater economic value. As the first step of commercialization, quality classification plays a vital role [1].
With the continuous development of computer technology, the grading of agricultural and sideline products is gradually developing towards visualization and automation [2][3][4][5][6][7]. Traditional grading of Korean pine seeds is usually achieved by manual sorting or mechanical vibration screening, which needs a lot of labor, has low grading accuracy, and Korean pine seeds are prone to collision and knock [8]. In this study, partial differential equation (PDE) method was applied to the classification of Korean pine seeds. The improved multi-level set C-V model was used to extract multiple Korean pine seeds simultaneously. According to the extracted contour information, the characteristic parameters such as fruit length and maximum transverse diameter were further obtained. According to the characteristic parameters, a comprehensive grading evaluation model of Korean pine seeds was

Experimental materials and equipment
The raw Korean pine seed samples were provided by the Liangshui National Nature Reserve in Yichun City, Heilongjiang Province. Before the experiment, all the Korean pine seed samples were stored at the conditions of a relative humidity of 50-60% and a temperature of -1~2 °C according to the pine nut storage standards. The Korean pine seed samples were sequentially numbered and the image data was collected.
The hardware system device for image acquisition of Korean pine seeds is shown in figure 1, and the schematic diagram is shown in figure 2. Among them, the camera is the AT-200CL 3CCD color camera of Denmark JAI Company, the lens is M2514-MP2 lens of Computer Company of Japan, the image acquisition card is X64-Xcelera-CL PX4 Dual, the light source is LED, the computer is Chinese Lenovo H3050 desktop computer.

Multiple objective extraction of Korean pine seeds based on improved multi-level set C-V model.
According to the difference of the average gray level between the target and background of Korean pine seeds, the closed curve can be used to segment the target and background areas of the image. The gray level average inside and outside the curve reflects the difference of the average gray level between the target and the background. Then the closed curve can be regarded as the outline of the Korean pine seed [9]. The energy function of C-V model with multi-level set is shown in equation 1 [10].
Wherein, i c is the average gray value of the target and background of Korean pine seeds, n is the number of different segmentation regions and m is the number of level sets, Since the initial embedding function   y x u , 0 is a distance function, it will deviate after a few iterations, so it needs to be initialized again. Therefore, a control unit is introduced into the energy function of multi-level set C-V model to improve the extraction rate of Korean pine seeds target: 2. An initial contour extraction method based on modified Ostu and morphology. Closed curve motion based on level set method maps two-dimensional curve into three-dimensional space, which greatly increases the computation of data and the iteration time of closed curve. If the initialized embedding function   y x u , 0 begins to iterate near the target, it will reduce the complexity of the operation, reduce the iteration time and improve the speed of segmentation. The traditional Ostu method uses the gray mean to represent the object and background. It mainly considers the whole gray characteristics of the object and background, but does not consider the characteristics of the points near the boundary, which results in inaccurate segmentation results [11]. Generally, the gray level distribution in the target area and background area is relatively uniform, while the gray level of the points near the boundary changes greatly, and the gray level change of the image boundary points can be approximated by the mean square deviation. Therefore, the average in Ostu is replaced by the mean square deviation, and: are target mean square error, background mean square error and total mean square error. And are target average, background average and total average, respectively. ) (i p is the frequency with gray value of i . Then the segmentation results of Korean pine seeds obtained by the improved Ostu method are as follows:  From the above segmentation results, we can see that there are holes in Korean pine seed targets (as shown in figure 4), so it needs to fill holes. It can be achieved by mathematical morphology operation, that is, using expansion operation to remove holes in the target area. Expansion operation is to merge the points contacted with the target area into the target area and increase the corresponding number of pixels in the target area [12]. The results of 2 times expansion in figure 3 is as shown in figure 5. The rough segmentation results of improved Ostu and morphology are used as the initial closed curve of improved C-V model, and the final segmentation results of Korean pine seeds are obtained. Figure 6 shows the initial closed curve of multi-level set obtained by improved Ostu and morphology. Figure 7 shows the contour of multi-Korean pine seeds obtained by improved multi-level set C-V model. The contour results are superimposed on the original gray-scale image to observe the accuracy of the extracted Korean pine seeds contour information.

Controlled experiment.
Using the methods described above, the target contours of Korean pine seeds were extracted by using C-V model, improved C-V model, improved Ostu model and improved C-V model of morphology.
In experiment 1, firstly, the image is smoothed and denoised by Gaussian, then the image is segmented by classical C-V model. Finally, the segmentation results are smoothed and denoised by Gaussian. In experiment 2, firstly, the image is smoothed and denoised by using the improved C-V model. Finally, the segmentation results are smoothed and denoised by using the improved C-V model. In experiment 3, firstly, the image is smoothed and denoised by using the rough segmentation results of improved Ostu and morphology as the initial closed curve of the improved C-V model, and then the image is segmented by using the improved C-V model. Finally, the segmentation results are smoothed and denoised by using the improved C-V model. Figure 8 shows two original gray images of individual Korean pine seeds randomly selected.
(a) (b) Figure 8. Single pine seed primitive gray image. As shown in figure 9 below, the results of contour extraction in controlled experiment are shown.  By comparing the results of the images, we can see that the contour extraction results of Korean pine seeds obtained by the experiment 1 are not convergent through the partial enlargement of the images of figure 9 (a) and figure 9 (d); The results of contour extraction by the experiment 2, at the top of figure 9 (b) and the bottom of figure 9 (e) are not completely close to the contour edge of the Korean pine seed object, that is, the contour results of the Korean pine seed object extracted are incomplete, while the contour extraction results obtained by the method of Experiment 3 are more accurately close to the edge of the Korean pine seed contour, and the target segmentation of the Korean pine seed object is better achieved.
The experimental results were further compared and analyzed in the form of charts. The comparison results are shown in table 1 below. From table 1, it can be seen that compared with experiment 2, the number of iterations and running time of experiment 3 are reduced by 93.33% and 95.71% respectively, and 37.55% and 43.08% respectively. The speed of approaching the contour edge of the Korean pine seed target is the fastest. Therefore, the Korean pine seed contour extraction method proposed in this study can achieve target segmentation more quickly, effectively and accurately.

Extraction of characteristic parameters.
From the shape analysis, Korean pine seeds are fruit apex and fruit base width, an obovate-triangle. The distance between the top and the bottom of Korean pine seed is called "fruit length". Vertical to the fruit length, the maximum width distance is called "transverse diameter". The characteristics of Korean pine seed can be characterized comprehensively and accurately by the fruit length and transverse diameter of Korean pine seed (as shown in figure 10). The determination of Korean pine seed length: the maximum distance between two points on the outline of Korean pine seed, the formula of calculating the distance between two points is as follows: Wherein,       Figure 13. Flow chart of algorithm.

Experimental materials and equipment
The statistical results of fruit length and maximum transverse diameter of the Korean pine seeds selected in this study are shown in figure 14 and figure 15. From figure 14 and figure 15, it can be seen that the fruit length of Korean pine seed samples ranged from 11.5 mm to 17 mm, and the maximum transverse diameter ranged from 6.5 mm to 11 mm. The average fruit length of Korean pine seeds was 14.47 mm and the mean square error was 1.08 mm. The percentage of Korean pine seeds whose fruit length distribution ranged from 12.5 mm to 16 mm was 76.13% of the total samples and the median was 14.52 mm in figure 14; The average maximum transverse diameter of Korean pine seeds was 9.11 mm and the mean square error was 0.77 mm. Among them, 83.69% of the total samples were Korean pine seeds whose maximum transverse diameter ranged from 7.5 mm to 10 mm. In figure 15, 9.06 mm was the median. The distribution of fruit length and maximum transverse diameter of the Korean pine seeds all have a certain normal distribution characteristics, which indicates the rationality of the samples selected in the experiment.  According to the ratio of 7:1, the calibration set and validation set of Korean pine seed samples were divided. Among them, the calibration set of Korean pine seed samples was used to establish the mathematical model, and the verification set of Korean pine seed samples was used to validate the model. In order to establish the mathematical model of Korean pine seed fruit length and maximum transverse diameter, the fitting results of primary polynomial and quadratic polynomial are shown in figure 16, figure 17, figure 18, figure 19 respectively.
The model evaluation parameters of the four mathematical models, RMSE standard deviation and R-square determination coefficient, were calculated respectively. Through comparative analysis, the better mathematical models of Korean pine seed fruit length and maximum transverse diameter were determined.     From table 2, it can be seen that the mathematical model constructed by quadratic fitting is more ideal for the fruit length of Korean pine seeds, and the mathematical model constructed by one-time fitting is more ideal for the maximum transverse diameter of Korean pine seeds. Among them, the RMSE and R-square of the mathematical model of Korean pine seed fruit length were 0.3412 and 0.9301 respectively, and that of the mathematical model of Korean pine seed maximum transverse diameter were 0.4165 and 0.7755 respectively.

Model validation
The validation set of Korean pine seeds was used to validate the established model of fruit length and maximum transverse diameter of Korean pine seeds. Figure 20 shows the extraction results of characteristic parameters of fruit length and maximum transverse diameter of multiple Korean pine seeds with different numbers, different emission locations and different morphologies. times respectively, and the iteration times of improved C-V model are 4 times, 8 times and 6 times respectively, showing that the time to extract the final feature parameters is 4.1094s, 5.1406s and 5.0469s respectively. In the process of extracting the characteristic parameters of multiple Korean pine seed targets, the order of computer discrimination is given from left to right and from top to bottom, that is, the order labeled in figure 20 is used to display the results.
Precision is used to describe the prediction accuracy of the model of fruit length and maximum transverse diameter. The calculation formula of accuracy is as follows: Wherein, r D represents the measured values, f D represents the predicted value of the model. The average prediction accuracy M of fruit length model was 98.54%, and that of maximum diameter model was 97.66%.

Standard for comprehensive evaluation and grading of Korean pine seeds
At present, there is no clear grading standard for Korean pine seeds. Therefore, this study classifies Korean pine seeds according to the law of consumers' selection and purchase, combining with the fruit length and the maximum transverse diameter of Korean pine seeds. The grading standard is shown in table 3. According to the fruit length and the maximum transverse diameter of Korean pine seeds, three grades of Korean pine seeds were classified, i.e. first-class, second-class and substandard. The weight of fruit length and maximum transverse diameter accounted for 55% and 45% respectively in the comprehensive evaluation classification standard. The formula for calculating the comprehensive evaluation classification standard was as follows: Wherein, W is comprehensive grading score. It is suggested that the score of first-class products should be greater than 13.3, that of second-class products should be between 10.25 and 13.3, and that of unqualified products should be less than 10.25.
In order to verify the reliability and accuracy of the grading method, 2200 samples of Korean pine seeds were randomly selected and screened by traditional mechanical vibration. The first-class products were 486, the second-class products were 1456, and the substandard products were 258; Using the method in this study to classify the products, the first-class products were 500, the secondclass products were 1432, and the substandard products were 268. The classification results were basically the same. The accuracy rates of the first-class, second-class and substandard products were 97.1%, 98.4% and 96.1% respectively, and the average classification accuracy was 97.2%. The reason for the difference of grading results is that the grading method in this study considers the comprehensive characteristics of Korean pine seeds, while the traditional mechanical vibration screening only relies on the single direction diameter of Korean pine seeds for grading. The grading results in this paper are more in line with consumers' visual habits and psychological needs.