| image = | kMeansAssignImg (inImg,inClustersCenters) |
| image = | kMeansAssignImg (inImg,maskImg,inClustersCenters) |
Clusters pixels of an input image based on minimum distance, given a set of clusters centroids.
This algorithm clusters pixels of an input image to clusters given clusters centroids.
Considering an image of size (x, y, z, c, t) (with x, y and z the sizes respectively along x, y and z-axis, c the number of color channels and t the number of elements in temporal sequence) as a set of x*y*z data vector of c*t dimension, and a set of n clusters of dimensions c*t (n > 1); for each data vector of the image, the algorithm assigns the cluster, the closest centroid to the data vector currently considered, based on the euclidean distance computed between data vectors and centroid vectors, both of dimensions c*t.
Input and output attributes of the algorithm are:
: the input image we want to classify,
: collection of centroids of clusters. Dimensions of clusters centers must equal to
,
: optional; information stored during the assignment process, such as the sums of data vectors for each cluster, the number of elements of each cluster and the compactness of each cluster. Used by k-means algorithm,
: image of identifiers of clusters for each pixel/voxel (identifiers in range [0..nbClusters-1]; must be a single grey levels image. Its size along x, y and z-axis must equal to InImg sizes along these same axis.Here is an example of clusters assignment algorithm applied to Lena RGB image, with 4 clusters centers: (223, 136, 126), (61, 3, 28) , (237, 230, 224) and (109, 69, 131):
In this figure, the first label (in black) has a value of 1. The label 0 corresponds to the case where a pixel/voxel has a value of False in the optional input mask image, is provided.
Here is an example of cluster assignment, by taking into account a mask with the centers (223, 136, 126), (61, 3, 28) , (237, 230, 224) and (109, 69, 131). In this case, black pixels in the label image correspond to black pixels in the mask image: