M-File Help: colorkmeans View code for colorkmeans

colorkmeans

Color image segmentation by clustering

L = colorkmeans(im, k, options) is a segmentation of the color image im into k classes. The label image L has the same row and column dimension as im and each pixel has a value in the range 0 to k-1 which indicates which cluster the corresponding pixel belongs to. A k-means clustering of the chromaticity of all input pixels is performed.

[L,C] = colorkmeans(im, k) as above but also returns the cluster centres C (Kx2) where the I'th row is the rg-chromaticity of the I'th cluster and corresponds to the label I. A k-means clustering of the chromaticity of all input pixels is performed.

[L,C,R] = colorkmeans(im, k) as above but also returns the residual R, the root mean square error of all pixel chromaticities with respect to their cluster centre.

L = colorkmeans(im, C) is a segmentation of the color image im into k classes which are defined by the cluster centres C (Kx2) in chromaticity space. Pixels are assigned to the closest (Euclidean) centre. Since cluster centres are provided the k-means segmentation step is not required.

Options

Various options are possible to choose the initial cluster centres for k-means:

'random' randomly choose K points from
'spread' randomly choose K values within the rectangle spanned by the input chromaticities.
'pick' interactively pick cluster centres

Notes

See also

rgb2xyz, kmeans


 

© 1990-2012 Peter Corke.