
During the growth of apples, they are very susceptible to the behavior of various borers, resulting in holes on the surface of apples caused by insects, which makes them lose their edible value and reduces their quality and commercial value. Therefore, whether apples are damaged by insects is one of the key indicators for judging the quality grade of apples. However, in the actual apple quality inspection and grading system, the apples are mainly graded based on indicators such as size and color, while the detection of insect defects still relies on manual visual inspection. This working method is inefficient and inaccurate, and it is difficult to ensure that the inference technology and spectral analysis are technologies that correlate the value of fruit quality information, with the advantages of being fast, non-destructive and reliable. The inference technology mainly successfully evaluates the research on the grading of apples in terms of size, color, shape, etc., and can also detect some defects on the surface of apples. Hyperspectral imaging technology combines the advantages of image processing and spectral analysis to quickly and non-destructively detect the internal characteristics of the research object. In recent years, it has been widely used in the detection technology of poor fruit quality.
1. Materials and Methods
1.1 Test samples The research object selected for this experiment was Red Fuji apples, and 160 apples were collected from the apple planting demonstration garden. The fruit diameter of these fruits ranged from 68.5 to 88 mm, and the mass ranged from 128 to 211 grams. Among them, 80 were worm-damaged apples. These worm-damaged apples were eaten by heartworms, leaving holes. The holes and the surrounding ulceration areas were about 7 to 50 mm; the other 80 were normal apples, and the fruit stalk/calyx area was about 50 to 120 mm. 50 were randomly selected from the worm-damaged apples and 50 from the normal apples to construct an algorithm for identifying apple worm damage and fruit stalk/calyx, and the remaining samples were used to verify the algorithm.
1.2 Hyperspectral image acquisition system
This study applied a 400-1000nm hyperspectral camera, and the FS13 product of Hangzhou Caipu Technology Co., Ltd. can be used for related research. The spectral range is 400-1000nm, the wavelength resolution is better than 2.5nm, and up to 1200 spectral channels. The acquisition speed can reach 128FPS in the full spectrum, and the highest after band selection is 3300Hz (supporting multi-region band selection).

2. Results and Analysis 2.1 Analysis of Relative Reflectance Spectral Curves The reflectance spectral curves of the regions of interest (injured area, fruit stalk area, calyx area and normal area) extracted from 80 apple insect-damaged samples and 80 normal apple samples were analyzed. The average relative reflectance spectral curves of samples of the same type are roughly the same, and the shapes and regularities of these reflectance spectral curves have little correlation with the number of samples. Figure 2 shows the average relative reflectance spectral curves of 160 samples in the range of 400 to 1000 nanometers.

As can be seen from Figure 2, there are certain differences in the reflectance spectrum curves of the insect-injured part of apples and the stalk area, calyx area and normal area. In the wavelength range of 500 to 1000 nanometers, the relative reflectance of the normal area is higher than that of the insect-injured part and the stalk area and calyx area. At 680 nanometers, there is an absorption peak in the spectral reflectance of the normal area, which is mainly caused by the absorption of chlorophyll on the surface of the fruit, reflecting the surface color information of the fruit. After the apple is invaded by insects, holes are formed on the surface of the apple, where chlorophyll is missing, and its color is significantly different from the normal surface, so the reflectance of the insect-injured area at 680 nanometers is greatly reduced compared with the normal area; at the same time, the chlorophyll content in the stalk area and calyx area is also low, so the reflectance of the stalk area and calyx area is also relatively low. Between 500 and 700 nanometers, the average relative reflectance of the insect-injured area is lower than the spectral relative reflectance of the stalk area and calyx area. Between 750 and 900 nanometers, the average relative reflectance of the insect-damaged area is between the spectral relative reflectance of the pedicel/calyx area. In most samples, the relative reflectance of the insect-damaged area is less than that of the calyx area, but greater than that of the pedicel area. 2.2 Division of regions of interest As shown in Figure 2, in the wavelength range of 800 to 980 nanometers, the relative reflectance between the insect-damaged area and the pedicel/calyx area is the largest at 900 nanometers, but the spectrum difference between the insect-damaged area and the normal area is the largest at 824 nanometers, and the relative reflectance difference with the pedicel/calyx area is also large. In the image under this band, the contrast between the insect-damaged area, the pedicel/calyx area and the normal area is strong, so 824 nanometers is selected as the characteristic wavelength, and the image under this wavelength is the characteristic image, as shown in Figures 3a, 3b, and 3c, which are the characteristic image of insect-damaged apple, the characteristic image of apple calyx part, and the characteristic image of apple pedicel part, respectively.

As can be seen from Figure 3, the grayscale value of the apple area is higher, while the grayscale value of the background area is lower, so the threshold segmentation method can be used to obtain the apple binary image. And the segmented binary image is expanded and eroded to obtain the final apple binary image, as shown in Figure 3d, Figure 3e and Figure 3f. Then use this binary image to mask the hyperspectral image to eliminate background noise, and perform principal component analysis on the masked hyperspectral image. From Figure 2, it can be found that the noise on the apple surface in the range of 400 to 500 meters and 980 to 1000 nanometers is relatively large. In addition, in the range of 500 to 620 and 950 to 980 nanometers, the spectral relative reflectance of the insect-infested area is not much different from the reflectance of the fruit stalk area, calyx area and normal area, so the band between 620 and 950 nanometers is selected for principal component analysis. From the previous analysis, it can be seen that in the band between 750 and 950 nanometers, the relative reflectivity of the insect-damaged area overlaps with the data of the fruit stalk/calyx area, so the segmentation of the insect-damaged area cannot be achieved using a limited band, and only the principal component image with obvious contrast can be selected for segmentation. Figure 3g, Figure 3h and Figure 3i are the PC1 image of the insect-damaged apple, the PC1 image of the apple calyx part, and the PC1 image of the apple fruit stalk part, respectively. It can be seen from the figure that the grayscale values of the insect-damaged area, the fruit stalk area and the calyx area in each PC1 image are low, and the boundaries with the surrounding are relatively clear, so the PC1 image is selected as the principal component image for subsequent processing. The maximum entropy threshold segmentation method is used to determine the apple insect-damaged part, the fruit stalk part and the calyx part. Figure 3i, Figure 3k and Figure 3i are the images after the segmentation of the insect-damaged part, the fruit stalk part and the flower camp part, respectively. 2.3 Extraction of feature vectors If there are pixels in the region of interest segmented from the PC1 image, the pixel may be the insect-damaged part, the fruit stem part or the calyx part. Then, according to the position of the pixel in the region of interest, extract the region of interest image with a size of 160x120 pixels of the surrounding image. If there are no pixels in the region of interest segmented from the PC1 image, it may be a normal apple. Then extract the region of interest image with a size of 160x120 pixels in the middle part of the apple in the PC1 image. In this study, the above series of processing was performed on 160 apple samples to obtain 320 region of interest images. Four texture features of energy, entropy, moment of inertia and correlation were extracted from these region of interest images, and texture feature analysis was performed on them. Table 1 shows the statistical values of each texture feature data of each region of interest image.

As shown in Table 1, the energy mean of the apple insect-injured area is higher than that of the normal area and the pedicel/calyx area, but the energy value of the apple insect-injured area overlaps with that of the normal area and the pedicel/calyx area. According to the coefficient of variation, the data of each energy value is relatively stable, but the data of the apple insect-injured area fluctuates greatly, but the P value of the significance test is small, so the energy mean of the apple insect-injured area is significantly different from that of the normal area and the pedicel/area. At the same time, the entropy and moment of inertia mean of the apple pedicel/area are higher than the mean of the normal area and the insect-injured part, and the entropy and moment of inertia values overlap between the regions. From the perspective of the coefficient of variation, the entropy and moment of inertia value data of each region are relatively stable, but the moment of inertia value data of the insect-injured area and the pedicel/calyx area fluctuates greatly, but the P value of the significance test is relatively small, so the entropy and moment of inertia mean of each region are significantly different. The correlation mean of the apple pedicel/calyx area is lower than the mean of the normal area and the insect-injured part, and the correlation values between the regions overlap. From the coefficient of variation, the data of each correlation value is relatively stable, and the significance test P value is less than 0.05, so the correlation means of each region have significant differences.
III. Conclusion This paper uses hyperspectral imaging technology to study the rapid, non-destructive and automatic identification of apple insect damage and fruit stalks/calyx. The results show that: 1) In the wavelength range of 600 to 1000 nanometers, there are certain differences in the reflectance spectrum curves of the apple insect damage area and normal area, and fruit stalks/calyx. 2) Through the segmentation of feature images, mask processing and principal component analysis of hyperspectral images, and maximum threshold segmentation of PC1 images, the insect damage area, fruit stalk area and calyx area can be effectively segmented. 3) The texture features and spectral features are integrated, and the support vector machine is used to identify apple insect damage. The experimental results show that the best recognition effect of electric injury fruit is achieved by selecting a region of interest image with a size of 160x120 pixels and using the radial basis kernel function, with an overall recognition rate of 97.8%.