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

n_clusters

int

3

Number of segmentation classes

m

float

2.0

Fuzziness degree

k1

float

0.1

First-order regularization weight for multiplier field

k2

float

0.1

Second-order regularization weight for multiplier field

max_iter

int

100

Maximum number of EM iterations

tol

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 image

  • predict(): Returns hard labels for each pixel

  • get_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”