x=imread('iceland.jpg');
xd=double(x); % Note that we have converted the default MATLAB
              % data type uint8, or unsigned integers, to double 
              % precision reals before we do the computation (pg 506)
r=xd(:,:,1);g=xd(:,:,2);b=xd(:,:,3);
%xgray=0.2126*r+0.7152*g+0.0722*b;
%figure(1);imagesc(uint8(xd))

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;
Q = p*8./hilb(8);
 
X = r(81:88,81:88);
X = g(81:88,81:88);
X = b(81:88,81:88);
Xd = double(X);
xc = Xd-128; %center
y = C*xc*C';
yq = round(y./Q)

for i = 1:8
    for j = 9-i:8
        y(i,j)=0;
    end
end

ydq=yq.*Q;
xdq = C'*ydq*C;
xe= xdq +128;

figure(2);imagesc(uint8(X))
figure(3);imagesc(uint8(xe),[0 255])
