*2.4. Hyperspectral Image Processing and Information Extraction*

The original hyperspectral image needs to be corrected to eliminate the influence of light source and camera dark current changes [30]. The standard white reference image was acquired using a white Teflon plate (99% reflectivity) under the same sampling environment as the sample. Turn off the light source and cover the lens to obtain a black reference image (0% reflectivity). The corrected image is calculated using the black and white reference image by Equation (2):

$$I\_C = \frac{I\_O - I\_B}{I\_W - I\_B} \tag{2}$$

where *IO* was the original hyperspectral image, *IW* and *IB* represented the white reference and black reference images, respectively, and *IC* was the corrected hyperspectral image. In this study, the hyperspectral image correction and subsequent data processing were performed in MATLAB 2019B (The MathWorks, Inc., Natick, MA, USA).

To extract the information of region of interest (ROI), the mask method was used to segment the target and background of the corrected hyperspectral images. The gray images at 849 and 1098 nm were used to construct a binary mask by setting appropriate thresholds, because the spectral intensity difference between the gray image background and maize was largest at 849 and 1098 nm wavelength images for Vis-SWNIR and LWNIR hyperspectral images, respectively. Then, the corresponding hyperspectral image was multiplied by the filtered mask to remove the background information. The original and denoised RGB images of maize with different mold levels were shown in Figure 2. After acquiring the ROI region, the average spectrum was extracted from all pixels of ROI region for each wavelength of the hyperspectral image. Due to the noise and useless information in the beginning and end bands, a total of 389 spectral variables within 399–1001 nm and 112 spectral variables within 1005–1701 nm were obtained from the hyperspectral images of Vis-SWNIR and LWNIR regions, respectively.

**Figure 2.** Original and denoised RGB images (red, green and blue three-channel color image) of maize with different mold levels.

The extraction of texture features was realized by the gray-level co-occurrence matrix (GLCM). The GLCM described the probability of occurrence of two pixels with different distances and directions in a gray image [31]. The data of four texture parameters (contrast, correlation, energy, and homogeneity) in each ROI band was extracted from the GLCM, by Equation (3)–(6). In this study, the pixel distance was set as 1, and only the GLCM in the four directions of 0◦, 45◦, 90◦, and 135◦ was considered. The average value in the four directions was used to describe each texture parameter characteristic. After removing the noise bands, four texture parameters feature matrices with sizes of 240 × 389 (240: number of samples; 389: number of variables) and 240 × 112 were obtained in the Vis-SWNIR and LWNIR bands, respectively.

$$contrast = \left(\sum\_{i=1}^{N} \sum\_{i=1}^{N} (i - j)^2 P(i, j)\right) \tag{3}$$

$$correction = \frac{\sum\_{i=1}^{N} \sum\_{i=1}^{N} (ij)P(i,j) - \mu\_i \mu\_j}{\sigma\_i \sigma\_j} \tag{4}$$

$$energy = \sum\_{i=1}^{N} \sum\_{i=1}^{N} P(i, j)^2 \tag{5}$$

$$homogeneity = \sum\_{i=1}^{N} \sum\_{i=1}^{N} \frac{P(i, j)}{1 + (i - j)^2} \tag{6}$$

where (*i*, *j*) was the pixel coordinate, *P*(*i*, *j*) was the joint probability with two neighboring pixels, and *N* (set *N* = 8 in this research) was the number of gray-levels. μ*i*, μ*j*, σ*i*, and σ*<sup>j</sup>* represented the mean and standard deviation of the row and columns in the GLCM, respectively.

#### *2.5. Spectral Data Preprocessing*

The hyperspectral data were easily interfered by random noise, stray light, background, and equipment in the hyperspectral images acquisition. To eliminate the influence of environmental factors and improve the correlation between spectral data and chemical

composition, it was necessary to preprocess the raw spectrum [32]. Hence, moving smooth, multiple scattering correction (msc), detrend, and mean centralization (center) were used in this study. Studies have indicated that the smooth was used to remove noise interference in the spectrum and improve the signal-to-noise ratio. Its basic idea is to smooth the raw data through the "averaging" or "fitting" of several points in a finite size spectral window. The spectral window size must be an odd number, and the wider the window, the lower the spectral resolution. Msc used the method of least squares to fit the linear relationship between each spectrum and the average spectrum. This means that msc could eliminate scattering bias. Detrend is an approach to eliminate the baseline drift in the spectrum and the influence of different sampling batches on the spectrum. Firstly, a trend line was derived from spectral values and wavelengths through least squares fitting, and then the trend line was subtracted from the original spectrum. The center was effective in enhancing the differences between data, its basic idea is to remove the column, row, or overall average from each column, row, or both separately [33–35]. In this study, smooth was firstly used to reduce the noise and interference existed in original spectra, and then msc, detrend, and center were employed secondly to process the spectra on the basis of smooth. The best spectral preprocessing method was determined by comparing the effects of different pretreatment methods on classification accuracy, then the spectral data processed by the best method were fused with texture information for further analysis.
