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, meanColors] = kmeans(shapedImg, k);
- pixel_labels = reshape(cluster_idx, x, y);
- meanColors = uint8(meanColors*255);
- outputImg = uint8(zeros(x,y,3));
- for i = 1:k
- A = uint8(zeros(x,y,3));
- A(:,:,1) = pixel_labels == i;
- A(:,:,2) = pixel_labels == i;
- A(:,:,3) = pixel_labels == i;
- A(:,:,1) = A(:,:,1) * meanColors(i,1);
- A(:,:,2) = A(:,:,2) * meanColors(i,2);
- A(:,:,3) = A(:,:,3) * meanColors(i,3);
- outputImg = outputImg + uint8(A);
- end
- imshow(outputImg)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement