## 3 Robust Clustering with Local Contextual Information (RC_LCI)
### Energy Minimization  
The optimization of \(b(x)\) and \(J(x)\) can be obtained by minimizing the energy function \(F\) about three independent variables \(\mathbf{w}\), \(\mathbf{c}\), and \(\mathbf{u}\). The process of energy minimization is achieved through alternative iterations, where variables \(\mathbf{w}\), \(\mathbf{c}\), and \(\mathbf{u}\) are obtained by fixing the other two variables in the last iteration. By fixing \(\mathbf{c}\) and \(\mathbf{u}\), the optimal solution of \(\mathbf{w}=(w_{1},\cdots,w_{N})^{T}\) can be obtained by solving the partial derivative  
\[\frac{\partial F}{\partial\mathbf{w}}=-2\int_{\Omega}G(x)I_{w}(x)\left(\lambda _{i}\sum_{i=1}^{N}c_{i}u_{i}(x)\right)dx+2\mathbf{w}\int_{\Omega}G(x)G^{T}(x) \left(\lambda_{i}\sum_{i=1}^{N}c_{i}^{2}u_{i}(x)\right)dx. \tag{20}\]  
Let Equation (20) equal 0, \(\mathbf{w}\) is given by  
\[\mathbf{w}=\left(\int_{\Omega}G(x)G^{T}(x)\left(\lambda_{i}\sum_{i=1}^{N}c_{i} ^{2}u_{i}(x)\right)dx\right)^{-1}\int_{\Omega}G(x)I_{w}(x)\left(\lambda_{i} \sum_{i=1}^{N}c_{i}u_{i}(x)\right)dx. \tag{21}\]  
Hence, bias field \(b(x)\) is obtained from the product of the basis functions and the optimal solution of \(\mathbf{w}\). By fixing \(\mathbf{w}\) and \(\mathbf{u}\), the optimal solution of \(\mathbf{c}=(c_{1},\cdots,c_{N})^{T}\) can be obtained by  
\[c_{i}=\frac{\int_{\Omega}I_{w}(x)b(x)u_{i}(x)dx}{\int_{\Omega}b^{2}(x)u_{i}(x )dx},\ i=1,\cdots,N. \tag{22}\]The binary function represents the membership function of each tissue, which can ensure that noisy free pixels can be correctly classified. So, the function \(\mathbf{u}=\left(u_{1},\cdots,u_{N}\right)^{T}\) can be expressed as  
\[u_{i}(x)=\left\{\begin{array}{l}1,i=\mathit{arg\,min}\{\alpha_{i}[I_{w}(x)] \}\\ 0,i\
eq\mathit{arg\,min}\{\alpha_{i}[I_{w}(x)]\}\end{array}\right., \tag{23}\]  
where \(\alpha_{i}(x)=\left|I_{w}(x)-\mathbf{w}^{T}G(x)c_{i}\right|^{2}\).  
In this study, 10 orthogonal three-order Legendre polynomial functions were used as the basis functions of bias field \(b(x)\), which can be represented by \(g_{1}(x)=1\), \(g_{2}(x)=x_{1}\), \(g_{3}(x)=(3x_{1}^{2}-1)/2\), \(g_{4}(x)=(5x_{1}^{3}-3x_{1})/2\), \(g_{5}(x)=x_{2}\), \(g_{6}(x)=x_{1}x_{2}\), \(g_{7}(x)=(3x_{1}^{2}-1)x_{2}/2\), \(g_{8}(x)=(3x_{2}^{2}-1)/2\), \(g_{9}(x)=(3x_{2}^{2}-1)x_{1}/2\), and \(g_{10}(x)=(5x_{2}^{3}-3x_{2})/2\), where \(x_{1}\) and \(x_{2}\) are directional components of image \(I(x)\), and \(\lambda_{i}=1,i=1,\ldots,N\). Then, the specific implementation process of RC_LCI can be summarized as the pseudocode in Algorithm 1.  
```
1.Input: Brain MRI to be segmented.
2.Image = denoising(Image, \(n_{k}\)) % Update each pixel according to Equations (8)-(11).
3.Basis = GetBasisOrder3(size(Image)) % Obtain basis functions according to Equation (14).
4.Randomly initialize bias field \(b\), cluster center \(C\), and membership function \(M\).
5.while\(C^{(n)}\) - \(C^{(n-1)}>0.001\)do
6.for\(i=1:\) size(Basis, 3)
7.\(v(i)=\) Basis \(*\) Image \(*\)\(C*M\)
8.for\(j=i:\) size(Basis, 3)
9.\(A(i,j)=\) Basis \(*\)\(C^{2}*M\)
10.\(A(j,i)=\)\(A(i,j)\)
11.endfor
12.endfor
13.\(w=\mathit{inv}(A)*v\)
14.for\(i=1:\) size(Basis, 3)
15.\(b=b+w(k)*\) Basis(\(k\))
16.endfor
17.for\(n=1:\) size(\(M,3\))
18.\(N=b*\) Image \(*\)\(M\)
19.\(D=b^{2}*M\)
20.\(C(n)=N/D\)
21.\(e\) (\(i\)) = (Image - \(C(i)*b)^{2}\)
22.endfor
23.N_min = min(\(e\), [[], 3)
24.for\(k=1:\) size(\(e\), 3)
25.\(M\)(\(:,:,k\)) = (N_min == \(k\))
26.endfor
27.endwhile
28.New_Image = C * \(M\)
29.Image_bc = New_Image./ \(b\) % Bias field correction image
30.Output: Bias field \(b\), bias field correction image, and segmentation result.
```  
**Algorithm 1**RC_LCI segmentation algorithm.