## 2 Materials and Methods
### Developed Algorithm for Foreign Material Detection
#### 2.5.1 Pixel-Level Classification  
In this study, the pixel-level classification was performed independently with the VNIR and SWIR spectral data as a first step of the data fusion. The pixel-level classification model consisted of four sub-models. The first sub-model was a principal component analysis (PCA)-based Mahalanobis distance (MD) metric model, called PCA-MD. The dimensionally reduced data using PCA, a powerful tool for informative variable selection [38], was used to calculate the MDs between the meat group and the FMs, where the meat group was the reference. The pretreated spectral matrices in the training set were linearly transformed into a set of linearly uncorrelated variables called principal components (PCs). The score values (latent features) of PC 1-5 from the PCA result of meat ROIs (30 mean spectra of muscle ROI and 10 mean spectra of fat ROI) were used as a reference in each data matrix of the VNIR and SWIR, respectively. Since the PC score values originated from the ROIs of chicken fillets and were used as a reference mean vector, the smaller MD value of each pixel indicated that they were similar to the chicken fillet. Each pixel was classified into meat or FM according to the threshold criterion of the measured MD value in the PCA domain. The other three sub-models were developed to detect blood spots (blood dots), glare, and black material with multispectral models, respectively. The PLSR analysis and the literature were used to find the key wavebands necessary for each sub-model and each modality. The PLSR was performed to select the most informative wavebands with large regression coefficient values [39]. The wavebands associated with color pigments and hydrogen-bonded compounds (i.e., C-H, O-H, and N-H) were found from previous studies [17; 39; 40]. The selected key wavebands were highly related to the components related to the color (400-800 nm) and chemical composition (800-2500 nm) of the chicken breast meat. The blood spot may occur due to hemorrhage caused by the rupture of blood vessels or from the leakage of red blood cells from the vessels. Glares were observed due to the excessive reflectance intensity toward the lens that might be generated from the specular reflection of water on the surface of the fillet. The second sub-model was a blood spot detection model. For this model, we defined several band ratios at 700 nm/415 nm, 650 nm/600 nm, 760 nm/700 nm, and 700 nm/450 nm in the VNIR modality. Thresholding at 450 nm and 560 nm was part of the developed blood spot detection model. The third sub-model was a glare detection model. For this model, we defined the threshold values higher or close to 100% at 480 nm (100%), 750 nm (97%), 850 nm (105%), 1080 nm (150%), 1414 nm (120%), and 2300 nm (90%) in the VNIR and SWIR ranges to differentiate between glare and some white FMs that generated the high reflection. Additional band ratios and thresholding were applied to develop the glare detection model. The fourth sub-model was a black material detection model. For this model, we defined the threshold values at 700 nm and 850 nm since the spectra of some dark areas of the chicken fillets were similar to the spectrum of black material except in a few single wavelengths including those two wavebands. These four sub-models with binary outputs were combined into a pixel-level classification algorithm, as shown in Figure 3. The algorithm is summarized in the following steps:  
1. A multi spectrum goes to the black material detector based on multispectral thresholding. If the pixel belongs to a black material, the algorithm stops with the FM output. Otherwise, go to step 2. 2. If the pixel is not a black material, a pre-treated spectrum goes to the PCA-MD model. If the output is meat, the algorithm stops. Otherwise, go to step 3. 3. If the pixel is neither black nor meat, it may belong to FM presumptively. This presumptive classification must be checked with blood spot and glare detection models, independently. If either sub-model classifies meat, the output is meat.