%input:
%inputFile: the picture file
%n_clus:the number of the clusters

%output
%img file 'output.jpg'

%example:
%main('1.jpg',4)
function main( inputFile, n_clus)
im_data = double(imread(inputFile));
%size of the img
[r,c,l]=size(im_data);
%change the matrix to data
for i = 1 : r
 for j = 1 : c
   data( (i-1)*c+j, :) = im_data(i,j,:);
 end
end

%find label and center
[label,center] = kmeans(data,n_clus);
%form the result 
for i =1:r
    for j = 1:c
        lab1 = label((i-1)*c+j);
        data1(i,j,:)= center(lab1,:);
    end
end
%write the new picture to file
imwrite(uint8(data1),'output.jpg','jpg')
return