Skip to content

Instantly share code, notes, and snippets.

@leVirve
Created February 22, 2016 09:28
Show Gist options
  • Save leVirve/a8c5da77df730b23b3ab to your computer and use it in GitHub Desktop.
Save leVirve/a8c5da77df730b23b3ab to your computer and use it in GitHub Desktop.
K-Means on RGB image
optns = statset('MaxIter', iters);
pixels = reshape(img(:), [], 3);
[idxs, centroids] = kmeans(pixels, k, 'options', optns);
img_map = centroids(idxs, :);
img_new = reshape(img_map(:), size(img));
imshow(img_new);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment