## Materials and Methods
### Image Preprocessing
#### 2.4.1 Image Repartition  
The k-means algorithm belongs to cluster analysis, which is used to divide a set of objects into several groups according to the similarity of each other, where the similar objects constitute a group. The k-means algorithm has proved useful in clustering and segmentation of hyperspectral images [21; 22; 23].  
It was obvious from the hyperspectral image that the sausage is mainly composed of two parts, lean meat and fat, and there were significant differences between the two parts due to chemical composition reflected in different hyperspectral images. So, if all the pixels of each ROI were averaged to generate one mean value in each band, a significant quantity of potential information would be lost.  
By using the k-means adaptive segmentation algorithm, all the pixels in each ROI were divided into two categories automatically, which can reduce the deviation from the judgment of human eyes, save time for manual segmentation, and allow for mining of more high-dimensional image information. As lean meat is always the main component of the sausage, the class with larger pixel number belongs to lean meat, and the other is fat. Through the k-means clustering algorithm, the categories of each pixel in the ROIs and the clustering centers of two classes were obtained. As the sausage samples of  
Figure 1: The flow chart of hyperspectral detection and image processing; The CCD camera was located at the top of the translation stage, through which the sausage hyperspectral image was acquired and transmitted to the computer. Then ENVI was used to visualize hyperspectral images and extract ROI (region of interesting). Finally, Python 2.7 was used to select effective wavelengths (EW) and model them.  
lean meat and fat often mixed together, the high spectral values of each pixel point represent the result of lean meat and fat's mix in different proportions. Therefore, the membership degree is introduced to evaluate the proportion of lean meat and fat to each pixel. Referencing the gravitational model, we call the similarity of samples compared to lean meat and fat in each pixel \(R_{L}\) and \(R_{F}\), and the definition is:  
\[{R_{L}}^{2} = \frac{1}{\left({H_{pix}-H_{L-mean}}\right)^{2}} \tag{2}\] \[{R_{F}}^{2} = \frac{1}{\left({H_{pix}-H_{F-mean}}\right)^{2}} \tag{3}\]  
where \(H_{pix}\) is the vector of spectral values in a pixel, \(H_{L}\) is the average spectral values' vector of lean meat class, and \(H_{F-mean}\) is the average spectral values' vector of fat class.  
Through the above formula, we can deduce the membership degree of lean meat and fat of each pixel in ROIs as follows:  
\[M_{L} = \frac{{R_{L}}^{2}}{{R_{L}}^{2}+{R_{F}}^{2}} \tag{4}\] \[M_{F} = \frac{{R_{F}}^{2}}{{R_{L}}^{2}+{R_{F}}^{2}} \tag{5}\]  
where \(M_{L}\) is the membership degree of lean meat in a pixel, and \(M_{F}\) is the membership degree of fat in a pixel. It is obvious that the sum of \(M_{L}\) and \(M_{F}\) of the same pixel is one.  
For each sample, the hyperspectral information corresponding to the lean meat (I\({}_{L}\)) is obtained according to the weight average of the lean meat membership degree, and so is the fat (I\({}_{F}\)). Figure 2 shows the segmentation effect of some samples.  
Figure 2: Seven groups of near infrared spectroscopy (NIR) hyperspectral images of sausage samples and the corresponding pseudo color images. The deeper the red, the higher the degree of lean meat membership.