AFCMAdaptive (Adaptive Fuzzy C-Means for Image Segmentation) Documentationο
π Overviewο
AFCMAdaptive is an image segmentation algorithm that extends Fuzzy C-Means by introducing a spatially varying multiplier field m(i,j). This adaptive mechanism improves segmentation in images with intensity inhomogeneity such as MRI or CT scans.
βοΈ Class Definitionο
Class Name: AFCMAdaptive
This class implements the AFCM algorithm with iterative updates for cluster centers, fuzzy membership, and the multiplier field.
class AFCMAdaptive:
def __init__(self, n_clusters: int = 3, m: float = 2.0, k1: float = 0.1, k2: float = 0.1,
max_iter: int = 100, tol: float = 1e-4):
...
π Parametersο
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
int |
3 |
Number of segmentation classes |
|
float |
2.0 |
Fuzziness degree |
|
float |
0.1 |
First-order regularization weight for multiplier field |
|
float |
0.1 |
Second-order regularization weight for multiplier field |
|
int |
100 |
Maximum number of EM iterations |
|
float |
1e-4 |
Convergence tolerance for center updates |
π Usage Examplesο
from soft_clustering._afcm_adaptive._afcm_adaptive import AFCMAdaptive
import numpy as np
# Sample synthetic image
image = np.zeros((64, 64))
image[:32, :] = 0.3
image[32:, :] = 0.7
image += np.random.normal(0, 0.05, image.shape)
model = AFCMAdaptive(n_clusters=2)
model.fit(image)
labels = model.predict()
membership = model.get_membership()
π₯ Input / π€ Outputο
Input to
fit(image):image (np.ndarray): 2D grayscale image with values β [0,1] or scaled
Returns:
predict()β 2D integer array with cluster labels (H x W)get_membership()β 3D array with fuzzy membership values (H x W x C)
π οΈ Methodsο
fit(image): Performs iterative fuzzy clustering on 2D imagepredict(): Returns hard labels for each pixelget_membership(): Returns fuzzy membership matrix for each class
π Implementation Notesο
Multiplier field m(i,j) is updated based on local pixel statistics
Uses Gaussian smoothing and Laplacian (βm, βΒ²m) for regularization
Memberships updated using a Mahalanobis-like normalized distance
Avoids hard intensity boundaries by spatial adaptation
π Referenceο
This implementation is based on:
βAn adaptive fuzzy C-means algorithm for image segmentation in the presence of intensity inhomogeneityβ