function Project5(image) Acolor = imagegrey(image); r = Acolor(:,:,1); g = Acolor(:,:,2); b = Acolor(:,:,3); Agray = Acolor(:,:,4); R = dereconstruct(r); G = dereconstruct(g); B = dereconstruct(b); GS = dereconstruct(Agray); %Special function cat for concatinating back to RGB AFinal = uint8(cat(3, R, G, B)); imagesc(AFinal, [0,255]); figure; imagesc(uint8(Agray),[0,255]);colormap(gray); figure; imagesc(uint8(GS),[0,255]);colormap(gray); function B = dereconstruct(A) sizeA = size(A); B = []; for i=1:sizeA(1)/8 for j =1:sizeA(2)/8 Ab = A((i-1)*8+1:8*i,(j-1)*8+1:8*j); % Unsupress this to preview 8x8 bit % if i==sizeA(1)/8 && j == sizeA(2)/8 % imagesc(Ab, [0, 255]); colormap(gray); % end Xf = Qdct(Ab); B((i-1)*8+1:8*i,(j-1)*8+1:8*j) = Xf; % if i==sizeA(1)/8 && j == sizeA(2)/8 % imagesc(Xf, [0, 255]); colormap(gray); % end end end function Acolor = imagegrey(image) A = imread(image); A = double(A); r=A(:,:,1); g=A(:,:,2); b=A(:,:,3); Agray=0.2126*r+0.7152*g+0.0722*b; Acolor = []; Acolor(:,:,1) = r; Acolor(:,:,2) = g; Acolor(:,:,3) = b; Acolor(:,:,4) = Agray; %Suppress below this to suppress grey image % imagesc(uint8(Agray)); % colormap(gray); % imagesc(Agray);colormap(gray); function Xf=Qdct(X) [m,n]=size(X);n=m; for i=2:n for j=1:n C(i,j)=sqrt(2/n)*cos((i-1)*(j-1/2)*pi/n); end end p = 1; %Choose whether you want to use the standard Q matrix or the recommended matrix for JPEG % Q = p*8./hilb(8); Q = p*[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]; C(1,1:n)=ones(1,n)/sqrt(n); Xd = double(X); Xc = Xd - 128; Y = C*Xc*C'; Yq = round(Y./Q); Ydq = Yq.*Q; Xdq = C'*Ydq*C; Xe = Xdq+128; Xf=Xe;