CLUSTER=1;
if(CLUSTER==1)
	im=imread('as_roma.jpg');
	im=im2double(im);
	[r,c,d]=size(im);
	
	% Vectorize image
	data=reshape(im,r*c,d);
	nclus=3;
	
	[distance,label,tse] = kmeans1(data,nclus);
end
clusters=zeros(1,nclus);
miu=zeros(1,3);
tmp=zeros(1,3);

for i=1:nclus
    j=find(label==i);
    for k=1:size(j,1)
        tmp(k,:)=data(j(k),:);
    end
    miu(1)=mean(tmp(:,1));
    miu(2)=mean(tmp(:,2));
    miu(3)=mean(tmp(:,3));    
    key(i,:)=miu;
end

% make new image
new_im=zeros(r,c,d);
cnt=1;
for j=1:c
    for i=1:r
        for k=1:nclus
            new_im(i,j,:)=key(label(cnt),:);
        end
        cnt=cnt+1;
    end
end
