## 2 Materials and Methods
### System Components and Data Acquisition  
A line-scan (NIR) hyperspectral imaging system was used for the purpose of the fast and non-destructive screening of almond samples. All of the images acquired by the system were obtained by a line-scan push-broom hyperspectral camera (Pika NIR-640, Resonon, Bozeman, MT) equipped with a Near Infrared (NIR) imager covering the 900-1700 nm spectral range with a 2.5 nm resolution. A spectral channel of 328 and a spatial channel of 640 were covered by the camera. The system lighting consisted of two 100 W tungsten-halogen light sources (LS-F100 HS, Seokwang optical, Korea) through optical fibers to line fittings (G(P)L30 \(\times\) 1.0-1000F). Figure 1 displays the system components and data acquisition with a 10 rpm conveyor belt speed.  
A graphical user interface was developed to control the prototype systems for data collection using MATLAB software. The system components are illustrated in Figure 1, in which the system's conveyor belt consists of seven vertical lines that seeds pass through. These vertical lines correspond to each connected ejector nozzle of the system. The camera was installed at a distance covering these seven lines 55 cm from the samples. Seeds were imaged under the above-displayed system by placing kernels on the conveyor belt. Each batch of kernels consisted of 28 seeds in every single capture conducted by the system. The seeds were arranged in alternating rows; the first row was used for almonds and the second row was used for apricot kernels.  
To transform the raw hyperspectral images into reflectance images, Equation (1) was used in a sequence to remove the noise generated by the device and the unwanted light intensity, in order to correct the non-uniform light of the images and produce images with an actual reflectance scale. The white reference was measured using a white Teflon tile with \(\sim\)99% reflectance before imaging the sample with the same illumination configuration. The same standard was obtained for the dark (covered lens) reference (\(\sim\)0% reflectance) data with the light sources turned off. The calibration image \(\mathbf{X_{cal}}\) was calculated by using the raw hyperspectral image \(\mathbf{X_{raw}}\), white reference image \(\mathbf{X_{ref}}\), and dark reference image \(\mathbf{X_{dark}}\) using the equation.  
\[\mathbf{X_{cal}}=\frac{\mathbf{X_{raw}}-\mathbf{X_{dark}}}{\mathbf{X_{ref}}- \mathbf{X_{dark}}} \tag{1}\]  
The calibrated hyperspectral image was segmented from the background using the average value of background and seed pixels to remove the non-uniform illumination or variation in the pixel-wise sensitivity of the background and fair reflection of the sample. The dead pixels generated by the camera detector were removed by applying a filter for individual samples. The full spectra were based on the total region of interest (ROI) from each sample and averaged before further analysis. The mean spectrum of each kernel was extracted from two varieties of almonds and two varieties of apricot kernels. Each variety had 112 kernels. Therefore, a total of 448 spectra were collected and used for the analysis. The total data were divided for each variety; 70% of spectral data were used for model building and 30% of spectral data were divided for model testing--the complete process of which is illustrated in Figure 2. The entire process was conducted using MATLAB software (version 8, the Math Works Inc. Natick, MA, USA).  
Figure 1: The hyperspectral imaging prototype used for collecting data.  
Figure 2: A schematic flow from data collection to the final online sorting application.