function lumin8(X, p) 
[m,n,l]=size(X);
imgc = zeros(m,n,l);
for i=2:n
    for j=1:n
        C(i,j)=sqrt(2/n)*cos((i-1)*(j-1/2)*pi/n);
    end
end
C(1,1:n)=ones(1,n)/sqrt(n);
 Qc = 99*ones(8,8);
 Qc(1,1:4) = [17,18,24,47];
 Qc(2,1:4) = [18,21,26,66];
 Qc(3,1:3) = [24 26 56];
 Qc(4,1:2) = [47 66];
 Xd = double(X);
 YUV = zeros(m,n,l);
 YUV(:,:,1) = 0.299*Xd(:,:,1) + 0.587*Xd(:,:,2) + 0.114*Xd(:,:,3);
 YUV(:,:,2) = Xd(:,:,3) - YUV(:,:,1);
 YUV(:,:,3) = Xd(:,:,1) - YUV(:,:,1);
for w=0:2
    Qy = (2^w)*[16,11,10,16,24,40,51,61;
     12,12,14,19,26,58,60,55;
     14,13,16,24,40,57,69,56;
     14,17,22,29,51,87,80,62;
     18,22,37,56,68,109,103,77;
     24,35,55,64,81,104,113,92;
     49,64,78,87,103,121,120,101;
     72,92,95,98,112,100,103,99];
for k=1:l
    if k == 1
        Xc = YUV(:,:,k) - 128;
        Y = C*Xc*C';
        Yq = round(Y./Qy);
        Ydq = Yq.*Qy;
        Xdq = C'*Ydq*C;
        Xe = Xdq+128;
        YUV(:,:,k) = Xe;
    else
        Xc = YUV(:,:,k) - 128;
        Y = C*Xc*C';
        Yq = round(Y./Qc);
        Ydq = Yq.*Qc;
        Xdq = C'*Ydq*C;
        Xe = Xdq+128;
        YUV(:,:,k) = Xe;
    end
end
imgc(:,:,1) = YUV(:,:,3) + YUV(:,:,1);
imgc(:,:,3) = YUV(:,:,2) + YUV(:,:,1);
imgc(:,:,2) = (YUV(:,:,1) - 0.299*Xd(:,:,1) - 0.114*Xd(:,:,3))/(0.587);
subplot(2,2,w+2)
imagesc(uint8(imgc));
title(['Compressed p = ' int2str(2^w)])
end
subplot(2,2,1)
imagesc(uint8(X));
title('Original(337:344,801:808)')