%% correct
colorimg = imread('hipster_cat2.jpeg');
figure(1);imagesc(colorimg);
x_color=double(colorimg);
r=x_color(:,:,1);g=x_color(:,:,2);b=x_color(:,:,3);
[m,n,p]=size(colorimg);
c_img=zeros(m,n,p);
s=m/8;
t=n/8;
k = 8;
for i=1:k
  for j=1:k
    C(i,j)=sqrt(2/k)*cos((i-1)*(j-1/2)*pi/(k));
  end
end
C(1,1:k)=ones(1,k)/sqrt(k);
p=4;

for k=1:p%for each color
for i=1:s
    for j=1:t
       X8 = Xd(((i-1)*8+1):(i*8),((j-1)*8+1):(j*8),k);
       Xc = X8 - 128;
       Y = C*Xc*C';
       Yq = round(Y./Q);
       Ydq = Yq.*Q;
       Xdq = C'*Ydq*C;
       Xe = Xdq+128;
       c_img(((i-1)*8+1):(i*8),((j-1)*8+1):(j*8),k) = Xe;
    end
end
end
figure;
imagesc(uint8(Xe));
