Q=xlsread('Qtable.xls','A2:H9');
row=512;  col=512;
fin_D04=fopen('D04.raw','r');
I_D04 = fread(fin_D04, [col row],'uint8=>uint8'); 
I_D04 = reshape(I_D04,row,col);
S04 = zeros(8,8);
for i=1:8:256
  for j=1:8:256  
      tmp = I_D04(i:i+7, j:j+7);
      tmp = dct2(tmp-128);
      Y = round(tmp./Q);
      S04(1:8,1:8) = Y;
  end
end
subplot(1,2,1)
imshow(S04);title('DCT of image D04.raw');

fin_D23=fopen('D23.raw','r');
I_D23 = fread(fin_D23, [col row],'uint8=>uint8'); 
I_D23 = reshape(I_D23,row,col);
S23 = zeros(8,8);
for i=1:8:256
  for j=1:8:256  
      tmp = I_D23(i:i+7, j:j+7);
      tmp = dct2(tmp-128);
      Y = round(tmp./Q);
      S23(1:8,1:8) = Y;
  end
end
subplot(1,2,2)
imshow(S23);title('DCT of image D23.raw');
