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:
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: