# Illuminant Estimation Using Adaptive Neuro-Fuzzy Inference System
## 3 Proposed Method
### Image Clustering  
In this stage, a two-step clustering is conducted and all the training images are effectively classified into a few small clusters. The clustering procedure uses k-means algorithm, since this algorithm has straightforward implementation and fast convergence. **Clustering based on CDF. ** In the two-step strategy, the first step is to cluster the training data into \(k_{1}\) clusters based on CDFs of all training images. Usually, the cluster number for k-means algorithm should be set in advance, or be searched by a certain optimal method like PSO (particle swarm optimization). In this study, we empirically chose \(k_{1}\) through many effective experiments on the training dataset. K-means algorithm is implemented based on iteration procedure. The starting points are provided by initial estimates of some centroids which are randomly selected from the dataset. The algorithm alternately iterates between assigning data points and updating centroids. During the iteration, the data point is assigned to its nearest centroid based on the squared Euclidean distance. After the k-means clustering based on CDF, the observations of the data matrix \(\Phi\) obtained via Equation (13) are partitioned into \(k_{1}\) clusters, and the algorithm finally returns an N-by-1 vector containing cluster indices of each observation. According to the cluster indices, each image in the training dataset should fall into \(k_{1}\) subsets as follows:  
\[S_{i}=\{I_{i,1},I_{i,2},\cdots,I_{i,n_{i}}\},i=1,2,\cdots,k_{1}, \tag{17}\]  
where \(n_{i}\) is the number of images in cluster \(S_{i}\), and \(\sum_{i=1}^{k_{1}}n_{i}=N\). It should be noted that the value of \(n_{i}\) maybe different for different clusters. Representing the cluster centroid of \(S_{i}\) as \(c_{i},i=1,2,\cdots,k_{1}\), the CDF centroid set is obtained as \(C_{cdf}=\{c_{1},c_{2},\cdots,c_{k_{1}}\}\). The squared Euclidean distance between the CDF vector \(\tilde{\phi}(I)\) of a given image and a cluster centroid \(c_{i}\) can be calculated, which will be used to measure what degree an image belongs to cluster \(S_{i}\). **Clustering based on IIF. ** In the two-step clustering, the second step is to classify each \(S_{i}\) of the training data into some sub-clusters based on IIFs of all training images. For simplicity, we divide each cluster \(S_{i}\) into the same number of sub-clusters, denoted as \(k_{2}\). As if the clustering is based on CDF, we use the k-means algorithm and still empirically chose the cluster number \(k_{2}\) through many experiments (The optimal values of \(k_{1}\) and \(k_{2}\) should be explored by testing experiments that will be discussed in Section 4.4). In each clustering for \(S_{i}\), the starting points for iteration are randomly selected from the corresponding image set of \(S_{i}\). However, during the iteration the data point is assigned to its nearest centroid based on the cosine distance, not based on the squared Euclidean distance like in CDF based clustering. For cluster \(S_{i}\), an IIF matrix \(\Theta_{i}\) is obtained as in Equation (16). Applying the k-means algorithm, the observations of \(\Theta_{i}\) are partitioned into \(k_{2}\) clusters. The algorithm returns a \(k_{2}\)-by-1 vector containing the cluster indices. According to the cluster indices, all images in cluster \(S_{i}\) are split into \(k_{2}\) subsets. This results in that the total cluster number for all training images equals \(k_{1}\cdot k_{2}\). Finally, for the entire training dataset, there are \(k_{1}\cdot k_{2}\) clusters as follows:  
\[SS_{ij}=\{I_{ij,1},I_{ij,2},\cdots,I_{ij,n_{ij}}\},i=1,2,\cdots,k_{1},j=1,2, \cdots,k_{2}, \tag{18}\]  
where \(n_{ij}\) is the number of images in cluster \(SS_{ij}\), and \(\sum_{i=1}^{k_{1}}\sum_{j=1}^{k_{2}}n_{ij}=N\). Representing the cluster centroid of \(SS_{ij}\) as \(c_{ij}\), the IIF centroid set is obtained as \(C_{ifl}=\{c_{ij},i=1,2,\cdots,k_{1},j=1,2,\cdots,k_{2}\}\).