kmeans_img
kmeans_img ¶
Cluster image pixels by RGB color using the requested backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
ndarray
|
RGB image with shape (H, W, 3). |
required |
n_clust
|
int
|
Number of color clusters. |
3
|
seed
|
int
|
Random seed passed to the selected KMeans implementation. |
42
|
device
|
str
|
"cpu" for scikit-learn or "cuda" for CuPy/cuML. CUDA clustering does not require cuCIM. |
'cpu'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
NumPy integer label image with shape (H, W), with labels starting at 1. |
ndarray
|
Images with fewer unique colors than requested clusters return zeros. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If CUDA clustering is requested without CuPy/cuML. |
ValueError
|
If the device is unsupported or KMeans rejects its inputs. |