# Emotion-Based Classification and Indexing for Wallpaper and Textile
## 3 The Proposed Scheme
### Feature Extraction
#### 3.1.3 Identification of the Main Colors  
The main colors of image are extracted using the second step of the flowchart in Figure 7. In this step, the representative colors of the processed images in _Lab_ color space are determined. The sources of the processed images can be referenced images or input images. Most conventional methods use cluster-skill to identify the main colors, according to the distribution of the image-pixels in the color space. The _k_-means clustering method [39] is widely used, but its drawback is that the initial points in the color space must be randomly chosen from the source image. Another common method is clustering vector quantization (VQ) [40], in which the nearest quantization vector centroid is moved towards the initial point by a small fraction of the distance. This classic quantization technique was initially developed for image processing. However, its disadvantage is its slow speed when the initial points are poor. More importantly, its performance significantly depends on the initially selected points. The selected representative points from image-pixels are gained by a method that combines two techniques in this study. First, adopting the skill of Independent Scalar Quantization (ISQ) [21] enables simply and quickly to acquire the initial point from the pixels of the RGB color space. Figure 8 shows the 3-D and 2-D diagrams and Figure 8a shows that the 3-D _Lab_ color space is quantized into 8 individual cubes of the same size, using ISQ. Figure 8b shows the pixels distributed in the 2-D _Lab_ color space. There are three cubes holding pixels, and the one cube with no pixels is called an empty cube. The centroids of these cubes, which are based on the distribution of the pixels, are computed using the pixels of the cube. Since an empty cube has no representative point, the number of initial points may be less than 8, but the maximum number is 8. [PERSON] [14] limited the maximum number of color combinations to five, so this method appropriately modulates those initial points to match the color combinations. Figure 8c shows how the LBG algorithm [23] is used to make necessary modifications after ISQ. The LBG algorithm is similar to a K-means clustering algorithm, which uses a set of input vectors, \(S=\{x_{i}\in R^{d}\mid i=1,2,\ldots,n\}\), as the input and generates a representative subset of vectors, initiate a codebook, \(C=\{c_{j}\in R^{d}\mid j=1,2,\ldots,K\}\), which is randomly selected, with a user-specified K << n as the output. Although the settings for Vector Quantization (VQ) are usually d = 16 and K = 256 or 512, the settings used in this study are d = 3 and K \(\leq\) 8. The algorithm is shown below:  
1. Input the training vectors, \(S=\{x_{i}\in R^{d}\mid i=1,2,\ldots,n\}\). 2. Initiate a codebook, \(C=\{c_{j}\in R^{d}\mid j=1,2,\ldots,K\}\), which is randomly selected. 3. Set \(D_{0}=0\) and let k = 0. 4. Classify the training vectors into K clusters, according to \(x_{i}\in S_{q}\) if \(\mid\)\(x_{i}-c_{q}\)\(\mid\)\(\mid\)\({}_{p}\)\(\leq\)\(\mid\)\(x_{i}\)\(-c_{j}\)\(\mid\)\(\mid\)\({}_{p}\) for \(j\
eq q\). Figure 8: **(a)** The 3-D color space is partitioned using the ISQ algorithm; (**b**) using the ISQ algorithm to identify an initial point, one cube is empty; and (**c**) using the LBG algorithm to improve the quality further. Step 5. Update the cluster centers, \(c_{j}\), \(j=1\), \(2\),..., K, using \(c_{j}=\sum_{x_{i\in S}}x_{i}/|S_{j}|\). Step 6. Set \(k\leftarrow k+1\) and compute the distortion \(D_{k}=\sum_{j=1}^{K}\sum_{x_{i\in S}}\big{|}\big{|}\ x_{i}-c_{j}\big{|}\big{|}_{p}\). Step 7. If \((D_{k-1}-D_{k})\ /D_{k}>\varepsilon\) (a small number), repeat Steps 4-6. Step 8. Output the codebook, \(C=|c_{j}\in R^{d}|\ j=1\), \(2\),..., K). The convergence of the LBG algorithm depends on the initial codebook, \(C\), the distortion, \(D_{k}\), and the threshold, \(\varepsilon\). The maximum number of iterations must be defined in order to ensure convergence.