close all;
clear all;
clc;

x = imread('baby_animal.jpg');
x=double(x);
r=x(:,:,1);g=x(:,:,2);b=x(:,:,3);
xgray=0.2126*r+0.7152*g+0.0722*b;
xgray=uint8(xgray);
imagesc(xgray);colormap(gray)

k = 1;
xb = xgray(k*8+1:k*8+8,k*8+1:k*8+8);


figure;
imagesc(xb);colormap(gray)


xd = double(xb);
xc=xd-128;

list = [1 2 4];

[m,n]=size(xc); m=n;
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);

str1 = 'p = ';


for p = list
    str2 = int2str(p);
    s = [str1 str2];
    Y=C*xc*C';
    Q = p*8./hilb(8);
    Yq=round(Y./Q)
    Ydq=Yq.*Q;
    Xdq=C'*Ydq*C;
    Xe=Xdq+128;
    Xf=uint8(Xe);
    figure;
    imagesc(Xf);colormap(gray)
    title(s)
end