## 2 Materials and Methods
### Segmentation  
In medical research and related fields, digital imaging plays a crucial role. Image segmentation techniques significantly contribute to precise diagnoses and treatment planning [20; 21]. The human brain consists of three essential components: white matter, cerebrospinal fluid, and gray matter. Brain lesions exhibit diverse characteristics, making their extraction from MR scans challenging. This study focuses on segmenting brain lesions using feature-based clustering and proposes the use of soft clustering techniques. Improved Fuzzy C-means Clustering (ImFCm)  
Fuzzy theory is instrumental in handling situations involving ambiguity or vagueness caused by incomplete, unreliable, or conflicting information. One of its applications is in the realm of data clustering through methods like Fuzzy c-means (FCM). FCM divides a dataset into N clusters, where each data point belongs to each cluster to a certain degree. For example, a point near the cluster center exhibits a high membership degree, while one farther away has a lower membership degree. This flexibility in membership degrees enables FCM to effectively handle complex and overlapping data structures. In the context of fuzzy clustering, unlike traditional clustering, where each sample is allocated to just a single cluster, fuzzy clustering permits a single sample to have associations with multiple clusters. The fundamental idea behind fuzzy clustering is that every element can be assigned to various clusters with diverse levels of membership. FCM (Fuzzy C-means) stands as a classic approach to fuzzy clustering. Our objective was to improve the method described in [23] by optimizing it using the FCM algorithm:  
\[J_{m}=\sum_{i=1}^{c}\sum_{k=1}^{n}u_{ik}^{m}d_{ik}^{2}=\sum_{i=1}^{c}\sum_{k=1 }^{n}u_{ik}^{m}\|x_{k}-v_{i}\|^{2} \tag{1}\]  
where \(m\) is a positive integer greater than one, \(u_{ik}\) indicates the level of membership of the \(k_{th}\) data sample in the \(i_{th}\) cluster, \(d_{ik}\) is the ratio of familiarity in the preceding \(n\) space, \(x_{k}\) signifies the \(k_{th}\) data sample, and \(v_{i}\) is the \(i_{th}\) cluster's center. In our study, we aimed to enhance the robustness of the Fuzzy C-means clustering method. Adjustments were made to specific components, as illustrated in Figure 2.  
The first part involved filtering the image by computing a distance window and identifying steady groups across a sliding window traversing the entire image. Initially, a padding was created based on half of the kernel to encompass the image borders during sliding. The image mean was computed using the padding, leveraging the cv2.copyMaskBorder  
Figure 2: Segmentation phase one (ImFCm). function to incorporate edges during the sliding process. The sliding window algorithm was determined, specifying parameters such as the neighbor effect and window size, while considering the identification of steady pixel groups for clustering. The Algorithm 4 for detecting stable clusters operates by identifying pixels with Gaussian filter values below or equal to the square root of the mean of the squared differences between the Gaussian values and the window size. The outcome of this segment yielded a filtered image, which was then utilized later in part three for computing fuzziness. The second part involved determining the histogram of the image using the CLAHE filter to enhance the image contrast and compute the intensity distribution of the improved image. This segment was utilized for calculating the centroid of the cluster. In the third part, several critical functions were included. Firstly, the membership function was initialized, indicating the degree of pixel belongingness to each cluster. The function for computing the centroid of clusters involves dividing the numerator by the denominator. The numerator constitutes the summation of the degree of fuzziness multiplied by the histogram and intensity with the power of membership, while the denominator is the summation of the histogram multiplied by the power of membership.