xco=imread('colorimg.jpg')
xdco=double(xco);
r=xdco(:,:,1);g=xdco(:,:,2); b=xdco(:,:,3);
%imagesc(xgray);colormap(gray)
n=8;
for i=2:n
   for j=1:n
       K(i,j)=sqrt(2/n)*cos((i-1)*(j-1/2)*pi/n);
   end
end
K(1,1:n)=ones(1,n)/sqrt(n);
p=4;

for k=1:8
    for l=1:8
         Q(k,l)=8*p*((k-1)+(l-1)+1);
    end
end



Xf=zeros(192,192,3);
for t=1:8:192
    for z=1:8:192
        
        %quantizing red
        Re=r(t:t+7,z:z+7);
        Red=Re-96;
        Yr=K*Red*K';
        YQr=round(Yr./Q);
        %quantizing green
        G=g(t:t+7,z:z+7);
        Gre=G-96;
        Yg=K*Gre*K';
        YQg=round(Yg./Q);
        %quantizing blue
        B=b(t:t+7,z:z+7);
        Blu=B-96;
        Yb=K*Blu*K';
        YQb=round(Yb./Q);

        %dequantizing red
        Ydqr=YQr.*Q;
        Xdqr=K'*Ydqr*K;
        Xer=Xdqr+96;
        Xf(t:t+7,z:z+7,1)=Xer;
        %dequantizing green
        Ydqg=YQg.*Q;
        Xdqg=K'*Ydqg*K;
        Xeg=Xdqg+96;
        Xf(t:t+7,z:z+7,2)=Xeg;
        %dequantizing blue
        Ydqb=YQb.*Q;
        Xdqb=K'*Ydqb*K;
        Xeb=Xdqb+96;
        Xf(t:t+7,z:z+7,3)=Xeb;
    end
end
figure;
imagesc(uint8(Xf));