function [ out ] = k_mean_clustering_rgb( im , k)
% > input parameter: original image, number of clusters; output parameter: segmented image 
% > converts the image to the necessary data-format 
% > calls vl_kmeans 
% > converts back the result to a normal image

im = double(im);

[width, height, channels] = size(im);
im_vector = reshape(im,width*height, 3);

[C, A] = vl_kmeans(im_vector', k);

im_vector(:,:) = C(:, A)';

out = uint8(reshape(im_vector(:,:),width,height, 3));

end



