x = imread('Trigena.jpg'); 
% Original should be a size with multiples of 8 
figure(3);imagesc(x);
title( 'Original');

x=double(x);
% r=x(:,:,1); g=x(:,:,2); b=x(:,:,3);
% xgray=0.2126*r+0.7152*g + 0.0722*b;

n=1;
sizeImage=size(x);
Xf=zeros(sizeImage(1));

for p = [1 2 4 10];
    p(n)
    % For Red
    for k=0:(sizeImage(1)/8)-1
        for l=0:(sizeImage(2)/8)-1
        c=x(8*k+1:8*k+8,8*l+1:8*l+8,1);
        c=dctV2(p(n),c);
        Xf(8*k+1:8*k+8,8*l+1:8*l+8,1)=c; 
        end
    end
    % For G
    for k=0:(sizeImage(1)/8)-1
        for l=0:(sizeImage(2)/8)-1
        c=x(8*k+1:8*k+8,8*l+1:8*l+8,2);
        c=dctV2(p(n),c);
        Xf(8*k+1:8*k+8,8*l+1:8*l+8,2)=c; 
        end
    end
    %For B
    for k=0:(sizeImage(1)/8)-1
        for l=0:(sizeImage(2)/8)-1
        c=x(8*k+1:8*k+8,8*l+1:8*l+8,3);
        c=dctV2(p(n),c);
        Xf(8*k+1:8*k+8,8*l+1:8*l+8,3)=c; 
        end
    end
    
figure(p(n));imagesc(uint8(Xf));
title(['Compressed p = 10' ]);
end



