
%read image and convert to graylevel
a1 = imread('diff.jpg');
%a = im2double(a1)
a = rgb2gray(a1);

m_org=size(a,1);
n_org=size(a,2);
%break into blocks( blockproc can also be used
imblk = im2col(a,[8 8]);
m_col=size(imblk,1);
n_col=size(imblk,2);
new = imblk';
new1 = ones(n_col,7);
for i = 1:n_col
    x=new(i,:);
    m = tanh(log(abs(invmoments(x))+2));
    new1(i,:)=m;
end
%form clustersssss
numcl = 4;
[distance,label,tse] = kmeans1(new1,numcl);
temp = ones(m_col,n_col);
for z =1:n_col;
    lab=label(z);
    temp(:,z)=lab*255/numcl;
end
%remap to original
temp2=mean(temp);
C = col2im(temp2,[8 8],[m_org n_org]);
k = wiener2(C,[3 3]);            
figure, imshow(C,gray(255))
figure, imshow(a1,gray(255))
figure, imshow(k,gray(255))
