%Black and White Code for one block
x = imread('hipster_cat2.jpeg');
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);

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

[m,n]=size(xc); m=n;
for i=1:n
    for j=1:n
        C(i,j)=sqrt(2)*cos((i-1)*(j-1/2)*pi/(n));
    end
end
C(1,1:n)=ones(1,n)/sqrt(n);

p = 1 %loss parameter, changes between 1,2, 4
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)

