Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [outputImg, meanColors] = quantize_RGB(origImg, k)
- imgDouble = im2double(origImg);
- [x,y,z] = size(imgDouble);
- shapedImg = reshape(imgDouble, x*y, 3);
- cluster_idx = kmeans(shapedImg, k);
- pixel_labels = reshape(cluster_idx, x, y);
- imshow(pixel_labels,[]), title('image labeled by cluster index');
- meanColors = 1;
- outputImg = pixel_labels;
- segmented_images = cell(1,3);
- rgb_label = repmat(pixel_labels,[1 1 3]);
- for j = 1:k
- color = imgDouble;
- color(rgb_label ~= j) = 0;
- segmented_images{j} = color;
- end
- outputImg = segmented_images;
- imshow(outputImg);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement