close all;
clear all;

color = imread('baby_animal.jpg');
figure;
imagesc(color);
x_color=double(color);
r=x_color(:,:,1);g=x_color(:,:,2);b=x_color(:,:,3);

n = 8;
for i=1:n
  for j=1:n
    C(i,j)=cos((i-1)*(2*j-1)*pi/(2*n));
  end
end
C=sqrt(2/n)*C;
C(1,:)=C(1,:)/sqrt(2);
p=4;

for k = 0:49
    for l = 0:49
        str1 = 'p = ';
        str2 = int2str(p);
        s = [str1 str2];

        Q = p*8./hilb(8);

        
        Red=r(8*l+1:8*l+8,8*k+1:8*k+8);
        Red_1 = Red-128;
       
        
        Y_red=C*Red_1*C';
        Yqr=round(Y_red./Q);
        Ydqr=Yqr.*Q;
        Xdqr=C'*Ydqr*C;
        Xer=Xdqr+128;
        Xf(l*8+1:l*8+8,k*8+1:k*8+8,1)=Xer;

        
        
        Blu=b(8*l+1:8*l+8,8*k+1:8*k+8);
        Blu_1 = Blu-128;
        
        Y_blu=C*Blu_1*C';
        Yqb=round(Y_blu./Q);
        Ydqb=Yqb.*Q;
        Xdqb=C'*Ydqb*C;
        Xeb=Xdqb+128;
        Xf(l*8+1:l*8+8,k*8+1:k*8+8,3)=Xeb;

        
        Green=g(8*l+1:8*l+8,8*k+1:8*k+8);
        Green_1 = Green-128;
        
        Y_green=C*Green_1*C';
        Yqg=round(Y_green./Q);
        Ydqg=Yqg.*Q;
        Xdqg=C'*Ydqg*C;
        Xeg=Xdqg+128;
        Xf(l*8+1:l*8+8,k*8+1:k*8+8,2)=Xeg;
        
         if k==1&&l==1
            Yqr
            Yqg
            Yqb
         end
        
    end
end

figure;
imagesc(uint8(Xf));
title(s);
        