{'fraction_non_alphanumeric': 0.02872640143237052, 'fraction_numerical': 0.014508017588667422, 'mean_word_length': 5.1645836714819024, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Apple Bruise Grading Using Piecewise Nonlinear Curve Fitting for Hyperspectral Imaging Data

Apple fruits can be easily damaged, and bruises occur on peels during harvest, transportation and storage, which could decrease fruit quality. This paper proposed an apple bruise grading method based on hyperspectral imaging (HSI). The spectral information of sound apples (Yantai Fuji 8) was first captured using a hyperspectral reflectance imaging device (386-1016 nm). These apples were then mechanically damaged by the same impact forces, and the bruised regions were exposed to room temperature for at most 120 min. The spectral data of the bruised apples at four different exposure times (30 min, 60 min, 90 min and 120 min) were obtained. The spectral data were preprocessed using Procrustes analysis (PA) to enable a more diverse distribution of the spectra among different patterns. To both accurately maintain the spectral information of different patterns and reduce the dimensions of the spectra, piecewise nonlinear curve fitting (PWCF) was presented using the least squares algorithm, where the resultant fitting coefficients from different spectral intervals were catenated into a low-dimension feature descriptor. The feature descriptors were then fed to an error-correction output coding-based support vector machine (ECOC-SVM) to grade the bruised apples. To further evaluate the performance of the presented PWCF, conventional algorithms, including the successive projections algorithm (SPA), genetic algorithm (GA), principal component analysis (PCA) and kernel principal component analysis (KPCA), were introduced for comparison. Experimental results showed that the proposed method obtained the best grading accuracy (97.33%) compared to the other methods.


I. INTRODUCTION
Apple is one of the most popular fruits around the world, and its annual production amounts to 80 million tons [1]. Apple fruits can be easily damaged during the process of harvest, transportation and postharvest storage, which might cause obvious bruising of the apples and thus decrease the fruit quality [2], [3]. Fruit sorting is usually considered to filter out defective apples. Generally, accurate bruise grading, especially the early detection and grading is an important procedure involved in an apple sorting system. Typical fruit bruise detection and grading methods are based on sensory evaluation [4]- [6] and physicochemical analysis [7]- [9].
The associate editor coordinating the review of this manuscript and approving it for publication was Jiachen Yang .
However, sensory evaluation-based methods heavily depend on personal subjective experience, leading to low reliability and poor repeatability, while physicochemical analysis-based methods usually require destructive sampling procedures, which are time-consuming, laborious and costly. Recently, many studies have focused on objective and nondestructive methods to detect and grade bruised fruits, especially those methods based on machine vision and spectral imaging techniques [10], [11].
The methods based on machine vision techniques usually capture optical imageries of unbruised and bruised fruits and detect bruises on fruits via appearance descriptors such as the peel color, local texture and local shape features [12]- [19]. Based on the red/green/blue (RGB) color space, Pawar and Deshpande [12] extracted the local texture and color features of pomegranate fruits using discrete wavelet transformation (DWT) and spatial gray-level dependency matrices (SGDM), respectively; the bruised regions of pomegranate fruits were detected using a support vector machine (SVM). Moradi et al. [13] extracted the local shape features of apples from the L * a * b * color space using the active contour model (ACM); then, the sound and bruised regions of the apple fruits were segmented separately by statistical histogrambased expectation maximization (SHEM), reaching an overall accuracy higher than 91%. Huang et al. [18] combined the Gabor texture descriptor and SVM classifier to detect bruised apples, with an accuracy of 85%. Zhu et al. [19] obtained high-dimensional Gabor features to describe the sound and defective regions of apple fruits from near-infrared images, followed by the dimension reduction procedure using kernel principal component analysis (KPCA); then, the defective apples were detected by SVM and achieved an accuracy of 90.6%. However, the detection performance of methods using machine vision techniques mainly depends on the appearance differences (e.g., peel color, local texture and local shape features) between the sound and bruised/defective fruits; therefore, these methods might fail to achieve accurate results because insufficient information could be extracted from the fruit regions without significant appearance differences, especially for fruits with slight bruising [3].
Spectral imaging techniques can not only capture the appearance changes caused by mechanical damage but also reflect the fruits' internal quality, which is more suitable than other techniques to detect and grade apple bruising. The methods based on hyperspectral imaging usually involve spectral data preprocessing, spectral feature dimension reduction and pattern classification [20]- [24]. Ji et al. [22] investigated the performance of grading defective potatoes using different preprocessing algorithms, including Savitzky-Golay smoothing (SGS), standard normal variable transform (SNV) and n-order derivative filtering, and conducted a performance comparison with the methodology based on the raw spectral data; they found that significant improvement in the accuracy of the grading of defective potatoes could be achieved, especially when using the SNV method. A similar conclusion was also drawn by Xing et al. [23], who adopted the multiplicative scatter correction (MSC) and Norris' firstorder derivative to preprocess the spectral data, and then apple (Jonagold) bruising was detected using partial least squares (PLS) analysis. Liu et al. [24] compared the performance of the detection of defects in hawthorn using different preprocessing algorithms, such as SNV, SGS, median filtering and MSC, and the results indicated that the SNV method was most suitable for the detection of hawthorn defects. The above studies show that spectral data preprocessing plays an important role in fruit or vegetable detection and grading applications. In addition, because the raw spectral data might carry some redundant information and could also lead to high calculation complexity, spectral feature dimension reduction is usually considered successively [25]- [31]. Li et al. [25] used weighted coefficient analysis to extract the optimal components for the description of citrus fungal infections from three different multi-spectral bands, and then the fungal infected citrus were detected using the combination of the bi-dimensional empirical mode decomposition and watershed segmentation, with a detection accuracy of 97.3%. Based on the principle component analysis (PCA), Lu et al. [26] extracted four principal components to describe the invisible bruise of kiwi fruits from hyperspectral reflectance data (600-1000 nm) and used the resultant components to model a parallelepiped classifier for the bruise detection. Tan et al. [27] selected the featured wavelengths using the successive projections algorithm (SPA) and achieved the grading of apple pulp bruise by the grid search based support vector machine (GS-SVM), with a grading accuracy of 95%. Liu et al. [28] first analysed the variation of content such as fructose, glucose, sucrose and total water-soluble sugar in fungal infected strawberries using high performance liquid chromatography(HPLC), and selected several featured wavelengths from the corresponding near-infrared hyperspectral data using SPA to aid the rapid detection of the fungal decay in strawberry. Moscetti et al. [29] adopted a near-infrared spectral imaging technique to capture information on olive fruits damaged by insects, selected several featured spectral wavelengths using a genetic algorithm (GA), and detected insect-damaged olives by using a combination of discriminant analysis and the k-nearest neighbor (k-NN) algorithm. ElMasry et al. [30] investigated the potential of using the hyperspectral imaging technique for the early detection of bruises on 'McIntosh' apples, where PLS and stepwise discriminant analysis were used to select the important characteristic wavelengths (750 nm, 820 nm and 960 nm) involved in the effective description of the symptoms of early apple bruising.
Although much effort has been made to detect fruit defects and bruises using hyperspectral imaging-based methods, most studies have mainly focused on binary classification tasks. To observe the dynamic changes of spectral response of the bruised apples that might be helpful for the early detection of bruised apples toward fruit sorting applications, the grading of apple bruise with respect to the exposure times were explored. In addition, although the conventional feature extraction algorithms (e.g., PCA and KPCA) are useful to conduct dimension reduction for the hyperspectral imaging data, it is difficult to guarantee that the transformed lowdimension data will maintain the optimal pattern classification performance. On the other hand, although some feature selection algorithms (e.g., SPA and GA) could be able to combine several characteristic spectral wavelengths for fruit classification tasks, they might attempt to ignore some specific wavelengths with similar spectral responses among different patterns and some ignored spectral wavelengths might still carry useful information for separating patterns that can be used to grade bruised fruits. Specifically, the above algorithms focus on only some portion of the informative spectral variables or transform instead of using the full spectrum. However, it could be regarded that the raw spectra of different patterns might also carry powerful information for the task of VOLUME 8, 2020 apple bruise grading, and thus, it would be interesting and useful to approximate the raw spectrum of an apple sample belonging to a certain pattern. Therefore, this study aimed to both maintain the spectral information for the sound/bruised apple fruits and reduce the dimensions of hyperspectral data using piecewise nonlinear curve fitting (PWCF) procedure to accurately represent spectral features. Furthermore, the error-correcting output code-based support vector machine (ECOC-SVM) was introduced to evaluate the apple bruise grading (multiclass classification) performance based on the presented PWCF.

A. SAMPLE PREPARATION AND HYPERSPECTRAL DATA ACQUISITION
A total of 75 undamaged apples (Yantai Fuji 8) with similar sizes, weights and maturity degrees were collected as the sound samples and stored in a room temperature environment (25 • C and 60% RH), as the short-time storage of the apples was considered. To manually generate apple samples with similar bruised appearances, an apple impact device was designed, as shown in Figure 1(a). The device consisted of a 25 g plastic cylinder (with a diameter of 10 mm and thickness of 1 mm), a plastic guide tube (25 cm in length), a trestle (20 cm in height) and an objective table (with an area of 20 cm 2 ). During the mechanical damage generation process, the regions approximately 2 cm from both the stalk and pedicle of the sound apples were first manually annotated as shown in Figure 2; a sound apple (marked as pattern P0) was then placed under the plastic guide tube, with its annotated regions facing the center of the guide tube; the plastic cylinder was freely dropped along the cylinder tube to form a bruised piece approximately 1.4 cm in diameter on the annotated regions of the sound apple. To ensure the generation of the same forces, the falling height of the cylinder and the orientation of the guide tube were fixed. Figure 1(b) shows the adopted hyperspectral imaging system, which consisted of a hyperspectral imaging camera (GaiaSky-Mini, Sichuan ShuangliHepu Technology Co., Ltd., China), four light sources with 50-W ELC halogen lamps, a sample carrier table, a data acquisition black box (60 cm × 70 cm × 80 cm) and a personal computer.
During the hyperspectral data acquisition phase, the sound apple fruit was placed on the sample carrier table, with one of its annotated regions facing the hyperspectral imaging camera (∼52 cm from the annotated regions). The range of the spectral wavelengths was 386∼1016 nm, the spectral imaging resolution was 786 pixels × 256 pixels, the forward speed of the imaging device was 0.08 cm/s and the exposure time was 9.98 ms. The raw hyperspectral data I were calibrated using dark and white calibration [32], and the resultant relative reflectance hyperspectral data R could be written as follows: where B refers to the dark hyperspectral value (with 0% reflectance) acquired by a camera lens fully covered by its black cap, and W is the white hyperspectral value acquired from a PETT reflectance panel with 100% reflectance values (HSIA-CT-250 × 280, Dualix, Sichuan, China). The hyperspectral data of the 75 sound apples were first collected using the hyperspectral imaging system. Then, all the sound apples were mechanically damaged, generating bruises on the annotated regions using the apple impact device. Since it was observed that the appearance of the mechanically damaged regions represented little changes with the exposure time longer than 120 min, the bruised apples were placed in the room temperature environment for at most 120 min, and the hyperspectral data of the apples at four different moments (including 30 min, 60 min, 90 min and 120 min) were recorded. Figure 2 shows some examples for the bruised apple samples with the above five degrees or bruising. The hyperspectral data of the different bruised apples were marked as patterns P1, P2, P3 and P4, respectively. Since there were two annotations (near the stalk and pedicel) on each apple, two groups of spectral data were recorded for each apple sample and were further regarded as two different instances in this study. Therefore, 150 instances were generated for each degree of bruising for the apple samples, and there were 750 instances for the samples with the five degrees of bruising. Three datasets consisting of 225, 225 and 300 instances were generated by randomly partitioning the 750 instances and were called the training, validation and test datasets, respectively.   Figure 3 summarizes the three main procedures of the proposed apple bruise grading method: spectral data preprocessing, spectral feature representation and pattern classification.

1) SPECTRAL DATA PREPROCESSING
As shown in Figure 2, the spectral data of both the sound (P0) and bruised (P1, P2, P3 and P4) regions were regarded as the regions of interest (ROIs) with a spatial resolution of 15 pixels × 15 pixels. The average spectral information of the ROIs was calculated using ENVI software (version V5.3).
The spectrum (spectral curve) of the sound or any bruised apple pattern could be regarded as a specified shape depicting the corresponding pattern. As reported by Goodall [33], PA is very suitable for the task of shape correspondence due to its orthogonal nature. A recent work [34] also reported that PA provided great potential for preprocessing the hyperspectral data and further brought significant improvements to the following pattern classification tasks. Therefore, the MSC, SNV, SGS-FD and PA were considered and used for the performance comparison during the spectral data preprocessing phase.

2) SPECTRAL FEATURE REPRESENTATION
The resultant hyperspectral data might contain some redundant information due to the large number of wavelength variables. In addition, the high dimensionality of the raw spectral data could further increase the calculation complexity of the following pattern classification procedures. To both maintain the spectral information of the sound or bruised apples as accurately as possible and reduce the spectral dimension, a spectral feature representation algorithm termed PWCF was proposed, where piecewise one-element high-order equations would be modelled to approximate the raw spectrum of an apple sample belonging to a certain pattern.
First-order derivative calculation was first adopted to locate the points with a zero first-order derivative from the full spectrum. The resultant points contained the potential piecewise points, which were used to segment the full spectrum into several disjointed spectral intervals with more regular shapes because the points with zero first-order derivatives might refer to the extreme points; thus, it would be helpful to obtain several local truncated spectra with low complexity by segmenting the full spectrum based on the extreme points. However, some extreme points were located within the relatively smooth regions, and it might be less useful to segment the raw spectrum into more disjointed intervals using such extreme points due to the low complexity of the relatively smooth regions. Therefore, by combining both the raw average spectrum and its first-order derivative, all the extreme points were reordered according to their corresponding reflectance spectral responses in the full spectrum, and the extreme points with high reflectance spectral responses were considered as additional potential piecewise points.
Furthermore, optimization of the number of spectral intervals (labeled as s) was then conducted using the trial-and-error method to further locate the optimal piecewise points for the task of apple bruise grading. Suppose that there are k reordered piecewise points, the raw average spectrum would be segmented into 2, 3, . . . , and (k + 1) disjointed spectral intervals. Specifically, only the first one reordered extreme point was used to truncate the raw average spectrum into 2 disjointed spectral intervals, only the first two reordered extreme points were used to truncate the raw average spectrum into 3 disjointed spectral intervals, and so forth. Since at most k extreme points were located, the maximum number of possible spectral intervals was (k + 1).
The least squares algorithm was then used to conduct the local spectrum curve fitting for each segmented spectral interval, and the corresponding fitting equation f (x) with respect to the spectral wavelength x could be written as follows: where a i (i = 0, 1, . . . , n) refers to the i-th fitting coefficient of f (x) and n is the order of the one-element fitting equation.
Obviously, due to the nonlinear shape of the spectral intervals, parameter n in Eq. (2) was set to larger than 2 (i.e., n ≥ 2). Finally, all the fitting coefficients from different spectral intervals were successively catenated into a feature descriptor for each raw spectrum.
To evaluate the feature representation performance of the proposed PWCF, conventional algorithms including SPA [27], [28], GA [29], PCA [21], [26] and KPCA [19] were introduced for the experimental comparison. In addition, the curve fitting based on the full average spectrum (considering that there was only one disjointed spectral interval) would serve as a baseline.

3) PATTERN CLASSIFICATION
Apple bruise grading refers to a multiclass pattern classification task. The work [35], [36] reported that the ECOC framework was suitable to solve multiclass learning problems. Therefore, this study aimed to model a multiclass SVM based on the ECOC framework [36] for the task of apple bruise grading.
The design of a multiclass SVM classifier based on the ECOC could be summarized as two main steps: (1) Coding for the training phase. Based on the training and validation dataset, 10 (there were 5 different patterns in this study) base SVM classifiers were first trained using the one-against-one manner, where each pattern was encoded into a unique 10-bit (the same as the number of generated base classifiers) binary codeword using the patterns' membership; thus, an encoded table with the size of 5 (patterns) × 10 (bits) was obtained.
(2) Decoding for the test phase. Using the 10 base SVM classifiers, a code would be generated for each instance in the test dataset and matched with the codeword of each pattern in the encoded table. Then, the test instance would be classified as the pattern with the closest codeword using Hamming distance decoding.

4) EVALUATION METRICS
The performance of the proposed method was evaluated using statistical metrics including the overall accuracy (A), precision (P), recall rate(R) and F1-score. The four metrics can be defined as follows: where TP is the number of correctly classified sound apple instances (pattern P0), TN is the number of correctly classified bruised apple instances (patterns P1, P2, P3 and P4), FP is the number of incorrectly classified bruised apple instances and FN is the number of incorrectly classified sound apple instances.

A. PERFORMANCE EVALUATION OF THE SPECTRAL DATA PREPROCESSING 1) ANALYSIS OF THE RAW AVERAGE SPECTRUM
Due to the low sensitivity of the adopted spectrometer, the wavelengths at both ends of the resultant spectra could usually be defined as noisy spectral regions. Considering the similar configuration reported by Miao et al. [34], only the truncated spectra ranging from 400 nm to 1014 nm were reserved for the following experiments and analysis. Figure 4 shows the reflectance spectra from the five apple patterns (i.e., P0, P1, P2, P3 and P4). As illustrated in Figure 4, the average spectra from the four bruised apples share a more similar tendency with respect to the spectral wavelengths, especially at some absorption peaks (e.g., 675 nm, 982 nm, etc.) than the sound apples, which could provide useful information to separate the patterns for sound apples from the other four bruised patterns. For example, Tan et al. [27] reported that the reflectance spectral response is sensitive to the concentration of pericarp chlorophyll near the wavelength of 680 nm; thus, the absorption peak at approximately 675 nm might be caused by the chlorophyll content in the apple pericarp. The bruised regions in the apple pericarp might affect the spectral absorption caused by chlorophyll, resulting in a decreased reflectance spectral response, as shown in Figure 4. In addition, with the increase in exposure time (from 30 min to 120 min) of the bruised regions, the apple tissue became oxidized, and the concentration of the chlorophyll content in the apple pericarp might degrade accordingly and further affect the reflectance spectral responses of the four bruised apple patterns, which could provide some information for recognizing apples with different degrees of bruising. A similar finding could also be observed at 982 nm. Baranowski et al. [32] found that the reflectance spectral responses could be affected by the vibration in the O-H bond; hence, the absorption peak at the wavelength of 982 nm might be caused by the O-H structure of water in apples. Specifically, with the increase in exposure time (from 30 min to 120 min) of the bruised regions, the concentration of water might decrease accordingly and further affect the reflectance spectral responses of the four bruised apple patterns.

2) ANALYSIS OF THE PREPROCESSING EFFECTS USING DIFFERENT ALGORITHMS
The performance of spectral data preprocessing using SNV, SGS-FD, MSC and PA was first evaluated. Figure 5 gives the preprocessing results on the raw average spectra from different apple patterns using the above algorithms.
As illustrated in Figure 5(a), compared to the raw average spectra, the results obtained by SNV provided significant differences at some absorption peaks (e.g., at wavelengths of 641 nm and 675 nm), which would be beneficial for more accurate classification of sound and bruised apple patterns.
However, except for some absorption peaks, the SNV might also result in similar spectra within several spectral intervals for different patterns; for instance, within the spectral range of 600-700 nm, the preprocessed spectra of the four bruised apple patterns provided small between-class variance, which might make it difficult to separate the four bruised patterns using the spectral information within such wavelength ranges. Similar results were also obtained by SGS-FD, as shown in Figure 5(b). Some absorption peaks of different spectra were further enhanced by the first-order derivative operation; however, some local noise could also be enlarged. On the other hand, a more diverse distribution of the resultant spectra from different apple patterns was generated by both MSC and PA than those generated using the other two preprocessing algorithms. The diverse distribution guaranteed the generation of sufficiently large between-class variances among the five apple patterns and more powerful feature representation for the following procedures, especially for the results obtained by PA.
To quantitatively evaluate how spectral data preprocessing affects the accuracy of apple bruise grading, ECOC-SVM was directly adopted on the full spectra obtained by the four different preprocessing algorithms. Furthermore, another ECOC-SVM model trained from the raw spectra without any preprocessing procedure was introduced as the baseline classifier. The above training processes were based on the training dataset. Using the validation dataset, the comparison results (recall rate R was given) are illustrated in Table 1. Table 1 demonstrates that encouraging grading results were obtained using all preprocessing algorithms compared to the results using the baseline classifier, especially when combined with the MSC and PA. This result is probably because within certain ranges of spectral wavelengths (e.g., 600-760 nm and 700-900 nm), more significant spectrum differences among different apple patterns were generated by these preprocessing algorithms and thus provided more useful discriminant information while modeling the ECOC-SVM classifiers. However, much less accurate grading results (with an average recall rate less than 46%, which was slightly better than that using the baseline classifier) were obtained using either SNV or SGS-FD than those obtained by both MSC and PA. According to Table 1, most of the incorrectly classified apple instances were from patterns P2, P3 and P4, probably because with the increase in exposure time of the bruised apple regions, the concentration of chlorophyll content in the apple pericarp degraded gradually and tended to converge [27], [37], resulting in similar reflectance spectral responses in the corresponding ranges. Such overlapping spectra among the three bruised apple patterns, i.e., P2, P3 and P4, could not be significantly separated by either SNV or SGS-FD, and it thus led to a low recall rate among the three patterns, as shown in Figure 5(a) and Figure 5(b). Although accurate results were obtained using both MSC and PA, high computational complexity for grading bruised apples using the full hyperspectrum was required, and it was necessary to conduct spectral feature representation for dimensional VOLUME 8, 2020 reduction. Due to the encouraging performance of spectral data preprocessing using both MSC and PA, spectral feature representation was conducted based on these two algorithms. Figure 6 provides an illustration of the raw average spectrum for all the apple instances, where all the reordered potential extreme points (7 points in total) were located at the wavelengths of 675 nm, 715 nm, 641 nm, 982 nm, 810 nm, 760 nm and 490 nm, respectively. As a result, the raw average spectrum could be segmented into 2, 3, 4, 5, 6, 7 and 8 disjointed spectral intervals, respectively.

B. SENSITIVITY ANALYSIS ON THE PARAMETERS IN PWCF
Since there are two important parameters (i.e., the number of disjointed spectral intervals s and the order of the oneelement fitting equation n) in the proposed PWCF, experiments were performed to (1) conduct the sensitivity analysis of the two parameters and (2) select the optimal combination of both s and n using 5-fold cross validation. As mentioned above, all the possible settings for the parameter s could be written as the set S = {k|1 ≤ k ≤ 8}. Considering both the nonlinear curve shape of the possible truncated spectra and the complexity of the curve fitting procedure, all possible settings for the parameter n formed the set N = {l|2 ≤ l ≤ 6}. To reduce the randomness of the instances partition involved in a single cross  validation, the 5-fold cross validation was independently conducted 20 times, and the resultant overall accuracy and corresponding standard deviation were considered for the parameter optimization. Table 2 and Table 3 show the grading results under different configurations for the two parameters using the training and validation datasets after being preprocessed by MSC and PA, respectively. The spectra processed by both MSC and PA reveal that (1) the grading results were much less sensitive to the settings of parameter n than parameter s; in addition, although a high value of n might usually guarantee a more precise curve fitting result, it not only requires a highlevel of computational complexity but also generates a large number of fitting coefficients, which would further increase the dimensions of the resultant feature descriptors; (2) much less accurate grading results were obtained when not enough disjointed spectral intervals (s 4) were considered. Small values of s generate intervals with wide spectral ranges, which might still carry complex and irregular curve shapes containing more absorption peaks. With the increase in the parameter s (at the threshold equaling 5), more acceptable grading results were obtained, probably due to the decrease in the complexity of the resultant intervals at narrower spectral ranges, which simplifies the nonlinear curve fitting procedure. However, the continuous increase in s (s 7) did not guarantee higher grading accuracy according to Table 2 and  Table 3, probably because the last two piecewise points (at 760 nm and 490 nm) fell into the spectral intervals with relatively smooth regions. It is less helpful to decrease the complexity of the raw spectrum by such truncations; furthermore, it might generate more breakpoints between the adjacent two spectral intervals, as shown in Figure 7, which gives the curve fitting results using different numbers of spectral intervals with a fixed value of n = 3. Table 2 and Table 3 also demonstrate that more encouraging results were generated from the spectra preprocessed VOLUME 8, 2020    using PA than those using MSC, especially when the number of spectral intervals was 6 and the order of the one-element fitting equation was 3. The preprocessed spectra provided large between-class variance among different patterns using PA, as indicated in Figure 5. Therefore, the optimal configuration of the parameters s and n involved in PWCF was determined by the tuple {6, 3} for the following experiments, where PA was chosen as the best preprocessing algorithm.

C. PERFORMANCE EVALUATION OF APPLE BRUISE GRADING 1) EVALUATION OF THE SPECTRAL FEATURE REPRESENTATION
To evaluate the feature representation performance of the proposed PWCF, traditional algorithms including SPA, GA, PCA and KPCA were introduced for comparison using the test dataset. Table 4, Table 5 and Table 6 give the grading results using the combination of different feature representation algorithms and the ECOC-SVM classifier. The overall grading accuracies A obtained by PWCF, SPA, GA, PCA and KPCA were 97.33%, 77.88%, 75.82%, 81.02 and 90.78%, respectively.
For all the feature representation algorithms used for comparison, the most acceptable results were obtained for the classification of sound apples (P0), probably due to the significant spectral differences between the sound apple pattern and the other bruised apple patterns, at least at some absorption peaks and within several spectral intervals.
The feature selection algorithms (SPA and GA) usually focus on specific characteristic spectral wavelengths based on a certain optimization function, but they might attempt to ignore some global and intrinsic characteristics contained in the full spectrum that could still provide a positive effect on the task of apple bruise grading. In addition, some feature selection algorithms might encounter the problem of resulting in local optima, which cannot always guarantee an acceptable combination of informative characteristic spectral bands. For example, it has been reported [38] that premature convergence might appear in GA and sometimes it might be difficult to prevent the generation of a local optima. On the other hand, the grading results obtained by both PCA and KPCA were better than those obtained using the feature selection algorithms, probably because PCA and KPCA considered the data transform using the full spectra while conducting the dimension reduction (e.g., only the first 8 components with accumulative variance of approximately 99% were extracted by PCA), and this process might preserve some intrinsic features of the spectra among different patterns. However, the principle components might not always guarantee the ability to classify all the apple patterns because PCA and KPCA consider only the data distribution along the orientation with the largest variability [39], [40], i.e., along the orientation with the widest distribution of scatters. In addition, the up-sampling nonlinear projection using the Gaussian kernel made it more possible to group different apple patterns in a very high-dimensional feature space specified by the KPCA; therefore, the KPCA-based feature representation was more suitable to grade the bruised apples than the PCA.
Unlike SPA, GA, PCA and KPCA, the proposed PWCF tries to approximate the basic shape of the full spectrum, which is suitable to preserve the intrinsic information of the original spectra for both the sound and bruised apple patterns. Using the parameters specified by the tuple {6, 3}, a number of 6 spectral intervals were fitted by the least squares algorithm, and there were 4 coefficients in each fitting equation. Hence, a total number of 6 × 4 = 24 fitting coefficients was calculated and formed the feature descriptor, so the PWCF could also be regarded as a dimensional reduction procedure compared to the original 1014 -400 + 1 = 615 spectral wavelengths in the full spectrum. The results in Table 4, Table 5 and Table 6 indicate that the best bruised apple grading performance (with regard to the metrics including R, P and F1score) was obtained using the proposed PWCF, compared to those using the other feature selection and feature extraction algorithms.

2) EVALUATION OF THE PATTERN CLASSIFICATION
To evaluate what benefit could be provided by the ECOC-SVM, a conventional multiclass SVM model (marked as C-SVM in this study) using the indirect application of oneagainst-one concepts and majority voting was created for performance comparison, where the publicly released LIB-SVM toolbox [41] was adopted. Based on the test dataset, Figure 8 gives the confusion matrices indicating the bruised VOLUME 8, 2020 apple grading results using the ECOC-SVM and C-SVM classifiers. Figure 8 demonstrates that the grading model incorporating the ECOC-SVM classifier provided a higher recall rate and precision on the test dataset than the C-SVM classifier. Specifically, 6 instances from pattern P1 was incorrectly predicted as pattern P2, and 2 instances from pattern P2 were incorrectly predicted as pattern P1, resulting in an overall grading accuracy of 97.33% using the combination of PA, PWCF and ECOC-SVM. On the other hand, more instances from patterns P1 and P2 were incorrectly predicted by the C-SVM classifier, resulting in an overall grading accuracy of 81% using the combination of PA, PWCF and C-SVM. The encouraging grading results provided by the ECOC-SVM were probably due to the advantage that the learning of the base SVM classifiers was viewed as a type of communication problem using the error-correcting coding framework, where the identity of the correct output pattern for any instance from the finite training dataset was transmitted over a channel consisting of both the input features and the basic SVM learning algorithm. According to the findings reported by Dietterich and Bakiri [35], this framework encoded each apple pattern into an error-correcting codeword with 10 bits and transmitted each bit via a separate learning process using the SVM algorithm, which could be able to recover the potential prediction errors likely introduced by a set of finite training instances and poor choice of input features.

IV. CONCLUSION
This paper proposed a novel apple bruise grading method based on the hyperspectral imaging technique. The main conclusions are as follows: (1) Compared to SNV and SGS-FD, a more diverse distribution of the resultant spectra among different bruised apple patterns could be obtained by either PA or MSC during spectral data preprocessing, which would bring significant benefits to successive bruised apple grading.
(2) The presented PWCF was more appropriate for the spectral feature representation of both sound and bruised apples than the conventional algorithms, such as SPA, GA, PCA and KPCA, and obtained the best overall grading accuracy of 97.33% when the tuple configuration of the two parameters (i.e., the number of spectral intervals and the order of the fitting equation) involved in the PWCF was {6, 3}, especially using the spectra preprocessed by PA.
(3) ECOC-SVM was more suitable to solve the multiclass classification problem than the conventional indirect application of the binary SVM concepts. Based on the spectral features generated using the PA and PWCF, an improvement of approximately 16.33% in the overall grading accuracy was obtained by the ECOC-SVM compared to the C-SVM.